Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
828bbc7
IBX-11939: Moved content and version languages from the bitmask to jo…
Steveb-p Nov 6, 2026
51f5a0f
IBX-11939: Added constants for the content translation table names
Steveb-p Nov 12, 2026
0c5ff95
IBX-11939: Made the language translation commands invokable
Steveb-p Nov 12, 2026
0299c11
IBX-11939: Typed FixtureImporter's constant and promoted its properties
Steveb-p Nov 12, 2026
b3a1968
IBX-11939: Moved the always_available backfill into the chunked Backf…
Steveb-p Nov 12, 2026
96e8ee5
IBX-11939: Covered always_available in the language translation commands
Steveb-p Nov 12, 2026
f2e43be
IBX-11939: Chunked the URL alias translations backfill by id
Steveb-p Nov 12, 2026
dbf1e50
IBX-11939: Deleted a translation only from versions that keep another…
Steveb-p Nov 12, 2026
dbb28fb
IBX-11939: Joined the version languages in the Filter instead of load…
Steveb-p Nov 12, 2026
20b4faa
IBX-11939: Loaded the version languages in the content handlers and p…
Steveb-p Nov 12, 2026
7ff1c45
IBX-11939: Removed the leftover Language\Gateway mock from the search…
Steveb-p Nov 13, 2026
5f50b0b
IBX-13142: Looked up the language table past the schema assets filter…
Steveb-p Nov 13, 2026
8a39622
IBX-13142: Fed the Mapper tests the version languages their fixtures'…
Steveb-p Nov 13, 2026
04e7e78
IBX-13142: Removed outdated comments from the language join table code
Steveb-p Nov 13, 2026
178bee7
IBX-13142: Replaced the deprecated introspectTable() calls with intro…
Steveb-p Nov 13, 2026
e3183ab
IBX-13142: Removed the language table name lookup, as the table keeps…
Steveb-p Nov 13, 2026
6957c1f
IBX-13142: Dropped the schema assets filter bypass from the language …
Steveb-p Nov 17, 2026
844b34a
IBX-11939: Moved the legacy search engine off the language bitmask
Steveb-p Nov 6, 2026
9c5d93f
IBX-13142: Backfilled the search word links in chunks, also on a rerun
Steveb-p Nov 13, 2026
36f7baf
IBX-13142: Matched the field language with a single COALESCE in legac…
Steveb-p Nov 13, 2026
6315ec2
IBX-13142: Selected the matched translation with the legacy search ro…
Steveb-p Nov 13, 2026
29b9ea8
IBX-13142: Built the content translation condition in one place in le…
Steveb-p Nov 13, 2026
a111c1a
IBX-13142: Promoted the constructor properties and declared strict ty…
Steveb-p Nov 13, 2026
cb447f0
IBX-13142: Replaced the deprecated introspectTable() calls with intro…
Steveb-p Nov 13, 2026
eabc420
IBX-13142: Dropped strict types from the word indexer gateway
Steveb-p Nov 17, 2026
923066a
IBX-11939: Moved URL aliases off the language bitmask
Steveb-p Nov 6, 2026
e6e2fc2
IBX-11939: Covered is_always_available in the language translation co…
Steveb-p Nov 13, 2026
1e0ee7a
IBX-11939: Chunked the URL alias always-available backfill by id
Steveb-p Nov 13, 2026
0a2ce86
IBX-13142: Loaded the URL alias languages for all returned rows in on…
Steveb-p Nov 13, 2026
b743220
IBX-13142: Restored swapped custom aliases only in the languages they…
Steveb-p Nov 13, 2026
c8cdb10
IBX-13142: Renamed the URL alias is_always_available column to always…
Steveb-p Nov 13, 2026
2ac98dc
IBX-13142: Promoted the constructor properties and declared strict ty…
Steveb-p Nov 13, 2026
35889e4
IBX-13142: Replaced the deprecated introspectTable() calls with intro…
Steveb-p Nov 13, 2026
5337aad
IBX-11939: Moved content types off the language bitmask
Steveb-p Nov 6, 2026
88d8e3b
IBX-13142: Loaded the content type translations in the handler instea…
Steveb-p Nov 13, 2026
cb5511f
IBX-13142: Ordered the content type language codes by language id
Steveb-p Nov 13, 2026
161323d
IBX-13142: Promoted the constructor properties and declared strict ty…
Steveb-p Nov 13, 2026
5ebe47a
IBX-11939: Moved object states off MaskGenerator
Steveb-p Nov 6, 2026
7e1345d
IBX-11939: Removed the language bitmask
Steveb-p Nov 6, 2026
d30feae
IBX-11939: Refused to drop the language masks while always_available …
Steveb-p Nov 12, 2026
4042f7e
IBX-13142: Moved the language mask drop to the end of the migration s…
Steveb-p Nov 13, 2026
1dbe831
IBX-13142: Stripped the always-available bit by each row's own langua…
Steveb-p Nov 13, 2026
f7568de
IBX-13142: Dropped the URL alias text and language index without a re…
Steveb-p Nov 13, 2026
7875fba
IBX-13142: Deleted a language's legacy search index rows with it inst…
Steveb-p Nov 13, 2026
8c057bb
IBX-13142: Stripped the legacy bit from fixtures only for ids that ar…
Steveb-p Nov 13, 2026
6c6a886
IBX-13142: Checked the translations and an alias of the content creat…
Steveb-p Nov 13, 2026
4806861
IBX-13142: Declared strict types in the content gateway, object state…
Steveb-p Nov 13, 2026
45d7109
IBX-13142: Replaced the deprecated introspectTable() calls with intro…
Steveb-p Nov 13, 2026
9d53ffe
IBX-13142: Added a test running the whole language bitmask upgrade on…
Steveb-p Nov 13, 2026
fa90b80
IBX-13142: Typed the language gateway constants
Steveb-p Nov 13, 2026
153157f
IBX-13142: Dropped the schema assets filter bypass from the language …
Steveb-p Nov 17, 2026
dd5f1d3
IBX-13142: Matched the name and field languages exactly in the Filter
Steveb-p Nov 17, 2026
8bb44d5
IBX-13142: Dropped the language mask mentions from the comments
Steveb-p Nov 17, 2026
8682b71
IBX-13142: Ran the language bitmask upgrade test on MySQL and Postgre…
Steveb-p Nov 13, 2026
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
"integration": [
"Composer\\Config::disableProcessTimeout",
"phpunit -c phpunit-integration-legacy.xml",
"phpunit -c phpunit-integration.xml"
"phpunit -c phpunit-integration.xml",
"phpunit -c phpunit-migrations.xml"
],
"test-integration-solr": "phpunit -c phpunit-integration-legacy-solr.xml",
"test": [
Expand Down
262 changes: 152 additions & 110 deletions data/mysql/cleandata.sql

Large diffs are not rendered by default.

288 changes: 165 additions & 123 deletions data/postgresql/cleandata.sql

Large diffs are not rendered by default.

224 changes: 1 addition & 223 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions phpunit-migrations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<phpunit
backupGlobals="false"
bootstrap="bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
failOnWarning="true"
failOnNotice="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnTestsThatTriggerDeprecations="true"
failOnDeprecation="true"
>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="migrations_upgrade">
<directory>tests/bundle/RepositoryInstaller/Migration/Upgrade</directory>
</testsuite>
</testsuites>
<source baseline="phpunit.baseline.xml" ignoreIndirectDeprecations="true" ignoreSuppressionOfDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
<extensions>
<bootstrap class="Symfony\Bridge\PhpUnit\SymfonyExtension"/>
</extensions>
</phpunit>
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</testsuite>
<testsuite name="bundle_installer">
<directory>tests/bundle/RepositoryInstaller</directory>
<exclude>tests/bundle/RepositoryInstaller/Migration/Upgrade</exclude>
</testsuite>
<testsuite name="bundle_io">
<directory>tests/bundle/IO</directory>
Expand Down
274 changes: 274 additions & 0 deletions src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Command;

use Doctrine\DBAL\Connection;
use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformName;
use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformResolver;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Backfills "always_available" and the language translation tables from the legacy language bitmask columns.
*/
#[AsCommand(
name: 'ibexa:languages:backfill-translations',
description: 'Backfills "always_available" and the language translation tables from the legacy language bitmask columns',
help: <<<'EOT'
The command <info>%command.name%</info> populates "ibexa_content_translation",
"ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" from the existing
"language_mask"/"lang_mask" bitmask columns, and sets "always_available" on "ibexa_content",
"ibexa_content_version" and "ibexa_url_alias_ml" from bit 0 of the mask. It is idempotent -
already-backfilled rows are skipped - so it is safe to re-run, including after
a partial/interrupted run.

Run <info>ibexa:languages:verify-translations</info> afterward to confirm the backfill is complete.
EOT,
)]
final class BackfillLanguageTranslationsCommand
{
private const string LANGUAGE_TABLE = 'ibexa_content_language';

private const int DEFAULT_BATCH_SIZE = 5000;

private const string TABLE_CONTENT = 'content';
private const string TABLE_CONTENT_VERSION = 'content_version';
private const string TABLE_URL_ALIAS = 'url_alias';
private const string TABLE_ALL = 'all';

private const array VALID_TABLES = [
self::TABLE_CONTENT,
self::TABLE_CONTENT_VERSION,
self::TABLE_URL_ALIAS,
];

public function __construct(private readonly Connection $connection) {}

public function __invoke(
OutputInterface $output,
#[Option(description: 'Which table to backfill: one of "content", "content_version", "url_alias", or "all" for all of them.', shortcut: 't')]
string $table = self::TABLE_ALL,
#[Option(description: 'Number of primary-key values processed per batch.')]
int $batchSize = self::DEFAULT_BATCH_SIZE,
#[Option(description: 'Report how many rows would be inserted per batch without writing anything.')]
bool $dryRun = false,
): int {
if ($batchSize < 1) {
throw new InvalidArgumentException('batch-size', 'must be a positive integer.');
}

$tables = $table === self::TABLE_ALL ? self::VALID_TABLES : [$table];
foreach ($tables as $singleTable) {
if (!in_array($singleTable, self::VALID_TABLES, true)) {
throw new InvalidArgumentException(
'table',
sprintf(
'"%s" is not one of "%s" or "%s".',
$singleTable,
implode('", "', self::VALID_TABLES),
self::TABLE_ALL
)
);
}
}

foreach ($tables as $singleTable) {
$this->backfillTable($singleTable, $batchSize, $dryRun, $output);
}

return Command::SUCCESS;
}

private function backfillTable(
string $table,
int $batchSize,
bool $dryRun,
OutputInterface $output
): void {
[$sourceTable, $pkColumn, $maskColumn, $insertSql, $alwaysAvailableColumn] = match ($table) {
self::TABLE_CONTENT => [
'ibexa_content',
'id',
'language_mask',
'INSERT %s INTO ibexa_content_translation (content_id, language_id)
SELECT c.id, l.id FROM ibexa_content c
JOIN %s l ON (c.language_mask & l.id) = l.id
WHERE c.id BETWEEN :from AND :to %s',
'always_available',
],
self::TABLE_CONTENT_VERSION => [
'ibexa_content_version',
'id',
'language_mask',
'INSERT %s INTO ibexa_content_version_translation (content_version_id, language_id)
SELECT v.id, l.id FROM ibexa_content_version v
JOIN %s l ON (v.language_mask & l.id) = l.id
WHERE v.id BETWEEN :from AND :to %s',
'always_available',
],
self::TABLE_URL_ALIAS => [
'ibexa_url_alias_ml',
'id',
'lang_mask',
'INSERT %s INTO ibexa_url_alias_ml_translation (parent, text_md5, language_id)
SELECT u.parent, u.text_md5, l.id FROM ibexa_url_alias_ml u
JOIN %s l ON (u.lang_mask & l.id) = l.id
WHERE u.id BETWEEN :from AND :to %s',
'always_available',
],
default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."),
};

if (!$this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn)) {
$output->writeln("<info>{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill.</info>");

return;
}

$languageTable = self::LANGUAGE_TABLE;

// MIN()/MAX() rather than COUNT()-based emptiness + a hardcoded lower bound of 1: some of
// these tables (e.g. "ibexa_url_alias_ml" for root-level aliases) legitimately use 0 as a
// valid primary-key value, so neither "MAX() === 0" nor an assumed start of 1 is safe here.
$range = $this->connection->fetchAssociative(
"SELECT MIN({$pkColumn}) AS min_id, MAX({$pkColumn}) AS max_id FROM {$sourceTable}"
);
if ($range === false || $range['min_id'] === null) {
$output->writeln("<info>{$sourceTable} is empty, nothing to backfill.</info>");

return;
}

$minId = (int)$range['min_id'];
$maxId = (int)$range['max_id'];

$output->writeln("<info>Backfilling {$sourceTable} ({$pkColumn} {$minId}..{$maxId}, batch size {$batchSize})...</info>");

$insertSql = sprintf($insertSql, $this->insertIgnoreKeyword(), $languageTable, $this->onConflictClause());
$alwaysAvailableMismatch = "{$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)";
$totalInserted = 0;
$totalFlagged = 0;

for ($from = $minId; $from <= $maxId; $from += $batchSize) {
$to = min($from + $batchSize - 1, $maxId);

if ($dryRun) {
$inserted = (int)$this->connection->fetchOne(
$this->buildDryRunCountSql($table, $languageTable),
['from' => $from, 'to' => $to]
);
$flagged = (int)$this->connection->fetchOne(
"SELECT COUNT(*) FROM {$sourceTable} WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}",
['from' => $from, 'to' => $to]
);
} else {
$inserted = $this->connection->executeStatement($insertSql, ['from' => $from, 'to' => $to]);
$flagged = $this->connection->executeStatement(
"UPDATE {$sourceTable} SET {$alwaysAvailableColumn} = (({$maskColumn} & 1) = 1)
WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}",
['from' => $from, 'to' => $to]
);
}

$totalInserted += $inserted;
$totalFlagged += $flagged;
$output->writeln(
sprintf(' %d..%d: %d row(s), %d always-available flag(s)%s', $from, $to, $inserted, $flagged, $dryRun ? ' (dry-run)' : ''),
OutputInterface::VERBOSITY_VERBOSE
);
}

