diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index bac2657eb2..85d9c076c0 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -141,6 +141,7 @@ tables: ezcontentclass_attribute: indexes: ezcontentclass_attr_ccid: { fields: [contentclass_id] } + ezcontentclass_attr_dts: { fields: [data_type_string] } id: id: { type: integer, nullable: false, options: { autoincrement: true } } version: { type: integer, nullable: false, options: { default: '0' } } diff --git a/src/contracts/Persistence/Content/Type/Handler.php b/src/contracts/Persistence/Content/Type/Handler.php index c6ab11b1fd..c115ac4e93 100644 --- a/src/contracts/Persistence/Content/Type/Handler.php +++ b/src/contracts/Persistence/Content/Type/Handler.php @@ -91,6 +91,11 @@ public function loadContentTypes($groupId, $status = Type::STATUS_DEFINED); */ public function loadContentTypeList(array $contentTypeIds): array; + /** + * @return \Ibexa\Contracts\Core\Persistence\Content\Type[] + */ + public function loadContentTypesByFieldDefinitionIdentifier(string $identifier): array; + /** * Loads a content type by id and status. * diff --git a/src/lib/Persistence/Cache/ContentTypeHandler.php b/src/lib/Persistence/Cache/ContentTypeHandler.php index 134311faaf..7ca287dbef 100644 --- a/src/lib/Persistence/Cache/ContentTypeHandler.php +++ b/src/lib/Persistence/Cache/ContentTypeHandler.php @@ -26,6 +26,7 @@ class ContentTypeHandler extends AbstractInMemoryPersistenceHandler implements C private const BY_IDENTIFIER_SUFFIX = 'by_identifier_suffix'; private const CONTENT_TYPE_LIST_BY_GROUP_IDENTIFIER = 'content_type_list_by_group'; private const BY_REMOTE_SUFFIX = 'by_remote_suffix'; + private const CONTENT_TYPE_LIST_BY_FIELD_DEFINITION_IDENTIFIER = 'content_type_list_by_field_definition_identifier'; private const TYPE_MAP_IDENTIFIER = 'type_map'; private const CONTENT_FIELDS_TYPE_IDENTIFIER = 'content_fields_type'; private const TYPE_WITHOUT_VALUE_IDENTIFIER = 'type_without_value'; @@ -303,6 +304,20 @@ function () use ($remoteId) { ); } + public function loadContentTypesByFieldDefinitionIdentifier(string $identifier): array + { + return $this->getListCacheValue( + $this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_LIST_BY_FIELD_DEFINITION_IDENTIFIER, [$identifier], true), + function () use ($identifier): array { + return $this->persistenceHandler->contentTypeHandler()->loadContentTypesByFieldDefinitionIdentifier($identifier); + }, + $this->getTypeTags, + $this->getTypeKeys, + null, + [$identifier] + ); + } + /** * {@inheritdoc} */ diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway.php b/src/lib/Persistence/Legacy/Content/Type/Gateway.php index 592354e40e..769f917ee6 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway.php @@ -116,6 +116,11 @@ abstract public function updateType(int $typeId, int $status, Type $type): void; */ abstract public function loadTypesListData(array $typeIds): array; + /** + * @return array + */ + abstract public function loadTypesDataByFieldDefinitionIdentifier(string $identifier): array; + abstract public function loadTypeData(int $typeId, int $status): array; abstract public function loadTypeDataByIdentifier(string $identifier, int $status): array; diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php index f947a15989..be8e087ed0 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php @@ -949,6 +949,20 @@ public function loadTypesListData(array $typeIds): array return $query->execute()->fetchAll(); } + public function loadTypesDataByFieldDefinitionIdentifier(string $identifier): array + { + $query = $this->getLoadTypeQueryBuilder(); + $query + ->andWhere( + $query->expr()->eq( + 'a.data_type_string', + $query->createNamedParameter($identifier) + ) + ); + + return $query->execute()->fetchAllAssociative(); + } + public function loadTypeData(int $typeId, int $status): array { $query = $this->getLoadTypeQueryBuilder(); diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php index 2b32c7d8d9..fd6229651d 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php @@ -245,6 +245,15 @@ public function loadTypeDataByRemoteId(string $remoteId, int $status): array } } + public function loadTypesDataByFieldDefinitionIdentifier(string $identifier): array + { + try { + return $this->innerGateway->loadTypesDataByFieldDefinitionIdentifier($identifier); + } catch (PDOException $e) { + throw DatabaseException::wrap($e); + } + } + public function countInstancesOfType(int $typeId): int { try { diff --git a/src/lib/Persistence/Legacy/Content/Type/Handler.php b/src/lib/Persistence/Legacy/Content/Type/Handler.php index 4f04557b13..8ade46c4bd 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Handler.php +++ b/src/lib/Persistence/Legacy/Content/Type/Handler.php @@ -195,6 +195,16 @@ public function loadContentTypeList(array $contentTypeIds): array ); } + /** + * @return \Ibexa\Contracts\Core\Persistence\Content\Type[] + */ + public function loadContentTypesByFieldDefinitionIdentifier(string $identifier): array + { + return $this->mapper->extractTypesFromRows( + $this->contentTypeGateway->loadTypesDataByFieldDefinitionIdentifier($identifier) + ); + } + /** * Loads a content type by id and status. * diff --git a/src/lib/Persistence/Legacy/Content/Type/MemoryCachingHandler.php b/src/lib/Persistence/Legacy/Content/Type/MemoryCachingHandler.php index 4452567ea3..9294d4769d 100644 --- a/src/lib/Persistence/Legacy/Content/Type/MemoryCachingHandler.php +++ b/src/lib/Persistence/Legacy/Content/Type/MemoryCachingHandler.php @@ -186,6 +186,22 @@ public function loadContentTypeList(array $contentTypeIds): array return $contentTypes; } + /** + * {@inheritdoc} + */ + public function loadContentTypesByFieldDefinitionIdentifier(string $identifier): array + { + $cacheKey = 'ibx-ctlbfdi-' . $identifier; + + $types = $this->cache->get($cacheKey); + if ($types === null) { + $types = $this->innerHandler->loadContentTypesByFieldDefinitionIdentifier($identifier); + $this->storeTypeCache($types, $cacheKey); + } + + return $types; + } + /** * {@inheritdoc} */ diff --git a/src/lib/Resources/settings/storage_engines/cache.yml b/src/lib/Resources/settings/storage_engines/cache.yml index 1fb13b0c3d..89953faf04 100644 --- a/src/lib/Resources/settings/storage_engines/cache.yml +++ b/src/lib/Resources/settings/storage_engines/cache.yml @@ -125,6 +125,7 @@ parameters: content_type_group: 'ctg-%s' content_type_group_with_id_suffix: 'ctg-%s-bi' content_type_group_with_by_remote_suffix: 'ctg-%s-br' + content_type_list_by_field_definition_identifier: 'ctlbfdi-%s' content_type_group_list: 'ctgl-%s' content_type_list_by_group: 'ctlbg-%s' image_variation: 'ig' diff --git a/tests/lib/Persistence/Cache/ContentTypeHandlerTest.php b/tests/lib/Persistence/Cache/ContentTypeHandlerTest.php index d5ee9bcfab..c6073f4640 100644 --- a/tests/lib/Persistence/Cache/ContentTypeHandlerTest.php +++ b/tests/lib/Persistence/Cache/ContentTypeHandlerTest.php @@ -204,6 +204,7 @@ public function providerForCachedLoadMethodsHit(): array ], ['loadAllGroups', [], 'ibx-ctgl', null, null, [['content_type_group_list', [], true]], ['ibx-ctgl'], [3 => $group]], ['loadContentTypes', [3, 0], 'ibx-ctlbg-3', null, null, [['content_type_list_by_group', [3], true]], ['ibx-ctlbg-3'], [$type]], + ['loadContentTypesByFieldDefinitionIdentifier', [3, 0], 'ibx-ctlbfdi-3', null, null, [['content_type_list_by_field_definition_identifier', [3], true]], ['ibx-ctlbfdi-3'], [$type]], ['loadContentTypeList', [[5]], 'ibx-ct-5', null, null, [['content_type', [], true]], ['ibx-ct'], [5 => $type], true], ['load', [5, 0], 'ibx-ct-5', null, null, [['content_type', [], true]], ['ibx-ct'], $type], [ diff --git a/tests/lib/Persistence/Legacy/Content/Type/ContentTypeHandlerTest.php b/tests/lib/Persistence/Legacy/Content/Type/ContentTypeHandlerTest.php index 053cd536a9..2226bc1508 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/ContentTypeHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/ContentTypeHandlerTest.php @@ -284,6 +284,30 @@ public function testLoadContentTypeList(): void ); } + public function testLoadContentTypesByFieldDefinitionIdentifier(): void + { + $gatewayMock = $this->getGatewayMock(); + $gatewayMock->expects($this->once()) + ->method('loadTypesDataByFieldDefinitionIdentifier') + ->with('ezstring') + ->willReturn([]); + + $mapperMock = $this->getMapperMock(); + $mapperMock->expects(self::once()) + ->method('extractTypesFromRows') + ->with([]) + ->willReturn([23 => new Type()]); + + $handler = $this->getHandler(); + $types = $handler->loadContentTypesByFieldDefinitionIdentifier('ezstring'); + + self::assertEquals( + [23 => new Type()], + $types, + 'Types not loaded correctly' + ); + } + public function testLoad() { $gatewayMock = $this->getGatewayMock();