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