Completed
Push — bookmark-exception-conversion ( 91b107...0b18a9 )
by
unknown
48:34 queued 30:01
created

ExceptionConversion::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 4
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Location 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\Location\Gateway;
10
11
use eZ\Publish\API\Repository\Values\Content\Query;
12
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
13
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway;
14
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct;
15
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct;
16
use Doctrine\DBAL\DBALException;
17
use PDOException;
18
use RuntimeException;
19
20
/**
21
 * Base class for location gateways.
22
 */
23
class ExceptionConversion extends Gateway
24
{
25
    /**
26
     * The wrapped gateway.
27
     *
28
     * @var Gateway
29
     */
30
    protected $innerGateway;
31
32
    /**
33
     * Creates a new exception conversion gateway around $innerGateway.
34
     *
35
     * @param Gateway $innerGateway
36
     */
37
    public function __construct(Gateway $innerGateway)
38
    {
39
        $this->innerGateway = $innerGateway;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getBasicNodeData($nodeId, array $translations = null, bool $useAlwaysAvailable = true)
46
    {
47
        try {
48
            return $this->innerGateway->getBasicNodeData($nodeId, $translations, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $translations defined by parameter $translations on line 45 can also be of type array; however, eZ\Publish\Core\Persiste...way::getBasicNodeData() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
49
        } catch (DBALException $e) {
50
            throw new RuntimeException('Database error', 0, $e);
51
        } catch (PDOException $e) {
52
            throw new RuntimeException('Database error', 0, $e);
53
        }
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getNodeDataList(array $locationIds, array $translations = null, bool $useAlwaysAvailable = true): iterable
60
    {
61
        try {
62
            return $this->innerGateway->getNodeDataList($locationIds, $translations, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $translations defined by parameter $translations on line 59 can also be of type array; however, eZ\Publish\Core\Persiste...eway::getNodeDataList() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
63
        } catch (DBALException | PDOException $e) {
64
            throw new RuntimeException('Database error', 0, $e);
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getBasicNodeDataByRemoteId($remoteId, array $translations = null, bool $useAlwaysAvailable = true)
72
    {
73
        try {
74
            return $this->innerGateway->getBasicNodeDataByRemoteId($remoteId, $translations, $useAlwaysAvailable);
0 ignored issues
show
Bug introduced by
It seems like $translations defined by parameter $translations on line 71 can also be of type array; however, eZ\Publish\Core\Persiste...sicNodeDataByRemoteId() does only seem to accept null|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
75
        } catch (DBALException $e) {
76
            throw new RuntimeException('Database error', 0, $e);
77
        } catch (PDOException $e) {
78
            throw new RuntimeException('Database error', 0, $e);
79
        }
80
    }
81
82
    /**
83
     * Returns total count and data for all Locations satisfying the parameters.
84
     *
85
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
86
     * @param int $offset
87
     * @param int|null $limit
88
     * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses
89
     *
90
     * @return mixed[][]
91
     */
92
    public function find(Criterion $criterion, $offset = 0, $limit = null, array $sortClauses = null)
93
    {
94
        try {
95
            return $this->innerGateway->find($criterion, $offset, $limit, $sortClauses);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eZ\Publish\Core\Persiste...ontent\Location\Gateway as the method find() does only exist in the following sub-classes of eZ\Publish\Core\Persiste...ontent\Location\Gateway: eZ\Publish\Core\Persiste...way\ExceptionConversion. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
96
        } catch (DBALException $e) {
97
            throw new RuntimeException('Database error', 0, $e);
98
        } catch (PDOException $e) {
99
            throw new RuntimeException('Database error', 0, $e);
100
        }
101
    }
102
103
    /**
104
     * Loads data for all Locations for $contentId, optionally only in the
105
     * subtree starting at $rootLocationId.
106
     *
107
     * @param int $contentId
108
     * @param int $rootLocationId
109
     *
110
     * @return array
111
     */
112
    public function loadLocationDataByContent($contentId, $rootLocationId = null)
113
    {
114
        try {
115
            return $this->innerGateway->loadLocationDataByContent($contentId, $rootLocationId);
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
     * @see \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway::loadParentLocationsDataForDraftContent
125
     */
126
    public function loadParentLocationsDataForDraftContent($contentId)
127
    {
128
        try {
129
            return $this->innerGateway->loadParentLocationsDataForDraftContent($contentId);
130
        } catch (DBALException $e) {
131
            throw new RuntimeException('Database error', 0, $e);
132
        } catch (PDOException $e) {
133
            throw new RuntimeException('Database error', 0, $e);
134
        }
135
    }
136
137
    /**
138
     * Find all content in the given subtree.
139
     *
140
     * @param mixed $sourceId
141
     * @param bool $onlyIds
142
     *
143
     * @return array
144
     */
145
    public function getSubtreeContent($sourceId, $onlyIds = false)
146
    {
147
        try {
148
            return $this->innerGateway->getSubtreeContent($sourceId, $onlyIds);
149
        } catch (DBALException $e) {
150
            throw new RuntimeException('Database error', 0, $e);
151
        } catch (PDOException $e) {
152
            throw new RuntimeException('Database error', 0, $e);
153
        }
154
    }
155
156
    /**
157
     * Returns data for the first level children of the location identified by given $locationId.
158
     *
159
     * @param mixed $locationId
160
     *
161
     * @return array
162
     */
163
    public function getChildren($locationId)
164
    {
165
        try {
166
            return $this->innerGateway->getChildren($locationId);
167
        } catch (DBALException $e) {
168
            throw new RuntimeException('Database error', 0, $e);
169
        } catch (PDOException $e) {
170
            throw new RuntimeException('Database error', 0, $e);
171
        }
172
    }
173
174
    /**
175
     * Update path strings to move nodes in the ezcontentobject_tree table.
176
     *
177
     * This query can likely be optimized to use some more advanced string
178
     * operations, which then depend on the respective database.
179
     *
180
     * @todo optimize
181
     *
182
     * @param array $fromPathString
183
     * @param array $toPathString
184
     */
185
    public function moveSubtreeNodes(array $fromPathString, array $toPathString)
186
    {
187
        try {
188
            return $this->innerGateway->moveSubtreeNodes($fromPathString, $toPathString);
189
        } catch (DBALException $e) {
190
            throw new RuntimeException('Database error', 0, $e);
191
        } catch (PDOException $e) {
192
            throw new RuntimeException('Database error', 0, $e);
193
        }
194
    }
195
196
    /**
197
     * Updated subtree modification time for all nodes on path.
198
     *
199
     * @param string $pathString
200
     * @param int|null $timestamp
201
     */
202
    public function updateSubtreeModificationTime($pathString, $timestamp = null)
203
    {
204
        try {
205
            return $this->innerGateway->updateSubtreeModificationTime($pathString, $timestamp);
206
        } catch (DBALException $e) {
207
            throw new RuntimeException('Database error', 0, $e);
208
        } catch (PDOException $e) {
209
            throw new RuntimeException('Database error', 0, $e);
210
        }
211
    }
212
213
    /**
214
     * Update node assignment table.
215
     *
216
     * @param int $contentObjectId
217
     * @param int $oldParent
218
     * @param int $newParent
219
     * @param int $opcode
220
     */
221
    public function updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode)
222
    {
223
        try {
224
            return $this->innerGateway->updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode);
225
        } catch (DBALException $e) {
226
            throw new RuntimeException('Database error', 0, $e);
227
        } catch (PDOException $e) {
228
            throw new RuntimeException('Database error', 0, $e);
229
        }
230
    }
231
232
    /**
233
     * Create locations from node assignments.
234
     *
235
     * Convert existing node assignments into real locations.
236
     *
237
     * @param mixed $contentId
238
     * @param mixed $versionNo
239
     */
240
    public function createLocationsFromNodeAssignments($contentId, $versionNo)
241
    {
242
        try {
243
            return $this->innerGateway->createLocationsFromNodeAssignments($contentId, $versionNo);
244
        } catch (DBALException $e) {
245
            throw new RuntimeException('Database error', 0, $e);
246
        } catch (PDOException $e) {
247
            throw new RuntimeException('Database error', 0, $e);
248
        }
249
    }
250
251
    /**
252
     * Updates all Locations of content identified with $contentId with $versionNo.
253
     *
254
     * @param mixed $contentId
255
     * @param mixed $versionNo
256
     */
257
    public function updateLocationsContentVersionNo($contentId, $versionNo)
258
    {
259
        try {
260
            return $this->innerGateway->updateLocationsContentVersionNo($contentId, $versionNo);
261
        } catch (DBALException $e) {
262
            throw new RuntimeException('Database error', 0, $e);
263
        } catch (PDOException $e) {
264
            throw new RuntimeException('Database error', 0, $e);
265
        }
266
    }
267
268
    /**
269
     * Sets a location to be hidden, and it self + all children to invisible.
270
     *
271
     * @param string $pathString
272
     */
273
    public function hideSubtree($pathString)
274
    {
275
        try {
276
            return $this->innerGateway->hideSubtree($pathString);
277
        } catch (DBALException $e) {
278
            throw new RuntimeException('Database error', 0, $e);
279
        } catch (PDOException $e) {
280
            throw new RuntimeException('Database error', 0, $e);
281
        }
282
    }
283
284
    /**
285
     * Sets a location to be unhidden, and self + children to visible unless a parent is hiding the tree.
286
     * If not make sure only children down to first hidden node is marked visible.
287
     *
288
     * @param string $pathString
289
     */
290
    public function unHideSubtree($pathString)
291
    {
292
        try {
293
            return $this->innerGateway->unHideSubtree($pathString);
294
        } catch (DBALException $e) {
295
            throw new RuntimeException('Database error', 0, $e);
296
        } catch (PDOException $e) {
297
            throw new RuntimeException('Database error', 0, $e);
298
        }
299
    }
300
301
    /**
302
     * @param string $pathString
303
     **/
304
    public function setNodeWithChildrenInvisible(string $pathString): void
305
    {
306
        try {
307
            $this->innerGateway->setNodeWithChildrenInvisible($pathString);
308
        } catch (DBALException $e) {
309
            throw new RuntimeException('Database error', 0, $e);
310
        } catch (PDOException $e) {
311
            throw new RuntimeException('Database error', 0, $e);
312
        }
313
    }
314
315
    /**
316
     * @param string $pathString
317
     **/
318
    public function setNodeHidden(string $pathString): void
319
    {
320
        try {
321
            $this->innerGateway->setNodeHidden($pathString);
322
        } catch (DBALException $e) {
323
            throw new RuntimeException('Database error', 0, $e);
324
        } catch (PDOException $e) {
325
            throw new RuntimeException('Database error', 0, $e);
326
        }
327
    }
328
329
    /**
330
     * @param string $pathString
331
     **/
332
    public function setNodeWithChildrenVisible(string $pathString): void
333
    {
334
        try {
335
            $this->innerGateway->setNodeWithChildrenVisible($pathString);
336
        } catch (DBALException $e) {
337
            throw new RuntimeException('Database error', 0, $e);
338
        } catch (PDOException $e) {
339
            throw new RuntimeException('Database error', 0, $e);
340
        }
341
    }
342
343
    /**
344
     * @param string $pathString
345
     **/
346
    public function setNodeUnhidden(string $pathString): void
347
    {
348
        try {
349
            $this->innerGateway->setNodeUnhidden($pathString);
350
        } catch (DBALException $e) {
351
            throw new RuntimeException('Database error', 0, $e);
352
        } catch (PDOException $e) {
353
            throw new RuntimeException('Database error', 0, $e);
354
        }
355
    }
356
357
    /**
358
     * Swaps the content object being pointed to by a location object.
359
     *
360
     * Make the location identified by $locationId1 refer to the Content
361
     * referred to by $locationId2 and vice versa.
362
     *
363
     * @param int $locationId1
364
     * @param int $locationId2
365
     *
366
     * @return bool
367
     */
368
    public function swap(int $locationId1, int $locationId2): bool
369
    {
370
        try {
371
            return $this->innerGateway->swap($locationId1, $locationId2);
372
        } catch (DBALException $e) {
373
            throw new RuntimeException('Database error', 0, $e);
374
        } catch (PDOException $e) {
375
            throw new RuntimeException('Database error', 0, $e);
376
        }
377
    }
378
379
    /**
380
     * Creates a new location in given $parentNode.
381
     *
382
     * @param \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct
383
     * @param array $parentNode
384
     *
385
     * @return \eZ\Publish\SPI\Persistence\Content\Location
386
     */
387
    public function create(CreateStruct $createStruct, array $parentNode)
388
    {
389
        try {
390
            return $this->innerGateway->create($createStruct, $parentNode);
391
        } catch (DBALException $e) {
392
            throw new RuntimeException('Database error', 0, $e);
393
        } catch (PDOException $e) {
394
            throw new RuntimeException('Database error', 0, $e);
395
        }
396
    }
397
398
    /**
399
     * Create an entry in the node assignment table.
400
     *
401
     * @param \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct
402
     * @param mixed $parentNodeId
403
     * @param int $type
404
     */
405
    public function createNodeAssignment(CreateStruct $createStruct, $parentNodeId, $type = self::NODE_ASSIGNMENT_OP_CODE_CREATE_NOP)
406
    {
407
        try {
408
            return $this->innerGateway->createNodeAssignment($createStruct, $parentNodeId, $type);
409
        } catch (DBALException $e) {
410
            throw new RuntimeException('Database error', 0, $e);
411
        } catch (PDOException $e) {
412
            throw new RuntimeException('Database error', 0, $e);
413
        }
414
    }
415
416
    /**
417
     * Deletes node assignment for given $contentId and $versionNo.
418
     *
419
     * @param int $contentId
420
     * @param int $versionNo
421
     */
422
    public function deleteNodeAssignment($contentId, $versionNo = null)
423
    {
424
        try {
425
            return $this->innerGateway->deleteNodeAssignment($contentId, $versionNo);
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
    /**
434
     * Updates an existing location.
435
     *
436
     * Will not throw anything if location id is invalid or no entries are affected.
437
     *
438
     * @param \eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct $location
439
     * @param int $locationId
440
     */
441
    public function update(UpdateStruct $location, $locationId)
442
    {
443
        try {
444
            return $this->innerGateway->update($location, $locationId);
445
        } catch (DBALException $e) {
446
            throw new RuntimeException('Database error', 0, $e);
447
        } catch (PDOException $e) {
448
            throw new RuntimeException('Database error', 0, $e);
449
        }
450
    }
451
452
    /**
453
     * Updates path identification string for given $locationId.
454
     *
455
     * @param mixed $locationId
456
     * @param mixed $parentLocationId
457
     * @param string $text
458
     */
459
    public function updatePathIdentificationString($locationId, $parentLocationId, $text)
460
    {
461
        try {
462
            return $this->innerGateway->updatePathIdentificationString($locationId, $parentLocationId, $text);
463
        } catch (DBALException $e) {
464
            throw new RuntimeException('Database error', 0, $e);
465
        } catch (PDOException $e) {
466
            throw new RuntimeException('Database error', 0, $e);
467
        }
468
    }
469
470
    /**
471
     * Deletes ezcontentobject_tree row for given $locationId (node_id).
472
     *
473
     * @param mixed $locationId
474
     */
475
    public function removeLocation($locationId)
476
    {
477
        try {
478
            return $this->innerGateway->removeLocation($locationId);
479
        } catch (DBALException $e) {
480
            throw new RuntimeException('Database error', 0, $e);
481
        } catch (PDOException $e) {
482
            throw new RuntimeException('Database error', 0, $e);
483
        }
484
    }
485
486
    /**
487
     * Returns id of the next in line node to be set as a new main node.
488
     *
489
     * This returns lowest node id for content identified by $contentId, and not of
490
     * the node identified by given $locationId (current main node).
491
     * Assumes that content has more than one location.
492
     *
493
     * @param mixed $contentId
494
     * @param mixed $locationId
495
     *
496
     * @return array
497
     */
498
    public function getFallbackMainNodeData($contentId, $locationId)
499
    {
500
        try {
501
            return $this->innerGateway->getFallbackMainNodeData($contentId, $locationId);
502
        } catch (DBALException $e) {
503
            throw new RuntimeException('Database error', 0, $e);
504
        } catch (PDOException $e) {
505
            throw new RuntimeException('Database error', 0, $e);
506
        }
507
    }
508
509
    /**
510
     * Sends a single location identified by given $locationId to the trash.
511
     *
512
     * The associated content object is left untouched.
513
     *
514
     * @param mixed $locationId
515
     *
516
     * @return bool
517
     */
518
    public function trashLocation($locationId)
519
    {
520
        try {
521
            return $this->innerGateway->trashLocation($locationId);
522
        } catch (DBALException $e) {
523
            throw new RuntimeException('Database error', 0, $e);
524
        } catch (PDOException $e) {
525
            throw new RuntimeException('Database error', 0, $e);
526
        }
527
    }
528
529
    /**
530
     * Returns a trashed location to normal state.
531
     *
532
     * Recreates the originally trashed location in the new position. If no new
533
     * position has been specified, it will be tried to re-create the location
534
     * at the old position. If this is not possible ( because the old location
535
     * does not exist any more) and exception is thrown.
536
     *
537
     * @param mixed $locationId
538
     * @param mixed $newParentId
539
     *
540
     * @return \eZ\Publish\SPI\Persistence\Content\Location
541
     */
542
    public function untrashLocation($locationId, $newParentId = null)
543
    {
544
        try {
545
            return $this->innerGateway->untrashLocation($locationId, $newParentId);
546
        } catch (DBALException $e) {
547
            throw new RuntimeException('Database error', 0, $e);
548
        } catch (PDOException $e) {
549
            throw new RuntimeException('Database error', 0, $e);
550
        }
551
    }
552
553
    /**
554
     * Loads trash data specified by location ID.
555
     *
556
     * @param mixed $locationId
557
     *
558
     * @return array
559
     */
560
    public function loadTrashByLocation($locationId)
561
    {
562
        try {
563
            return $this->innerGateway->loadTrashByLocation($locationId);
564
        } catch (DBALException $e) {
565
            throw new RuntimeException('Database error', 0, $e);
566
        } catch (PDOException $e) {
567
            throw new RuntimeException('Database error', 0, $e);
568
        }
569
    }
570
571
    /**
572
     * Removes every entries in the trash.
573
     * Will NOT remove associated content objects nor attributes.
574
     *
575
     * Basically truncates ezcontentobject_trash table.
576
     */
577
    public function cleanupTrash()
578
    {
579
        try {
580
            return $this->innerGateway->cleanupTrash();
581
        } catch (DBALException $e) {
582
            throw new RuntimeException('Database error', 0, $e);
583
        } catch (PDOException $e) {
584
            throw new RuntimeException('Database error', 0, $e);
585
        }
586
    }
587
588
    /**
589
     * Lists trashed items.
590
     * Returns entries from ezcontentobject_trash.
591
     *
592
     * @param int $offset
593
     * @param int $limit
594
     * @param array $sort
595
     *
596
     * @return array
597
     */
598
    public function listTrashed($offset, $limit, array $sort = null)
599
    {
600
        try {
601
            return $this->innerGateway->listTrashed($offset, $limit, $sort);
602
        } catch (DBALException $e) {
603
            throw new RuntimeException('Database error', 0, $e);
604
        } catch (PDOException $e) {
605
            throw new RuntimeException('Database error', 0, $e);
606
        }
607
    }
608
609
    /**
610
     * Removes trashed element identified by $id from trash.
611
     * Will NOT remove associated content object nor attributes.
612
     *
613
     * @param int $id The trashed location Id
614
     */
615
    public function removeElementFromTrash($id)
616
    {
617
        try {
618
            return $this->innerGateway->removeElementFromTrash($id);
619
        } catch (DBALException $e) {
620
            throw new RuntimeException('Database error', 0, $e);
621
        } catch (PDOException $e) {
622
            throw new RuntimeException('Database error', 0, $e);
623
        }
624
    }
625
626
    /**
627
     * Set section on all content objects in the subtree.
628
     *
629
     * @param mixed $pathString
630
     * @param mixed $sectionId
631
     *
632
     * @return bool
633
     */
634
    public function setSectionForSubtree($pathString, $sectionId)
635
    {
636
        try {
637
            return $this->innerGateway->setSectionForSubtree($pathString, $sectionId);
638
        } catch (DBALException $e) {
639
            throw new RuntimeException('Database error', 0, $e);
640
        } catch (PDOException $e) {
641
            throw new RuntimeException('Database error', 0, $e);
642
        }
643
    }
644
645
    /**
646
     * Returns how many locations given content object identified by $contentId has.
647
     *
648
     * @param int $contentId
649
     *
650
     * @return int
651
     */
652
    public function countLocationsByContentId($contentId)
653
    {
654
        try {
655
            return $this->innerGateway->countLocationsByContentId($contentId);
656
        } catch (DBALException $e) {
657
            throw new RuntimeException('Database error', 0, $e);
658
        } catch (PDOException $e) {
659
            throw new RuntimeException('Database error', 0, $e);
660
        }
661
    }
662
663
    /**
664
     * Changes main location of content identified by given $contentId to location identified by given $locationId.
665
     *
666
     * Updates ezcontentobject_tree table for the given $contentId and eznode_assignment table for the given
667
     * $contentId, $parentLocationId and $versionNo
668
     *
669
     * @param mixed $contentId
670
     * @param mixed $locationId
671
     * @param mixed $versionNo version number, needed to update eznode_assignment table
672
     * @param mixed $parentLocationId parent location of location identified by $locationId, needed to update
673
     *        eznode_assignment table
674
     */
675
    public function changeMainLocation($contentId, $locationId, $versionNo, $parentLocationId)
676
    {
677
        try {
678
            return $this->innerGateway->changeMainLocation($contentId, $locationId, $versionNo, $parentLocationId);
679
        } catch (DBALException $e) {
680
            throw new RuntimeException('Database error', 0, $e);
681
        } catch (PDOException $e) {
682
            throw new RuntimeException('Database error', 0, $e);
683
        }
684
    }
685
686
    /**
687
     * Get the total number of all Locations, except the Root node.
688
     *
689
     * @see loadAllLocationsData
690
     *
691
     * @return int
692
     */
693
    public function countAllLocations()
694
    {
695
        try {
696
            return $this->innerGateway->countAllLocations();
697
        } catch (DBALException $e) {
698
            throw new RuntimeException('Database error', 0, $e);
699
        } catch (PDOException $e) {
700
            throw new RuntimeException('Database error', 0, $e);
701
        }
702
    }
703
704
    /**
705
     * Load data of every Location, except the Root node.
706
     *
707
     * @param int $offset Paginator offset
708
     * @param int $limit Paginator limit
709
     *
710
     * @return array
711
     */
712
    public function loadAllLocationsData($offset, $limit)
713
    {
714
        try {
715
            return $this->innerGateway->loadAllLocationsData($offset, $limit);
716
        } catch (DBALException $e) {
717
            throw new RuntimeException('Database error', 0, $e);
718
        } catch (PDOException $e) {
719
            throw new RuntimeException('Database error', 0, $e);
720
        }
721
    }
722
}
723