Skip to content
Merged
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
25 changes: 10 additions & 15 deletions src/bundle/Core/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ private function addUITranslationsSection(ArrayNodeDefinition $rootNode): void
* <code>
* ibexa:
* installer:
* schema_builder_event:
* enabled: true
* doctrine_migrations: true
* </code>
*
* @param ArrayNodeDefinition $rootNode
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 17 additions & 18 deletions src/bundle/RepositoryInstaller/Installer/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CoreInstaller extends DbBasedInstaller implements Installer

private DbPlatformFactoryInterface $dbPlatformFactory;

private bool $schemaBuilderEventEnabled;
private bool $doctrineMigrationsEnabled;

private ?TaggedMigrationsRunner $taggedMigrationsRunner;

Expand All @@ -54,15 +54,15 @@ public function __construct(
SchemaBuilderInterface $schemaBuilder,
SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass,
DbPlatformFactoryInterface $dbPlatformFactory,
bool $schemaBuilderEventEnabled,
bool $doctrineMigrationsEnabled,
?TaggedMigrationsRunner $taggedMigrationsRunner = null
) {
parent::__construct($db);

$this->schemaBuilder = $schemaBuilder;
$this->schemaAssetsFilterBypass = $schemaAssetsFilterBypass;
$this->dbPlatformFactory = $dbPlatformFactory;
$this->schemaBuilderEventEnabled = $schemaBuilderEventEnabled;
$this->doctrineMigrationsEnabled = $doctrineMigrationsEnabled;
$this->taggedMigrationsRunner = $taggedMigrationsRunner;
}

Expand All @@ -77,31 +77,30 @@ 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;
}

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.'
);
Expand Down Expand Up @@ -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'));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
5 changes: 5 additions & 0 deletions src/contracts/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<int, string>|null $fieldIdentifiersToValidate List of field identifiers for partial validation or null
* for case of full validation. Empty identifiers array is equal to no validation.
Expand All @@ -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<int, string> $translations List of language codes of translations which will be included
* in a published version.
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 @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,29 @@ public static function translationsConfigurationProvider(): iterable
];
}

/**
* @param array<string, mixed> $config
*/
#[DataProvider('provideInstallerDoctrineMigrationsConfiguration')]
public function testInstallerDoctrineMigrationsConfiguration(
array $config,
bool $expectedParameterValue
): void {
$this->load($config);

$this->assertContainerBuilderHasParameter('ibexa.installer.doctrine_migrations.enabled', $expectedParameterValue);
}

/**
* @return iterable<string, array{array<string, mixed>, 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'])) {
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/Core/Repository/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/Persistence/Cache/ContentHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
];
Expand Down
Loading