Completed
Push — ezp-26146_location_swap_incons... ( 4a02af...baaf24 )
by
unknown
21:53
created

ExceptionConversion::getNextId()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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
    /**
105
     * Swaps the content being referred to by two aliases.
106
     *
107
     * @param mixed $locationId1
108
     * @param mixed $locationId2
109
     *
110
     * @return bool
111
     */
112 View Code Duplication
    public function swap($locationId1, $locationId2)
113
    {
114
        try {
115
            return $this->innerGateway->swap($locationId1, $locationId2);
116
        } catch (DBALException $e) {
117
            throw new \RuntimeException('Database error', 0, $e);
118
        } catch (PDOException $e) {
119
            throw new \RuntimeException('Database error', 0, $e);
120
        }
121
    }
122
123
    /**
124
     * Marks all entries with given $id as history entries.
125
     *
126
     * This method is used by Handler::locationMoved(). For this reason rows are not updated with next id value as
127
     * all entries with given id are being marked as history and there is no need for id separation.
128
     * Thus only "link" and "is_original" columns are updated.
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