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