Completed
Push — test-fieldrelation-location-se... ( 448993...a417bd )
by
unknown
13:37
created

ExceptionConversion::loadLocationEntries()   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 3
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
     * Marks all entries with given $id as history entries.
106
     *
107
     * This method is used by Handler::locationMoved(). For this reason rows are not updated with next id value as
108
     * all entries with given id are being marked as history and there is no need for id separation.
109
     * Thus only "link" and "is_original" columns are updated.
110
     *
111
     * @param mixed $id
112
     * @param mixed $link
113
     */
114
    public function historizeId($id, $link)
115
    {
116
        try {
117
            $this->innerGateway->historizeId($id, $link);
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
     * Updates parent id of autogenerated entries.
127
     *
128
     * Update includes history entries.
129
     *
130
     * @param mixed $oldParentId
131
     * @param mixed $newParentId
132
     */
133
    public function reparent($oldParentId, $newParentId)
134
    {
135
        try {
136
            $this->innerGateway->reparent($oldParentId, $newParentId);
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 single row data matched by composite primary key.
146
     *
147
     * Use optional parameter $languageMaskMatch to additionally limit the query match with languages
148
     *
149
     * @param mixed $parentId
150
     * @param string $textMD5
151
     * @param array $values associative array with column names as keys and column values as values
152
     */
153 View Code Duplication
    public function updateRow($parentId, $textMD5, array $values)
154
    {
155
        try {
156
            $this->innerGateway->updateRow($parentId, $textMD5, $values);
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
     * Inserts new row in urlalias_ml table.
166
     *
167
     * @param array $values
168
     *
169
     * @return mixed
170
     */
171
    public function insertRow(array $values)
172
    {
173
        try {
174
            return $this->innerGateway->insertRow($values);
175
        } catch (DBALException $e) {
176
            throw new \RuntimeException('Database error', 0, $e);
177
        } catch (PDOException $e) {
178
            throw new \RuntimeException('Database error', 0, $e);
179
        }
180
    }
181
182
    /**
183
     * Loads single row data matched by composite primary key.
184
     *
185
     * @param mixed $parentId
186
     * @param string $textMD5
187
     *
188
     * @return array
189
     */
190
    public function loadRow($parentId, $textMD5)
191
    {
192
        try {
193
            return $this->innerGateway->loadRow($parentId, $textMD5);
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 autogenerated entry id by given $action and optionally $parentId.
203
     *
204
     * @param string $action
205
     * @param mixed|null $parentId
206
     *
207
     * @return array
208
     */
209
    public function loadAutogeneratedEntry($action, $parentId = null)
210
    {
211
        try {
212
            return $this->innerGateway->loadAutogeneratedEntry($action, $parentId);
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
     * Deletes all rows with given $action and optionally $id.
222
     *
223
     * If $id is set only autogenerated entries will be removed.
224
     *
225
     * @param string $action
226
     * @param mixed|null $id
227
     */
228 View Code Duplication
    public function remove($action, $id = null)
229
    {
230
        try {
231
            $this->innerGateway->remove($action, $id);
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
     * Loads paged list of global aliases.
241
     *
242
     * @param string|null $languageCode
243
     * @param int $offset
244
     * @param int $limit
245
     *
246
     * @return array
247
     */
248
    public function listGlobalEntries($languageCode = null, $offset = 0, $limit = -1)
249
    {
250
        try {
251
            return $this->innerGateway->listGlobalEntries($languageCode, $offset, $limit);
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
     * Deletes single custom alias row matched by composite primary key.
261
     *
262
     * If $id is set only autogenerated entries will be removed.
263
     *
264
     * @param mixed $parentId
265
     * @param string $textMD5
266
     *
267
     * @return bool
268
     */
269
    public function removeCustomAlias($parentId, $textMD5)
270
    {
271
        try {
272
            return $this->innerGateway->removeCustomAlias($parentId, $textMD5);
273
        } catch (DBALException $e) {
274
            throw new \RuntimeException('Database error', 0, $e);
275
        } catch (PDOException $e) {
276
            throw new \RuntimeException('Database error', 0, $e);
277
        }
278
    }
279
280
    /**
281
     * Loads complete URL alias data by given array of path hashes.
282
     *
283
     * @param string[] $urlHashes URL string hashes
284
     *
285
     * @return array
286
     */
287
    public function loadUrlAliasData(array $urlHashes)
288
    {
289
        try {
290
            return $this->innerGateway->loadUrlAliasData($urlHashes);
291
        } catch (DBALException $e) {
292
            throw new \RuntimeException('Database error', 0, $e);
293
        } catch (PDOException $e) {
294
            throw new \RuntimeException('Database error', 0, $e);
295
        }
296
    }
297
298
    /**
299
     * Loads all data for the path identified by given $id.
300
     *
301
     * @param mixed $id
302
     *
303
     * @return array
304
     */
305
    public function loadPathData($id)
306
    {
307
        try {
308
            return $this->innerGateway->loadPathData($id);
309
        } catch (DBALException $e) {
310
            throw new \RuntimeException('Database error', 0, $e);
311
        } catch (PDOException $e) {
312
            throw new \RuntimeException('Database error', 0, $e);
313
        }
314
    }
315
316
    /**
317
     * Loads path data identified by given ordered array of hierarchy data.
318
     *
319
     * The first entry in $hierarchyData corresponds to the top-most path element in the path, the second entry the
320
     * child of the first path element and so on.
321
     * This method is faster than self::getPath() since it can fetch all elements using only one query, but can be used
322
     * only for autogenerated paths.
323
     *
324
     * @param array $hierarchyData
325
     *
326
     * @return array
327
     */
328
    public function loadPathDataByHierarchy(array $hierarchyData)
329
    {
330
        try {
331
            return $this->innerGateway->loadPathDataByHierarchy($hierarchyData);
332
        } catch (DBALException $e) {
333
            throw new \RuntimeException('Database error', 0, $e);
334
        } catch (PDOException $e) {
335
            throw new \RuntimeException('Database error', 0, $e);
336
        }
337
    }
338
339
    /**
340
     * Loads all autogenerated entries with given $parentId with optionally included history entries.
341
     *
342
     * @param mixed $parentId
343
     * @param bool $includeHistory
344
     *
345
     * @return array
346
     */
347
    public function loadAutogeneratedEntries($parentId, $includeHistory = false)
348
    {
349
        try {
350
            return $this->innerGateway->loadAutogeneratedEntries($parentId, $includeHistory);
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
     * Returns next value for "id" column.
360
     *
361
     * @return mixed
362
     */
363
    public function getNextId()
364
    {
365
        try {
366
            return $this->innerGateway->getNextId();
367
        } catch (DBALException $e) {
368
            throw new \RuntimeException('Database error', 0, $e);
369
        } catch (PDOException $e) {
370
            throw new \RuntimeException('Database error', 0, $e);
371
        }
372
    }
373
}
374