Skip to content

Commit cc9da9b

Browse files
committed
IBX-9103: Replaced Relation const calls with RelationType enum
1 parent e6ad1d2 commit cc9da9b

File tree

15 files changed

+150
-148
lines changed

15 files changed

+150
-148
lines changed

src/lib/FieldType/ImageAsset/Type.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
1515
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1616
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
17-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
17+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1818
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1919
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
2020
use Ibexa\Core\FieldType\FieldType;
@@ -270,7 +270,7 @@ public function getRelations(SPIValue $fieldValue): array
270270
{
271271
$relations = [];
272272
if ($fieldValue->destinationContentId !== null) {
273-
$relations[Relation::ASSET] = [$fieldValue->destinationContentId];
273+
$relations[RelationType::ASSET->value] = [$fieldValue->destinationContentId];
274274
}
275275

276276
return $relations;

src/lib/FieldType/Relation/Type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
1313
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1414
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
15+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1516
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1617
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
1718
use Ibexa\Core\FieldType\FieldType;
@@ -347,7 +348,7 @@ public function getRelations(SPIValue $fieldValue)
347348
{
348349
$relations = [];
349350
if ($fieldValue->destinationContentId !== null) {
350-
$relations[Relation::FIELD] = [$fieldValue->destinationContentId];
351+
$relations[RelationType::FIELD->value] = [$fieldValue->destinationContentId];
351352
}
352353

353354
return $relations;

src/lib/FieldType/RelationList/Type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
1313
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1414
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
15+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1516
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1617
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
1718
use Ibexa\Core\FieldType\FieldType;
@@ -468,7 +469,7 @@ public function getRelations(SPIValue $value)
468469
{
469470
/* @var \Ibexa\Core\FieldType\RelationList\Value $value */
470471
return [
471-
Relation::FIELD => $value->destinationContentIds,
472+
RelationType::FIELD->value => $value->destinationContentIds,
472473
];
473474
}
474475

src/lib/Persistence/Cache/ContentHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
1717
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
1818
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
19-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as APIRelation;
19+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2020

2121
/**
2222
* @covers \Ibexa\Core\Persistence\Cache\ContentHandler
@@ -364,7 +364,7 @@ public function deleteContent($contentId)
364364
// Load reverse field relations first
365365
$reverseRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations(
366366
$contentId,
367-
APIRelation::FIELD | APIRelation::ASSET
367+
RelationType::FIELD->value | RelationType::ASSET->value
368368
);
369369

370370
$return = $this->persistenceHandler->contentHandler()->deleteContent($contentId);

src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
2424
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
2525
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
26-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
26+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2727
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo as APIVersionInfo;
2828
use Ibexa\Core\Base\Exceptions\BadStateException;
2929
use Ibexa\Core\Base\Exceptions\NotFoundException;
@@ -1187,7 +1187,7 @@ public function removeReverseFieldRelations(int $contentId): void
11871187
)
11881188
)
11891189
->setParameter('content_id', $contentId, ParameterType::INTEGER)
1190-
->setParameter('relation_type', Relation::FIELD | Relation::ASSET, ParameterType::INTEGER);
1190+
->setParameter('relation_type', RelationType::FIELD->value | RelationType::ASSET->value, ParameterType::INTEGER);
11911191

11921192
$statement = $query->execute();
11931193

src/lib/Repository/ContentService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinat
22512251
'sourceContentVersionNo' => $sourceVersion->versionNo,
22522252
'sourceFieldDefinitionId' => null,
22532253
'destinationContentId' => $destinationContent->id,
2254-
'type' => APIRelation::COMMON,
2254+
'type' => RelationType::COMMON->value,
22552255
]
22562256
)
22572257
);
@@ -2295,7 +2295,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
22952295
$spiRelationsCount = $this->persistenceHandler->contentHandler()->countRelations(
22962296
(int)$sourceVersion->getContentInfo()->getId(),
22972297
$sourceVersion->versionNo,
2298-
APIRelation::COMMON
2298+
RelationType::COMMON->value
22992299
);
23002300

23012301
if ($spiRelationsCount === 0) {
@@ -2310,7 +2310,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
23102310
$spiRelationsCount,
23112311
0,
23122312
$sourceVersion->versionNo,
2313-
APIRelation::COMMON
2313+
RelationType::COMMON->value
23142314
);
23152315

23162316
// there should be only one relation of type COMMON for each destination,
@@ -2322,7 +2322,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
23222322
if ($spiRelation->destinationContentId == $destinationContent->id) {
23232323
$this->persistenceHandler->contentHandler()->removeRelation(
23242324
$spiRelation->id,
2325-
APIRelation::COMMON,
2325+
RelationType::COMMON->value,
23262326
$spiRelation->destinationContentId
23272327
);
23282328
}

tests/integration/Core/Repository/ContentServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ protected function assertExpectedRelations($relations)
35573557
{
35583558
self::assertEquals(
35593559
[
3560-
'type' => Relation::COMMON,
3560+
'type' => RelationType::COMMON->value,
35613561
'sourceFieldDefinitionIdentifier' => null,
35623562
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
35633563
'destinationContentInfo' => self::MEDIA_REMOTE_ID,

tests/lib/FieldType/ImageAssetTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Ibexa\Contracts\Core\Repository\ContentService;
1515
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1616
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
17-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
17+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1818
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
1919
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
2020
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
@@ -427,7 +427,7 @@ public function testGetRelations()
427427

428428
self::assertEquals(
429429
[
430-
Relation::ASSET => [$destinationContentId],
430+
RelationType::ASSET->value => [$destinationContentId],
431431
],
432432
$fieldType->getRelations($fieldType->acceptValue($destinationContentId))
433433
);

tests/lib/FieldType/RelationListTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Ibexa\Contracts\Core\Persistence\Content\Handler as SPIContentHandler;
1212
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
1313
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
14-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
14+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1515
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
1616
use Ibexa\Core\FieldType\RelationList\Type as RelationList;
1717
use Ibexa\Core\FieldType\RelationList\Value;
@@ -844,7 +844,7 @@ public function testGetRelations()
844844
$ft = $this->createFieldTypeUnderTest();
845845
self::assertEquals(
846846
[
847-
Relation::FIELD => [70, 72],
847+
RelationType::FIELD->value => [70, 72],
848848
],
849849
$ft->getRelations($ft->acceptValue([70, 72]))
850850
);

tests/lib/FieldType/RelationTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use Ibexa\Contracts\Core\Persistence\Content\Handler as SPIContentHandler;
1212
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
1313
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
14-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
14+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
1515
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1616
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
17-
use Ibexa\Core\FieldType\Relation\Type as RelationType;
17+
use Ibexa\Core\FieldType\Relation\Type as Type;
1818
use Ibexa\Core\FieldType\Relation\Value;
1919
use Ibexa\Core\FieldType\ValidationError;
2020
use Ibexa\Core\Repository\Validator\TargetContentValidatorInterface;
@@ -75,7 +75,7 @@ protected function setUp(): void
7575
*/
7676
protected function createFieldTypeUnderTest()
7777
{
78-
$fieldType = new RelationType(
78+
$fieldType = new Type(
7979
$this->contentHandler,
8080
$this->targetContentValidator
8181
);
@@ -104,7 +104,7 @@ protected function getSettingsSchemaExpectation()
104104
return [
105105
'selectionMethod' => [
106106
'type' => 'int',
107-
'default' => RelationType::SELECTION_BROWSE,
107+
'default' => Type::SELECTION_BROWSE,
108108
],
109109
'selectionRoot' => [
110110
'type' => 'string',
@@ -313,13 +313,13 @@ public function provideValidFieldSettings()
313313
return [
314314
[
315315
[
316-
'selectionMethod' => RelationType::SELECTION_BROWSE,
316+
'selectionMethod' => Type::SELECTION_BROWSE,
317317
'selectionRoot' => 42,
318318
],
319319
],
320320
[
321321
[
322-
'selectionMethod' => RelationType::SELECTION_DROPDOWN,
322+
'selectionMethod' => Type::SELECTION_DROPDOWN,
323323
'selectionRoot' => 'some-key',
324324
],
325325
],
@@ -356,7 +356,7 @@ public function provideInValidFieldSettings()
356356
// Unknown key
357357
[
358358
'unknownKey' => 23,
359-
'selectionMethod' => RelationType::SELECTION_BROWSE,
359+
'selectionMethod' => Type::SELECTION_BROWSE,
360360
'selectionRoot' => 42,
361361
],
362362
],
@@ -370,7 +370,7 @@ public function provideInValidFieldSettings()
370370
[
371371
// Invalid selectionRoot
372372
[
373-
'selectionMethod' => RelationType::SELECTION_DROPDOWN,
373+
'selectionMethod' => Type::SELECTION_DROPDOWN,
374374
'selectionRoot' => [],
375375
],
376376
],
@@ -385,7 +385,7 @@ public function testGetRelations()
385385
$ft = $this->createFieldTypeUnderTest();
386386
self::assertEquals(
387387
[
388-
Relation::FIELD => [70],
388+
RelationType::FIELD->value => [70],
389389
],
390390
$ft->getRelations($ft->acceptValue(70))
391391
);

tests/lib/Persistence/Cache/ContentHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
1818
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
1919
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
20-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as APIRelation;
20+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2121
use Ibexa\Core\Persistence\Cache\ContentHandler;
2222

2323
/**
@@ -53,7 +53,7 @@ public function providerForUnCachedMethods(): array
5353
//['deleteContent', [2]], own tests for relations complexity
5454
['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']],
5555
['addRelation', [new RelationCreateStruct(['destinationContentId' => 2, 'sourceContentId' => 4])], [['content', [2], false], ['content', [4], false]], null, ['c-2', 'c-4']],
56-
['removeRelation', [66, APIRelation::COMMON, 2], [['content', [2], false], ['relation', [66], false]], null, ['c-2', 're-66']],
56+
['removeRelation', [66, RelationType::COMMON->value, 2], [['content', [2], false], ['relation', [66], false]], null, ['c-2', 're-66']],
5757
['loadReverseRelations', [2, 3]],
5858
['publish', [2, 3, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']],
5959
[
@@ -450,7 +450,7 @@ public function testDeleteContent()
450450
$innerHandlerMock
451451
->expects(self::once())
452452
->method('loadReverseRelations')
453-
->with(2, APIRelation::FIELD | APIRelation::ASSET)
453+
->with(2, RelationType::FIELD->value | RelationType::ASSET->value)
454454
->willReturn(
455455
[
456456
new SPIRelation(['sourceContentId' => 42]),

tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Ibexa\Contracts\Core\Persistence\Content\Type;
2020
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
2121
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
22-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as RelationValue;
22+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2323
use Ibexa\Core\Base\Exceptions\NotFoundException;
2424
use Ibexa\Core\Persistence\Legacy\Content\FieldHandler;
2525
use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
@@ -925,14 +925,14 @@ public function testAddRelation()
925925
$expectedRelationObject->sourceContentId = 23;
926926
$expectedRelationObject->sourceContentVersionNo = 1;
927927
$expectedRelationObject->destinationContentId = 66;
928-
$expectedRelationObject->type = RelationValue::COMMON;
928+
$expectedRelationObject->type = RelationType::COMMON->value;
929929

930930
// relation create struct
931931
$relationCreateStruct = new Relation\CreateStruct();
932932
$relationCreateStruct->destinationContentId = 66;
933933
$relationCreateStruct->sourceContentId = 23;
934934
$relationCreateStruct->sourceContentVersionNo = 1;
935-
$relationCreateStruct->type = RelationValue::COMMON;
935+
$relationCreateStruct->type = RelationType::COMMON->value;
936936

937937
$handler = $this->getContentHandler();
938938

@@ -969,10 +969,10 @@ public function testRemoveRelation()
969969
->method('deleteRelation')
970970
->with(
971971
self::equalTo(1),
972-
self::equalTo(RelationValue::COMMON),
972+
self::equalTo(RelationType::COMMON->value),
973973
);
974974

975-
$this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
975+
$this->getContentHandler()->removeRelation(1, RelationType::COMMON->value);
976976
}
977977

978978
protected function getRelationFixture()

tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
1818
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
1919
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
20-
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as RelationValue;
20+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2121
use Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase;
2222
use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue;
2323
use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase;
@@ -1250,13 +1250,13 @@ public function testLoadRelationsByType()
12501250

12511251
$gateway = $this->getDatabaseGateway();
12521252

1253-
$relations = $gateway->loadRelations(57, null, RelationValue::COMMON);
1253+
$relations = $gateway->loadRelations(57, null, RelationType::COMMON->value);
12541254

12551255
self::assertCount(1, $relations, 'Expecting one relation to be loaded');
12561256

12571257
$this->assertValuesInRows(
12581258
'ezcontentobject_link_relation_type',
1259-
[RelationValue::COMMON],
1259+
[RelationType::COMMON->value],
12601260
$relations
12611261
);
12621262

@@ -1290,7 +1290,7 @@ public function testLoadRelationsNoResult()
12901290

12911291
$gateway = $this->getDatabaseGateway();
12921292

1293-
$relations = $gateway->loadRelations(57, 1, RelationValue::EMBED);
1293+
$relations = $gateway->loadRelations(57, 1, RelationType::EMBED->value);
12941294

12951295
self::assertCount(0, $relations, 'Expecting no relation to be loaded');
12961296
}
@@ -1318,7 +1318,7 @@ public function testLoadReverseRelationsWithType()
13181318

13191319
$gateway = $this->getDatabaseGateway();
13201320

1321-
$relations = $gateway->loadReverseRelations(58, RelationValue::COMMON);
1321+
$relations = $gateway->loadReverseRelations(58, RelationType::COMMON->value);
13221322

13231323
self::assertCount(1, $relations);
13241324

@@ -1330,7 +1330,7 @@ public function testLoadReverseRelationsWithType()
13301330

13311331
$this->assertValuesInRows(
13321332
'ezcontentobject_link_relation_type',
1333-
[RelationValue::COMMON],
1333+
[RelationType::COMMON->value],
13341334
$relations
13351335
);
13361336
}
@@ -1399,7 +1399,7 @@ public function testDeleteRelation()
13991399
self::assertEquals(4, $this->countContentRelations(57));
14001400

14011401
$gateway = $this->getDatabaseGateway();
1402-
$gateway->deleteRelation(2, RelationValue::COMMON);
1402+
$gateway->deleteRelation(2, RelationType::COMMON->value);
14031403

14041404
self::assertEquals(3, $this->countContentRelations(57));
14051405
}
@@ -1412,11 +1412,11 @@ public function testDeleteRelationWithCompositeBitmask(): void
14121412
$this->insertRelationFixture();
14131413

14141414
$gateway = $this->getDatabaseGateway();
1415-
$gateway->deleteRelation(11, RelationValue::COMMON);
1415+
$gateway->deleteRelation(11, RelationType::COMMON->value);
14161416

14171417
$query = $this->getDatabaseConnection()->createQueryBuilder();
14181418
$this->assertQueryResult(
1419-
[['relation_type' => RelationValue::LINK]],
1419+
[['relation_type' => RelationType::LINK->value]],
14201420
$query
14211421
->select(['relation_type'])
14221422
->from('ezcontentobject_link')
@@ -1951,7 +1951,7 @@ protected function getRelationCreateStructFixture()
19511951
$struct->sourceContentId = 1;
19521952
$struct->sourceContentVersionNo = 1;
19531953
$struct->sourceFieldDefinitionId = 0;
1954-
$struct->type = RelationValue::COMMON;
1954+
$struct->type = RelationType::COMMON->value;
19551955

19561956
return $struct;
19571957
}

0 commit comments

Comments
 (0)