$output->writeln(sprintf(
'<info>%s%s: %d row(s) %s, %d always-available flag(s) %s.</info>',
$dryRun ? '[dry-run] ' : '',
$sourceTable,
$totalInserted,
$dryRun ? 'would be inserted' : 'inserted',
$totalFlagged,
$dryRun ? 'would be updated' : 'updated'
));
}

/**
* Mirrors the real INSERT's idempotency (via insertIgnoreKeyword()/onConflictClause()) with an
* explicit "NOT EXISTS" against the target translation table: without it, re-running
* `--dry-run` after a prior (partial or complete) backfill would count every mask-derived pair
* again, including ones already present, and report them as "would be inserted" when a real run
* would actually leave them untouched.
*/
private function buildDryRunCountSql(
string $table,
string $languageTable
): string {
return match ($table) {
self::TABLE_CONTENT => "SELECT COUNT(*) FROM ibexa_content c
JOIN {$languageTable} l ON (c.language_mask & l.id) = l.id
WHERE c.id BETWEEN :from AND :to
AND NOT EXISTS (
SELECT 1 FROM ibexa_content_translation t
WHERE t.content_id = c.id AND t.language_id = l.id
)",
self::TABLE_CONTENT_VERSION => "SELECT COUNT(*) FROM ibexa_content_version v
JOIN {$languageTable} l ON (v.language_mask & l.id) = l.id
WHERE v.id BETWEEN :from AND :to
AND NOT EXISTS (
SELECT 1 FROM ibexa_content_version_translation t
WHERE t.content_version_id = v.id AND t.language_id = l.id
)",
self::TABLE_URL_ALIAS => "SELECT COUNT(*) FROM ibexa_url_alias_ml u
JOIN {$languageTable} l ON (u.lang_mask & l.id) = l.id
WHERE u.id BETWEEN :from AND :to
AND NOT EXISTS (
SELECT 1 FROM ibexa_url_alias_ml_translation t
WHERE t.parent = u.parent AND t.text_md5 = u.text_md5 AND t.language_id = l.id
)",
default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."),
};
}

private function insertIgnoreKeyword(): string
{
return match ($this->resolvePlatformName()) {
DatabasePlatformName::MySQL => 'IGNORE',
DatabasePlatformName::SQLite => 'OR IGNORE',
DatabasePlatformName::PostgreSQL => '',
};
}

/**
* Appended after the SELECT to make the insert idempotent on platforms that don't support
* "INSERT IGNORE" (MySQL is handled via insertIgnoreKeyword() instead, since its "ON DUPLICATE
* KEY" clause needs different syntax for an INSERT ... SELECT).
*/
private function onConflictClause(): string
{
return match ($this->resolvePlatformName()) {
DatabasePlatformName::PostgreSQL => 'ON CONFLICT DO NOTHING',
DatabasePlatformName::SQLite => '', // OR IGNORE is part of the INSERT keyword, not a trailing clause
DatabasePlatformName::MySQL => '',
};
}

private function resolvePlatformName(): DatabasePlatformName
{
$platform = $this->connection->getDatabasePlatform();
$name = DatabasePlatformResolver::resolveName($platform);
if ($name === null) {
throw new InvalidArgumentException(
'platform',
sprintf('Unsupported database platform: %s', $platform::class)
);
}

return $name;
}
}
Loading
Loading