diff --git a/src/bundle/Core/DependencyInjection/Configuration.php b/src/bundle/Core/DependencyInjection/Configuration.php index bee69df7cd..df48c60088 100644 --- a/src/bundle/Core/DependencyInjection/Configuration.php +++ b/src/bundle/Core/DependencyInjection/Configuration.php @@ -575,8 +575,7 @@ private function addUITranslationsSection(ArrayNodeDefinition $rootNode): void * * ibexa: * installer: - * schema_builder_event: - * enabled: true + * doctrine_migrations: true * * * @param ArrayNodeDefinition $rootNode @@ -586,20 +585,16 @@ private function addInstallerSection(ArrayNodeDefinition $rootNode): ArrayNodeDe return $rootNode ->children() ->arrayNode('installer') + ->addDefaultsIfNotSet() ->children() - ->arrayNode('schema_builder_event') - ->info('Configuration of the legacy, event-driven database schema building mechanism used by the "ibexa:install" command') - ->children() - ->booleanNode('enabled') - ->defaultTrue() - ->info( - 'Whether "ibexa:install" dispatches Ibexa\Contracts\DoctrineSchema\Event\SchemaBuilderEvent ' . - 'to let packages contribute their database schema via an event subscriber, as opposed to ' . - 'the schema being installed from static SQL migrations. ' . - 'Disable once all installed packages have migrated away from the event-driven mechanism.' - ) - ->end() - ->end() + ->arrayNode('doctrine_migrations') + ->info( + 'Whether "ibexa:install" installs the database schema and the core bootstrap data by running the ' . + 'Doctrine Migrations tagged with Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationTag ' . + '(requires "ibexa/doctrine-migrations"), instead of dispatching the legacy, event-driven ' . + 'Ibexa\Contracts\DoctrineSchema\Event\SchemaBuilderEvent.' + ) + ->canBeEnabled() ->end() ->end() ->end() diff --git a/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php b/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php index 8b2c50eebc..553cb4642b 100644 --- a/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php +++ b/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php @@ -344,8 +344,8 @@ private function registerInstallerConfiguration( ContainerBuilder $container ): void { $container->setParameter( - 'ibexa.installer.schema_builder_event.enabled', - $config['installer']['schema_builder_event']['enabled'] ?? true + 'ibexa.installer.doctrine_migrations.enabled', + $config['installer']['doctrine_migrations']['enabled'] ); } diff --git a/src/bundle/RepositoryInstaller/Bootstrapper/DoctrineMigrationsSchemaHook.php b/src/bundle/RepositoryInstaller/Bootstrapper/DoctrineMigrationsSchemaHook.php index 80989c2a9d..9773c2a368 100644 --- a/src/bundle/RepositoryInstaller/Bootstrapper/DoctrineMigrationsSchemaHook.php +++ b/src/bundle/RepositoryInstaller/Bootstrapper/DoctrineMigrationsSchemaHook.php @@ -19,8 +19,8 @@ /** * @internal for internal use by Ibexa packages' integration test setup * - * Installs the database schema the way a real `ibexa:install` does when the SchemaBuilderEvent path - * is turned off: by running every Ibexa-tagged Doctrine migration via {@see TaggedMigrationsRunner} + * Installs the database schema the way a real `ibexa:install` does when "ibexa.installer.doctrine_migrations" + * is enabled: by running every Ibexa-tagged Doctrine migration via {@see TaggedMigrationsRunner} * — the very same service {@see CoreInstaller} uses, so * a test database built this way is built by the production code path, not by a re-implementation * of it. diff --git a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php index 35669a3e74..a7a398bdee 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -41,7 +41,7 @@ class CoreInstaller extends DbBasedInstaller implements Installer private DbPlatformFactoryInterface $dbPlatformFactory; - private bool $schemaBuilderEventEnabled; + private bool $doctrineMigrationsEnabled; private ?TaggedMigrationsRunner $taggedMigrationsRunner; @@ -54,7 +54,7 @@ public function __construct( SchemaBuilderInterface $schemaBuilder, SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass, DbPlatformFactoryInterface $dbPlatformFactory, - bool $schemaBuilderEventEnabled, + bool $doctrineMigrationsEnabled, ?TaggedMigrationsRunner $taggedMigrationsRunner = null ) { parent::__construct($db); @@ -62,7 +62,7 @@ public function __construct( $this->schemaBuilder = $schemaBuilder; $this->schemaAssetsFilterBypass = $schemaAssetsFilterBypass; $this->dbPlatformFactory = $dbPlatformFactory; - $this->schemaBuilderEventEnabled = $schemaBuilderEventEnabled; + $this->doctrineMigrationsEnabled = $doctrineMigrationsEnabled; $this->taggedMigrationsRunner = $taggedMigrationsRunner; } @@ -77,23 +77,22 @@ private function getIbexaDatabasePlatform(): AbstractPlatform /** * Imports the core database schema. * - * When the "ibexa.installer.schema_builder_event.enabled" setting is enabled (the default), the schema - * is built by dispatching the legacy event-driven {@see SchemaBuilderEvent}, + * By default, the schema is built by dispatching the legacy event-driven {@see SchemaBuilderEvent}, * allowing other packages to contribute their own tables via an event subscriber. * - * Otherwise, the schema is installed by {@see TaggedMigrationsRunner}, which runs every not-yet-executed - * migration tagged with {@see IbexaMigrationTag::TAG} - * (core's own {@see InstallSchemaMigration} plus any other - * package's) via the application's Doctrine Migrations DependencyFactory. + * When the "ibexa.installer.doctrine_migrations" setting is enabled, the schema is installed by + * {@see TaggedMigrationsRunner} instead, which runs every not-yet-executed migration tagged with + * {@see IbexaMigrationTag::TAG} (core's own {@see InstallSchemaMigration} plus any other package's) + * via the application's Doctrine Migrations DependencyFactory. * * @throws Exception - * @throws RuntimeException if "ibexa.installer.schema_builder_event.enabled" is disabled but - * "ibexa/doctrine-migrations" isn't installed/enabled to run the migrations-based path instead + * @throws RuntimeException if "ibexa.installer.doctrine_migrations" is enabled but + * "ibexa/doctrine-migrations" isn't installed/enabled to run the migrations-based path * @throws MigrationFailedException if one of those migrations fails */ public function importSchema() { - if ($this->schemaBuilderEventEnabled) { + if (!$this->doctrineMigrationsEnabled) { $this->executeQueries($this->getQueriesFromSchemaBuilderEvent()); return; @@ -101,7 +100,7 @@ public function importSchema() if ($this->taggedMigrationsRunner === null) { throw new RuntimeException( - 'Disabling "ibexa.installer.schema_builder_event.enabled" requires the "' . + 'Enabling "ibexa.installer.doctrine_migrations" requires the "' . IbexaOnlyDependencyFactory::SERVICE_ID . '" service (provided by "ibexa/doctrine-migrations", ' . 'with Ibexa\Bundle\DoctrineMigrations\IbexaDoctrineMigrationsBundle registered) to be available.' ); @@ -187,18 +186,18 @@ private function executeQueries(array $queries): void /** * Imports the core bootstrap data. * - * When the "ibexa.installer.schema_builder_event.enabled" setting is enabled (the default), this imports - * the DBMS-specific "cleandata.sql" file directly. + * By default, this imports the DBMS-specific "cleandata.sql" file directly. * - * Otherwise, this is a no-op: {@see ImportDataMigration} is - * tagged and already runs as part of {@see importSchema()}'s call to {@see TaggedMigrationsRunner}. + * When the "ibexa.installer.doctrine_migrations" setting is enabled, this is a no-op instead: + * {@see ImportDataMigration} is tagged and already runs as part of {@see importSchema()}'s call to + * {@see TaggedMigrationsRunner}. * * @throws Exception * @throws InvalidArgumentException */ public function importData() { - if ($this->schemaBuilderEventEnabled) { + if (!$this->doctrineMigrationsEnabled) { $this->runQueriesFromFile($this->getKernelSQLFileForDBMS('cleandata.sql')); } } diff --git a/src/bundle/RepositoryInstaller/Resources/config/services.yml b/src/bundle/RepositoryInstaller/Resources/config/services.yml index 15fd0d58bb..bff0dbfc32 100644 --- a/src/bundle/RepositoryInstaller/Resources/config/services.yml +++ b/src/bundle/RepositoryInstaller/Resources/config/services.yml @@ -28,7 +28,7 @@ services: autowire: true parent: Ibexa\Bundle\RepositoryInstaller\Installer\DbBasedInstaller arguments: - $schemaBuilderEventEnabled: '%ibexa.installer.schema_builder_event.enabled%' + $doctrineMigrationsEnabled: '%ibexa.installer.doctrine_migrations.enabled%' # Optional: TaggedMigrationsRunner's own service definition may not exist at all # (RemoveTaggedMigrationsRunnerPass removes it when "ibexa/doctrine-migrations" isn't # installed/enabled) - autowiring alone can't express "pass null if absent". diff --git a/src/contracts/Repository/ContentService.php b/src/contracts/Repository/ContentService.php index dc12f1b4da..bf604f0a00 100644 --- a/src/contracts/Repository/ContentService.php +++ b/src/contracts/Repository/ContentService.php @@ -278,6 +278,8 @@ public function deleteContent(ContentInfo $contentInfo): array; * It can be changed on updating the version. * * @throws UnauthorizedException if the current user is not allowed to create the draft. + * @throws BadStateException if no version is given and the content is not published, or if the given version is a draft. + * @throws InvalidArgumentException if the given version does not belong to the given content. * * @param User|null $creator Used as creator of the draft if given; otherwise uses current user. * @param Language|null $language If not set the draft is created with the initialLanguage code of the source version or if not present with the main language. @@ -328,6 +330,7 @@ public function loadContentDraftList( * @throws ContentFieldValidationException if a field in the $contentUpdateStruct is not valid. * @throws ContentValidationException if a required field is set to an empty value. * @throws InvalidArgumentException if a field value is not accepted by the field type. + * @throws NotFoundException if a field value cannot be processed, e.g. rich text in an unsupported XML namespace. * * @param array|null $fieldIdentifiersToValidate List of field identifiers for partial validation or null * for case of full validation. Empty identifiers array is equal to no validation. @@ -350,6 +353,8 @@ public function updateContent( * * @throws UnauthorizedException if the user is not allowed to publish this version. * @throws BadStateException if the version is not a draft. + * @throws ContentFieldValidationException if a field of a published translation is not valid, e.g. a required field is empty. + * @throws NotFoundException if the content item, or the parent Location of its first publication, no longer exists. * * @param array $translations List of language codes of translations which will be included * in a published version. diff --git a/src/lib/Persistence/Cache/ContentHandler.php b/src/lib/Persistence/Cache/ContentHandler.php index d98e095baa..98a63036bb 100644 --- a/src/lib/Persistence/Cache/ContentHandler.php +++ b/src/lib/Persistence/Cache/ContentHandler.php @@ -157,7 +157,7 @@ public function load( $versionNo = null, ?array $translations = null ) { - $keySuffix = $versionNo ? "-{$versionNo}-" : '-'; + $keySuffix = null !== $versionNo ? "-{$versionNo}-" : '-'; $keySuffix .= empty($translations) ? self::ALL_TRANSLATIONS_KEY : implode('|', $translations); return $this->getCacheValue( @@ -268,7 +268,7 @@ public function loadVersionInfo( $contentId, $versionNo = null ) { - $keySuffix = $versionNo ? "-{$versionNo}" : ''; + $keySuffix = null !== $versionNo ? "-{$versionNo}" : ''; $cacheItem = $this->cache->getItem( $this->cacheIdentifierGenerator->generateKey( self::CONTENT_VERSION_INFO_IDENTIFIER, diff --git a/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php b/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php index 7e55b2467e..5b437725b7 100644 --- a/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php +++ b/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php @@ -189,6 +189,29 @@ public static function translationsConfigurationProvider(): iterable ]; } + /** + * @param array $config + */ + #[DataProvider('provideInstallerDoctrineMigrationsConfiguration')] + public function testInstallerDoctrineMigrationsConfiguration( + array $config, + bool $expectedParameterValue + ): void { + $this->load($config); + + $this->assertContainerBuilderHasParameter('ibexa.installer.doctrine_migrations.enabled', $expectedParameterValue); + } + + /** + * @return iterable, bool}> + */ + public static function provideInstallerDoctrineMigrationsConfiguration(): iterable + { + yield 'not configured' => [[], false]; + yield 'enabled' => [['installer' => ['doctrine_migrations' => true]], true]; + yield 'enabled (nested)' => [['installer' => ['doctrine_migrations' => ['enabled' => true]]], true]; + } + public function testImageMagickConfigurationFilters(): void { if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { diff --git a/tests/integration/Core/Repository/ContentServiceTest.php b/tests/integration/Core/Repository/ContentServiceTest.php index 0ef2cf9f59..4b43fe226d 100644 --- a/tests/integration/Core/Repository/ContentServiceTest.php +++ b/tests/integration/Core/Repository/ContentServiceTest.php @@ -2469,6 +2469,19 @@ public function testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParamete $this->contentService->loadVersionInfoById($content->id, 2); } + /** + * @covers \Ibexa\Contracts\Core\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) + */ + public function testLoadVersionInfoByIdThrowsNotFoundExceptionForVersionZeroWhenCurrentVersionIsCached(): void + { + $content = $this->createContentVersion1(); + $this->contentService->loadVersionInfoById($content->id); + + $this->expectException(NotFoundException::class); + + $this->contentService->loadVersionInfoById($content->id, 0); + } + /** * Test for the loadContentByVersionInfo() method. */ @@ -2778,6 +2791,19 @@ public function testLoadContentThrowsNotFoundExceptionWithThirdParameter(): void $this->contentService->loadContent($content->id, null, 2); } + /** + * @covers \Ibexa\Contracts\Core\Repository\ContentService::loadContent($contentId, $languages, $versionNo) + */ + public function testLoadContentThrowsNotFoundExceptionForVersionZeroWhenCurrentVersionIsCached(): void + { + $content = $this->createContentVersion1(); + $this->contentService->loadContent($content->id); + + $this->expectException(NotFoundException::class); + + $this->contentService->loadContent($content->id, null, 0); + } + /** * Test for the loadContentByRemoteId() method. */ diff --git a/tests/lib/Persistence/Cache/ContentHandlerTest.php b/tests/lib/Persistence/Cache/ContentHandlerTest.php index ec0072bc25..c7000144a5 100644 --- a/tests/lib/Persistence/Cache/ContentHandlerTest.php +++ b/tests/lib/Persistence/Cache/ContentHandlerTest.php @@ -105,6 +105,7 @@ public static function providerForCachedLoadMethodsHit(): array ['load', [2, 1], 'ibx-c-2-1-' . ContentHandler::ALL_TRANSLATIONS_KEY, null, null, [['content', [], true]], ['ibx-c'], $content], ['load', [2, 1, ['eng-GB', 'eng-US']], 'ibx-c-2-1-eng-GB|eng-US', null, null, [['content', [], true]], ['ibx-c'], $content], ['load', [2], 'ibx-c-2-' . ContentHandler::ALL_TRANSLATIONS_KEY, null, null, [['content', [], true]], ['ibx-c'], $content], + ['load', [2, 0], 'ibx-c-2-0-' . ContentHandler::ALL_TRANSLATIONS_KEY, null, null, [['content', [], true]], ['ibx-c'], $content], ['load', [2, null, ['eng-GB', 'eng-US']], 'ibx-c-2-eng-GB|eng-US', null, null, [['content', [], true]], ['ibx-c'], $content], ['loadContentList', [[2]], 'ibx-c-2-' . ContentHandler::ALL_TRANSLATIONS_KEY, null, null, [['content', [], true]], ['ibx-c'], [2 => $content], true], ['loadContentList', [[5], ['eng-GB', 'eng-US']], 'ibx-c-5-eng-GB|eng-US', null, null, [['content', [], true]], ['ibx-c'], [5 => $content], true], @@ -114,6 +115,7 @@ public static function providerForCachedLoadMethodsHit(): array ['loadRelation', [66], 'ibx-re-66', null, null, [['relation', [66], true]], ['ibx-re-66'], new SPIRelation()], ['loadVersionInfo', [2, 1], 'ibx-cvi-2-1', null, null, [['content_version_info', [2], true]], ['ibx-cvi-2'], $version], ['loadVersionInfo', [2], 'ibx-cvi-2', null, null, [['content_version_info', [2], true]], ['ibx-cvi-2'], $version], + ['loadVersionInfo', [2, 0], 'ibx-cvi-2-0', null, null, [['content_version_info', [2], true]], ['ibx-cvi-2'], $version], ['listVersions', [2], 'ibx-c-2-vl', null, null, [['content_version_list', [2], true]], ['ibx-c-2-vl'], [$version]], ['loadVersionInfoList', [[2]], 'ibx-cvi-2', null, null, [['content_version_info', [], true]], ['ibx-cvi'], [2 => $version], true], ];