Completed
Push — 7.0 ( 6c9b08...431e20 )
by André
18:57
created

ExceptionConversion::updateRow()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 3
dl 10
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
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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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
     * @param mixed $id
322
     *
323
     * @return array
324
     */
325
    public function loadPathData($id)
326
    {
327
        try {
328
            return $this->innerGateway->loadPathData($id);
329
        } catch (DBALException $e) {
330
            throw new \RuntimeException('Database error', 0, $e);
331
        } catch (PDOException $e) {
332
            throw new \RuntimeException('Database error', 0, $e);
333
        }
334
    }
335
336
    /**
337
     * Loads path data identified by given ordered array of hierarchy data.
338
     *
339
     * The first entry in $hierarchyData corresponds to the top-most path element in the path, the second entry the
340
     * child of the first path element and so on.
341
     * This method is faster than self::getPath() since it can fetch all elements using only one query, but can be used
342
     * only for autogenerated paths.
343
     *
344
     * @param array $hierarchyData
345
     *
346
     * @return array
347
     */
348
    public function loadPathDataByHierarchy(array $hierarchyData)
349
    {
350
        try {
351
            return $this->innerGateway->loadPathDataByHierarchy($hierarchyData);
352
        } catch (DBALException $e) {
353
            throw new \RuntimeException('Database error', 0, $e);
354
        } catch (PDOException $e) {
355
            throw new \RuntimeException('Database error', 0, $e);
356
        }
357
    }
358
359
    /**
360
     * Loads all autogenerated entries with given $parentId with optionally included history entries.
361
     *
362
     * @param mixed $parentId
363
     * @param bool $includeHistory
364
     *
365
     * @return array
366
     */
367
    public function loadAutogeneratedEntries($parentId, $includeHistory = false)
368
    {
369
        try {
370
            return $this->innerGateway->loadAutogeneratedEntries($parentId, $includeHistory);
371
        } catch (DBALException $e) {
372
            throw new \RuntimeException('Database error', 0, $e);
373
        } catch (PDOException $e) {
374
            throw new \RuntimeException('Database error', 0, $e);
375
        }
376
    }
377
378
    /**
379
     * Returns next value for "id" column.
380
     *
381
     * @return mixed
382
     */
383
    public function getNextId()
384
    {
385
        try {
386
            return $this->innerGateway->getNextId();
387
        } catch (DBALException $e) {
388
            throw new \RuntimeException('Database error', 0, $e);
389
        } catch (PDOException $e) {
390
            throw new \RuntimeException('Database error', 0, $e);
391
        }
392
    }
393
394
    public function getLocationContentMainLanguageId($locationId)
395
    {
396
        try {
397
            return $this->innerGateway->getLocationContentMainLanguageId($locationId);
398
        } catch (DBALException $e) {
399
            throw new \RuntimeException('Database error', 0, $e);
400
        } catch (PDOException $e) {
401
            throw new \RuntimeException('Database error', 0, $e);
402
        }
403
    }
404
405
    /**
406
     * {@inheritdoc}
407
     */
408 View Code Duplication
    public function bulkRemoveTranslation($languageId, $actions)
409
    {
410
        try {
411
            return $this->innerGateway->bulkRemoveTranslation($languageId, $actions);
412
        } catch (DBALException $e) {
413
            throw new \RuntimeException('Database error', 0, $e);
414
        } catch (PDOException $e) {
415
            throw new \RuntimeException('Database error', 0, $e);
416
        }
417
    }
418
419
    /**
420
     * {@inheritdoc}
421
     */
422 View Code Duplication
    public function archiveUrlAliasesForDeletedTranslations($locationId, $parentId, array $languageIds)
423
    {
424
        try {
425
            $this->innerGateway->archiveUrlAliasesForDeletedTranslations($locationId, $parentId, $languageIds);
426
        } catch (DBALException $e) {
427
            throw new \RuntimeException('Database error', 0, $e);
428
        } catch (PDOException $e) {
429
            throw new \RuntimeException('Database error', 0, $e);
430
        }
431
    }
432
}
433