1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the Section Gateway class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway; |
12
|
|
|
use Doctrine\DBAL\DBALException; |
13
|
|
|
use PDOException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* UrlAlias Handler. |
17
|
|
|
*/ |
18
|
|
|
class ExceptionConversion extends Gateway |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The wrapped gateway. |
22
|
|
|
* |
23
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway |
24
|
|
|
*/ |
25
|
|
|
protected $innerGateway; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Creates a new exception conversion gateway around $innerGateway. |
29
|
|
|
* |
30
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway $innerGateway |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Gateway $innerGateway) |
33
|
|
|
{ |
34
|
|
|
$this->innerGateway = $innerGateway; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function setTable($name) |
38
|
|
|
{ |
39
|
|
|
try { |
40
|
|
|
return $this->innerGateway->setTable($name); |
41
|
|
|
} catch (DBALException $e) { |
42
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
43
|
|
|
} catch (PDOException $e) { |
44
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Loads list of aliases by given $locationId. |
50
|
|
|
* |
51
|
|
|
* @param mixed $locationId |
52
|
|
|
* @param bool $custom |
53
|
|
|
* @param mixed $languageId |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function loadLocationEntries($locationId, $custom = false, $languageId = false) |
58
|
|
|
{ |
59
|
|
|
try { |
60
|
|
|
return $this->innerGateway->loadLocationEntries($locationId, $custom); |
61
|
|
|
} catch (DBALException $e) { |
62
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
63
|
|
|
} catch (PDOException $e) { |
64
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns boolean indicating if the row with given $id is special root entry. |
70
|
|
|
* |
71
|
|
|
* Special root entry entry will have parentId=0 and text=''. |
72
|
|
|
* In standard installation this entry will point to location with id=2. |
73
|
|
|
* |
74
|
|
|
* @param mixed $id |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function isRootEntry($id) |
79
|
|
|
{ |
80
|
|
|
try { |
81
|
|
|
return $this->innerGateway->isRootEntry($id); |
82
|
|
|
} catch (DBALException $e) { |
83
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
84
|
|
|
} catch (PDOException $e) { |
85
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Downgrades autogenerated entry matched by given $action and $languageId and negatively matched by |
91
|
|
|
* composite primary key. |
92
|
|
|
* |
93
|
|
|
* If language mask of the found entry is composite (meaning it consists of multiple language ids) given |
94
|
|
|
* $languageId will be removed from mask. Otherwise entry will be marked as history. |
95
|
|
|
* |
96
|
|
|
* @param string $action |
97
|
|
|
* @param mixed $languageId |
98
|
|
|
* @param mixed $newId |
99
|
|
|
* @param mixed $parentId |
100
|
|
|
* @param string $textMD5 |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function cleanupAfterPublish($action, $languageId, $newId, $parentId, $textMD5) |
103
|
|
|
{ |
104
|
|
|
try { |
105
|
|
|
$this->innerGateway->cleanupAfterPublish($action, $languageId, $newId, $parentId, $textMD5); |
106
|
|
|
} catch (DBALException $e) { |
107
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
108
|
|
|
} catch (PDOException $e) { |
109
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
View Code Duplication |
public function historizeBeforeSwap($action, $languageMask) |
114
|
|
|
{ |
115
|
|
|
try { |
116
|
|
|
$this->innerGateway->historizeBeforeSwap($action, $languageMask); |
117
|
|
|
} catch (DBALException $e) { |
118
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
119
|
|
|
} catch (PDOException $e) { |
120
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Marks all entries with given $id as history entries. |
126
|
|
|
* |
127
|
|
|
* This method is used by Handler::locationMoved(). Each row is separately historized |
128
|
|
|
* because future publishing needs to be able to take over history entries safely. |
129
|
|
|
* |
130
|
|
|
* @param mixed $id |
131
|
|
|
* @param mixed $link |
132
|
|
|
*/ |
133
|
|
|
public function historizeId($id, $link) |
134
|
|
|
{ |
135
|
|
|
try { |
136
|
|
|
$this->innerGateway->historizeId($id, $link); |
137
|
|
|
} catch (DBALException $e) { |
138
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
139
|
|
|
} catch (PDOException $e) { |
140
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Updates parent id of autogenerated entries. |
146
|
|
|
* |
147
|
|
|
* Update includes history entries. |
148
|
|
|
* |
149
|
|
|
* @param mixed $oldParentId |
150
|
|
|
* @param mixed $newParentId |
151
|
|
|
*/ |
152
|
|
|
public function reparent($oldParentId, $newParentId) |
153
|
|
|
{ |
154
|
|
|
try { |
155
|
|
|
$this->innerGateway->reparent($oldParentId, $newParentId); |
156
|
|
|
} catch (DBALException $e) { |
157
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
158
|
|
|
} catch (PDOException $e) { |
159
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Updates single row data matched by composite primary key. |
165
|
|
|
* |
166
|
|
|
* Use optional parameter $languageMaskMatch to additionally limit the query match with languages |
167
|
|
|
* |
168
|
|
|
* @param mixed $parentId |
169
|
|
|
* @param string $textMD5 |
170
|
|
|
* @param array $values associative array with column names as keys and column values as values |
171
|
|
|
*/ |
172
|
|
View Code Duplication |
public function updateRow($parentId, $textMD5, array $values) |
173
|
|
|
{ |
174
|
|
|
try { |
175
|
|
|
$this->innerGateway->updateRow($parentId, $textMD5, $values); |
176
|
|
|
} catch (DBALException $e) { |
177
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
178
|
|
|
} catch (PDOException $e) { |
179
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Inserts new row in urlalias_ml table. |
185
|
|
|
* |
186
|
|
|
* @param array $values |
187
|
|
|
* |
188
|
|
|
* @return mixed |
189
|
|
|
*/ |
190
|
|
|
public function insertRow(array $values) |
191
|
|
|
{ |
192
|
|
|
try { |
193
|
|
|
return $this->innerGateway->insertRow($values); |
194
|
|
|
} catch (DBALException $e) { |
195
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
196
|
|
|
} catch (PDOException $e) { |
197
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Loads single row data matched by composite primary key. |
203
|
|
|
* |
204
|
|
|
* @param mixed $parentId |
205
|
|
|
* @param string $textMD5 |
206
|
|
|
* |
207
|
|
|
* @return array |
208
|
|
|
*/ |
209
|
|
|
public function loadRow($parentId, $textMD5) |
210
|
|
|
{ |
211
|
|
|
try { |
212
|
|
|
return $this->innerGateway->loadRow($parentId, $textMD5); |
213
|
|
|
} catch (DBALException $e) { |
214
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
215
|
|
|
} catch (PDOException $e) { |
216
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Loads autogenerated entry id by given $action and optionally $parentId. |
222
|
|
|
* |
223
|
|
|
* @param string $action |
224
|
|
|
* @param mixed|null $parentId |
225
|
|
|
* |
226
|
|
|
* @return array |
227
|
|
|
*/ |
228
|
|
|
public function loadAutogeneratedEntry($action, $parentId = null) |
229
|
|
|
{ |
230
|
|
|
try { |
231
|
|
|
return $this->innerGateway->loadAutogeneratedEntry($action, $parentId); |
232
|
|
|
} catch (DBALException $e) { |
233
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
234
|
|
|
} catch (PDOException $e) { |
235
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Deletes all rows with given $action and optionally $id. |
241
|
|
|
* |
242
|
|
|
* If $id is set only autogenerated entries will be removed. |
243
|
|
|
* |
244
|
|
|
* @param string $action |
245
|
|
|
* @param mixed|null $id |
246
|
|
|
*/ |
247
|
|
View Code Duplication |
public function remove($action, $id = null) |
248
|
|
|
{ |
249
|
|
|
try { |
250
|
|
|
$this->innerGateway->remove($action, $id); |
251
|
|
|
} catch (DBALException $e) { |
252
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
253
|
|
|
} catch (PDOException $e) { |
254
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Loads paged list of global aliases. |
260
|
|
|
* |
261
|
|
|
* @param string|null $languageCode |
262
|
|
|
* @param int $offset |
263
|
|
|
* @param int $limit |
264
|
|
|
* |
265
|
|
|
* @return array |
266
|
|
|
*/ |
267
|
|
|
public function listGlobalEntries($languageCode = null, $offset = 0, $limit = -1) |
268
|
|
|
{ |
269
|
|
|
try { |
270
|
|
|
return $this->innerGateway->listGlobalEntries($languageCode, $offset, $limit); |
271
|
|
|
} catch (DBALException $e) { |
272
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
273
|
|
|
} catch (PDOException $e) { |
274
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Deletes single custom alias row matched by composite primary key. |
280
|
|
|
* |
281
|
|
|
* If $id is set only autogenerated entries will be removed. |
282
|
|
|
* |
283
|
|
|
* @param mixed $parentId |
284
|
|
|
* @param string $textMD5 |
285
|
|
|
* |
286
|
|
|
* @return bool |
287
|
|
|
*/ |
288
|
|
|
public function removeCustomAlias($parentId, $textMD5) |
289
|
|
|
{ |
290
|
|
|
try { |
291
|
|
|
return $this->innerGateway->removeCustomAlias($parentId, $textMD5); |
292
|
|
|
} catch (DBALException $e) { |
293
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
294
|
|
|
} catch (PDOException $e) { |
295
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Loads complete URL alias data by given array of path hashes. |
301
|
|
|
* |
302
|
|
|
* @param string[] $urlHashes URL string hashes |
303
|
|
|
* |
304
|
|
|
* @return array |
305
|
|
|
*/ |
306
|
|
|
public function loadUrlAliasData(array $urlHashes) |
307
|
|
|
{ |
308
|
|
|
try { |
309
|
|
|
return $this->innerGateway->loadUrlAliasData($urlHashes); |
310
|
|
|
} catch (DBALException $e) { |
311
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
312
|
|
|
} catch (PDOException $e) { |
313
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Loads all data for the path identified by given $id. |
319
|
|
|
* |
320
|
|
|
* @param mixed $id |
321
|
|
|
* |
322
|
|
|
* @return array |
323
|
|
|
*/ |
324
|
|
|
public function loadPathData($id) |
325
|
|
|
{ |
326
|
|
|
try { |
327
|
|
|
return $this->innerGateway->loadPathData($id); |
328
|
|
|
} catch (DBALException $e) { |
329
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
330
|
|
|
} catch (PDOException $e) { |
331
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Loads path data identified by given ordered array of hierarchy data. |
337
|
|
|
* |
338
|
|
|
* The first entry in $hierarchyData corresponds to the top-most path element in the path, the second entry the |
339
|
|
|
* child of the first path element and so on. |
340
|
|
|
* This method is faster than self::getPath() since it can fetch all elements using only one query, but can be used |
341
|
|
|
* only for autogenerated paths. |
342
|
|
|
* |
343
|
|
|
* @param array $hierarchyData |
344
|
|
|
* |
345
|
|
|
* @return array |
346
|
|
|
*/ |
347
|
|
|
public function loadPathDataByHierarchy(array $hierarchyData) |
348
|
|
|
{ |
349
|
|
|
try { |
350
|
|
|
return $this->innerGateway->loadPathDataByHierarchy($hierarchyData); |
351
|
|
|
} catch (DBALException $e) { |
352
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
353
|
|
|
} catch (PDOException $e) { |
354
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Loads all autogenerated entries with given $parentId with optionally included history entries. |
360
|
|
|
* |
361
|
|
|
* @param mixed $parentId |
362
|
|
|
* @param bool $includeHistory |
363
|
|
|
* |
364
|
|
|
* @return array |
365
|
|
|
*/ |
366
|
|
|
public function loadAutogeneratedEntries($parentId, $includeHistory = false) |
367
|
|
|
{ |
368
|
|
|
try { |
369
|
|
|
return $this->innerGateway->loadAutogeneratedEntries($parentId, $includeHistory); |
370
|
|
|
} catch (DBALException $e) { |
371
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
372
|
|
|
} catch (PDOException $e) { |
373
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Returns next value for "id" column. |
379
|
|
|
* |
380
|
|
|
* @return mixed |
381
|
|
|
*/ |
382
|
|
|
public function getNextId() |
383
|
|
|
{ |
384
|
|
|
try { |
385
|
|
|
return $this->innerGateway->getNextId(); |
386
|
|
|
} catch (DBALException $e) { |
387
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
388
|
|
|
} catch (PDOException $e) { |
389
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|
393
|
|
View Code Duplication |
public function getLocationContentMainLanguageId($locationId) |
394
|
|
|
{ |
395
|
|
|
try { |
396
|
|
|
return $this->innerGateway->getLocationContentMainLanguageId($locationId); |
397
|
|
|
} catch (DBALException $e) { |
398
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
399
|
|
|
} catch (PDOException $e) { |
400
|
|
|
throw new \RuntimeException('Database error', 0, $e); |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|