Skip to content

IBX-9103: Replaced Relation const calls with RelationType enum #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/FieldType/ImageAsset/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
use Ibexa\Core\FieldType\FieldType;
Expand Down Expand Up @@ -270,7 +270,7 @@ public function getRelations(SPIValue $fieldValue): array
{
$relations = [];
if ($fieldValue->destinationContentId !== null) {
$relations[Relation::ASSET] = [$fieldValue->destinationContentId];
$relations[RelationType::ASSET->value] = [$fieldValue->destinationContentId];
}

return $relations;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/FieldType/Relation/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
use Ibexa\Core\FieldType\FieldType;
Expand Down Expand Up @@ -347,7 +348,7 @@ public function getRelations(SPIValue $fieldValue)
{
$relations = [];
if ($fieldValue->destinationContentId !== null) {
$relations[Relation::FIELD] = [$fieldValue->destinationContentId];
$relations[RelationType::FIELD->value] = [$fieldValue->destinationContentId];
}

return $relations;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/FieldType/RelationList/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
use Ibexa\Core\FieldType\FieldType;
Expand Down Expand Up @@ -468,7 +469,7 @@ public function getRelations(SPIValue $value)
{
/* @var \Ibexa\Core\FieldType\RelationList\Value $value */
return [
Relation::FIELD => $value->destinationContentIds,
RelationType::FIELD->value => $value->destinationContentIds,
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Persistence/Cache/ContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as APIRelation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;

/**
* @covers \Ibexa\Core\Persistence\Cache\ContentHandler
Expand Down Expand Up @@ -364,7 +364,7 @@ public function deleteContent($contentId)
// Load reverse field relations first
$reverseRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations(
$contentId,
APIRelation::FIELD | APIRelation::ASSET
RelationType::FIELD->value | RelationType::ASSET->value
);

$return = $this->persistenceHandler->contentHandler()->deleteContent($contentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo as APIVersionInfo;
use Ibexa\Core\Base\Exceptions\BadStateException;
use Ibexa\Core\Base\Exceptions\NotFoundException;
Expand Down Expand Up @@ -1187,7 +1188,7 @@ public function removeReverseFieldRelations(int $contentId): void
)
)
->setParameter('content_id', $contentId, ParameterType::INTEGER)
->setParameter('relation_type', Relation::FIELD, ParameterType::INTEGER);
->setParameter('relation_type', RelationType::FIELD->value, ParameterType::INTEGER);

$statement = $query->execute();

Expand Down
8 changes: 4 additions & 4 deletions src/lib/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinat
'sourceContentVersionNo' => $sourceVersion->versionNo,
'sourceFieldDefinitionId' => null,
'destinationContentId' => $destinationContent->id,
'type' => APIRelation::COMMON,
'type' => RelationType::COMMON->value,
]
)
);
Expand Down Expand Up @@ -2295,7 +2295,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
$spiRelationsCount = $this->persistenceHandler->contentHandler()->countRelations(
(int)$sourceVersion->getContentInfo()->getId(),
$sourceVersion->versionNo,
APIRelation::COMMON
RelationType::COMMON->value
);

if ($spiRelationsCount === 0) {
Expand All @@ -2310,7 +2310,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
$spiRelationsCount,
0,
$sourceVersion->versionNo,
APIRelation::COMMON
RelationType::COMMON->value
);

// there should be only one relation of type COMMON for each destination,
Expand All @@ -2322,7 +2322,7 @@ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $desti
if ($spiRelation->destinationContentId == $destinationContent->id) {
$this->persistenceHandler->contentHandler()->removeRelation(
$spiRelation->id,
APIRelation::COMMON,
RelationType::COMMON->value,
$spiRelation->destinationContentId
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Core/Repository/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3557,7 +3557,7 @@ protected function assertExpectedRelations($relations)
{
self::assertEquals(
[
'type' => Relation::COMMON,
'type' => RelationType::COMMON->value,
'sourceFieldDefinitionIdentifier' => null,
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
'destinationContentInfo' => self::MEDIA_REMOTE_ID,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/FieldType/ImageAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
Expand Down Expand Up @@ -427,7 +427,7 @@ public function testGetRelations()

self::assertEquals(
[
Relation::ASSET => [$destinationContentId],
RelationType::ASSET->value => [$destinationContentId],
],
$fieldType->getRelations($fieldType->acceptValue($destinationContentId))
);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/FieldType/RelationListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Handler as SPIContentHandler;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
use Ibexa\Core\FieldType\RelationList\Type as RelationList;
use Ibexa\Core\FieldType\RelationList\Value;
Expand Down Expand Up @@ -844,7 +844,7 @@ public function testGetRelations()
$ft = $this->createFieldTypeUnderTest();
self::assertEquals(
[
Relation::FIELD => [70, 72],
RelationType::FIELD->value => [70, 72],
],
$ft->getRelations($ft->acceptValue([70, 72]))
);
Expand Down
18 changes: 9 additions & 9 deletions tests/lib/FieldType/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use Ibexa\Contracts\Core\Persistence\Content\Handler as SPIContentHandler;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
use Ibexa\Core\FieldType\Relation\Type as RelationType;
use Ibexa\Core\FieldType\Relation\Type as Type;
use Ibexa\Core\FieldType\Relation\Value;
use Ibexa\Core\FieldType\ValidationError;
use Ibexa\Core\Repository\Validator\TargetContentValidatorInterface;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function setUp(): void
*/
protected function createFieldTypeUnderTest()
{
$fieldType = new RelationType(
$fieldType = new Type(
$this->contentHandler,
$this->targetContentValidator
);
Expand Down Expand Up @@ -104,7 +104,7 @@ protected function getSettingsSchemaExpectation()
return [
'selectionMethod' => [
'type' => 'int',
'default' => RelationType::SELECTION_BROWSE,
'default' => Type::SELECTION_BROWSE,
],
'selectionRoot' => [
'type' => 'string',
Expand Down Expand Up @@ -313,13 +313,13 @@ public function provideValidFieldSettings()
return [
[
[
'selectionMethod' => RelationType::SELECTION_BROWSE,
'selectionMethod' => Type::SELECTION_BROWSE,
'selectionRoot' => 42,
],
],
[
[
'selectionMethod' => RelationType::SELECTION_DROPDOWN,
'selectionMethod' => Type::SELECTION_DROPDOWN,
'selectionRoot' => 'some-key',
],
],
Expand Down Expand Up @@ -356,7 +356,7 @@ public function provideInValidFieldSettings()
// Unknown key
[
'unknownKey' => 23,
'selectionMethod' => RelationType::SELECTION_BROWSE,
'selectionMethod' => Type::SELECTION_BROWSE,
'selectionRoot' => 42,
],
],
Expand All @@ -370,7 +370,7 @@ public function provideInValidFieldSettings()
[
// Invalid selectionRoot
[
'selectionMethod' => RelationType::SELECTION_DROPDOWN,
'selectionMethod' => Type::SELECTION_DROPDOWN,
'selectionRoot' => [],
],
],
Expand All @@ -385,7 +385,7 @@ public function testGetRelations()
$ft = $this->createFieldTypeUnderTest();
self::assertEquals(
[
Relation::FIELD => [70],
RelationType::FIELD->value => [70],
],
$ft->getRelations($ft->acceptValue(70))
);
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Persistence/Cache/ContentHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as APIRelation;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Core\Persistence\Cache\ContentHandler;

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ public function providerForUnCachedMethods(): array
//['deleteContent', [2]], own tests for relations complexity
['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']],
['addRelation', [new RelationCreateStruct(['destinationContentId' => 2, 'sourceContentId' => 4])], [['content', [2], false], ['content', [4], false]], null, ['c-2', 'c-4']],
['removeRelation', [66, APIRelation::COMMON, 2], [['content', [2], false], ['relation', [66], false]], null, ['c-2', 're-66']],
['removeRelation', [66, RelationType::COMMON->value, 2], [['content', [2], false], ['relation', [66], false]], null, ['c-2', 're-66']],
['loadReverseRelations', [2, 3]],
['publish', [2, 3, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']],
[
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testDeleteContent()
$innerHandlerMock
->expects(self::once())
->method('loadReverseRelations')
->with(2, APIRelation::FIELD | APIRelation::ASSET)
->with(2, RelationType::FIELD->value | RelationType::ASSET->value)
->willReturn(
[
new SPIRelation(['sourceContentId' => 42]),
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as RelationValue;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Ibexa\Core\Persistence\Legacy\Content\FieldHandler;
use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
Expand Down Expand Up @@ -925,14 +925,14 @@ public function testAddRelation()
$expectedRelationObject->sourceContentId = 23;
$expectedRelationObject->sourceContentVersionNo = 1;
$expectedRelationObject->destinationContentId = 66;
$expectedRelationObject->type = RelationValue::COMMON;
$expectedRelationObject->type = RelationType::COMMON->value;

// relation create struct
$relationCreateStruct = new Relation\CreateStruct();
$relationCreateStruct->destinationContentId = 66;
$relationCreateStruct->sourceContentId = 23;
$relationCreateStruct->sourceContentVersionNo = 1;
$relationCreateStruct->type = RelationValue::COMMON;
$relationCreateStruct->type = RelationType::COMMON->value;

$handler = $this->getContentHandler();

Expand Down Expand Up @@ -969,10 +969,10 @@ public function testRemoveRelation()
->method('deleteRelation')
->with(
self::equalTo(1),
self::equalTo(RelationValue::COMMON),
self::equalTo(RelationType::COMMON->value),
);

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

protected function getRelationFixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation as RelationValue;
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
use Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase;
use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue;
use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase;
Expand Down Expand Up @@ -1250,13 +1250,13 @@ public function testLoadRelationsByType()

$gateway = $this->getDatabaseGateway();

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

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

$this->assertValuesInRows(
'ezcontentobject_link_relation_type',
[RelationValue::COMMON],
[RelationType::COMMON->value],
$relations
);

Expand Down Expand Up @@ -1290,7 +1290,7 @@ public function testLoadRelationsNoResult()

$gateway = $this->getDatabaseGateway();

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

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

$gateway = $this->getDatabaseGateway();

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

self::assertCount(1, $relations);

Expand All @@ -1330,7 +1330,7 @@ public function testLoadReverseRelationsWithType()

$this->assertValuesInRows(
'ezcontentobject_link_relation_type',
[RelationValue::COMMON],
[RelationType::COMMON->value],
$relations
);
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public function testDeleteRelation()
self::assertEquals(4, $this->countContentRelations(57));

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

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

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

$query = $this->getDatabaseConnection()->createQueryBuilder();
$this->assertQueryResult(
[['relation_type' => RelationValue::LINK]],
[['relation_type' => RelationType::LINK->value]],
$query
->select(['relation_type'])
->from('ezcontentobject_link')
Expand Down Expand Up @@ -1951,7 +1951,7 @@ protected function getRelationCreateStructFixture()
$struct->sourceContentId = 1;
$struct->sourceContentVersionNo = 1;
$struct->sourceFieldDefinitionId = 0;
$struct->type = RelationValue::COMMON;
$struct->type = RelationType::COMMON->value;

return $struct;
}
Expand Down
Loading
Loading