Completed
Push — 7.5 ( 467086...6987e3 )
by Łukasz
19:03
created

ExceptionConversion::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Content Gateway base 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\Gateway;
10
11
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway;
12
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
13
use eZ\Publish\SPI\Persistence\Content;
14
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
15
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
16
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
17
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\Field;
19
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
20
use Doctrine\DBAL\DBALException;
21
use PDOException;
22
use RuntimeException;
23
24
/**
25
 * Base class for content gateways.
26
 */
27
class ExceptionConversion extends Gateway
28
{
29
    /**
30
     * The wrapped gateway.
31
     *
32
     * @var Gateway
33
     */
34
    protected $innerGateway;
35
36
    /**
37
     * Creates a new exception conversion gateway around $innerGateway.
38
     *
39
     * @param Gateway $innerGateway
40
     */
41
    public function __construct(Gateway $innerGateway)
42
    {
43
        $this->innerGateway = $innerGateway;
44
    }
45
46
    /**
47
     * Get context definition for external storage layers.
48
     *
49
     * @return array
50
     */
51
    public function getContext()
52
    {
53
        try {
54
            return $this->innerGateway->getContext();
55
        } catch (DBALException $e) {
56
            throw new RuntimeException('Database error', 0, $e);
57
        } catch (PDOException $e) {
58
            throw new RuntimeException('Database error', 0, $e);
59
        }
60
    }
61
62
    /**
63
     * Inserts a new content object.
64
     *
65
     * @param \eZ\Publish\SPI\Persistence\Content\CreateStruct $struct
66
     * @param mixed $currentVersionNo
67
     *
68
     * @return int ID
69
     */
70
    public function insertContentObject(CreateStruct $struct, $currentVersionNo = 1)
71
    {
72
        try {
73
            return $this->innerGateway->insertContentObject($struct, $currentVersionNo);
74
        } catch (DBALException $e) {
75
            throw new RuntimeException('Database error', 0, $e);
76
        } catch (PDOException $e) {
77
            throw new RuntimeException('Database error', 0, $e);
78
        }
79
    }
80
81
    /**
82
     * Inserts a new version.
83
     *
84
     * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo
85
     * @param \eZ\Publish\SPI\Persistence\Content\Field[] $fields
86
     *
87
     * @return int ID
88
     */
89
    public function insertVersion(VersionInfo $versionInfo, array $fields)
90
    {
91
        try {
92
            return $this->innerGateway->insertVersion($versionInfo, $fields);
93
        } catch (DBALException $e) {
94
            throw new RuntimeException('Database error', 0, $e);
95
        } catch (PDOException $e) {
96
            throw new RuntimeException('Database error', 0, $e);
97
        }
98
    }
99
100
    /**
101
     * Updates an existing content identified by $contentId in respect to $struct.
102
     *
103
     * @param int $contentId
104
     * @param \eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct $struct
105
     * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $prePublishVersionInfo Provided on publish
106
     */
107
    public function updateContent($contentId, MetadataUpdateStruct $struct, VersionInfo $prePublishVersionInfo = null)
108
    {
109
        try {
110
            return $this->innerGateway->updateContent($contentId, $struct, $prePublishVersionInfo);
111
        } catch (DBALException $e) {
112
            throw new RuntimeException('Database error', 0, $e);
113
        } catch (PDOException $e) {
114
            throw new RuntimeException('Database error', 0, $e);
115
        }
116
    }
117
118
    /**
119
     * Updates version $versionNo for content identified by $contentId, in respect to $struct.
120
     *
121
     * @param int $contentId
122
     * @param int $versionNo
123
     * @param \eZ\Publish\SPI\Persistence\Content\UpdateStruct $struct
124
     */
125
    public function updateVersion($contentId, $versionNo, UpdateStruct $struct)
126
    {
127
        try {
128
            return $this->innerGateway->updateVersion($contentId, $versionNo, $struct);
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 "always available" flag for content identified by $contentId, in respect to $alwaysAvailable.
138
     *
139
     * @param int $contentId
140
     * @param bool $newAlwaysAvailable New "always available" value
141
     */
142
    public function updateAlwaysAvailableFlag($contentId, $newAlwaysAvailable)
143
    {
144
        try {
145
            return $this->innerGateway->updateAlwaysAvailableFlag($contentId, $newAlwaysAvailable);
146
        } catch (DBALException $e) {
147
            throw new RuntimeException('Database error', 0, $e);
148
        } catch (PDOException $e) {
149
            throw new RuntimeException('Database error', 0, $e);
150
        }
151
    }
152
153
    /**
154
     * Sets the state of object identified by $contentId and $version to $state.
155
     *
156
     * The $status can be one of STATUS_DRAFT, STATUS_PUBLISHED, STATUS_ARCHIVED
157
     *
158
     * @param int $contentId
159
     * @param int $version
160
     * @param int $status
161
     *
162
     * @return bool
163
     */
164
    public function setStatus($contentId, $version, $status)
165
    {
166
        try {
167
            return $this->innerGateway->setStatus($contentId, $version, $status);
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
    public function setPublishedStatus(int $contentId, int $status): void
176
    {
177
        try {
178
            $this->innerGateway->setPublishedStatus($contentId, $status);
179
        } catch (DBALException | PDOException $e) {
180
            throw new RuntimeException('Database error', 0, $e);
181
        }
182
    }
183
184
    /**
185
     * Inserts a new field.
186
     *
187
     * Only used when a new field is created (i.e. a new object or a field in a
188
     * new language!). After that, field IDs need to stay the same, only the
189
     * version number changes.
190
     *
191
     * @param \eZ\Publish\SPI\Persistence\Content $content
192
     * @param \eZ\Publish\SPI\Persistence\Content\Field $field
193
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
194
     *
195
     * @return int ID
196
     */
197
    public function insertNewField(Content $content, Field $field, StorageFieldValue $value)
198
    {
199
        try {
200
            return $this->innerGateway->insertNewField($content, $field, $value);
201
        } catch (DBALException $e) {
202
            throw new RuntimeException('Database error', 0, $e);
203
        } catch (PDOException $e) {
204
            throw new RuntimeException('Database error', 0, $e);
205
        }
206
    }
207
208
    /**
209
     * Inserts an existing field.
210
     *
211
     * Used to insert a field with an exsting ID but a new version number.
212
     *
213
     * @param Content $content
214
     * @param Field $field
215
     * @param StorageFieldValue $value
216
     */
217
    public function insertExistingField(Content $content, Field $field, StorageFieldValue $value)
218
    {
219
        try {
220
            return $this->innerGateway->insertExistingField($content, $field, $value);
221
        } catch (DBALException $e) {
222
            throw new RuntimeException('Database error', 0, $e);
223
        } catch (PDOException $e) {
224
            throw new RuntimeException('Database error', 0, $e);
225
        }
226
    }
227
228
    /**
229
     * Updates an existing field.
230
     *
231
     * @param Field $field
232
     * @param StorageFieldValue $value
233
     */
234
    public function updateField(Field $field, StorageFieldValue $value)
235
    {
236
        try {
237
            return $this->innerGateway->updateField($field, $value);
238
        } catch (DBALException $e) {
239
            throw new RuntimeException('Database error', 0, $e);
240
        } catch (PDOException $e) {
241
            throw new RuntimeException('Database error', 0, $e);
242
        }
243
    }
244
245
    /**
246
     * Updates an existing, non-translatable field.
247
     *
248
     * @param \eZ\Publish\SPI\Persistence\Content\Field $field
249
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
250
     * @param int $contentId
251
     */
252
    public function updateNonTranslatableField(
253
        Field $field,
254
        StorageFieldValue $value,
255
        $contentId
256
    ) {
257
        try {
258
            return $this->innerGateway->updateNonTranslatableField($field, $value, $contentId);
259
        } catch (DBALException $e) {
260
            throw new RuntimeException('Database error', 0, $e);
261
        } catch (PDOException $e) {
262
            throw new RuntimeException('Database error', 0, $e);
263
        }
264
    }
265
266
    /**
267
     * {@inheritdoc}
268
     */
269
    public function load($contentId, $version = null, array $translations = null)
270
    {
271
        try {
272
            return $this->innerGateway->load($contentId, $version, $translations);
0 ignored issues
show
Bug introduced by
It seems like $translations defined by parameter $translations on line 269 can also be of type array; however, eZ\Publish\Core\Persiste...Content\Gateway::load() 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...
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
     * {@inheritdoc}
282
     */
283
    public function loadContentList(array $contentIds, array $translations = null): array
284
    {
285
        try {
286
            return $this->innerGateway->loadContentList($contentIds, $translations);
0 ignored issues
show
Bug introduced by
It seems like $translations defined by parameter $translations on line 283 can also be of type array; however, eZ\Publish\Core\Persiste...eway::loadContentList() 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...
287
        } catch (DBALException | PDOException $e) {
288
            throw new RuntimeException('Database error', 0, $e);
289
        }
290
    }
291
292
    /**
293
     * Loads data for a content object identified by its remote ID.
294
     *
295
     * Returns an array with the relevant data.
296
     *
297
     * @param mixed $remoteId
298
     *
299
     * @return array
300
     */
301
    public function loadContentInfoByRemoteId($remoteId)
302
    {
303
        try {
304
            return $this->innerGateway->loadContentInfoByRemoteId($remoteId);
305
        } catch (DBALException $e) {
306
            throw new \RuntimeException('Database error', 0, $e);
307
        } catch (\PDOException $e) {
308
            throw new \RuntimeException('Database error', 0, $e);
309
        }
310
    }
311
312
    /**
313
     * Loads info for a content object identified by its location ID (node ID).
314
     *
315
     * Returns an array with the relevant data.
316
     *
317
     * @param int $locationId
318
     *
319
     * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
320
     *
321
     * @return array
322
     */
323
    public function loadContentInfoByLocationId($locationId)
324
    {
325
        try {
326
            return $this->innerGateway->loadContentInfoByLocationId($locationId);
327
        } catch (DBALException $e) {
328
            throw new \RuntimeException('Database error', 0, $e);
329
        } catch (\PDOException $e) {
330
            throw new \RuntimeException('Database error', 0, $e);
331
        }
332
    }
333
334
    /**
335
     * Loads info for content identified by $contentId.
336
     * Will basically return a hash containing all field values for ezcontentobject table plus following keys:
337
     *  - always_available => Boolean indicating if content's language mask contains alwaysAvailable bit field
338
     *  - main_language_code => Language code for main (initial) language. E.g. "eng-GB".
339
     *
340
     * @param int $contentId
341
     *
342
     * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
343
     *
344
     * @return array
345
     */
346
    public function loadContentInfo($contentId)
347
    {
348
        try {
349
            return $this->innerGateway->loadContentInfo($contentId);
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
    public function loadContentInfoList(array $contentIds)
358
    {
359
        try {
360
            return $this->innerGateway->loadContentInfoList($contentIds);
361
        } catch (DBALException $e) {
362
            throw new RuntimeException('Database error', 0, $e);
363
        } catch (PDOException $e) {
364
            throw new RuntimeException('Database error', 0, $e);
365
        }
366
    }
367
368
    /**
369
     * Loads version info for content identified by $contentId and $versionNo.
370
     * Will basically return a hash containing all field values from ezcontentobject_version table plus following keys:
371
     *  - names => Hash of content object names. Key is the language code, value is the name.
372
     *  - languages => Hash of language ids. Key is the language code (e.g. "eng-GB"), value is the language numeric id without the always available bit.
373
     *  - initial_language_code => Language code for initial language in this version.
374
     *
375
     * @param int $contentId
376
     * @param int|null $versionNo
377
     *
378
     * @return array
379
     */
380
    public function loadVersionInfo($contentId, $versionNo = null)
381
    {
382
        try {
383
            return $this->innerGateway->loadVersionInfo($contentId, $versionNo);
384
        } catch (DBALException $e) {
385
            throw new RuntimeException('Database error', 0, $e);
386
        } catch (PDOException $e) {
387
            throw new RuntimeException('Database error', 0, $e);
388
        }
389
    }
390
391
    /**
392
     * Returns the number of all versions with given status created by the given $userId.
393
     *
394
     * @param int $userId
395
     * @param int $status
396
     *
397
     * @return int
398
     */
399
    public function countVersionsForUser(int $userId, int $status = VersionInfo::STATUS_DRAFT): int
400
    {
401
        try {
402
            return $this->innerGateway->countVersionsForUser($userId, $status);
403
        } catch (DBALException | PDOException $e) {
404
            throw new RuntimeException('Database error', 0, $e);
405
        }
406
    }
407
408
    /**
409
     * Returns data for all versions with given status created by the given $userId.
410
     *
411
     * @param int $userId
412
     * @param int $status
413
     *
414
     * @return string[][]
415
     */
416
    public function listVersionsForUser($userId, $status = VersionInfo::STATUS_DRAFT, int $offset = 0, int $limit = -1)
417
    {
418
        try {
419
            return $this->innerGateway->listVersionsForUser($userId, $status, $offset, $limit);
420
        } catch (DBALException $e) {
421
            throw new RuntimeException('Database error', 0, $e);
422
        } catch (PDOException $e) {
423
            throw new RuntimeException('Database error', 0, $e);
424
        }
425
    }
426
427
    /**
428
     * {@inheritdoc}
429
     */
430
    public function loadVersionsForUser($userId, $status = VersionInfo::STATUS_DRAFT, int $offset = 0, int $limit = -1): array
431
    {
432
        try {
433
            return $this->innerGateway->loadVersionsForUser($userId, $status, $offset, $limit);
434
        } catch (DBALException | PDOException $e) {
435
            throw new RuntimeException('Database error', 0, $e);
436
        }
437
    }
438
439
    /**
440
     * Returns all version data for the given $contentId.
441
     *
442
     * Result is returned with oldest version first (using version id as it has index and is auto increment).
443
     *
444
     * @param mixed $contentId
445
     * @param mixed|null $status Optional argument to filter versions by status, like {@see VersionInfo::STATUS_ARCHIVED}.
446
     * @param int $limit Limit for items returned, -1 means none.
447
     *
448
     * @return string[][]
449
     */
450
    public function listVersions($contentId, $status = null, $limit = -1)
451
    {
452
        try {
453
            return $this->innerGateway->listVersions($contentId, $status, $limit);
454
        } catch (DBALException $e) {
455
            throw new RuntimeException('Database error', 0, $e);
456
        } catch (PDOException $e) {
457
            throw new RuntimeException('Database error', 0, $e);
458
        }
459
    }
460
461
    /**
462
     * Returns all version numbers for the given $contentId.
463
     *
464
     * @param mixed $contentId
465
     *
466
     * @return int[]
467
     */
468
    public function listVersionNumbers($contentId)
469
    {
470
        try {
471
            return $this->innerGateway->listVersionNumbers($contentId);
472
        } catch (DBALException $e) {
473
            throw new RuntimeException('Database error', 0, $e);
474
        } catch (PDOException $e) {
475
            throw new RuntimeException('Database error', 0, $e);
476
        }
477
    }
478
479
    /**
480
     * Returns last version number for content identified by $contentId.
481
     *
482
     * @param int $contentId
483
     *
484
     * @return int
485
     */
486
    public function getLastVersionNumber($contentId)
487
    {
488
        try {
489
            return $this->innerGateway->getLastVersionNumber($contentId);
490
        } catch (DBALException $e) {
491
            throw new RuntimeException('Database error', 0, $e);
492
        } catch (PDOException $e) {
493
            throw new RuntimeException('Database error', 0, $e);
494
        }
495
    }
496
497
    /**
498
     * Returns all IDs for locations that refer to $contentId.
499
     *
500
     * @param int $contentId
501
     *
502
     * @return int[]
503
     */
504
    public function getAllLocationIds($contentId)
505
    {
506
        try {
507
            return $this->innerGateway->getAllLocationIds($contentId);
508
        } catch (DBALException $e) {
509
            throw new RuntimeException('Database error', 0, $e);
510
        } catch (PDOException $e) {
511
            throw new RuntimeException('Database error', 0, $e);
512
        }
513
    }
514
515
    /**
516
     * Returns all field IDs of $contentId grouped by their type.
517
     * If $versionNo is set only field IDs for that version are returned.
518
     * If $languageCode is set, only field IDs for that language are returned.
519
     *
520
     * @param int $contentId
521
     * @param int|null $versionNo
522
     * @param string|null $languageCode
523
     *
524
     * @return int[][]
525
     */
526
    public function getFieldIdsByType($contentId, $versionNo = null, $languageCode = null)
527
    {
528
        try {
529
            return $this->innerGateway->getFieldIdsByType($contentId, $versionNo, $languageCode);
530
        } catch (DBALException $e) {
531
            throw new RuntimeException('Database error', 0, $e);
532
        } catch (PDOException $e) {
533
            throw new RuntimeException('Database error', 0, $e);
534
        }
535
    }
536
537
    /**
538
     * Deletes relations to and from $contentId.
539
     * If $versionNo is set only relations for that version are deleted.
540
     *
541
     * @param int $contentId
542
     * @param int|null $versionNo
543
     */
544
    public function deleteRelations($contentId, $versionNo = null)
545
    {
546
        try {
547
            return $this->innerGateway->deleteRelations($contentId, $versionNo);
548
        } catch (DBALException $e) {
549
            throw new RuntimeException('Database error', 0, $e);
550
        } catch (PDOException $e) {
551
            throw new RuntimeException('Database error', 0, $e);
552
        }
553
    }
554
555
    /**
556
     * Removes relations to Content with $contentId from Relation and RelationList field type fields.
557
     *
558
     * @param int $contentId
559
     */
560
    public function removeReverseFieldRelations($contentId)
561
    {
562
        try {
563
            return $this->innerGateway->removeReverseFieldRelations($contentId);
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
     * Deletes the field with the given $fieldId.
573
     *
574
     * @param int $fieldId
575
     */
576
    public function deleteField($fieldId)
577
    {
578
        try {
579
            return $this->innerGateway->deleteField($fieldId);
580
        } catch (DBALException $e) {
581
            throw new RuntimeException('Database error', 0, $e);
582
        } catch (PDOException $e) {
583
            throw new RuntimeException('Database error', 0, $e);
584
        }
585
    }
586
587
    /**
588
     * Deletes all fields of $contentId in all versions.
589
     * If $versionNo is set only fields for that version are deleted.
590
     *
591
     * @param int $contentId
592
     * @param int|null $versionNo
593
     */
594
    public function deleteFields($contentId, $versionNo = null)
595
    {
596
        try {
597
            return $this->innerGateway->deleteFields($contentId, $versionNo);
598
        } catch (DBALException $e) {
599
            throw new RuntimeException('Database error', 0, $e);
600
        } catch (PDOException $e) {
601
            throw new RuntimeException('Database error', 0, $e);
602
        }
603
    }
604
605
    /**
606
     * Deletes all versions of $contentId.
607
     * If $versionNo is set only that version is deleted.
608
     *
609
     * @param int $contentId
610
     * @param int|null $versionNo
611
     */
612
    public function deleteVersions($contentId, $versionNo = null)
613
    {
614
        try {
615
            return $this->innerGateway->deleteVersions($contentId, $versionNo);
616
        } catch (DBALException $e) {
617
            throw new RuntimeException('Database error', 0, $e);
618
        } catch (PDOException $e) {
619
            throw new RuntimeException('Database error', 0, $e);
620
        }
621
    }
622
623
    /**
624
     * Deletes all names of $contentId.
625
     * If $versionNo is set only names for that version are deleted.
626
     *
627
     * @param int $contentId
628
     * @param int|null $versionNo
629
     */
630
    public function deleteNames($contentId, $versionNo = null)
631
    {
632
        try {
633
            return $this->innerGateway->deleteNames($contentId, $versionNo);
634
        } catch (DBALException $e) {
635
            throw new RuntimeException('Database error', 0, $e);
636
        } catch (PDOException $e) {
637
            throw new RuntimeException('Database error', 0, $e);
638
        }
639
    }
640
641
    /**
642
     * Sets the content object name.
643
     *
644
     * @param int $contentId
645
     * @param int $version
646
     * @param string $name
647
     * @param string $language
648
     */
649
    public function setName($contentId, $version, $name, $language)
650
    {
651
        try {
652
            return $this->innerGateway->setName($contentId, $version, $name, $language);
653
        } catch (DBALException $e) {
654
            throw new RuntimeException('Database error', 0, $e);
655
        } catch (PDOException $e) {
656
            throw new RuntimeException('Database error', 0, $e);
657
        }
658
    }
659
660
    /**
661
     * Deletes the actual content object referred to by $contentId.
662
     *
663
     * @param int $contentId
664
     */
665
    public function deleteContent($contentId)
666
    {
667
        try {
668
            return $this->innerGateway->deleteContent($contentId);
669
        } catch (DBALException $e) {
670
            throw new RuntimeException('Database error', 0, $e);
671
        } catch (PDOException $e) {
672
            throw new RuntimeException('Database error', 0, $e);
673
        }
674
    }
675
676
    /**
677
     * Loads data of related to/from $contentId.
678
     *
679
     * @param int $contentId
680
     * @param int $contentVersionNo
681
     * @param int $relationType
682
     *
683
     * @return mixed[][] Content data, array structured like {@see \eZ\Publish\Core\Persistence\Legacy\Content\Gateway::load()}
684
     */
685
    public function loadRelations($contentId, $contentVersionNo = null, $relationType = null)
686
    {
687
        try {
688
            return $this->innerGateway->loadRelations($contentId, $contentVersionNo, $relationType);
689
        } catch (DBALException $e) {
690
            throw new RuntimeException('Database error', 0, $e);
691
        } catch (PDOException $e) {
692
            throw new RuntimeException('Database error', 0, $e);
693
        }
694
    }
695
696
    /**
697
     * {@inheritdoc}
698
     */
699
    public function countReverseRelations(int $contentId, ?int $relationType = null): int
700
    {
701
        try {
702
            return $this->innerGateway->countReverseRelations($contentId, $relationType);
703
        } catch (DBALException | PDOException $e) {
704
            throw new RuntimeException('Database error', 0, $e);
705
        }
706
    }
707
708
    /**
709
     * Loads data of related to/from $contentId.
710
     *
711
     * @param int $contentId
712
     * @param bool $reverse Reverse relation, default false
0 ignored issues
show
Bug introduced by
There is no parameter named $reverse. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
713
     * @param int $contentVersionNo
0 ignored issues
show
Bug introduced by
There is no parameter named $contentVersionNo. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
714
     * @param int $relationType
715
     *
716
     * @return mixed[][] Content data, array structured like {@see \eZ\Publish\Core\Persistence\Legacy\Content\Gateway::load()}
717
     */
718
    public function loadReverseRelations($contentId, $relationType = null)
719
    {
720
        try {
721
            return $this->innerGateway->loadReverseRelations($contentId, $relationType);
722
        } catch (DBALException $e) {
723
            throw new RuntimeException('Database error', 0, $e);
724
        } catch (PDOException $e) {
725
            throw new RuntimeException('Database error', 0, $e);
726
        }
727
    }
728
729
    /**
730
     * Deletes the relation with the given $relationId.
731
     *
732
     * @param int $relationId
733
     * @param int $type {@see \eZ\Publish\API\Repository\Values\Content\Relation::COMMON,
734
     *                 \eZ\Publish\API\Repository\Values\Content\Relation::EMBED,
735
     *                 \eZ\Publish\API\Repository\Values\Content\Relation::LINK,
736
     *                 \eZ\Publish\API\Repository\Values\Content\Relation::FIELD}
737
     */
738
    public function deleteRelation($relationId, $type)
739
    {
740
        try {
741
            return $this->innerGateway->deleteRelation($relationId, $type);
742
        } catch (DBALException $e) {
743
            throw new RuntimeException('Database error', 0, $e);
744
        } catch (PDOException $e) {
745
            throw new RuntimeException('Database error', 0, $e);
746
        }
747
    }
748
749
    /**
750
     * Inserts a new relation database record.
751
     *
752
     * @param \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct $createStruct
0 ignored issues
show
Documentation introduced by
There is no parameter named $createStruct. Did you maybe mean $struct?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
753
     *
754
     * @return int ID the inserted ID
755
     */
756
    public function insertRelation(RelationCreateStruct $struct)
757
    {
758
        try {
759
            return $this->innerGateway->insertRelation($struct);
760
        } catch (DBALException $e) {
761
            throw new RuntimeException('Database error', 0, $e);
762
        } catch (PDOException $e) {
763
            throw new RuntimeException('Database error', 0, $e);
764
        }
765
    }
766
767
    /**
768
     * Returns all Content IDs for a given $contentTypeId.
769
     *
770
     * @param int $contentTypeId
771
     *
772
     * @return int[]
773
     */
774
    public function getContentIdsByContentTypeId($contentTypeId)
775
    {
776
        try {
777
            return $this->innerGateway->getContentIdsByContentTypeId($contentTypeId);
778
        } catch (DBALException $e) {
779
            throw new RuntimeException('Database error', 0, $e);
780
        } catch (PDOException $e) {
781
            throw new RuntimeException('Database error', 0, $e);
782
        }
783
    }
784
785
    /**
786
     * Load name data for set of content id's and corresponding version number.
787
     *
788
     * @param array[] $rows array of hashes with 'id' and 'version' to load names for
789
     *
790
     * @return array
791
     */
792
    public function loadVersionedNameData($rows)
793
    {
794
        try {
795
            return $this->innerGateway->loadVersionedNameData($rows);
796
        } catch (DBALException $e) {
797
            throw new RuntimeException('Database error', 0, $e);
798
        } catch (PDOException $e) {
799
            throw new RuntimeException('Database error', 0, $e);
800
        }
801
    }
802
803
    /**
804
     * Batch method for copying all relation meta data for copied Content object.
805
     *
806
     * {@inheritdoc}
807
     *
808
     * @param int $originalContentId
809
     * @param int $copiedContentId
810
     * @param int|null $versionNo If specified only copy for a given version number, otherwise all.
811
     */
812
    public function copyRelations($originalContentId, $copiedContentId, $versionNo = null)
813
    {
814
        try {
815
            return $this->innerGateway->copyRelations($originalContentId, $copiedContentId, $versionNo);
816
        } catch (DBALException $e) {
817
            throw new RuntimeException('Database error', 0, $e);
818
        } catch (PDOException $e) {
819
            throw new RuntimeException('Database error', 0, $e);
820
        }
821
    }
822
823
    /**
824
     * Remove the specified translation from all the Versions of a Content Object.
825
     *
826
     * @param int $contentId
827
     * @param string $languageCode language code of the translation
828
     */
829
    public function deleteTranslationFromContent($contentId, $languageCode)
830
    {
831
        try {
832
            return $this->innerGateway->deleteTranslationFromContent($contentId, $languageCode);
833
        } catch (DBALException $e) {
834
            throw new RuntimeException('Database error', 0, $e);
835
        } catch (PDOException $e) {
836
            throw new RuntimeException('Database error', 0, $e);
837
        }
838
    }
839
840
    /**
841
     * Delete Content fields (attributes) for the given Translation.
842
     * If $versionNo is given, fields for that Version only will be deleted.
843
     *
844
     * @param string $languageCode
845
     * @param int $contentId
846
     * @param int $versionNo (optional) filter by versionNo
847
     */
848
    public function deleteTranslatedFields($languageCode, $contentId, $versionNo = null)
849
    {
850
        try {
851
            return $this->innerGateway->deleteTranslatedFields($languageCode, $contentId, $versionNo);
852
        } catch (DBALException $e) {
853
            throw new RuntimeException('Database error', 0, $e);
854
        } catch (PDOException $e) {
855
            throw new RuntimeException('Database error', 0, $e);
856
        }
857
    }
858
859
    /**
860
     * Delete the specified Translation from the given Version.
861
     *
862
     * @param int $contentId
863
     * @param int $versionNo
864
     * @param string $languageCode
865
     */
866
    public function deleteTranslationFromVersion($contentId, $versionNo, $languageCode)
867
    {
868
        try {
869
            return $this->innerGateway->deleteTranslationFromVersion($contentId, $versionNo, $languageCode);
870
        } catch (DBALException $e) {
871
            throw new RuntimeException('Database error', 0, $e);
872
        } catch (PDOException $e) {
873
            throw new RuntimeException('Database error', 0, $e);
874
        }
875
    }
876
}
877