From dc0feb1f5180947aadbc5d659603a49c466c4dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 19 Oct 2026 14:13:50 +0200 Subject: [PATCH 1/3] IBX-11939: Replaced `ibexa.installer.schema_builder_event` with an opt-in `ibexa.installer.doctrine_migrations` (#892) --- phpunit.xml | 2 +- .../DependencyInjection/Configuration.php | 25 ++++++------- .../IbexaCoreExtension.php | 4 +-- .../DoctrineMigrationsSchemaHook.php | 4 +-- .../Installer/CoreInstaller.php | 35 +++++++++---------- .../Resources/config/services.yml | 2 +- .../IbexaCoreExtensionTest.php | 24 +++++++++++++ 7 files changed, 57 insertions(+), 39 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 86124fd431..23c0c440e1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,7 +11,7 @@ > - + diff --git a/src/bundle/Core/DependencyInjection/Configuration.php b/src/bundle/Core/DependencyInjection/Configuration.php index 5d16ca7111..8947f0adec 100644 --- a/src/bundle/Core/DependencyInjection/Configuration.php +++ b/src/bundle/Core/DependencyInjection/Configuration.php @@ -574,8 +574,7 @@ private function addUITranslationsSection($rootNode): ArrayNodeDefinition * * ibexa: * installer: - * schema_builder_event: - * enabled: true + * doctrine_migrations: true * * * @param ArrayNodeDefinition $rootNode @@ -585,20 +584,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 afcd6809e0..5030ff2303 100644 --- a/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php +++ b/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php @@ -358,8 +358,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 61f580b158..e14b16633f 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 901a5d490c..04d407d496 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -34,43 +34,42 @@ class CoreInstaller extends DbBasedInstaller implements Installer /** @var SchemaBuilderInterface */ protected $schemaBuilder; - private bool $schemaBuilderEventEnabled; + private bool $doctrineMigrationsEnabled; private ?TaggedMigrationsRunner $taggedMigrationsRunner; public function __construct( Connection $db, SchemaBuilderInterface $schemaBuilder, - bool $schemaBuilderEventEnabled, + bool $doctrineMigrationsEnabled, ?TaggedMigrationsRunner $taggedMigrationsRunner = null ) { parent::__construct($db); $this->schemaBuilder = $schemaBuilder; - $this->schemaBuilderEventEnabled = $schemaBuilderEventEnabled; + $this->doctrineMigrationsEnabled = $doctrineMigrationsEnabled; $this->taggedMigrationsRunner = $taggedMigrationsRunner; } /** * 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 DBALException - * @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; @@ -78,7 +77,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.' ); @@ -164,18 +163,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 DBALException * @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 e7e1d58400..9f9b1f283b 100644 --- a/src/bundle/RepositoryInstaller/Resources/config/services.yml +++ b/src/bundle/RepositoryInstaller/Resources/config/services.yml @@ -27,7 +27,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/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php b/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php index 6ff75099d5..c0527424fb 100644 --- a/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php +++ b/tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php @@ -189,6 +189,30 @@ public function translationsConfigurationProvider(): iterable ]; } + /** + * @dataProvider provideInstallerDoctrineMigrationsConfiguration + * + * @param array $config + */ + public function testInstallerDoctrineMigrationsConfiguration( + array $config, + bool $expectedParameterValue + ): void { + $this->load($config); + + $this->assertContainerBuilderHasParameter('ibexa.installer.doctrine_migrations.enabled', $expectedParameterValue); + } + + /** + * @return iterable, bool}> + */ + public 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() { if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { From 63a3931cd1a89deb0b5299312e8f343b1bfc9578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Nowak?= Date: Tue, 20 Oct 2026 08:04:46 +0200 Subject: [PATCH 2/3] IBX-12861: Fixed cache keys of content and version info loaded with version number 0 (#893) The persistence cache built the key suffix with a falsy check, so version 0 shared the key of the current version: it returned the current version on a warm cache and threw NotFound on a cold one. Only `null` now maps to the current version; keys for `null` and positive version numbers are unchanged. Co-authored-by: Claude Opus 5.5 --- src/lib/Persistence/Cache/ContentHandler.php | 4 +-- .../Core/Repository/ContentServiceTest.php | 26 +++++++++++++++++++ .../Persistence/Cache/ContentHandlerTest.php | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/Persistence/Cache/ContentHandler.php b/src/lib/Persistence/Cache/ContentHandler.php index 9b2ac098e1..551d757674 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/integration/Core/Repository/ContentServiceTest.php b/tests/integration/Core/Repository/ContentServiceTest.php index bf9a27003c..9982879fb1 100644 --- a/tests/integration/Core/Repository/ContentServiceTest.php +++ b/tests/integration/Core/Repository/ContentServiceTest.php @@ -2726,6 +2726,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. * @@ -3059,6 +3072,19 @@ public function testLoadContentThrowsNotFoundExceptionWithThirdParameter() $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 371a3b8770..b4c0244f2f 100644 --- a/tests/lib/Persistence/Cache/ContentHandlerTest.php +++ b/tests/lib/Persistence/Cache/ContentHandlerTest.php @@ -107,6 +107,7 @@ public 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], @@ -116,6 +117,7 @@ public 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], ]; From 705e088017ccc96296077744914a65fb16e184ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Nowak?= Date: Tue, 20 Oct 2026 08:52:34 +0200 Subject: [PATCH 3/3] IBX-12861: Declared exceptions thrown by ContentService draft and publish methods (#895) Co-authored-by: Claude Opus 5.5 --- src/contracts/Repository/ContentService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/contracts/Repository/ContentService.php b/src/contracts/Repository/ContentService.php index d81d760728..ce1298f472 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.