From 828bbc79672f6659551baee1e341446492bdf503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 19:34:26 +0100 Subject: [PATCH 01/54] IBX-11939: Moved content and version languages from the bitmask to join tables Adds ibexa_content_translation and ibexa_content_version_translation (and ibexa_url_alias_ml_translation, which the same migration creates) and an always_available column on ibexa_content and ibexa_content_version, backfills them from the language masks, and switches the content and location gateways, the content mapper and the Filter to them. The content gateway keeps writing the masks and the always-available bit of the field and name language ids, which the remaining readers still use until the bitmask is removed. Adds the ibexa:languages:backfill-translations and ibexa:languages:verify-translations commands, and the new columns and rows to cleandata.sql. FixtureImporter fills the join tables for fixtures that still carry masks, and creates its SchemaAssetsFilterBypass itself when it isn't given one. --- data/mysql/cleandata.sql | 119 +++++-- data/postgresql/cleandata.sql | 119 +++++-- phpstan-baseline.neon | 6 - .../BackfillLanguageTranslationsCommand.php | 322 ++++++++++++++++++ .../VerifyLanguageTranslationsCommand.php | 316 +++++++++++++++++ .../Resources/config/doctrine_migrations.php | 15 + src/bundle/Core/Resources/config/services.yml | 12 + .../config/storage/legacy/schema.yaml | 30 ++ ...ContentAlwaysAvailableColumnsMigration.php | 107 ++++++ .../AddLanguageTranslationTablesMigration.php | 147 ++++++++ .../BackfillLanguageTranslationsMigration.php | 177 ++++++++++ .../add-language-translation-tables-mysql.sql | 21 ++ ...language-translation-tables-postgresql.sql | 24 ++ ...add-language-translation-tables-sqlite.sql | 42 +++ .../Persistence/Fixture/FixtureImporter.php | 299 +++++++++++++++- .../Test/Repository/SetupFactory/Legacy.php | 2 +- .../Content/Gateway/DoctrineDatabase.php | 260 ++++++++++++-- .../Gateway/DoctrineDatabase/QueryBuilder.php | 4 +- .../Legacy/Content/Language/Gateway.php | 21 ++ .../Language/Gateway/DoctrineDatabase.php | 65 ++++ .../Language/Gateway/ExceptionConversion.php | 18 + .../Location/Gateway/DoctrineDatabase.php | 57 ++-- src/lib/Persistence/Legacy/Content/Mapper.php | 75 ++-- .../Content/LanguageCodeQueryBuilder.php | 18 +- .../Content/Doctrine/DoctrineGateway.php | 62 +++- .../Mapper/DoctrineGatewayDataMapper.php | 17 +- .../Location/Doctrine/DoctrineGateway.php | 2 +- .../storage_engines/legacy/content.yml | 1 + .../storage_engines/legacy/filter.yaml | 2 +- .../storage_engines/legacy/location.yml | 2 +- ...ackfillLanguageTranslationsCommandTest.php | 276 +++++++++++++++ .../Resources/services/fixture-services.yaml | 1 + .../BinaryBaseStorageGatewayTest.php | 3 +- tests/integration/Core/TestKernel.php | 13 + .../UserStorageGatewayTestCase.php | 3 +- .../Content/Gateway/DoctrineDatabaseTest.php | 43 +++ .../Location/Gateway/DoctrineDatabaseTest.php | 38 ++- .../Gateway/DoctrineDatabaseTrashTest.php | 2 +- .../Persistence/Legacy/Content/MapperTest.php | 62 +++- .../Content/UrlAlias/UrlAliasHandlerTest.php | 2 +- .../_fixtures/extract_content_from_rows.php | 54 +-- ...ct_content_from_rows_multiple_versions.php | 210 ++++++------ .../extract_content_from_rows_result.php | 82 ++++- ...rsion_info_from_rows_multiple_versions.php | 14 +- ...nguageCodeQueryBuilderQueryBuilderTest.php | 4 +- ...alOperatorQueryBuilderQueryBuilderTest.php | 8 +- tests/lib/Persistence/Legacy/TestCase.php | 4 +- .../Legacy/Content/HandlerContentSortTest.php | 2 + .../Legacy/Content/HandlerContentTest.php | 2 + 49 files changed, 2844 insertions(+), 341 deletions(-) create mode 100644 src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php create mode 100644 src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php create mode 100644 src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php create mode 100644 src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php create mode 100644 src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-mysql.sql create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-postgresql.sql create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-sqlite.sql create mode 100644 tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php diff --git a/data/mysql/cleandata.sql b/data/mysql/cleandata.sql index 1443e8283a..bdd26ad126 100644 --- a/data/mysql/cleandata.sql +++ b/data/mysql/cleandata.sql @@ -84,19 +84,33 @@ VALUES (1031216928, 14, 1, 1033922106, 14, 'Content'), (1031216941, 14, 2, 1033922113, 14, 'Users'), (1032009743, 14, 3, 1033922120, 14, 'Media'); -INSERT INTO `ibexa_content` (`content_type_id`, `current_version`, `id`, `initial_language_id`, `language_mask`, `modified`, `name`, `owner_id`, `published`, `remote_id`, `section_id`, `status`) -VALUES (1,9,1,2,3,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), - (3,1,4,2,3,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), - (4,2,10,2,3,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), - (3,1,11,2,3,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), - (3,1,12,2,3,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), - (3,1,13,2,3,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), - (4,3,14,2,3,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), - (1,1,41,2,3,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), - (3,1,42,2,3,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), - (1,1,49,2,3,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), - (1,1,50,2,3,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), - (1,1,51,2,3,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); +INSERT INTO `ibexa_content` (`content_type_id`, `current_version`, `id`, `initial_language_id`, `language_mask`, `always_available`, `modified`, `name`, `owner_id`, `published`, `remote_id`, `section_id`, `status`) +VALUES (1,9,1,2,3,1,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), + (3,1,4,2,3,1,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), + (4,2,10,2,3,1,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), + (3,1,11,2,3,1,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), + (3,1,12,2,3,1,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), + (3,1,13,2,3,1,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), + (4,3,14,2,3,1,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), + (1,1,41,2,3,1,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), + (3,1,42,2,3,1,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), + (1,1,49,2,3,1,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), + (1,1,50,2,3,1,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), + (1,1,51,2,3,1,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); + +INSERT INTO `ibexa_content_translation` (`content_id`, `language_id`) +VALUES (1,2), + (4,2), + (10,2), + (11,2), + (12,2), + (13,2), + (14,2), + (41,2), + (42,2), + (49,2), + (50,2), + (51,2); INSERT INTO `ibexa_content_field` (`attribute_original_id`, `content_type_field_definition_id`, `contentobject_id`, `data_float`, `data_int`, `data_text`, `data_type_string`, `id`, `language_code`, `language_id`, `sort_key_int`, `sort_key_string`, `version`) VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',3,0,'ibexa platform',9), @@ -169,19 +183,33 @@ VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96 (50,1,1,2,0,0,52,1081860720,52,43,'media/files','/1/43/52/',0,'0b113a208f7890f9ad3c24444ff5988c',9,1), (51,1,1,2,0,0,53,1081860720,53,43,'media/multimedia','/1/43/53/',0,'4f18b82c75f10aad476cae5adf98c11f',9,1); -INSERT INTO `ibexa_content_version` (`contentobject_id`, `created`, `creator_id`, `id`, `initial_language_id`, `language_mask`, `modified`, `status`, `user_id`, `version`, `workflow_event_pos`) -VALUES (4,0,14,4,2,3,0,1,0,1,1), - (11,1033920737,14,439,2,3,1033920746,1,0,1,0), - (12,1033920760,14,440,2,3,1033920775,1,0,1,0), - (13,1033920786,14,441,2,3,1033920794,1,0,1,0), - (41,1060695450,14,472,2,3,1060695457,1,0,1,0), - (42,1072180278,14,473,2,3,1072180330,1,0,1,0), - (10,1072180337,14,474,2,3,1072180405,1,0,2,0), - (49,1080220181,14,488,2,3,1080220197,1,0,1,0), - (50,1080220211,14,489,2,3,1080220220,1,0,1,0), - (51,1080220225,14,490,2,3,1080220233,1,0,1,0), - (14,1301061783,14,499,2,3,1301062024,1,0,3,0), - (1,1448889045,14,506,2,3,1448889046,1,0,9,0); +INSERT INTO `ibexa_content_version` (`contentobject_id`, `created`, `creator_id`, `id`, `initial_language_id`, `language_mask`, `always_available`, `modified`, `status`, `user_id`, `version`, `workflow_event_pos`) +VALUES (4,0,14,4,2,3,1,0,1,0,1,1), + (11,1033920737,14,439,2,3,1,1033920746,1,0,1,0), + (12,1033920760,14,440,2,3,1,1033920775,1,0,1,0), + (13,1033920786,14,441,2,3,1,1033920794,1,0,1,0), + (41,1060695450,14,472,2,3,1,1060695457,1,0,1,0), + (42,1072180278,14,473,2,3,1,1072180330,1,0,1,0), + (10,1072180337,14,474,2,3,1,1072180405,1,0,2,0), + (49,1080220181,14,488,2,3,1,1080220197,1,0,1,0), + (50,1080220211,14,489,2,3,1,1080220220,1,0,1,0), + (51,1080220225,14,490,2,3,1,1080220233,1,0,1,0), + (14,1301061783,14,499,2,3,1,1301062024,1,0,3,0), + (1,1448889045,14,506,2,3,1,1448889046,1,0,9,0); + +INSERT INTO `ibexa_content_version_translation` (`content_version_id`, `language_id`) +VALUES (4,2), + (439,2), + (440,2), + (441,2), + (472,2), + (473,2), + (474,2), + (488,2), + (489,2), + (490,2), + (499,2), + (506,2); INSERT INTO `ibexa_node_assignment` (`contentobject_id`, `contentobject_version`, `from_node_id`, `id`, `is_main`, `op_code`, `parent_node`, `parent_remote_id`, `remote_id`, `sort_field`, `sort_order`, `priority`, `is_hidden`) VALUES (8,2,0,4,1,2,5,'','0',1,1,0,0), @@ -280,9 +308,42 @@ VALUES ('nop:','nop',1,17,0,0,1,17,0,'media2','50e2736330de124f6edea9b008556fe6' ('eznode:51','eznode',1,32,0,0,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); INSERT INTO `ibexa_url_alias_ml_incr` (`id`) -VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), - (18), (19), (20), (21), (22), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), - (34), (35), (36), (37); +VALUES (1), + (2), + (3), + (4), + (5), + (6), + (7), + (8), + (9), + (10), + (11), + (12), + (13), + (14), + (15), + (16), + (17), + (18), + (19), + (20), + (21), + (22), + (24), + (25), + (26), + (27), + (28), + (29), + (30), + (31), + (32), + (33), + (34), + (35), + (36), + (37); INSERT INTO `ibexa_user` (`contentobject_id`, `email`, `login`, `password_hash`, `password_hash_type`) VALUES (10,'anonymous@link.invalid','anonymous','$2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC',7), diff --git a/data/postgresql/cleandata.sql b/data/postgresql/cleandata.sql index 88fb833efb..360dab6304 100644 --- a/data/postgresql/cleandata.sql +++ b/data/postgresql/cleandata.sql @@ -84,19 +84,33 @@ VALUES (1031216928, 14, 1, 1033922106, 14, 'Content'), (1031216941, 14, 2, 1033922113, 14, 'Users'), (1032009743, 14, 3, 1033922120, 14, 'Media'); -INSERT INTO "ibexa_content" ("content_type_id", "current_version", "id", "initial_language_id", "language_mask", "modified", "name", "owner_id", "published", "remote_id", "section_id", "status") -VALUES (1,9,1,2,3,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), - (3,1,4,2,3,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), - (4,2,10,2,3,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), - (3,1,11,2,3,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), - (3,1,12,2,3,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), - (3,1,13,2,3,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), - (4,3,14,2,3,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), - (1,1,41,2,3,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), - (3,1,42,2,3,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), - (1,1,49,2,3,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), - (1,1,50,2,3,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), - (1,1,51,2,3,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); +INSERT INTO "ibexa_content" ("content_type_id", "current_version", "id", "initial_language_id", "language_mask", "always_available", "modified", "name", "owner_id", "published", "remote_id", "section_id", "status") +VALUES (1,9,1,2,3,TRUE,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), + (3,1,4,2,3,TRUE,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), + (4,2,10,2,3,TRUE,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), + (3,1,11,2,3,TRUE,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), + (3,1,12,2,3,TRUE,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), + (3,1,13,2,3,TRUE,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), + (4,3,14,2,3,TRUE,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), + (1,1,41,2,3,TRUE,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), + (3,1,42,2,3,TRUE,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), + (1,1,49,2,3,TRUE,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), + (1,1,50,2,3,TRUE,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), + (1,1,51,2,3,TRUE,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); + +INSERT INTO "ibexa_content_translation" ("content_id", "language_id") +VALUES (1,2), + (4,2), + (10,2), + (11,2), + (12,2), + (13,2), + (14,2), + (41,2), + (42,2), + (49,2), + (50,2), + (51,2); INSERT INTO "ibexa_content_field" ("attribute_original_id", "content_type_field_definition_id", "contentobject_id", "data_float", "data_int", "data_text", "data_type_string", "id", "language_code", "language_id", "sort_key_int", "sort_key_string", "version") VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',3,0,'ibexa platform',9), @@ -169,19 +183,33 @@ VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96 (50,1,1,2,0,0,52,1081860720,52,43,'media/files','/1/43/52/',0,'0b113a208f7890f9ad3c24444ff5988c',9,1), (51,1,1,2,0,0,53,1081860720,53,43,'media/multimedia','/1/43/53/',0,'4f18b82c75f10aad476cae5adf98c11f',9,1); -INSERT INTO "ibexa_content_version" ("contentobject_id", "created", "creator_id", "id", "initial_language_id", "language_mask", "modified", "status", "user_id", "version", "workflow_event_pos") -VALUES (4,0,14,4,2,3,0,1,0,1,1), - (11,1033920737,14,439,2,3,1033920746,1,0,1,0), - (12,1033920760,14,440,2,3,1033920775,1,0,1,0), - (13,1033920786,14,441,2,3,1033920794,1,0,1,0), - (41,1060695450,14,472,2,3,1060695457,1,0,1,0), - (42,1072180278,14,473,2,3,1072180330,1,0,1,0), - (10,1072180337,14,474,2,3,1072180405,1,0,2,0), - (49,1080220181,14,488,2,3,1080220197,1,0,1,0), - (50,1080220211,14,489,2,3,1080220220,1,0,1,0), - (51,1080220225,14,490,2,3,1080220233,1,0,1,0), - (14,1301061783,14,499,2,3,1301062024,1,0,3,0), - (1,1448889045,14,506,2,3,1448889046,1,0,9,0); +INSERT INTO "ibexa_content_version" ("contentobject_id", "created", "creator_id", "id", "initial_language_id", "language_mask", "always_available", "modified", "status", "user_id", "version", "workflow_event_pos") +VALUES (4,0,14,4,2,3,TRUE,0,1,0,1,1), + (11,1033920737,14,439,2,3,TRUE,1033920746,1,0,1,0), + (12,1033920760,14,440,2,3,TRUE,1033920775,1,0,1,0), + (13,1033920786,14,441,2,3,TRUE,1033920794,1,0,1,0), + (41,1060695450,14,472,2,3,TRUE,1060695457,1,0,1,0), + (42,1072180278,14,473,2,3,TRUE,1072180330,1,0,1,0), + (10,1072180337,14,474,2,3,TRUE,1072180405,1,0,2,0), + (49,1080220181,14,488,2,3,TRUE,1080220197,1,0,1,0), + (50,1080220211,14,489,2,3,TRUE,1080220220,1,0,1,0), + (51,1080220225,14,490,2,3,TRUE,1080220233,1,0,1,0), + (14,1301061783,14,499,2,3,TRUE,1301062024,1,0,3,0), + (1,1448889045,14,506,2,3,TRUE,1448889046,1,0,9,0); + +INSERT INTO "ibexa_content_version_translation" ("content_version_id", "language_id") +VALUES (4,2), + (439,2), + (440,2), + (441,2), + (472,2), + (473,2), + (474,2), + (488,2), + (489,2), + (490,2), + (499,2), + (506,2); INSERT INTO "ibexa_node_assignment" ("contentobject_id", "contentobject_version", "from_node_id", "id", "is_main", "op_code", "parent_node", "parent_remote_id", "remote_id", "sort_field", "sort_order", "priority", "is_hidden") VALUES (8,2,0,4,1,2,5,'','0',1,1,0,0), @@ -280,9 +308,42 @@ VALUES ('nop:','nop',1,17,0,0,1,17,0,'media2','50e2736330de124f6edea9b008556fe6' ('eznode:51','eznode',1,32,0,0,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); INSERT INTO "ibexa_url_alias_ml_incr" ("id") -VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), - (18), (19), (20), (21), (22), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), - (34), (35), (36), (37); +VALUES (1), + (2), + (3), + (4), + (5), + (6), + (7), + (8), + (9), + (10), + (11), + (12), + (13), + (14), + (15), + (16), + (17), + (18), + (19), + (20), + (21), + (22), + (24), + (25), + (26), + (27), + (28), + (29), + (30), + (31), + (32), + (33), + (34), + (35), + (36), + (37); INSERT INTO "ibexa_user" ("contentobject_id", "email", "login", "password_hash", "password_hash_type") VALUES (10,'anonymous@link.invalid','anonymous','$2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC',7), diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c1f779ff0..b42edb33fb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11478,12 +11478,6 @@ parameters: count: 2 path: src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php - - - message: '#^Call to function is_int\(\) with 2\|int\<4, max\> will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: src/lib/Persistence/Legacy/Content/Mapper.php - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Mapper\:\:extractContentInfoFromRows\(\) has parameter \$rows with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php new file mode 100644 index 0000000000..3d219f54d7 --- /dev/null +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -0,0 +1,322 @@ +addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + sprintf( + 'Which table to backfill: one of "%s", or "%s" for all of them.', + implode('", "', self::VALID_TABLES), + self::TABLE_ALL + ), + self::TABLE_ALL + ) + ->addOption( + 'batch-size', + null, + InputOption::VALUE_OPTIONAL, + 'Number of primary-key values processed per batch.', + (string)self::DEFAULT_BATCH_SIZE + ) + ->addOption( + 'dry-run', + null, + InputOption::VALUE_NONE, + 'Report how many rows would be inserted per batch without writing anything.' + ) + ->setHelp( + <<%command.name% populates "ibexa_content_translation", +"ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" from the existing +"language_mask"/"lang_mask" bitmask columns. It is idempotent - already-backfilled rows are +skipped - so it is safe to re-run, including after a partial/interrupted run. + +Run ibexa:languages:verify-translations afterward to confirm the backfill is complete. +EOT + ); + } + + protected function execute( + InputInterface $input, + OutputInterface $output + ): int { + $table = $input->getOption('table'); + $batchSize = (int)$input->getOption('batch-size'); + $dryRun = (bool)$input->getOption('dry-run'); + + 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 self::SUCCESS; + } + + private function backfillTable( + string $table, + int $batchSize, + bool $dryRun, + OutputInterface $output + ): void { + [$sourceTable, $pkColumn, $maskColumn, $insertSql] = 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', + ], + 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', + ], + self::TABLE_URL_ALIAS => [ + 'ibexa_url_alias_ml', + 'parent', + '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.parent BETWEEN :from AND :to %s', + ], + default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), + }; + + // The mask column is dropped once a schema has fully completed the language bitmask + // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never + // had it to begin with - in both cases there is nothing left to backfill, and the mask-based + // queries below would otherwise fail outright with "no such column"/"undefined column". + $schemaManager = $this->connection->createSchemaManager(); + if (!$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn)) { + $output->writeln("{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill."); + + return; + } + + $languageTable = $this->resolveLanguageTableName($schemaManager); + + // 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("{$sourceTable} is empty, nothing to backfill."); + + return; + } + + $minId = (int)$range['min_id']; + $maxId = (int)$range['max_id']; + + $output->writeln("Backfilling {$sourceTable} ({$pkColumn} {$minId}..{$maxId}, batch size {$batchSize})..."); + + $insertSql = sprintf($insertSql, $this->insertIgnoreKeyword(), $languageTable, $this->onConflictClause()); + $totalInserted = 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] + ); + } else { + $inserted = $this->connection->executeStatement($insertSql, ['from' => $from, 'to' => $to]); + } + + $totalInserted += $inserted; + $output->writeln( + sprintf(' %d..%d: %d row(s)%s', $from, $to, $inserted, $dryRun ? ' (dry-run)' : ''), + OutputInterface::VERBOSITY_VERBOSE + ); + } + + $output->writeln(sprintf( + '%s%s: %d row(s) %s.', + $dryRun ? '[dry-run] ' : '', + $sourceTable, + $totalInserted, + $dryRun ? 'would be inserted' : 'inserted' + )); + } + + /** + * 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.parent 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}\"."), + }; + } + + /** + * Not yet renamed to "ibexa_language" at the point in the real migration sequence where this + * command's logic normally runs (as part of BackfillLanguageTranslationsMigration) - that + * rename happens later, in RenameLanguageTableMigration. When run manually/standalone + * after the full sequence (or against a fresh install, which starts from the renamed schema), + * the table is already "ibexa_language". + * + * @param AbstractSchemaManager $schemaManager + */ + private function resolveLanguageTableName(AbstractSchemaManager $schemaManager): string + { + return $schemaManager->tablesExist(['ibexa_content_language']) + ? 'ibexa_content_language' + : 'ibexa_language'; + } + + 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; + } +} diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php new file mode 100644 index 0000000000..fa8f164d37 --- /dev/null +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -0,0 +1,316 @@ + [source table carrying the legacy mask, mask column]. + * + * @var array + */ + private const array SOURCE_TABLES = [ + self::TABLE_CONTENT => ['ibexa_content', 'language_mask'], + self::TABLE_CONTENT_VERSION => ['ibexa_content_version', 'language_mask'], + self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask'], + ]; + + /** + * @return array{missing: string, orphaned: string, fixMissing: string, fixOrphaned: string} + */ + private function buildQueries( + string $table, + string $languageTable + ): array { + return match ($table) { + self::TABLE_CONTENT => [ + 'missing' => "SELECT COUNT(*) FROM ibexa_content c + JOIN {$languageTable} l ON (c.language_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_translation ct + WHERE ct.content_id = c.id AND ct.language_id = l.id + )", + 'orphaned' => 'SELECT COUNT(*) FROM ibexa_content_translation ct + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content c + WHERE c.id = ct.content_id AND (c.language_mask & ct.language_id) = ct.language_id + )', + 'fixMissing' => "INSERT INTO ibexa_content_translation (content_id, language_id) + SELECT c.id, l.id FROM ibexa_content c + JOIN {$languageTable} l ON (c.language_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_translation ct + WHERE ct.content_id = c.id AND ct.language_id = l.id + )", + // No alias on the DELETE target: SQLite's DELETE FROM does not accept one. + 'fixOrphaned' => 'DELETE FROM ibexa_content_translation + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content c + WHERE c.id = ibexa_content_translation.content_id + AND (c.language_mask & ibexa_content_translation.language_id) = ibexa_content_translation.language_id + )', + ], + self::TABLE_CONTENT_VERSION => [ + 'missing' => "SELECT COUNT(*) FROM ibexa_content_version v + JOIN {$languageTable} l ON (v.language_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_version_translation vt + WHERE vt.content_version_id = v.id AND vt.language_id = l.id + )", + 'orphaned' => 'SELECT COUNT(*) FROM ibexa_content_version_translation vt + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_version v + WHERE v.id = vt.content_version_id AND (v.language_mask & vt.language_id) = vt.language_id + )', + 'fixMissing' => "INSERT INTO ibexa_content_version_translation (content_version_id, language_id) + SELECT v.id, l.id FROM ibexa_content_version v + JOIN {$languageTable} l ON (v.language_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_version_translation vt + WHERE vt.content_version_id = v.id AND vt.language_id = l.id + )", + // No alias on the DELETE target: SQLite's DELETE FROM does not accept one. + 'fixOrphaned' => 'DELETE FROM ibexa_content_version_translation + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_version v + WHERE v.id = ibexa_content_version_translation.content_version_id + AND (v.language_mask & ibexa_content_version_translation.language_id) = ibexa_content_version_translation.language_id + )', + ], + self::TABLE_URL_ALIAS => [ + 'missing' => "SELECT COUNT(*) FROM ibexa_url_alias_ml u + JOIN {$languageTable} l ON (u.lang_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_url_alias_ml_translation ut + WHERE ut.parent = u.parent AND ut.text_md5 = u.text_md5 AND ut.language_id = l.id + )", + 'orphaned' => 'SELECT COUNT(*) FROM ibexa_url_alias_ml_translation ut + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_url_alias_ml u + WHERE u.parent = ut.parent AND u.text_md5 = ut.text_md5 + AND (u.lang_mask & ut.language_id) = ut.language_id + )', + 'fixMissing' => "INSERT 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 {$languageTable} l ON (u.lang_mask & l.id) = l.id + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_url_alias_ml_translation ut + WHERE ut.parent = u.parent AND ut.text_md5 = u.text_md5 AND ut.language_id = l.id + )", + // No alias on the DELETE target: SQLite's DELETE FROM does not accept one. + 'fixOrphaned' => 'DELETE FROM ibexa_url_alias_ml_translation + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_url_alias_ml u + WHERE u.parent = ibexa_url_alias_ml_translation.parent + AND u.text_md5 = ibexa_url_alias_ml_translation.text_md5 + AND (u.lang_mask & ibexa_url_alias_ml_translation.language_id) = ibexa_url_alias_ml_translation.language_id + )', + ], + default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), + }; + } + + public function __construct(private readonly Connection $connection) + { + parent::__construct(); + } + + protected function configure(): void + { + $this + ->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + sprintf( + 'Which table to verify: one of "%s", or "%s" for all of them.', + implode('", "', self::VALID_TABLES), + self::TABLE_ALL + ), + self::TABLE_ALL + ) + ->addOption( + 'fix', + null, + InputOption::VALUE_NONE, + 'Insert missing rows and delete orphaned rows to bring the translation table back in sync.' + ) + ->setHelp( + <<%command.name% compares "ibexa_content_translation", +"ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" against the +"language_mask"/"lang_mask" columns they were backfilled from, reporting: + - missing: a language bit set in the mask with no corresponding translation row + - orphaned: a translation row whose bit is no longer set in the mask + +Exits non-zero if any drift is found and --fix was not passed. Run this after +ibexa:languages:backfill-translations, and again before relying on the translation +tables for anything - a clean report here is the precondition for every later migration step. +EOT + ); + } + + protected function execute( + InputInterface $input, + OutputInterface $output + ): int { + $table = $input->getOption('table'); + $fix = (bool)$input->getOption('fix'); + + $tables = $table === self::TABLE_ALL ? self::VALID_TABLES : [$table]; + foreach ($tables as $singleTable) { + if (!isset(self::SOURCE_TABLES[$singleTable])) { + throw new InvalidArgumentException( + 'table', + sprintf( + '"%s" is not one of "%s" or "%s".', + $singleTable, + implode('", "', self::VALID_TABLES), + self::TABLE_ALL + ) + ); + } + } + + $clean = true; + foreach ($tables as $singleTable) { + $clean = $this->verifyTable($singleTable, $fix, $output) && $clean; + } + + if ($clean) { + $output->writeln('All checked translation tables are in sync with their language masks.'); + + return self::SUCCESS; + } + + if ($fix) { + $output->writeln('Drift found and fixed.'); + + return self::SUCCESS; + } + + $output->writeln('Drift found. Re-run with --fix to correct it.'); + + return self::FAILURE; + } + + private function verifyTable( + string $table, + bool $fix, + OutputInterface $output + ): bool { + [$sourceTable, $maskColumn] = self::SOURCE_TABLES[$table]; + + // The mask column is dropped once a schema has fully completed the language bitmask + // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never + // had it to begin with - in both cases there is nothing left to verify, and the mask-based + // queries below would otherwise fail outright with "no such column"/"undefined column". + $schemaManager = $this->connection->createSchemaManager(); + if (!$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn)) { + $output->writeln("{$table}: {$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to verify."); + + return true; + } + + $languageTable = $this->resolveLanguageTableName($schemaManager); + $queries = $this->buildQueries($table, $languageTable); + + $missing = (int)$this->connection->fetchOne($queries['missing']); + $orphaned = (int)$this->connection->fetchOne($queries['orphaned']); + + if ($missing === 0 && $orphaned === 0) { + $output->writeln("{$table}: in sync."); + + return true; + } + + $output->writeln(sprintf( + '%s: %d missing, %d orphaned row(s).', + $table, + $missing, + $orphaned + )); + + if (!$fix) { + return false; + } + + if ($missing > 0) { + $inserted = $this->connection->executeStatement($queries['fixMissing']); + $output->writeln(" inserted {$inserted} missing row(s)."); + } + + if ($orphaned > 0) { + $deleted = $this->connection->executeStatement($queries['fixOrphaned']); + $output->writeln(" deleted {$deleted} orphaned row(s)."); + } + + return true; + } + + /** + * Not yet renamed to "ibexa_language" at the point in the real migration sequence where this + * command's logic normally runs (as part of BackfillLanguageTranslationsMigration/ + * DropLanguageBitmaskColumnsMigration) - that rename happens later, in + * RenameLanguageTableMigration. When run manually/standalone after the full sequence + * (or against a fresh install, which starts from the renamed schema), the table is already + * "ibexa_language". + * + * @param AbstractSchemaManager $schemaManager + */ + private function resolveLanguageTableName(AbstractSchemaManager $schemaManager): string + { + return $schemaManager->tablesExist(['ibexa_content_language']) + ? 'ibexa_content_language' + : 'ibexa_language'; + } +} diff --git a/src/bundle/Core/Resources/config/doctrine_migrations.php b/src/bundle/Core/Resources/config/doctrine_migrations.php index 063b326a44..e1c274671c 100644 --- a/src/bundle/Core/Resources/config/doctrine_migrations.php +++ b/src/bundle/Core/Resources/config/doctrine_migrations.php @@ -6,8 +6,11 @@ */ declare(strict_types=1); +use Ibexa\Bundle\RepositoryInstaller\Migration\AddContentAlwaysAvailableColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddContentVersionUniqueIndexMigration; +use Ibexa\Bundle\RepositoryInstaller\Migration\AddLanguageTranslationTablesMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddUrlAliasMlLinkIndexMigration; +use Ibexa\Bundle\RepositoryInstaller\Migration\BackfillLanguageTranslationsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsTo6_0Migration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertPostgreSqlSerialColumnsToIdentityMigration; @@ -79,4 +82,16 @@ $services->set(RemoveStateAssignLocationLimitationsMigration::class) ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); + + $services->set(AddContentAlwaysAvailableColumnsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + + $services->set(AddLanguageTranslationTablesMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + + $services->set(BackfillLanguageTranslationsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); }; diff --git a/src/bundle/Core/Resources/config/services.yml b/src/bundle/Core/Resources/config/services.yml index 70aa74e0c7..d077cc25cf 100644 --- a/src/bundle/Core/Resources/config/services.yml +++ b/src/bundle/Core/Resources/config/services.yml @@ -290,6 +290,18 @@ services: tags: - { name: console.command } + Ibexa\Bundle\Core\Command\BackfillLanguageTranslationsCommand: + arguments: + $connection: '@ibexa.persistence.connection' + tags: + - { name: console.command } + + Ibexa\Bundle\Core\Command\VerifyLanguageTranslationsCommand: + arguments: + $connection: '@ibexa.persistence.connection' + tags: + - { name: console.command } + Ibexa\Bundle\Core\Session\Handler\NativeSessionHandler: class: Ibexa\Bundle\Core\Session\Handler\NativeSessionHandler arguments: diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index 72615c3a5d..6e34a1d916 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -229,6 +229,7 @@ tables: current_version: { type: integer, nullable: true } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } language_mask: { type: bigint, nullable: false, options: { default: '0' } } + always_available: { type: boolean, nullable: false, options: { default: false } } modified: { type: integer, nullable: false, options: { default: '0' } } name: { type: string, nullable: true, length: 255 } owner_id: { type: integer, nullable: false, options: { default: '0' } } @@ -327,11 +328,30 @@ tables: creator_id: { type: integer, nullable: false, options: { default: '0' } } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } language_mask: { type: bigint, nullable: false, options: { default: '0' } } + always_available: { type: boolean, nullable: false, options: { default: false } } modified: { type: integer, nullable: false, options: { default: '0' } } status: { type: integer, nullable: false, options: { default: '0' } } user_id: { type: integer, nullable: false, options: { default: '0' } } version: { type: integer, nullable: false, options: { default: '0' } } workflow_event_pos: { type: integer, nullable: true, options: { default: '0' } } + ibexa_content_translation: + indexes: + ibexa_content_translation_language: { fields: [language_id, content_id] } + id: + content_id: { type: integer, nullable: false } + language_id: { type: bigint, nullable: false } + foreignKeys: + ibexa_content_translation_content_fk: { fields: [content_id], foreignTable: ibexa_content, foreignFields: [id], options: { onDelete: CASCADE, onUpdate: CASCADE } } + ibexa_content_translation_language_fk: { fields: [language_id], foreignTable: ibexa_content_language, foreignFields: [id], options: { onDelete: RESTRICT, onUpdate: CASCADE } } + ibexa_content_version_translation: + indexes: + ibexa_content_version_translation_language: { fields: [language_id, content_version_id] } + id: + content_version_id: { type: integer, nullable: false } + language_id: { type: bigint, nullable: false } + foreignKeys: + ibexa_content_version_translation_version_fk: { fields: [content_version_id], foreignTable: ibexa_content_version, foreignFields: [id], options: { onDelete: CASCADE, onUpdate: CASCADE } } + ibexa_content_version_translation_language_fk: { fields: [language_id], foreignTable: ibexa_content_language, foreignFields: [id], options: { onDelete: RESTRICT, onUpdate: CASCADE } } ibexa_dfs_file: indexes: ibexa_dfs_file_name_trunk: { fields: [name_trunk], options: { lengths: ['191'] } } @@ -600,6 +620,16 @@ tables: ibexa_url_alias_ml_incr: id: id: { type: integer, nullable: false, options: { autoincrement: true } } + ibexa_url_alias_ml_translation: + indexes: + ibexa_url_alias_ml_translation_language: { fields: [language_id] } + id: + parent: { type: integer, nullable: false } + text_md5: { type: string, nullable: false, length: 32 } + language_id: { type: bigint, nullable: false } + foreignKeys: + ibexa_url_alias_ml_translation_alias_fk: { fields: [parent, text_md5], foreignTable: ibexa_url_alias_ml, foreignFields: [parent, text_md5], options: { onDelete: CASCADE, onUpdate: CASCADE } } + ibexa_url_alias_ml_translation_language_fk: { fields: [language_id], foreignTable: ibexa_content_language, foreignFields: [id], options: { onDelete: RESTRICT, onUpdate: CASCADE } } ibexa_url_wildcard: id: id: { type: integer, nullable: false, options: { autoincrement: true } } diff --git a/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php new file mode 100644 index 0000000000..ce83b07f5a --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php @@ -0,0 +1,107 @@ +hasTable()/hasColumn() would always report false there. + */ +final class AddContentAlwaysAvailableColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string CONTENT_TABLE = 'ibexa_content'; + private const string CONTENT_VERSION_TABLE = 'ibexa_content_version'; + private const string ALWAYS_AVAILABLE_COLUMN = 'always_available'; + + public function getDescription(): string + { + return 'Adds "always_available" columns to "ibexa_content" and "ibexa_content_version", backfilled from the language mask'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 00:00:00'); + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::CONTENT_TABLE, self::CONTENT_VERSION_TABLE])) { + return; + } + + $hasContentColumn = $schemaManager->introspectTable(self::CONTENT_TABLE) + ->hasColumn(self::ALWAYS_AVAILABLE_COLUMN); + $hasContentVersionColumn = $schemaManager->introspectTable(self::CONTENT_VERSION_TABLE) + ->hasColumn(self::ALWAYS_AVAILABLE_COLUMN); + + if ($hasContentColumn && $hasContentVersionColumn) { + // Already fully applied - avoid an unconditional full-table backfill re-scan once this + // migration has genuinely completed. + return; + } + + if (!$hasContentColumn) { + $this->addSql($this->buildAddColumnSql(self::CONTENT_TABLE)); + } + + if (!$hasContentVersionColumn) { + $this->addSql($this->buildAddColumnSql(self::CONTENT_VERSION_TABLE)); + } + + $this->addSql($this->buildBackfillSql(self::CONTENT_TABLE)); + $this->addSql($this->buildBackfillSql(self::CONTENT_VERSION_TABLE)); + } + + private function buildAddColumnSql(string $table): string + { + $columnDefinition = match (true) { + $this->isMySQL(), $this->isMariaDB() => "TINYINT(1) DEFAULT '0' NOT NULL", + $this->isPostgreSQL() => "BOOLEAN DEFAULT 'false' NOT NULL", + default => "BOOLEAN DEFAULT '0' NOT NULL", + }; + + return "ALTER TABLE {$table} ADD COLUMN " . self::ALWAYS_AVAILABLE_COLUMN . " {$columnDefinition}"; + } + + private function buildBackfillSql(string $table): string + { + $trueLiteral = $this->isPostgreSQL() ? 'true' : '1'; + + return "UPDATE {$table} SET " . self::ALWAYS_AVAILABLE_COLUMN . " = {$trueLiteral} WHERE (language_mask & 1) = 1"; + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php new file mode 100644 index 0000000000..89fe520380 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php @@ -0,0 +1,147 @@ +hasTable() would always report false there. + */ +final class AddLanguageTranslationTablesMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string CONTENT_TABLE = 'ibexa_content'; + + /** + * Not yet renamed to "ibexa_language" at this point in the migration sequence - that rename + * happens later, in {@see RenameLanguageTableMigration}. + * + * @var array> + */ + private const array FOREIGN_KEYS = [ + 'ibexa_content_translation' => [ + 'ibexa_content_translation_content_fk' => 'FOREIGN KEY (content_id) REFERENCES ibexa_content (id) ON DELETE CASCADE ON UPDATE CASCADE', + 'ibexa_content_translation_language_fk' => 'FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) ON DELETE RESTRICT ON UPDATE CASCADE', + ], + 'ibexa_content_version_translation' => [ + 'ibexa_content_version_translation_version_fk' => 'FOREIGN KEY (content_version_id) REFERENCES ibexa_content_version (id) ON DELETE CASCADE ON UPDATE CASCADE', + 'ibexa_content_version_translation_language_fk' => 'FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) ON DELETE RESTRICT ON UPDATE CASCADE', + ], + 'ibexa_url_alias_ml_translation' => [ + 'ibexa_url_alias_ml_translation_alias_fk' => 'FOREIGN KEY (parent, text_md5) REFERENCES ibexa_url_alias_ml (parent, text_md5) ON DELETE CASCADE ON UPDATE CASCADE', + 'ibexa_url_alias_ml_translation_language_fk' => 'FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) ON DELETE RESTRICT ON UPDATE CASCADE', + ], + ]; + + public function getDescription(): string + { + return 'Creates "ibexa_content_translation", "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation"'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 01:00:00'); + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::CONTENT_TABLE])) { + return; + } + + $allTablesExist = $schemaManager->tablesExist(array_keys(self::FOREIGN_KEYS)); + + if ($this->isSqlite()) { + if ($allTablesExist) { + return; + } + + $this->addSqlFile(__DIR__ . '/sql/add-language-translation-tables-sqlite.sql'); + + return; + } + + $missingForeignKeys = $this->findMissingForeignKeys($schemaManager); + + if ($allTablesExist && $missingForeignKeys === []) { + return; + } + + if ($this->isMySQL() || $this->isMariaDB()) { + $this->addSqlFile(__DIR__ . '/sql/add-language-translation-tables-mysql.sql'); + } elseif ($this->isPostgreSQL()) { + $this->addSqlFile(__DIR__ . '/sql/add-language-translation-tables-postgresql.sql'); + } + + foreach ($missingForeignKeys as [$table, $constraintName, $definition]) { + $this->addSql("ALTER TABLE {$table} ADD CONSTRAINT {$constraintName} {$definition}"); + } + } + + /** + * @param AbstractSchemaManager $schemaManager + * + * @return list + */ + private function findMissingForeignKeys(AbstractSchemaManager $schemaManager): array + { + $missing = []; + + foreach (self::FOREIGN_KEYS as $table => $foreignKeys) { + $existingTable = $schemaManager->tablesExist([$table]) + ? $schemaManager->introspectTable($table) + : null; + + foreach ($foreignKeys as $constraintName => $definition) { + if ($existingTable !== null && $existingTable->hasForeignKey($constraintName)) { + continue; + } + + $missing[] = [$table, $constraintName, $definition]; + } + } + + return $missing; + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php new file mode 100644 index 0000000000..0f69d1abf0 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php @@ -0,0 +1,177 @@ +hasTable()/hasColumn() would always report false there. + */ +final class BackfillLanguageTranslationsMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const int BATCH_SIZE = 5000; + + public function getDescription(): string + { + return 'Backfills the language translation tables from the legacy language bitmask columns'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 02:00:00'); + } + + public function isTransactional(): bool + { + return false; + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + if (!$this->connection->createSchemaManager()->tablesExist(['ibexa_content_translation'])) { + // AddLanguageTranslationTablesMigration hasn't run yet (or "ibexa_content" itself + // doesn't exist - a project-only install without core's own content tables). + return; + } + + $this->backfillTable( + 'ibexa_content', + 'language_mask', + 'id', + 'INSERT %s INTO ibexa_content_translation (content_id, language_id) + SELECT c.id, l.id FROM ibexa_content c + JOIN ibexa_content_language l ON (c.language_mask & l.id) = l.id + WHERE c.id BETWEEN :from AND :to %s' + ); + + $this->backfillTable( + 'ibexa_content_version', + 'language_mask', + 'id', + 'INSERT %s INTO ibexa_content_version_translation (content_version_id, language_id) + SELECT v.id, l.id FROM ibexa_content_version v + JOIN ibexa_content_language l ON (v.language_mask & l.id) = l.id + WHERE v.id BETWEEN :from AND :to %s' + ); + + $this->backfillTable( + 'ibexa_url_alias_ml', + 'lang_mask', + 'parent', + '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 ibexa_content_language l ON (u.lang_mask & l.id) = l.id + WHERE u.parent BETWEEN :from AND :to %s' + ); + } + + private function backfillTable( + string $sourceTable, + string $maskColumn, + string $pkColumn, + string $insertSqlTemplate + ): void { + $schemaManager = $this->connection->createSchemaManager(); + if ( + !$schemaManager->tablesExist([$sourceTable]) + || !$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn) + ) { + // Column already dropped (re-running after a prior upgrade already completed this + // step), or a fresh install whose schema.yaml never had it. + return; + } + + // 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) { + return; + } + + $minId = (int)$range['min_id']; + $maxId = (int)$range['max_id']; + + $insertSql = sprintf($insertSqlTemplate, $this->insertIgnoreKeyword(), $this->onConflictClause()); + + for ($from = $minId; $from <= $maxId; $from += self::BATCH_SIZE) { + $to = min($from + self::BATCH_SIZE - 1, $maxId); + $this->addSql( + $insertSql, + ['from' => $from, 'to' => $to], + ['from' => ParameterType::INTEGER, 'to' => ParameterType::INTEGER] + ); + } + } + + private function insertIgnoreKeyword(): string + { + if ($this->isMySQL() || $this->isMariaDB()) { + return 'IGNORE'; + } + if ($this->isSqlite()) { + return 'OR IGNORE'; + } + + return ''; + } + + /** + * 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 + { + if ($this->isPostgreSQL()) { + return 'ON CONFLICT DO NOTHING'; + } + + return ''; + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-mysql.sql b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-mysql.sql new file mode 100644 index 0000000000..54676cad54 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-mysql.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS ibexa_content_translation ( + content_id INT NOT NULL, + language_id BIGINT NOT NULL, + INDEX ibexa_content_translation_language (language_id, content_id), + PRIMARY KEY(content_id, language_id) +) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB; +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_content_version_translation ( + content_version_id INT NOT NULL, + language_id BIGINT NOT NULL, + INDEX ibexa_content_version_translation_language (language_id, content_version_id), + PRIMARY KEY(content_version_id, language_id) +) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB; +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_url_alias_ml_translation ( + parent INT NOT NULL, + text_md5 VARCHAR(32) NOT NULL, + language_id BIGINT NOT NULL, + INDEX ibexa_url_alias_ml_translation_language (language_id), + PRIMARY KEY(parent, text_md5, language_id) +) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB; diff --git a/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-postgresql.sql b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-postgresql.sql new file mode 100644 index 0000000000..6ce52a1371 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-postgresql.sql @@ -0,0 +1,24 @@ +CREATE TABLE IF NOT EXISTS ibexa_content_translation ( + content_id INT NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(content_id, language_id) +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_content_translation_language ON ibexa_content_translation (language_id, content_id); +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_content_version_translation ( + content_version_id INT NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(content_version_id, language_id) +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_content_version_translation_language ON ibexa_content_version_translation (language_id, content_version_id); +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_url_alias_ml_translation ( + parent INT NOT NULL, + text_md5 VARCHAR(32) NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(parent, text_md5, language_id) +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_url_alias_ml_translation_language ON ibexa_url_alias_ml_translation (language_id); diff --git a/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-sqlite.sql b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-sqlite.sql new file mode 100644 index 0000000000..2d56c9fcfe --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/add-language-translation-tables-sqlite.sql @@ -0,0 +1,42 @@ +CREATE TABLE IF NOT EXISTS ibexa_content_translation ( + content_id INTEGER NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(content_id, language_id), + CONSTRAINT ibexa_content_translation_content_fk + FOREIGN KEY (content_id) REFERENCES ibexa_content (id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT ibexa_content_translation_language_fk + FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) + ON DELETE RESTRICT ON UPDATE CASCADE +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_content_translation_language ON ibexa_content_translation (language_id, content_id); +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_content_version_translation ( + content_version_id INTEGER NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(content_version_id, language_id), + CONSTRAINT ibexa_content_version_translation_version_fk + FOREIGN KEY (content_version_id) REFERENCES ibexa_content_version (id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT ibexa_content_version_translation_language_fk + FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) + ON DELETE RESTRICT ON UPDATE CASCADE +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_content_version_translation_language ON ibexa_content_version_translation (language_id, content_version_id); +-- ibexa:sql-statement-separator +CREATE TABLE IF NOT EXISTS ibexa_url_alias_ml_translation ( + parent INTEGER NOT NULL, + text_md5 VARCHAR(32) NOT NULL, + language_id BIGINT NOT NULL, + PRIMARY KEY(parent, text_md5, language_id), + CONSTRAINT ibexa_url_alias_ml_translation_alias_fk + FOREIGN KEY (parent, text_md5) REFERENCES ibexa_url_alias_ml (parent, text_md5) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT ibexa_url_alias_ml_translation_language_fk + FOREIGN KEY (language_id) REFERENCES ibexa_content_language (id) + ON DELETE RESTRICT ON UPDATE CASCADE +); +-- ibexa:sql-statement-separator +CREATE INDEX IF NOT EXISTS ibexa_url_alias_ml_translation_language ON ibexa_url_alias_ml_translation (language_id); diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index a0780d0ec9..94629a63dd 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -11,9 +11,12 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception as DBALException; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Column; use Ibexa\Contracts\Core\Test\Persistence\AppendOnlyFixture; use Ibexa\Contracts\Core\Test\Persistence\Fixture; +use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; +use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; /** * Database fixture importer. @@ -24,12 +27,29 @@ final class FixtureImporter { private Connection $connection; + private SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass; + + /** + * Join tables referencing "ibexa_content_language" (ON DELETE RESTRICT), keyed to the table owning their rows. + */ + private const LANGUAGE_TRANSLATION_TABLES = [ + 'ibexa_content_translation' => 'ibexa_content', + 'ibexa_content_version_translation' => 'ibexa_content_version', + 'ibexa_url_alias_ml_translation' => 'ibexa_url_alias_ml', + ]; + /** @var array */ private static array $resetSequenceStatements = []; - public function __construct(Connection $connection) - { + /** @var array */ + private static array $existingColumnsByTable = []; + + public function __construct( + Connection $connection, + ?SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass = null + ) { $this->connection = $connection; + $this->schemaAssetsFilterBypass = $schemaAssetsFilterBypass ?? new SchemaAssetsFilterBypass(); } /** @@ -39,27 +59,292 @@ public function import(Fixture $fixture): void { $data = $fixture->load(); - $tablesList = array_keys($data); + // Fixtures (e.g. ibexa/test-core's own bundled baseline, which this package doesn't + // control) predate tables being renamed/dropped over time (e.g. ibexa_content_language + // becoming ibexa_language) - silently skip tables that no longer exist, same as + // getExistingColumns() already does for individual columns below. + $tablesList = array_values(array_filter( + array_keys($data), + fn (string $table): bool => $this->tableExists($table) + )); + $detachedTranslations = []; if (!$fixture instanceof AppendOnlyFixture) { + $detachedTranslations = $this->detachLanguageTranslations($tablesList); // truncate all tables, even the ones initially empty (some tests are affected by this) $this->truncateTables(array_reverse($tablesList)); } $nonEmptyTablesData = array_filter( $data, - static function ($tableData): bool { - return !empty($tableData); - } + static fn (array $tableData, string $table): bool => !empty($tableData) && in_array($table, $tablesList, true), + ARRAY_FILTER_USE_BOTH ); foreach ($nonEmptyTablesData as $table => $rows) { + // Fixtures predate columns being dropped over time (e.g. the language bitmask + // columns) - silently drop unknown keys rather than letting every fixture file need + // updating in lockstep with schema changes. + $existingColumns = $this->getExistingColumns($table); foreach ($rows as $row) { - $this->connection->insert($table, $row); + $this->connection->insert($table, array_intersect_key($row, array_flip($existingColumns))); } } if ($this->connection->getDatabasePlatform()->supportsSequences()) { $this->resetSequences($tablesList); } + + $this->reattachLanguageTranslations($detachedTranslations); + $this->backfillLanguageBitmaskColumns($nonEmptyTablesData); + } + + /** + * A fixture replacing the languages can't truncate "ibexa_content_language" while the translation rows + * of tables it leaves alone (e.g. the base fixture's URL aliases) still reference it. Take them + * out first, so reattachLanguageTranslations() can put back the ones whose language is still + * there, the same rows the legacy bitmask columns kept. Rows of tables the fixture replaces are + * dropped, backfillLanguageBitmaskColumns() rebuilds those. + * + * @param string[] $tablesList + * + * @return array>> + * + * @throws Exception + */ + private function detachLanguageTranslations(array $tablesList): array + { + if (!in_array('ibexa_content_language', $tablesList, true)) { + return []; + } + + $detached = []; + foreach (self::LANGUAGE_TRANSLATION_TABLES as $table => $ownerTable) { + if (!$this->tableExists($table)) { + continue; + } + if (!in_array($ownerTable, $tablesList, true)) { + $detached[$table] = $this->connection->fetchAllAssociative('SELECT * FROM ' . $table); + } + $this->connection->executeStatement('DELETE FROM ' . $table); + } + + return $detached; + } + + /** + * @param array>> $detachedTranslations + * + * @throws Exception + */ + private function reattachLanguageTranslations(array $detachedTranslations): void + { + if (empty($detachedTranslations)) { + return; + } + + $validLanguageIds = $this->loadValidLanguageIds(); + foreach ($detachedTranslations as $table => $rows) { + foreach ($rows as $row) { + if (in_array((int)$row['language_id'], $validLanguageIds, true)) { + $this->connection->insert($table, $row); + } + } + } + } + + /** + * @return string[] + */ + private function getExistingColumns(string $table): array + { + if (!isset(self::$existingColumnsByTable[$table])) { + $columns = $this->connection->createSchemaManager()->listTableColumns($table); + self::$existingColumnsByTable[$table] = array_map( + static fn (Column $column): string => $column->getName(), + $columns + ); + } + + return self::$existingColumnsByTable[$table]; + } + + /** + * Fixture data predates "always_available"/"is_always_available" becoming plain columns and + * the "ibexa_content_translation"/"ibexa_content_version_translation"/ + * "ibexa_url_alias_ml_translation" join tables - it only ever set "language_mask"/"lang_mask", + * which import() now silently drops (see getExistingColumns()) since the column may no longer + * exist. Backfill the modern columns/tables from those same fixture values here, once, so every + * fixture-loading path behaves like rows actually written through the gateways - mirrors what + * the real Add*AlwaysAvailableColumns/AddLanguageTranslationTables/ + * AddSearchObjectWordLinkLanguageIdColumns migrations backfill for production upgrades. + * + * Reimplements the (small, stable) bitmask decode directly rather than depending on + * Persistence\Legacy's MaskGenerator - this is a test-only concern in a Contracts package that + * must not depend on a specific storage engine's internals. + * + * @param array>> $nonEmptyTablesData + */ + private function backfillLanguageBitmaskColumns(array $nonEmptyTablesData): void + { + if (!$this->tableExists('ibexa_content_translation')) { + // Schema predates this migration entirely (or has already dropped the join tables in + // some hypothetical future) - nothing to backfill into. + return; + } + + $validLanguageIds = null; + + // The join tables aren't part of the fixture's own table list, so import()'s + // truncate-then-insert loop never clears them directly; do it explicitly rather than rely + // on FK cascade behavior varying by platform/driver. + if (!empty($nonEmptyTablesData['ibexa_content'])) { + $this->connection->executeStatement('DELETE FROM ibexa_content_translation'); + } + if (!empty($nonEmptyTablesData['ibexa_content_version'])) { + $this->connection->executeStatement('DELETE FROM ibexa_content_version_translation'); + } + if (!empty($nonEmptyTablesData['ibexa_url_alias_ml']) && $this->tableExists('ibexa_url_alias_ml_translation')) { + $this->connection->executeStatement('DELETE FROM ibexa_url_alias_ml_translation'); + } + + if (!empty($nonEmptyTablesData['ibexa_content'])) { + $validLanguageIds = $this->loadValidLanguageIds(); + foreach ($nonEmptyTablesData['ibexa_content'] as $row) { + if (!array_key_exists('language_mask', $row)) { + continue; + } + $mask = (int)$row['language_mask']; + $this->connection->executeStatement( + 'UPDATE ibexa_content SET always_available = :alwaysAvailable WHERE id = :id', + ['alwaysAvailable' => ($mask & 1) === 1, 'id' => $row['id']], + ['alwaysAvailable' => ParameterType::BOOLEAN, 'id' => ParameterType::INTEGER] + ); + foreach ($this->extractLanguageIds($mask, $validLanguageIds) as $languageId) { + $this->connection->executeStatement( + 'INSERT INTO ibexa_content_translation (content_id, language_id) VALUES (:id, :languageId)', + ['id' => $row['id'], 'languageId' => $languageId], + ['id' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + } + } + } + + if (!empty($nonEmptyTablesData['ibexa_content_version'])) { + $validLanguageIds ??= $this->loadValidLanguageIds(); + foreach ($nonEmptyTablesData['ibexa_content_version'] as $row) { + if (!array_key_exists('language_mask', $row)) { + continue; + } + $mask = (int)$row['language_mask']; + $this->connection->executeStatement( + 'UPDATE ibexa_content_version SET always_available = :alwaysAvailable WHERE id = :id', + ['alwaysAvailable' => ($mask & 1) === 1, 'id' => $row['id']], + ['alwaysAvailable' => ParameterType::BOOLEAN, 'id' => ParameterType::INTEGER] + ); + foreach ($this->extractLanguageIds($mask, $validLanguageIds) as $languageId) { + $this->connection->executeStatement( + 'INSERT INTO ibexa_content_version_translation (content_version_id, language_id) VALUES (:id, :languageId)', + ['id' => $row['id'], 'languageId' => $languageId], + ['id' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + } + } + } + + if (!empty($nonEmptyTablesData['ibexa_url_alias_ml']) && $this->tableExists('ibexa_url_alias_ml_translation')) { + $validLanguageIds ??= $this->loadValidLanguageIds(); + foreach ($nonEmptyTablesData['ibexa_url_alias_ml'] as $row) { + if (!array_key_exists('lang_mask', $row)) { + continue; + } + $mask = (int)$row['lang_mask']; + foreach ($this->extractLanguageIds($mask, $validLanguageIds) as $languageId) { + $this->connection->executeStatement( + 'INSERT INTO ibexa_url_alias_ml_translation (parent, text_md5, language_id) VALUES (:parent, :textMd5, :languageId)', + ['parent' => $row['parent'], 'textMd5' => $row['text_md5'], 'languageId' => $languageId], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING, 'languageId' => ParameterType::INTEGER] + ); + } + } + } + + if (!empty($nonEmptyTablesData['ibexa_search_object_word_link']) && $this->tableExists('ibexa_search_object_word_link') && in_array('language_id', $this->getExistingColumns('ibexa_search_object_word_link'), true)) { + foreach ($nonEmptyTablesData['ibexa_search_object_word_link'] as $row) { + if (!array_key_exists('language_mask', $row)) { + continue; + } + $mask = (int)$row['language_mask']; + $this->connection->executeStatement( + 'UPDATE ibexa_search_object_word_link + SET language_id = :languageId, is_main_and_always_available = :alwaysAvailable + WHERE id = :id', + [ + 'languageId' => $mask & ~1, + 'alwaysAvailable' => ($mask & 1) === 1, + 'id' => $row['id'], + ], + [ + 'languageId' => ParameterType::INTEGER, + 'alwaysAvailable' => ParameterType::BOOLEAN, + 'id' => ParameterType::INTEGER, + ] + ); + } + } + } + + /** + * tablesExist() goes through AbstractSchemaManager::listTableNames(), which is filtered by + * whatever schema assets filter is configured on the connection (e.g. + * ManagedTablesSchemaAssetFilter, which hides every table not backed by a registered ORM + * entity - i.e. all of Ibexa's own legacy/join tables). Bypass it, same as + * LegacySchemaImporter does, or this always reports these tables as absent and every backfill + * below silently no-ops. + */ + private function tableExists(string $table): bool + { + return $this->schemaAssetsFilterBypass->call( + $this->connection, + fn (): bool => $this->connection->createSchemaManager()->tablesExist([$table]) + ); + } + + /** + * @return int[] + */ + private function loadValidLanguageIds(): array + { + if (!$this->tableExists('ibexa_content_language')) { + return []; + } + + return array_map( + 'intval', + $this->connection->fetchFirstColumn('SELECT id FROM ibexa_content_language') + ); + } + + /** + * Decodes real (non-always-available) language ids out of a legacy bitmask, restricted to ids + * actually present in ibexa_content_language (mirrors the old SQL backfill's implicit + * JOIN ibexa_content_language filter, needed since ibexa_content_translation's language_id has + * a real FK to it). + * + * @param int[] $validLanguageIds + * + * @return int[] + */ + private function extractLanguageIds( + int $mask, + array $validLanguageIds + ): array { + $languageIds = []; + for ($languageId = 2; $languageId <= $mask; $languageId *= 2) { + if (($mask & $languageId) === $languageId && in_array($languageId, $validLanguageIds, true)) { + $languageIds[] = $languageId; + } + } + + return $languageIds; } /** diff --git a/src/contracts/Test/Repository/SetupFactory/Legacy.php b/src/contracts/Test/Repository/SetupFactory/Legacy.php index 391474c383..8b542d2ac2 100644 --- a/src/contracts/Test/Repository/SetupFactory/Legacy.php +++ b/src/contracts/Test/Repository/SetupFactory/Legacy.php @@ -164,7 +164,7 @@ public function insertData(): void $connection = $this->getDatabaseConnection(); $this->cleanupVarDir($this->getInitialVarDir()); - $fixtureImporter = new FixtureImporter($connection); + $fixtureImporter = new FixtureImporter($connection, new SchemaAssetsFilterBypass()); $fixtureImporter->import($this->getInitialDataFixture()); } diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index f44187ed7e..f150c5b3f8 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -118,12 +118,22 @@ public function insertContentObject( ), ParameterType::INTEGER ), + 'always_available' => $query->createPositionalParameter( + $struct->alwaysAvailable, + ParameterType::BOOLEAN + ), ] ); $query->executeStatement(); - return (int)$this->connection->lastInsertId(); + $contentId = (int)$this->connection->lastInsertId(); + $this->insertContentTranslations( + $contentId, + $this->collectFieldLanguageCodes($struct->fields, $initialLanguageCode) + ); + + return $contentId; } public function insertVersion( @@ -173,12 +183,122 @@ public function insertVersion( ), ParameterType::INTEGER ), + 'always_available' => $query->createPositionalParameter( + $versionInfo->contentInfo->alwaysAvailable, + ParameterType::BOOLEAN + ), ] ); $query->executeStatement(); - return (int)$this->connection->lastInsertId(); + $versionId = (int)$this->connection->lastInsertId(); + $this->insertVersionTranslations( + $versionId, + $this->collectFieldLanguageCodes($fields, $versionInfo->initialLanguageCode) + ); + + return $versionId; + } + + /** + * Collects the unique language codes a Content/Version's fields are written in, always + * including $initialLanguageCode, for populating "ibexa_content_translation"/ + * "ibexa_content_version_translation". + * + * @param Field[] $fields + * + * @return string[] + */ + private function collectFieldLanguageCodes( + array $fields, + string $initialLanguageCode + ): array { + $languageCodes = [$initialLanguageCode => true]; + foreach ($fields as $field) { + $languageCodes[$field->languageCode] = true; + } + + return array_keys($languageCodes); + } + + /** + * @param string[] $languageCodes + */ + private function insertContentTranslations( + int $contentId, + array $languageCodes + ): void { + foreach (array_unique($languageCodes) as $languageCode) { + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; + $this->connection->executeStatement( + 'INSERT INTO ibexa_content_translation (content_id, language_id) VALUES (:contentId, :languageId)', + ['contentId' => $contentId, 'languageId' => $languageId], + ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + } + } + + /** + * @param string[] $languageCodes + */ + private function insertVersionTranslations( + int $versionId, + array $languageCodes + ): void { + foreach (array_unique($languageCodes) as $languageCode) { + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; + $this->connection->executeStatement( + 'INSERT INTO ibexa_content_version_translation (content_version_id, language_id) VALUES (:versionId, :languageId)', + ['versionId' => $versionId, 'languageId' => $languageId], + ['versionId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + } + } + + /** + * Adds $languageCodes to Version $versionId's translations, leaving any already present + * untouched - mirrors updateVersion()'s additive bit-OR merge onto "language_mask". + * + * @param string[] $languageCodes + */ + private function addVersionTranslationsIfMissing( + int $versionId, + array $languageCodes + ): void { + foreach (array_unique($languageCodes) as $languageCode) { + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; + $this->connection->executeStatement( + 'INSERT INTO ibexa_content_version_translation (content_version_id, language_id) + SELECT :versionId, :languageId + WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_version_translation + WHERE content_version_id = :versionId AND language_id = :languageId + )', + ['versionId' => $versionId, 'languageId' => $languageId], + ['versionId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + } + } + + /** + * Replaces Content $contentId's translations with exactly $languageCodes - mirrors + * updateContent()'s publish-time replace of "language_mask" with the newly published + * version's language set (not a union with whatever the content previously had). + * + * @param string[] $languageCodes + */ + private function replaceContentTranslations( + int $contentId, + array $languageCodes + ): void { + $this->connection->executeStatement( + 'DELETE FROM ibexa_content_translation WHERE content_id = :contentId', + ['contentId' => $contentId], + ['contentId' => ParameterType::INTEGER] + ); + + $this->insertContentTranslations($contentId, $languageCodes); } public function updateContent( @@ -234,14 +354,19 @@ public function updateContent( } if ($prePublishVersionInfo !== null) { + $alwaysAvailable = $struct->alwaysAvailable ?? $prePublishVersionInfo->contentInfo->alwaysAvailable; $mask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( $prePublishVersionInfo->languageCodes, - $struct->alwaysAvailable ?? $prePublishVersionInfo->contentInfo->alwaysAvailable + $alwaysAvailable ); $query->set( 'language_mask', $query->createNamedParameter($mask, ParameterType::INTEGER, ':languageMask') ); + $query->set( + 'always_available', + $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') + ); $hasSetClause = true; } @@ -260,6 +385,10 @@ public function updateContent( if (isset($struct->alwaysAvailable) || isset($struct->mainLanguageId)) { $this->updateAlwaysAvailableFlag($contentId, $struct->alwaysAvailable); } + + if ($prePublishVersionInfo !== null) { + $this->replaceContentTranslations($contentId, $prePublishVersionInfo->languageCodes); + } } /** @@ -308,6 +437,24 @@ public function updateVersion( ->setParameter('version_no', $versionNo, ParameterType::INTEGER); $query->executeStatement(); + + $versionId = $this->connection->createQueryBuilder() + ->select('id') + ->from(self::CONTENT_VERSION_TABLE) + ->where('contentobject_id = :content_id') + ->andWhere('version = :version_no') + ->setParameter('content_id', $contentId, ParameterType::INTEGER) + ->setParameter('version_no', $versionNo, ParameterType::INTEGER) + ->executeQuery() + ->fetchOne(); + + $this->addVersionTranslationsIfMissing( + (int)$versionId, + $this->collectFieldLanguageCodes( + $struct->fields, + $this->languageHandler->load($struct->initialLanguageId)->languageCode + ) + ); } public function updateAlwaysAvailableFlag( @@ -346,7 +493,11 @@ private function updateContentItemAlwaysAvailableFlag( $query = $this->connection->createQueryBuilder(); $expr = $query->expr(); $query - ->update(self::CONTENT_ITEM_TABLE); + ->update(self::CONTENT_ITEM_TABLE) + ->set( + 'always_available', + $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') + ); $this ->setLanguageMaskForUpdateQuery($alwaysAvailable, $query, 'language_mask') ->where( @@ -756,7 +907,7 @@ private function internalLoadContent( 'c.published AS content_published', 'c.status AS content_status', 'c.name AS content_name', - 'c.language_mask AS content_language_mask', + 'c.always_available AS content_always_available', 'c.is_hidden AS content_is_hidden', 'v.id AS content_version_id', 'v.version AS content_version_version', @@ -764,7 +915,7 @@ private function internalLoadContent( 'v.creator_id AS content_version_creator_id', 'v.created AS content_version_created', 'v.status AS content_version_status', - 'v.language_mask AS content_version_language_mask', + 'v.always_available AS content_version_always_available', 'v.initial_language_id AS content_version_initial_language_id', 'a.id AS content_field_id', 'a.content_type_field_definition_id AS content_field_content_type_field_definition_id', @@ -2045,7 +2196,7 @@ private function deleteTranslationFromContentNames( } /** - * Remove language from language_mask of ibexa_content. + * Remove language from ibexa_content_translation and the language_mask of ibexa_content. * * @param int $contentId * @param int $languageId @@ -2056,36 +2207,41 @@ private function deleteTranslationFromContentObject( $contentId, $languageId ) { + $hasOtherLanguages = (bool)$this->connection->fetchOne( + 'SELECT 1 FROM ibexa_content_translation WHERE content_id = :contentId AND language_id != :languageId', + ['contentId' => $contentId, 'languageId' => $languageId], + ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); + + // most likely somehow it was the last remaining translation + if (!$hasOtherLanguages) { + throw new BadStateException( + '$languageCode', + 'The provided translation is the only translation in this version' + ); + } + $query = $this->connection->createQueryBuilder(); $query->update(Gateway::CONTENT_ITEM_TABLE) // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS ->set('language_mask', 'language_mask & ~ ' . $languageId) ->set('modified', ':now') ->where('id = :contentId') - ->andWhere( - // make sure removed translation is not the last one (incl. alwaysAvailable) - $query->expr()->and( - 'language_mask & ~ ' . $languageId . ' <> 0', - 'language_mask & ~ ' . $languageId . ' <> 1' - ) - ) ->setParameter('now', time()) ->setParameter('contentId', $contentId) ; + $query->executeStatement(); - $rowCount = $query->executeStatement(); - - // no rows updated means that most likely somehow it was the last remaining translation - if ($rowCount === 0) { - throw new BadStateException( - '$languageCode', - 'The provided translation is the only translation in this version' - ); - } + $this->connection->executeStatement( + 'DELETE FROM ibexa_content_translation WHERE content_id = :contentId AND language_id = :languageId', + ['contentId' => $contentId, 'languageId' => $languageId], + ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] + ); } /** - * Remove language from language_mask of ibexa_content_version and update initialLanguageId + * Remove language from ibexa_content_version_translation and the language_mask of ibexa_content_version, + * and update initialLanguageId * if it matches the removed one. * * @param int|null $versionNo optional, if specified, apply to this Version only. @@ -2098,8 +2254,9 @@ private function deleteTranslationFromContentVersions( ?int $versionNo = null ) { $contentTable = Gateway::CONTENT_ITEM_TABLE; + $versionTable = Gateway::CONTENT_VERSION_TABLE; $query = $this->connection->createQueryBuilder(); - $query->update(Gateway::CONTENT_VERSION_TABLE) + $query->update($versionTable) // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS ->set('language_mask', 'language_mask & ~ ' . $languageId) ->set('modified', ':now') @@ -2113,10 +2270,7 @@ private function deleteTranslationFromContentVersions( ->where('contentobject_id = :contentId') ->andWhere( // make sure removed translation is not the last one (incl. alwaysAvailable) - $query->expr()->and( - 'language_mask & ~ ' . $languageId . ' <> 0', - 'language_mask & ~ ' . $languageId . ' <> 1' - ) + "EXISTS (SELECT 1 FROM ibexa_content_version_translation cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" ) ->setParameter('now', time()) ->setParameter('contentId', $contentId) @@ -2130,15 +2284,57 @@ private function deleteTranslationFromContentVersions( ; } - $rowCount = $query->executeStatement(); + // Checked as its own query rather than via the UPDATE's affected-row count: MySQL's PDO + // driver reports "rows changed", not "rows matched", by default - if a version's + // "modified"/"initial_language_id" happen to already hold the values being set (e.g. two + // operations landing within the same time() second), MySQL reports 0 affected rows even + // though the WHERE/EXISTS clause matched, which would incorrectly look like "no other + // translation exists" here. + $hasOtherLanguagesQuery = $this->connection->createQueryBuilder(); + $hasOtherLanguagesQuery + ->select('1') + ->from($versionTable) + ->where('contentobject_id = :contentId') + ->andWhere( + "EXISTS (SELECT 1 FROM ibexa_content_version_translation cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" + ) + ->setParameter('contentId', $contentId) + ->setParameter('languageId', $languageId) + ; - // no rows updated means that most likely somehow it was the last remaining translation - if ($rowCount === 0) { + if (null !== $versionNo) { + $hasOtherLanguagesQuery + ->andWhere('version = :versionNo') + ->setParameter('versionNo', $versionNo) + ; + } + + $hasOtherLanguages = (bool)$hasOtherLanguagesQuery->executeQuery()->fetchOne(); + + // most likely somehow it was the last remaining translation + if (!$hasOtherLanguages) { throw new BadStateException( '$languageCode', 'The provided translation is the only translation in this version' ); } + + $query->executeStatement(); + + $deleteQuery = 'DELETE FROM ibexa_content_version_translation + WHERE language_id = :languageId + AND content_version_id IN ( + SELECT id FROM ibexa_content_version WHERE contentobject_id = :contentId' + . (null !== $versionNo ? ' AND version = :versionNo' : '') . ')'; + + $deleteParams = ['contentId' => $contentId, 'languageId' => $languageId]; + $deleteTypes = ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER]; + if (null !== $versionNo) { + $deleteParams['versionNo'] = $versionNo; + $deleteTypes['versionNo'] = ParameterType::INTEGER; + } + + $this->connection->executeStatement($deleteQuery, $deleteParams, $deleteTypes); } /** diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase/QueryBuilder.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase/QueryBuilder.php index 6fbfb3097b..c8e8251d05 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase/QueryBuilder.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase/QueryBuilder.php @@ -148,7 +148,7 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder 'v.status AS content_version_status', 'v.contentobject_id AS content_version_contentobject_id', 'v.initial_language_id AS content_version_initial_language_id', - 'v.language_mask AS content_version_language_mask', + 'v.always_available AS content_version_always_available', // Content main location 't.main_node_id AS content_tree_main_node_id', // Content object @@ -163,7 +163,7 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder 'c.published AS content_published', 'c.status AS content_status', 'c.name AS content_name', - 'c.language_mask AS content_language_mask', + 'c.always_available AS content_always_available', 'c.is_hidden AS content_is_hidden' ) ->from(Gateway::CONTENT_VERSION_TABLE, 'v') diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway.php b/src/lib/Persistence/Legacy/Content/Language/Gateway.php index eba63900a7..581dc421db 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway.php @@ -89,4 +89,25 @@ abstract public function deleteLanguage(int $id): void; * Check whether a language may be deleted. */ abstract public function canDeleteLanguage(int $id): bool; + + /** + * Loads which languages each of the given Content ids is translated into, from + * "ibexa_content_translation" (the relational replacement for "ibexa_content.language_mask"). + * + * @param int[] $contentIds + * + * @return array Content id => language ids + */ + abstract public function loadContentTranslations(array $contentIds): array; + + /** + * Loads which languages each of the given Content Version ids is translated into, from + * "ibexa_content_version_translation" (the relational replacement for + * "ibexa_content_version.language_mask"). + * + * @param int[] $versionIds + * + * @return array Version id => language ids + */ + abstract public function loadVersionTranslations(array $versionIds): array; } diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php index c23b3b884f..be70c79ed9 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php @@ -212,6 +212,71 @@ private function countTableData( return (int)$query->executeQuery()->fetchOne(); } + /** + * @param int[] $contentIds + * + * @return array + */ + public function loadContentTranslations(array $contentIds): array + { + return $this->loadTranslations('ibexa_content_translation', 'content_id', $contentIds); + } + + /** + * @param int[] $versionIds + * + * @return array + */ + public function loadVersionTranslations(array $versionIds): array + { + return $this->loadTranslations('ibexa_content_version_translation', 'content_version_id', $versionIds); + } + + /** + * @param int[] $ids + * + * @return array + */ + private function loadTranslations( + string $tableName, + string $idColumn, + array $ids + ): array { + if (empty($ids)) { + return []; + } + + // Explicit ORDER BY, not just "no ORDER BY happens to come out consistently": without one, + // PostgreSQL (unlike MySQL/InnoDB's PK-clustered storage) can pick a different scan + // strategy - and therefore a different per-id row order - depending on how many ids are in + // this call's IN() list. Different call sites batch different numbers of ids at once (e.g. + // the Legacy Search Engine loads a whole result page in one call, while another caller might + // batch differently), so relying on incidental order would make language_id ordering + // inconsistent between them on Postgres specifically, even though every call goes through + // this exact same method. + $query = $this->connection->createQueryBuilder(); + $rows = $query + ->select($idColumn, 'language_id') + ->from($tableName) + ->where( + $query->expr()->in( + $idColumn, + $query->createNamedParameter($ids, ArrayParameterType::INTEGER, ':ids') + ) + ) + ->orderBy($idColumn) + ->addOrderBy('language_id') + ->executeQuery() + ->fetchAllAssociative(); + + $translations = []; + foreach ($rows as $row) { + $translations[(int)$row[$idColumn]][] = (int)$row['language_id']; + } + + return $translations; + } + private function getDatabasePlatform(): AbstractPlatform { try { diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php index 9ea2ae27a7..953818c355 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php @@ -96,4 +96,22 @@ public function canDeleteLanguage(int $id): bool throw DatabaseException::wrap($e); } } + + public function loadContentTranslations(array $contentIds): array + { + try { + return $this->innerGateway->loadContentTranslations($contentIds); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } + + public function loadVersionTranslations(array $versionIds): array + { + try { + return $this->innerGateway->loadVersionTranslations($versionIds); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } } diff --git a/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php index ead5424742..bf39b43185 100644 --- a/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -11,21 +11,18 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Location; use Ibexa\Contracts\Core\Persistence\Content\Location\CreateStruct; use Ibexa\Contracts\Core\Persistence\Content\Location\Handler; use Ibexa\Contracts\Core\Persistence\Content\Location\UpdateStruct; use Ibexa\Contracts\Core\Persistence\Filter\Query\CountQueryBuilder; -use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; -use Ibexa\Core\Base\Exceptions\DatabaseException; use Ibexa\Core\Base\Exceptions\NotFoundException as NotFound; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; @@ -46,7 +43,7 @@ final class DoctrineDatabase extends Gateway public function __construct( private readonly Connection $connection, - private readonly MaskGenerator $languageMaskGenerator, + private readonly LanguageHandler $languageHandler, private readonly CriteriaConverter $trashCriteriaConverter, private readonly SortClauseConverter $trashSortClauseConverter, private readonly CountQueryBuilder $countQueryBuilder @@ -1479,14 +1476,11 @@ private function appendContentItemTranslationsConstraint( bool $useAlwaysAvailable ): void { $expr = $queryBuilder->expr(); - try { - $mask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - $translations, - $useAlwaysAvailable - ); - } catch (NotFoundException $e) { + $languages = iterator_to_array($this->languageHandler->loadListByLanguageCodes($translations)); + if (array_diff($translations, array_keys($languages)) !== []) { return; } + $languageIds = array_map(static fn ($language): int => $language->id, array_values($languages)); $queryBuilder->leftJoin( 't', @@ -1495,13 +1489,35 @@ private function appendContentItemTranslationsConstraint( $expr->eq('t.contentobject_id', 'c.id') ); + $translationSubQuery = $this->connection->createQueryBuilder(); + $translationSubQuery + ->select('1') + ->from('ibexa_content_translation', 'ct') + ->where( + $translationSubQuery->expr()->and( + 'ct.content_id = c.id', + $translationSubQuery->expr()->in( + 'ct.language_id', + $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); + + $translationConditions = [ + sprintf('EXISTS (%s)', $translationSubQuery->getSQL()), + ]; + + if ($useAlwaysAvailable) { + $translationConditions[] = $expr->eq( + 'c.always_available', + $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN) + ); + } + $queryBuilder->andWhere( $expr->or( - $expr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression('c.language_mask', (string)$mask), - '0' - ), - // Root location doesn't have language mask + $expr->or(...$translationConditions), + // Root location doesn't have a translation row $expr->eq( 't.node_id', 't.parent_node_id' @@ -1633,13 +1649,4 @@ private function addSort( $this->trashSortClauseConverter->applyJoin($query, $sort, $languageSettings); $this->trashSortClauseConverter->applyOrderBy($query); } - - private function getDatabasePlatform(): AbstractPlatform - { - try { - return $this->connection->getDatabasePlatform(); - } catch (Exception $e) { - throw DatabaseException::wrap($e); - } - } } diff --git a/src/lib/Persistence/Legacy/Content/Mapper.php b/src/lib/Persistence/Legacy/Content/Mapper.php index 21363c4bf7..ae56715388 100644 --- a/src/lib/Persistence/Legacy/Content/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Mapper.php @@ -23,6 +23,8 @@ use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** @@ -71,18 +73,22 @@ class Mapper private FieldTypeAliasResolverInterface $fieldTypeAliasResolver; + private LanguageGateway $languageGateway; + public function __construct( Registry $converterRegistry, LanguageHandler $languageHandler, ContentTypeHandler $contentTypeHandler, EventDispatcherInterface $eventDispatcher, - FieldTypeAliasResolverInterface $fieldTypeAliasResolver + FieldTypeAliasResolverInterface $fieldTypeAliasResolver, + LanguageGateway $languageGateway ) { $this->converterRegistry = $converterRegistry; $this->languageHandler = $languageHandler; $this->contentTypeHandler = $contentTypeHandler; $this->eventDispatcher = $eventDispatcher; $this->fieldTypeAliasResolver = $fieldTypeAliasResolver; + $this->languageGateway = $languageGateway; } /** @@ -239,10 +245,15 @@ public function extractContentFromRows( $versionInfos = []; $fields = []; + $versionLanguageIds = $this->languageGateway->loadVersionTranslations( + array_unique(array_map(static fn (array $row): int => (int)$row["{$prefix}version_id"], $rows)) + ); + $fieldDefinitions = $this->loadCachedVersionFieldDefinitionsPerLanguage( $rows, $prefix, - $translations + $translations, + $versionLanguageIds ); foreach ($rows as $row) { @@ -258,7 +269,11 @@ public function extractContentFromRows( } if (!isset($versionInfos[$contentId][$versionId])) { - $versionInfos[$contentId][$versionId] = $this->extractVersionInfoFromRow($row); + $versionInfos[$contentId][$versionId] = $this->extractVersionInfoFromRow( + $row, + [], + $versionLanguageIds[$versionId] ?? [] + ); } $fieldId = (int)$row["{$prefix}field_id"]; @@ -342,6 +357,8 @@ private function buildContentObjects( * @phpstan-param TRawContentRow[] $rows * * @param string[]|null $translations + * @param array $versionLanguageIds Version id => language ids, as returned by + * {@see Gateway::loadVersionTranslations()} * * @phpstan-return TVersionedLanguageFieldDefinitionsMap * @@ -350,7 +367,8 @@ private function buildContentObjects( private function loadCachedVersionFieldDefinitionsPerLanguage( array $rows, string $prefix, - ?array $translations = null + ?array $translations, + array $versionLanguageIds ): array { $fieldDefinitions = []; $contentTypes = []; @@ -360,13 +378,12 @@ private function loadCachedVersionFieldDefinitionsPerLanguage( $contentId = (int)$row["{$prefix}id"]; $versionId = (int)$row["{$prefix}version_id"]; $contentTypeId = (int)$row["{$prefix}content_type_id"]; - $languageMask = (int)$row["{$prefix}version_language_mask"]; if (isset($fieldDefinitions[$contentId][$versionId])) { continue; } - $allLanguagesCodes = $this->extractLanguageCodesFromMask($languageMask, $allLanguages); + $allLanguagesCodes = $this->mapLanguageIdsToCodes($versionLanguageIds[$versionId] ?? [], $allLanguages); $languageCodes = empty($translations) ? $allLanguagesCodes : array_intersect($translations, $allLanguagesCodes); $contentTypes[$contentTypeId] = $contentTypes[$contentTypeId] ?? $this->contentTypeHandler->load($contentTypeId); $contentType = $contentTypes[$contentTypeId]; @@ -406,7 +423,7 @@ public function extractContentInfoFromRow( $contentInfo->ownerId = (int)$row["{$prefix}owner_id"]; $contentInfo->publicationDate = (int)$row["{$prefix}published"]; $contentInfo->modificationDate = (int)$row["{$prefix}modified"]; - $contentInfo->alwaysAvailable = 1 === ((int)$row["{$prefix}language_mask"] & 1); + $contentInfo->alwaysAvailable = (bool)$row["{$prefix}always_available"]; $contentInfo->mainLanguageCode = $this->languageHandler->load($row["{$prefix}initial_language_id"])->languageCode; $contentInfo->remoteId = (string)$row["{$prefix}remote_id"]; $contentInfo->mainLocationId = ($row["{$treePrefix}main_node_id"] !== null ? (int)$row["{$treePrefix}main_node_id"] : null); @@ -446,12 +463,15 @@ public function extractContentInfoFromRows( * * @param array $row * @param array $names + * @param int[] $languageIds Language ids this version is translated into, as returned by + * {@see Gateway::loadVersionTranslations()} * * @return VersionInfo */ private function extractVersionInfoFromRow( array $row, - array $names = [] + array $names, + array $languageIds ) { $versionInfo = new VersionInfo(); $versionInfo->id = (int)$row['content_version_id']; @@ -465,11 +485,7 @@ private function extractVersionInfoFromRow( // Map language codes $allLanguages = $this->loadAllLanguagesWithIdKey(); - $versionInfo->languageCodes = $this->extractLanguageCodesFromMask( - (int)$row['content_version_language_mask'], - $allLanguages, - $missing - ); + $versionInfo->languageCodes = $this->mapLanguageIdsToCodes($languageIds, $allLanguages, $missing); $initialLanguageId = (int)$row['content_version_initial_language_id']; if (isset($allLanguages[$initialLanguageId])) { $versionInfo->initialLanguageCode = $allLanguages[$initialLanguageId]->languageCode; @@ -506,6 +522,9 @@ public function extractVersionInfoListFromRows( } $allLanguages = $this->loadAllLanguagesWithIdKey(); + $versionLanguageIds = $this->languageGateway->loadVersionTranslations( + array_unique(array_map(static fn (array $row): int => (int)$row['content_version_id'], $rows)) + ); $versionInfoList = []; foreach ($rows as $row) { $versionId = $row['content_id'] . '_' . $row['content_version_version']; @@ -520,8 +539,8 @@ public function extractVersionInfoListFromRows( $versionInfo->status = (int)$row['content_version_status']; $versionInfo->names = $nameData[$versionId]; $versionInfoList[$versionId] = $versionInfo; - $versionInfo->languageCodes = $this->extractLanguageCodesFromMask( - (int)$row['content_version_language_mask'], + $versionInfo->languageCodes = $this->mapLanguageIdsToCodes( + $versionLanguageIds[$versionInfo->id] ?? [], $allLanguages, $missing ); @@ -545,32 +564,24 @@ public function extractVersionInfoListFromRows( } /** - * @param int $languageMask - * @param Language[] $allLanguages + * @param int[] $languageIds + * @param Language[] $allLanguages Keyed by language id * @param int[] &$missing * * @return string[] */ - private function extractLanguageCodesFromMask( - int $languageMask, + private function mapLanguageIdsToCodes( + array $languageIds, array $allLanguages, &$missing = [] ) { - $exp = 2; $result = []; - - // Decomposition of $languageMask into its binary components to extract language codes - // check if $exp has not overflown and became float (happens for the last possible language in the mask) - while (is_int($exp) && $exp <= $languageMask) { - if ($languageMask & $exp) { - if (isset($allLanguages[$exp])) { - $result[] = $allLanguages[$exp]->languageCode; - } else { - $missing[] = $exp; - } + foreach ($languageIds as $languageId) { + if (isset($allLanguages[$languageId])) { + $result[] = $allLanguages[$languageId]->languageCode; + } else { + $missing[] = $languageId; } - - $exp *= 2; } return $result; diff --git a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php index 0a7f03774d..dd62180e2c 100644 --- a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php +++ b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php @@ -9,6 +9,7 @@ namespace Ibexa\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Content; use Doctrine\DBAL\ArrayParameterType; +use Doctrine\DBAL\ParameterType; use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LanguageCode; use Ibexa\Contracts\Core\Repository\Values\Filter\CriterionQueryBuilder; @@ -37,10 +38,15 @@ public function buildQueryConstraint( $queryBuilder ->joinOnce( 'version', + 'ibexa_content_version_translation', + 'version_translation', + 'version_translation.content_version_id = version.id' + ) + ->joinOnce( + 'version_translation', Gateway::CONTENT_LANGUAGE_TABLE, 'language', - // bitwise and for exact language ID match - 'language.id & version.language_mask = language.id' + 'language.id = version_translation.language_id' ); // at this point $criterion->value is guaranteed to be an array @@ -53,7 +59,13 @@ public function buildQueryConstraint( ); if ($criterion->matchAlwaysAvailable) { - $expr = (string)$queryBuilder->expr()->or($expr, 'version.language_mask & 1 = 1'); + $expr = (string)$queryBuilder->expr()->or( + $expr, + $queryBuilder->expr()->eq( + 'version.always_available', + $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN) + ) + ); } return $expr; diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index 460192bca9..3a66fcf586 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -15,6 +15,7 @@ use Ibexa\Contracts\Core\Persistence\Filter\SortClauseVisitor; use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Filter\Gateway\Gateway; use Traversable; @@ -33,7 +34,7 @@ final class DoctrineGateway implements Gateway 'content_type_id' => 'content.content_type_id', 'content_current_version' => 'content.current_version', 'content_initial_language_id' => 'content.initial_language_id', - 'content_language_mask' => 'content.language_mask', + 'content_always_available' => 'content.always_available', 'content_modified' => 'content.modified', 'content_name' => 'content.name', 'content_owner_id' => 'content.owner_id', @@ -49,7 +50,7 @@ final class DoctrineGateway implements Gateway 'content_version_created' => 'version.created', 'content_version_modified' => 'version.modified', 'content_version_status' => 'version.status', - 'content_version_language_mask' => 'version.language_mask', + 'content_version_always_available' => 'version.always_available', 'content_version_initial_language_id' => 'version.initial_language_id', // Main Location (nullable) 'content_main_location_id' => 'main_location.main_node_id', @@ -59,7 +60,8 @@ public function __construct( private readonly Connection $connection, private readonly CriterionVisitor $criterionVisitor, private readonly SortClauseVisitor $sortClauseVisitor, - private readonly CountQueryBuilder $countQueryBuilder + private readonly CountQueryBuilder $countQueryBuilder, + private readonly LanguageGateway $languageGateway ) {} /** @@ -95,6 +97,7 @@ public function find( // get additional data for the same query constraints $names = $this->bulkFetchVersionNames(clone $query); $fieldValues = $this->bulkFetchFieldValues(clone $query); + $translations = $this->bulkFetchVersionTranslations(clone $query); $query->setFirstResult($offset); if ($limit > 0) { @@ -115,6 +118,7 @@ public function find( $contentId, $versionNo ); + $row['content_version_translations'] = $translations[(int)$row['content_version_id']] ?? []; yield $row; } @@ -214,7 +218,15 @@ private function bulkFetchVersionNames(FilteringQueryBuilder $query): array (string)$query->expr()->and( 'content.id = content_name.contentobject_id', 'version.version = content_name.content_version', - 'version.language_mask & content_name.language_id > 0' + // content_name.language_id may still carry a stray pre-migration "always + // available" bit (+1) that was never cleaned up retroactively - tolerate it + // the same defensive way LanguagePriorityConditionBuilder does for + // ibexa_content_field.language_id. + 'EXISTS ( + SELECT 1 FROM ibexa_content_version_translation cvt + WHERE cvt.content_version_id = version.id + AND content_name.language_id IN (cvt.language_id, cvt.language_id + 1) + )' ) ) // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints @@ -250,7 +262,14 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array (string)$query->expr()->and( 'content.id = content_field.contentobject_id', 'version.version = content_field.version', - 'version.language_mask & content_field.language_id = content_field.language_id' + // content_field.language_id may still carry a stray pre-migration "always + // available" bit (+1) that was never cleaned up retroactively - see the same + // tolerance in bulkFetchVersionNames() above. + 'EXISTS ( + SELECT 1 FROM ibexa_content_version_translation cvt + WHERE cvt.content_version_id = version.id + AND content_field.language_id IN (cvt.language_id, cvt.language_id + 1) + )' ) ) // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints @@ -261,6 +280,39 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array return $query->executeQuery()->fetchAllAssociative(); } + /** + * Bulk-fetches, for the same query constraints, which languages each matched content version is + * translated into - avoids the N+1 that would result from calling + * {@see LanguageGateway::loadVersionTranslations()} once per row in the data mapper instead. + * + * Deliberately reuses that same gateway method (batched with every matching version id at once) + * rather than reimplementing the query as a join against the main criteria query, like + * {@see bulkFetchVersionNames()}/{@see bulkFetchFieldValues()} above do: other callers (e.g. the + * Legacy Search Engine) also load translations through this same shared method, batched with + * their own, differently-sized id lists - reusing it here, rather than a bespoke query, is what + * guarantees every caller agrees on each version's language order. + * + * @return array Content version id => language ids + */ + private function bulkFetchVersionTranslations(FilteringQueryBuilder $query): array + { + $query + // completely reset SELECT part to get only needed data + ->select('version.id AS content_version_id') + ->distinct() + // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints + ->setMaxResults(null) + ->setFirstResult(0) + ->resetOrderBy(); + + $versionIds = array_map( + 'intval', + $query->executeQuery()->fetchFirstColumn() + ); + + return $this->languageGateway->loadVersionTranslations($versionIds); + } + private function getColumns(): Traversable { foreach (self::COLUMN_MAP as $columnAlias => $columnName) { diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Mapper/DoctrineGatewayDataMapper.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Mapper/DoctrineGatewayDataMapper.php index e6e05ea452..5b7b8ccfff 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Mapper/DoctrineGatewayDataMapper.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Mapper/DoctrineGatewayDataMapper.php @@ -18,7 +18,6 @@ use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue; use Ibexa\Core\Persistence\Legacy\Filter\Gateway\Content\Doctrine\DoctrineGateway; use Ibexa\Core\Persistence\Legacy\Filter\Gateway\Content\GatewayDataMapper; @@ -31,9 +30,6 @@ final class DoctrineGatewayDataMapper implements GatewayDataMapper /** @var ConverterRegistry */ private $converterRegistry; - /** @var MaskGenerator */ - private $languageMaskGenerator; - /** @var LanguageHandler */ private $languageHandler; @@ -42,12 +38,10 @@ final class DoctrineGatewayDataMapper implements GatewayDataMapper public function __construct( LanguageHandler $languageHandler, - MaskGenerator $languageMaskGenerator, ContentTypeHandler $contentTypeHandler, ConverterRegistry $converterRegistry, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver ) { - $this->languageMaskGenerator = $languageMaskGenerator; $this->languageHandler = $languageHandler; $this->contentTypeHandler = $contentTypeHandler; $this->converterRegistry = $converterRegistry; @@ -107,9 +101,12 @@ private function mapVersionDataToPersistenceVersionInfo(array $row): VersionInfo $versionInfo->status = (int)$row['content_version_status']; $versionInfo->names = $row['content_version_names']; - // Map language codes - $versionInfo->languageCodes = $this->languageMaskGenerator->extractLanguageCodesFromMask( - (int)$row['content_version_language_mask'] + // Map language codes - "content_version_translations" is bulk-fetched once for the whole + // result page by DoctrineGateway::find(), not queried per row here, to avoid an N+1. + $languageIds = $row['content_version_translations']; + $versionInfo->languageCodes = array_map( + fn (int $languageId): string => $this->languageHandler->load($languageId)->languageCode, + $languageIds ); $versionInfo->initialLanguageCode = $this->languageHandler->load( (int)$row['content_version_initial_language_id'] @@ -196,7 +193,7 @@ public function mapContentMetadataToPersistenceContentInfo(array $row): ContentI $contentInfo->ownerId = (int)$row['content_owner_id']; $contentInfo->publicationDate = (int)$row['content_published']; $contentInfo->modificationDate = (int)$row['content_modified']; - $contentInfo->alwaysAvailable = 1 === ($row['content_language_mask'] & 1); + $contentInfo->alwaysAvailable = (bool)$row['content_always_available']; $contentInfo->mainLanguageCode = $mainLanguage->languageCode; $contentInfo->remoteId = $row['content_remote_id']; $contentInfo->mainLocationId = $row['content_main_location_id'] !== null diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php index d0f317364a..ba0e26ccb7 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php @@ -93,7 +93,7 @@ private function buildQuery(FilteringCriterion $criterion): FilteringQueryBuilde 'content.content_type_id AS content_type_id', 'content.current_version AS content_current_version', 'content.initial_language_id AS content_initial_language_id', - 'content.language_mask AS content_language_mask', + 'content.always_available AS content_always_available', 'content.modified AS content_modified', 'content.name AS content_name', 'content.owner_id AS content_owner_id', diff --git a/src/lib/Resources/settings/storage_engines/legacy/content.yml b/src/lib/Resources/settings/storage_engines/legacy/content.yml index 4c9885041e..5a15664274 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content.yml @@ -12,6 +12,7 @@ services: - '@ibexa.spi.persistence.legacy.content_type.handler' - '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' + - '@ibexa.persistence.legacy.language.gateway' Ibexa\Core\Persistence\Legacy\Content\Mapper\ResolveVirtualFieldSubscriber: arguments: diff --git a/src/lib/Resources/settings/storage_engines/legacy/filter.yaml b/src/lib/Resources/settings/storage_engines/legacy/filter.yaml index 5b23edfb25..d90f1376a5 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/filter.yaml +++ b/src/lib/Resources/settings/storage_engines/legacy/filter.yaml @@ -30,7 +30,6 @@ services: Ibexa\Core\Persistence\Legacy\Filter\Gateway\Content\Mapper\DoctrineGatewayDataMapper: arguments: $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' - $languageMaskGenerator: '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' $contentTypeHandler: '@Ibexa\Contracts\Core\Persistence\Content\Type\Handler' $converterRegistry: '@Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry' @@ -45,6 +44,7 @@ services: Ibexa\Core\Persistence\Legacy\Filter\Gateway\Content\Doctrine\DoctrineGateway: arguments: $connection: '@ibexa.persistence.connection' + $languageGateway: '@ibexa.persistence.legacy.language.gateway' Ibexa\Core\Persistence\Legacy\Filter\Handler\ContentFilteringHandler: arguments: diff --git a/src/lib/Resources/settings/storage_engines/legacy/location.yml b/src/lib/Resources/settings/storage_engines/legacy/location.yml index d6e86033d5..04aabbf418 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/location.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/location.yml @@ -3,7 +3,7 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase arguments: - '@ibexa.api.storage_engine.legacy.connection' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + - '@ibexa.spi.persistence.legacy.language.handler' - '@ibexa.core.trash.search.legacy.gateway.criteria_converter' - '@ibexa.core.trash.search.legacy.gateway.sort_clause_converter' - '@Ibexa\Contracts\Core\Persistence\Filter\Query\CountQueryBuilder' diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php new file mode 100644 index 0000000000..95ef486468 --- /dev/null +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -0,0 +1,276 @@ +insertDatabaseFixture( + __DIR__ . '/../../../lib/Persistence/Legacy/Content/_fixtures/languages.php' + ); + + $connection = $this->getDatabaseConnection(); + + // content id 1: eng-US only, not always available -> mask 2 + // content id 2: eng-US + eng-GB, always available -> mask 7 + $connection->insert('ibexa_content', [ + 'id' => 1, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => 2, + 'language_mask' => 2, + 'always_available' => 0, + 'name' => 'Foo', + 'owner_id' => 14, + 'remote_id' => 'foo', + ]); + $connection->insert('ibexa_content', [ + 'id' => 2, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => 2, + 'language_mask' => 7, + 'always_available' => 1, + 'name' => 'Bar', + 'owner_id' => 14, + 'remote_id' => 'bar', + ]); + + $connection->insert('ibexa_content_version', [ + 'id' => 1, + 'contentobject_id' => 1, + 'version' => 1, + 'initial_language_id' => 2, + 'language_mask' => 2, + ]); + $connection->insert('ibexa_content_version', [ + 'id' => 2, + 'contentobject_id' => 2, + 'version' => 1, + 'initial_language_id' => 2, + 'language_mask' => 7, + ]); + + $connection->insert('ibexa_url_alias_ml', [ + 'parent' => 0, + // md5('foo') - written as a literal hex digest, matching the convention other UrlAlias + // fixtures in this repo already use, since a live md5() call here trips Sonar's weak-hash + // rule even though this is just a lookup key, not a security-sensitive hash. + 'text_md5' => 'acbd18db4cc2f85cedef654fccc4a4d8', + 'id' => 1, + 'text' => 'foo', + 'action' => 'eznode:1', + 'action_type' => 'eznode', + 'lang_mask' => 7, + ], ['lang_mask' => ParameterType::INTEGER]); + } + + public function testBackfillPopulatesTranslationTablesFromMasks(): void + { + $exitCode = (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) + ->execute(['--table' => 'all']) + ; + + self::assertSame(0, $exitCode); + + self::assertEqualsCanonicalizing( + [[1, 2], [2, 2], [2, 4]], + $this->fetchPairs('ibexa_content_translation', 'content_id') + ); + self::assertEqualsCanonicalizing( + [[1, 2], [2, 2], [2, 4]], + $this->fetchPairs('ibexa_content_version_translation', 'content_version_id') + ); + self::assertEqualsCanonicalizing( + [[2], [4]], + array_map( + static fn (array $row): array => [(int)$row['language_id']], + $this->getDatabaseConnection()->fetchAllAssociative( + 'SELECT language_id FROM ibexa_url_alias_ml_translation' + ) + ) + ); + } + + public function testBackfillIsIdempotent(): void + { + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); + (new CommandTester($command))->execute(['--table' => 'content']); + (new CommandTester($command))->execute(['--table' => 'content']); + + self::assertEqualsCanonicalizing( + [[1, 2], [2, 2], [2, 4]], + $this->fetchPairs('ibexa_content_translation', 'content_id') + ); + } + + public function testBackfillDryRunDoesNotWrite(): void + { + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); + (new CommandTester($command))->execute(['--table' => 'content', '--dry-run' => true]); + + self::assertSame([], $this->fetchPairs('ibexa_content_translation', 'content_id')); + } + + public function testBackfillDryRunReportsNothingRemainingAfterRealBackfill(): void + { + $connection = $this->getDatabaseConnection(); + (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) + ->execute(['--table' => 'content']); + + // A dry-run preview after a real backfill must report that nothing is left to insert - not + // recount every mask-derived pair as if none of them already existed. + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); + $tester->execute(['--table' => 'content', '--dry-run' => true]); + + self::assertStringContainsString('0 row(s) would be inserted', $tester->getDisplay()); + // The real rows from the earlier backfill must not have been touched by the dry-run. + self::assertEqualsCanonicalizing( + [[1, 2], [2, 2], [2, 4]], + $this->fetchPairs('ibexa_content_translation', 'content_id') + ); + } + + public function testVerifyReportsCleanAfterBackfill(): void + { + (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) + ->execute(['--table' => 'all']); + + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($this->getDatabaseConnection())); + $exitCode = $tester->execute(['--table' => 'all']); + + self::assertSame(0, $exitCode); + self::assertStringContainsString('in sync', $tester->getDisplay()); + } + + public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void + { + $connection = $this->getDatabaseConnection(); + + // Missing: content 1's translation was never backfilled. + $connection->insert('ibexa_content_translation', ['content_id' => 2, 'language_id' => 2]); + $connection->insert('ibexa_content_translation', ['content_id' => 2, 'language_id' => 4]); + // Orphaned: language 4 is not part of content 1's mask (2). + $connection->insert('ibexa_content_translation', ['content_id' => 1, 'language_id' => 4]); + + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $exitCode = $tester->execute(['--table' => 'content']); + + self::assertSame(1, $exitCode); + self::assertStringContainsString('1 missing, 1 orphaned', $tester->getDisplay()); + + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); + + self::assertSame(0, $fixExitCode); + self::assertEqualsCanonicalizing( + [[1, 2], [2, 2], [2, 4]], + $this->fetchPairs('ibexa_content_translation', 'content_id') + ); + } + + /** + * Both commands are explicitly documented as usable standalone, outside of a migration run - + * but a schema that already completed the language bitmask migration (or a fresh install, + * which starts from that same final state) has neither the "ibexa_content_language" name nor + * the mask columns these commands' queries otherwise assume. Without a guard, that crashes with + * a raw "no such table"/"no such column" DB exception instead of reporting there is nothing to + * do. + */ + public function testBackfillReportsNothingToDoOnAnAlreadyMigratedSchema(): void + { + $connection = $this->getDatabaseConnection(); + $this->simulateFullyMigratedSchema($connection); + + try { + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); + $exitCode = $tester->execute(['--table' => 'all']); + + self::assertSame(0, $exitCode); + self::assertStringContainsString('already migrated, nothing to backfill', $tester->getDisplay()); + } finally { + $this->restorePreMigrationSchema($connection); + } + } + + public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void + { + $connection = $this->getDatabaseConnection(); + $this->simulateFullyMigratedSchema($connection); + + try { + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $exitCode = $tester->execute(['--table' => 'all']); + + self::assertSame(0, $exitCode); + self::assertStringContainsString('already migrated, nothing to verify', $tester->getDisplay()); + } finally { + $this->restorePreMigrationSchema($connection); + } + } + + /** + * Undoes setUp()'s pre-migration simulation: renames the language table to its final name and + * drops the mask columns, matching the state a schema is in once DropLanguageBitmaskColumnsMigration + * and RenameLanguageTableMigration have both run (or a fresh install, which never had + * them at all). + */ + private function simulateFullyMigratedSchema(Connection $connection): void + { + $connection->executeStatement('ALTER TABLE ibexa_content_language RENAME TO ibexa_language'); + // SQLite can't drop a column an index still covers + $connection->executeStatement('DROP INDEX ibexa_content_lmask'); + $connection->executeStatement('DROP INDEX ibexa_url_alias_ml_text_lang'); + $connection->executeStatement('ALTER TABLE ibexa_content DROP COLUMN language_mask'); + $connection->executeStatement('ALTER TABLE ibexa_content_version DROP COLUMN language_mask'); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml DROP COLUMN lang_mask'); + } + + /** + * Mirror image of simulateFullyMigratedSchema(): restores the pre-migration state the next + * test's setUp() expects to find, via the shared SQLite connection pool. + */ + private function restorePreMigrationSchema(Connection $connection): void + { + $connection->executeStatement('ALTER TABLE ibexa_language RENAME TO ibexa_content_language'); + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_content_version ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); + } + + /** + * @return list + */ + private function fetchPairs( + string $table, + string $idColumn + ): array { + $rows = $this->getDatabaseConnection()->fetchAllAssociative( + "SELECT {$idColumn}, language_id FROM {$table}" + ); + + return array_map( + static fn (array $row): array => [(int)$row[$idColumn], (int)$row['language_id']], + $rows + ); + } +} diff --git a/tests/bundle/Core/Resources/services/fixture-services.yaml b/tests/bundle/Core/Resources/services/fixture-services.yaml index dfe6d24f5c..a0620cb82a 100644 --- a/tests/bundle/Core/Resources/services/fixture-services.yaml +++ b/tests/bundle/Core/Resources/services/fixture-services.yaml @@ -17,3 +17,4 @@ services: public: true arguments: - '@doctrine.dbal.default_connection' + - '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' diff --git a/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php b/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php index c39f717128..b5d840e19b 100644 --- a/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php +++ b/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php @@ -16,6 +16,7 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture; use Ibexa\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway as BinaryBaseStorageGateway; use Ibexa\Core\FieldType\BinaryFile\BinaryFileStorage\Gateway\DoctrineStorage; +use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Integration\Core\BaseCoreFieldTypeIntegrationTestCase; /** @@ -27,7 +28,7 @@ protected function setUp(): void { parent::setUp(); - $importer = new FixtureImporter($this->getDatabaseConnection()); + $importer = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); $importer->import(new YamlFixture(__DIR__ . '/_fixtures/ibexa_binary_file.yaml')); } diff --git a/tests/integration/Core/TestKernel.php b/tests/integration/Core/TestKernel.php index d789717031..3b8a4fdec2 100644 --- a/tests/integration/Core/TestKernel.php +++ b/tests/integration/Core/TestKernel.php @@ -16,9 +16,11 @@ use Ibexa\Contracts\Core\Repository\BookmarkService; use Ibexa\Contracts\Core\Repository\TrashService; use Ibexa\Contracts\Core\Test\IbexaTestKernel; +use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Contracts\Test\Core\IbexaTestKernel as BaseIbexaTestKernel; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; /** * Loads the same fixture set {@see IbexaTestKernel} (the package-internal @@ -48,6 +50,17 @@ public function registerContainerConfiguration(LoaderInterface $loader): void __DIR__ . '/Repository/_fixtures/Legacy/data/test_data.yaml', ]); }); + + $loader->load(static function (ContainerBuilder $container): void { + // ibexa/test-core's own fixture-services.yaml only passes a Connection to + // FixtureImporter - it predates the SchemaAssetsFilterBypassInterface argument this + // package's FixtureImporter gained for the language join-table backfill. Re-wire the + // shared definition here rather than waiting for it to catch up. + $container->getDefinition('test.ibexa.fixture_importer')->setArguments([ + new Reference('ibexa.persistence.connection'), + new Reference(SchemaAssetsFilterBypassInterface::class), + ]); + }); } public function registerBundles(): iterable diff --git a/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php b/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php index 27c57a522b..d8039fb9ba 100644 --- a/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php +++ b/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php @@ -11,6 +11,7 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture; use Ibexa\Core\FieldType\User\UserStorage\Gateway; use Ibexa\Core\Repository\Values\User\User; +use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Integration\Core\BaseCoreFieldTypeIntegrationTestCase; use PHPUnit\Framework\Attributes\DataProvider; @@ -72,7 +73,7 @@ public function testCountUsersWithUnsupportedHashType( ?string $fixtureFilePath ): void { if (null !== $fixtureFilePath) { - $importer = new FixtureImporter($this->getDatabaseConnection()); + $importer = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); $importer->import(new YamlFixture($fixtureFilePath)); } diff --git a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php index 30e05c600b..ab10faafe6 100644 --- a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php @@ -43,6 +43,29 @@ class DoctrineDatabaseTest extends LanguageAwareTestCase */ protected $databaseGateway; + /** + * None of this file's fixtures populate "ibexa_content_language", but insertContentObject()/ + * insertVersion()/updateVersion() now also write to "ibexa_content_translation"/ + * "ibexa_content_version_translation", which FK-reference it - seed the same 3 languages + * LanguageHandlerMock already pretends exist, so those inserts don't violate the constraint. + */ + protected function setUp(): void + { + parent::setUp(); + + foreach ($this->getLanguageHandler()->loadAll() as $language) { + $this->getDatabaseConnection()->insert( + 'ibexa_content_language', + [ + 'id' => $language->id, + 'locale' => $language->languageCode, + 'name' => $language->name, + 'disabled' => 0, + ] + ); + } + } + /** * @todo Fix not available fields */ @@ -64,6 +87,7 @@ public function testInsertContentObject(): void 'initial_language_id' => '2', 'remote_id' => 'some_remote_id', 'language_mask' => '3', + 'always_available' => '1', 'modified' => '0', 'published' => '0', 'status' => ContentInfo::STATUS_DRAFT, @@ -80,6 +104,7 @@ public function testInsertContentObject(): void 'initial_language_id', 'remote_id', 'language_mask', + 'always_available', 'modified', 'published', 'status' @@ -188,6 +213,7 @@ public function testInsertVersion(): void 'workflow_event_pos' => '0', 'version' => '1', 'language_mask' => '5', + 'always_available' => '1', 'initial_language_id' => '4', // Not needed, according to field mapping document // 'user_id', @@ -204,6 +230,7 @@ public function testInsertVersion(): void 'workflow_event_pos', 'version', 'language_mask', + 'always_available', 'initial_language_id' )->from(Gateway::CONTENT_VERSION_TABLE) ); @@ -1438,6 +1465,14 @@ public function testUpdateAlwaysAvailableFlagRemove(): void $gateway->updateAlwaysAvailableFlag(103, false); $connection = $this->getDatabaseConnection(); + self::assertQueryResult( + [['always_available' => 0]], + $connection->createQueryBuilder() + ->select('always_available') + ->from(Gateway::CONTENT_ITEM_TABLE) + ->where('id = 103') + ); + $query = $connection->createQueryBuilder(); self::assertQueryResult( [['id' => 2]], @@ -1505,6 +1540,14 @@ public function testUpdateAlwaysAvailableFlagAdd(): void $gateway->updateAlwaysAvailableFlag($contentId, true); $connection = $this->getDatabaseConnection(); + self::assertQueryResult( + [['always_available' => 1]], + $connection->createQueryBuilder() + ->select('always_available') + ->from(Gateway::CONTENT_ITEM_TABLE) + ->where('id = 102') + ); + $expectedLanguageId = 3; self::assertQueryResult( [['id' => $expectedLanguageId]], diff --git a/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php index 9c246443be..6cacddafb7 100644 --- a/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php @@ -28,7 +28,7 @@ protected function getLocationGateway() { return new DoctrineDatabase( $this->getDatabaseConnection(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getTrashCriteriaConverterDependency(), $this->getTrashSortClauseConverterDependency(), $this->getLimitedCountQueryBuilderDependency() @@ -106,6 +106,42 @@ public function testLoadInvalidLocation(): void $gateway->getBasicNodeData(1337); } + public function testLoadLocationFiltersByTranslationTable(): void + { + // LanguageHandlerMock resolves "eng-GB" to id 4. + $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); + $connection = $this->getDatabaseConnection(); + $connection->insert('ibexa_content_language', [ + 'id' => 4, + 'locale' => 'eng-GB', + 'name' => 'British english', + 'disabled' => 0, + ]); + $connection->insert('ibexa_content_translation', ['content_id' => 75, 'language_id' => 4]); + + $gateway = $this->getLocationGateway(); + + $data = $gateway->getBasicNodeData(77, ['eng-GB'], false); + self::assertLoadLocationProperties($data); + } + + public function testLoadLocationFiltersOutContentMissingFromTranslationTable(): void + { + $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); + $connection = $this->getDatabaseConnection(); + $connection->insert('ibexa_content_language', [ + 'id' => 4, + 'locale' => 'eng-GB', + 'name' => 'British english', + 'disabled' => 0, + ]); + // No matching row in ibexa_content_translation, and content 75 is not always-available. + + $this->expectException(NotFoundException::class); + + $this->getLocationGateway()->getBasicNodeData(77, ['eng-GB'], false); + } + public function testLoadLocationDataByContent(): void { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); diff --git a/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTrashTest.php b/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTrashTest.php index 71af7a9921..e4eef11e40 100644 --- a/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTrashTest.php +++ b/tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTrashTest.php @@ -24,7 +24,7 @@ protected function getLocationGateway() { return new DoctrineDatabase( $this->getDatabaseConnection(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getTrashCriteriaConverterDependency(), $this->getTrashSortClauseConverterDependency(), $this->getLimitedCountQueryBuilderDependency(), diff --git a/tests/lib/Persistence/Legacy/Content/MapperTest.php b/tests/lib/Persistence/Legacy/Content/MapperTest.php index e6782198bf..140fd95c2c 100644 --- a/tests/lib/Persistence/Legacy/Content/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/MapperTest.php @@ -24,6 +24,7 @@ use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry; use Ibexa\Core\Persistence\Legacy\Content\Gateway; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Handler; use Ibexa\Core\Persistence\Legacy\Content\Mapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper\ResolveVirtualFieldSubscriber; @@ -159,6 +160,7 @@ public function testConvertToStorageValue(): void $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub(), ); $res = $mapper->convertToStorageValue($field); @@ -185,7 +187,7 @@ public function testExtractContentFromRows(): void 'ibexa_image', 'ibexa_datetime', 'ibexa_keyword', - ], count($rowsFixture) - 1); + ], null); $mapper = new Mapper( $reg, @@ -193,6 +195,7 @@ public function testExtractContentFromRows(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub($rowsFixture), ); $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); @@ -225,7 +228,7 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void 'ibexa_datetime', 'ibexa_keyword', 'eznumber', - ], count($rowsFixture) - 1); + ], null); $mapper = new Mapper( $reg, @@ -233,13 +236,25 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub($rowsFixture), ); $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); $expectedContent = $this->getContentExtractReference(); + // Virtual "eznumber" fields (no data rows for this field definition at all) are + // synthesized once per recognized language - eng-US right after the real field rows, + // eng-GB at the very end after the eng-GB virtual fields for pre-existing definitions. + array_splice($expectedContent->fields, 9, 0, [ + new Field([ + 'type' => 'eznumber', + 'languageCode' => 'eng-US', + 'value' => new FieldValue(), + 'versionNo' => 2, + ]), + ]); $expectedContent->fields[] = new Field([ 'type' => 'eznumber', - 'languageCode' => 'eng-US', + 'languageCode' => 'eng-GB', 'value' => new FieldValue(), 'versionNo' => 2, ]); @@ -275,7 +290,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { 'ibexa_image', 'ibexa_datetime', 'ibexa_keyword', - ], count($rowsFixture) - 2); + ], null); $mapper = new Mapper( $reg, @@ -283,6 +298,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub($rowsFixture), ); $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); @@ -329,6 +345,7 @@ public function testExtractContentFromRowsMultipleVersions(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub($rowsFixture), ); $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); @@ -495,6 +512,7 @@ public function testExtractContentInfoFromRow( $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub(), ); self::assertEquals($contentInfoReference, $mapper->extractContentInfoFromRow($fixtures, $prefix)); } @@ -655,9 +673,45 @@ protected function getMapper($valueConverter = null) $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->getLanguageGatewayStub(), ); } + /** + * Builds a Language Gateway stub whose loadVersionTranslations() collects the distinct set of + * real (non-always-available) language ids each version's fields are written in from $rows - + * the relational replacement for decoding "content_version_language_mask". + * + * These fixtures predate "content_field_language_id" always being a pure id - some rows still + * carry the legacy "indicator" encoding (id with the always-available bit folded in), so mask + * it off the same way decoding "content_version_language_mask" used to (implicitly, by never + * testing bit 0). + * + * @param array> $rows + */ + protected function getLanguageGatewayStub( + array $rows = [], + string $prefix = 'content_' + ): LanguageGateway { + $versionLanguageIds = []; + foreach ($rows as $row) { + $versionId = (int)$row["{$prefix}version_id"]; + $languageId = (int)$row["{$prefix}field_language_id"] & ~1; + if (!isset($versionLanguageIds[$versionId])) { + $versionLanguageIds[$versionId] = []; + } + if (!in_array($languageId, $versionLanguageIds[$versionId], true)) { + $versionLanguageIds[$versionId][] = $languageId; + } + } + + $gateway = $this->createMock(LanguageGateway::class); + $gateway->method('loadVersionTranslations')->willReturn($versionLanguageIds); + $gateway->method('loadContentTranslations')->willReturn([]); + + return $gateway; + } + /** * Returns a FieldValue converter registry mock. * diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index 00bd4a6888..27a488034e 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -5369,7 +5369,7 @@ protected function getLocationGateway() if (!isset($this->locationGateway)) { $this->locationGateway = new DoctrineDatabaseLocation( $this->getDatabaseConnection(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getTrashCriteriaConverterDependency(), $this->getTrashSortClauseConverterDependency(), $this->getLimitedCountQueryBuilderDependency() diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows.php index ade04f1293..84f218df69 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows.php @@ -4,7 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ -return [ +return [ 0 => [ 'content_id' => 226, 'content_content_type_id' => 16, @@ -17,7 +17,7 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, @@ -25,7 +25,7 @@ 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1332, 'content_field_content_type_field_definition_id' => 183, @@ -51,14 +51,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1333, 'content_field_content_type_field_definition_id' => 184, @@ -71,7 +72,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => 'something', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 2 => [ 'content_id' => 226, @@ -85,14 +85,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1334, 'content_field_content_type_field_definition_id' => 185, @@ -107,7 +108,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 3 => [ 'content_id' => 226, @@ -121,14 +121,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1337, 'content_field_content_type_field_definition_id' => 188, @@ -141,7 +142,6 @@ 'content_field_sort_key_int' => 1, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 4 => [ 'content_id' => 226, @@ -155,14 +155,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1338, 'content_field_content_type_field_definition_id' => 189, @@ -177,7 +178,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 5 => [ 'content_id' => 226, @@ -191,14 +191,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1340, 'content_field_content_type_field_definition_id' => 191, @@ -211,7 +212,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 6 => [ 'content_id' => 226, @@ -225,14 +225,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1341, 'content_field_content_type_field_definition_id' => 192, @@ -245,7 +246,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 7 => [ 'content_id' => 226, @@ -259,14 +259,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 1342, 'content_field_content_type_field_definition_id' => 193, @@ -279,7 +280,6 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], 8 => [ 'content_id' => 226, @@ -293,14 +293,15 @@ 'content_published' => 1313047907, 'content_status' => 1, 'content_name' => 'Something', - 'content_language_mask' => 2, + 'content_always_available' => 0, + 'content_is_hidden' => 0, 'content_version_id' => 676, 'content_version_version' => 2, 'content_version_modified' => 1313061404, 'content_version_creator_id' => 14, 'content_version_created' => 1313061317, 'content_version_status' => 1, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_version_initial_language_id' => 2, 'content_field_id' => 4000, 'content_field_content_type_field_definition_id' => 193, @@ -313,6 +314,5 @@ 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', 'content_tree_main_node_id' => 228, - 'content_is_hidden' => 0, ], ]; diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php index 2125d3b1f8..fe5d8b5962 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php @@ -4,141 +4,141 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ -return [ +return [ 0 => [ - 'content_id' => '11', - 'content_content_type_id' => '3', - 'content_section_id' => '2', - 'content_owner_id' => '14', + 'content_id' => 11, + 'content_content_type_id' => 3, + 'content_section_id' => 2, + 'content_owner_id' => 14, 'content_remote_id' => '5f7f0bdb3381d6a461d8c29ff53d908f', - 'content_current_version' => '2', - 'content_initial_language_id' => '2', - 'content_modified' => '1311154215', - 'content_published' => '1033920746', - 'content_status' => '1', - 'content_version_id' => '439', + 'content_current_version' => 2, + 'content_initial_language_id' => 2, + 'content_modified' => 1311154215, + 'content_published' => 1033920746, + 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => '3', - 'content_version_version' => '1', - 'content_version_modified' => '1033920746', - 'content_version_creator_id' => '14', - 'content_version_created' => '1033920737', - 'content_version_status' => '3', - 'content_version_language_mask' => '3', - 'content_version_initial_language_id' => '2', - 'content_field_id' => '22', - 'content_field_content_type_field_definition_id' => '6', + 'content_always_available' => 1, + 'content_is_hidden' => 0, + 'content_version_id' => 439, + 'content_version_version' => 1, + 'content_version_modified' => 1033920746, + 'content_version_creator_id' => 14, + 'content_version_created' => 1033920737, + 'content_version_status' => 3, + 'content_version_always_available' => 1, + 'content_version_initial_language_id' => 2, + 'content_field_id' => 22, + 'content_field_content_type_field_definition_id' => 6, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => '3', - 'content_field_data_float' => '0.0', - 'content_field_data_int' => '0', + 'content_field_language_id' => 3, + 'content_field_data_float' => 0.0, + 'content_field_data_int' => 0, 'content_field_data_text' => 'Guest accounts', - 'content_field_sort_key_int' => '0', + 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', - 'content_tree_main_node_id' => '12', - 'content_is_hidden' => '0', + 'content_tree_main_node_id' => 12, ], 1 => [ - 'content_id' => '11', - 'content_content_type_id' => '3', - 'content_section_id' => '2', - 'content_owner_id' => '14', + 'content_id' => 11, + 'content_content_type_id' => 3, + 'content_section_id' => 2, + 'content_owner_id' => 14, 'content_remote_id' => '5f7f0bdb3381d6a461d8c29ff53d908f', - 'content_current_version' => '2', - 'content_initial_language_id' => '2', - 'content_modified' => '1311154215', - 'content_published' => '1033920746', - 'content_status' => '1', - 'content_version_id' => '439', + 'content_current_version' => 2, + 'content_initial_language_id' => 2, + 'content_modified' => 1311154215, + 'content_published' => 1033920746, + 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => '3', - 'content_version_version' => '1', - 'content_version_modified' => '1033920746', - 'content_version_creator_id' => '14', - 'content_version_created' => '1033920737', - 'content_version_status' => '3', - 'content_version_language_mask' => '3', - 'content_version_initial_language_id' => '2', - 'content_field_id' => '23', - 'content_field_content_type_field_definition_id' => '7', + 'content_always_available' => 1, + 'content_is_hidden' => 0, + 'content_version_id' => 439, + 'content_version_version' => 1, + 'content_version_modified' => 1033920746, + 'content_version_creator_id' => 14, + 'content_version_created' => 1033920737, + 'content_version_status' => 3, + 'content_version_always_available' => 1, + 'content_version_initial_language_id' => 2, + 'content_field_id' => 23, + 'content_field_content_type_field_definition_id' => 7, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => '3', - 'content_field_data_float' => '0.0', - 'content_field_data_int' => '0', + 'content_field_language_id' => 3, + 'content_field_data_float' => 0.0, + 'content_field_data_int' => 0, 'content_field_data_text' => '', - 'content_field_sort_key_int' => '0', + 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', - 'content_tree_main_node_id' => '12', - 'content_is_hidden' => '0', + 'content_tree_main_node_id' => 12, ], 2 => [ - 'content_id' => '11', - 'content_content_type_id' => '3', - 'content_section_id' => '2', - 'content_owner_id' => '14', + 'content_id' => 11, + 'content_content_type_id' => 3, + 'content_section_id' => 2, + 'content_owner_id' => 14, 'content_remote_id' => '5f7f0bdb3381d6a461d8c29ff53d908f', - 'content_current_version' => '2', - 'content_initial_language_id' => '2', - 'content_modified' => '1311154215', - 'content_published' => '1033920746', - 'content_status' => '1', - 'content_version_id' => '674', + 'content_current_version' => 2, + 'content_initial_language_id' => 2, + 'content_modified' => 1311154215, + 'content_published' => 1033920746, + 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => '3', - 'content_version_version' => '2', - 'content_version_modified' => '1311154215', - 'content_version_creator_id' => '14', - 'content_version_created' => '1311154215', - 'content_version_status' => '1', - 'content_version_language_mask' => '3', - 'content_version_initial_language_id' => '2', - 'content_field_id' => '22', - 'content_field_content_type_field_definition_id' => '6', + 'content_always_available' => 1, + 'content_is_hidden' => 0, + 'content_version_id' => 674, + 'content_version_version' => 2, + 'content_version_modified' => 1311154215, + 'content_version_creator_id' => 14, + 'content_version_created' => 1311154215, + 'content_version_status' => 1, + 'content_version_always_available' => 1, + 'content_version_initial_language_id' => 2, + 'content_field_id' => 22, + 'content_field_content_type_field_definition_id' => 6, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => '3', - 'content_field_data_float' => '0.0', - 'content_field_data_int' => '0', + 'content_field_language_id' => 3, + 'content_field_data_float' => 0.0, + 'content_field_data_int' => 0, 'content_field_data_text' => 'Members', - 'content_field_sort_key_int' => '0', + 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => 'members', - 'content_tree_main_node_id' => '12', - 'content_is_hidden' => '0', + 'content_tree_main_node_id' => 12, ], 3 => [ - 'content_id' => '11', - 'content_content_type_id' => '3', - 'content_section_id' => '2', - 'content_owner_id' => '14', + 'content_id' => 11, + 'content_content_type_id' => 3, + 'content_section_id' => 2, + 'content_owner_id' => 14, 'content_remote_id' => '5f7f0bdb3381d6a461d8c29ff53d908f', - 'content_current_version' => '2', - 'content_initial_language_id' => '2', - 'content_modified' => '1311154215', - 'content_published' => '1033920746', - 'content_status' => '1', - 'content_version_id' => '674', + 'content_current_version' => 2, + 'content_initial_language_id' => 2, + 'content_modified' => 1311154215, + 'content_published' => 1033920746, + 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => '3', - 'content_version_version' => '2', - 'content_version_modified' => '1311154215', - 'content_version_creator_id' => '14', - 'content_version_created' => '1311154215', - 'content_version_status' => '1', - 'content_version_language_mask' => '3', - 'content_version_initial_language_id' => '2', - 'content_field_id' => '23', - 'content_field_content_type_field_definition_id' => '7', + 'content_always_available' => 1, + 'content_is_hidden' => 0, + 'content_version_id' => 674, + 'content_version_version' => 2, + 'content_version_modified' => 1311154215, + 'content_version_creator_id' => 14, + 'content_version_created' => 1311154215, + 'content_version_status' => 1, + 'content_version_always_available' => 1, + 'content_version_initial_language_id' => 2, + 'content_field_id' => 23, + 'content_field_content_type_field_definition_id' => 7, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => '3', - 'content_field_data_float' => '0.0', - 'content_field_data_int' => '0', + 'content_field_language_id' => 3, + 'content_field_data_float' => 0.0, + 'content_field_data_int' => 0, 'content_field_data_text' => '', - 'content_field_sort_key_int' => '0', + 'content_field_sort_key_int' => 0, 'content_field_sort_key_string' => '', - 'content_tree_main_node_id' => '12', - 'content_is_hidden' => '0', + 'content_tree_main_node_id' => 12, ], ]; diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php index 727fd2b185..2d9b76ab2a 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php @@ -23,7 +23,7 @@ $versionInfo->creationDate = 1313061317; $versionInfo->status = 1; $versionInfo->initialLanguageCode = 'eng-US'; -$versionInfo->languageCodes = ['eng-US']; +$versionInfo->languageCodes = ['eng-US', 'eng-GB']; $versionInfo->contentInfo = new ContentInfo(); $versionInfo->contentInfo->id = 226; @@ -122,4 +122,84 @@ $content->fields[] = $field; +$field = new Field(); +$field->id = 4000; +$field->fieldDefinitionId = 193; +$field->type = 'ibexa_keyword'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 183; +$field->type = 'ibexa_string'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 184; +$field->type = 'ibexa_string'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 185; +$field->type = 'ibexa_author'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 188; +$field->type = 'ibexa_boolean'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 189; +$field->type = 'ibexa_image'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 191; +$field->type = 'ibexa_datetime'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + +$field = new Field(); +$field->id = 0; +$field->fieldDefinitionId = 192; +$field->type = 'ibexa_datetime'; +$field->value = new FieldValue(); +$field->languageCode = 'eng-GB'; +$field->versionNo = 2; + +$content->fields[] = $field; + return $content; diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_version_info_from_rows_multiple_versions.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_version_info_from_rows_multiple_versions.php index d7562c9719..6fb7602856 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_version_info_from_rows_multiple_versions.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_version_info_from_rows_multiple_versions.php @@ -4,7 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ -return [ +return [ 0 => [ 'content_version_id' => 439, 'content_version_version' => 1, @@ -12,8 +12,9 @@ 'content_version_creator_id' => 14, 'content_version_created' => 1033920737, 'content_version_status' => 3, + 'content_version_contentobject_id' => 11, 'content_version_initial_language_id' => 2, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_tree_main_node_id' => 12, 'content_id' => 11, 'content_content_type_id' => 3, @@ -26,9 +27,8 @@ 'content_published' => 1033920746, 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => 3, + 'content_always_available' => 1, 'content_is_hidden' => 0, - 'content_version_contentobject_id' => 11, ], 1 => [ 'content_version_id' => 674, @@ -37,8 +37,9 @@ 'content_version_creator_id' => 14, 'content_version_created' => 1311154215, 'content_version_status' => 1, + 'content_version_contentobject_id' => 11, 'content_version_initial_language_id' => 2, - 'content_version_language_mask' => 3, + 'content_version_always_available' => 1, 'content_tree_main_node_id' => 12, 'content_id' => 11, 'content_content_type_id' => 3, @@ -51,8 +52,7 @@ 'content_published' => 1033920746, 'content_status' => 1, 'content_name' => 'Members', - 'content_language_mask' => 3, + 'content_always_available' => 1, 'content_is_hidden' => 0, - 'content_version_contentobject_id' => 11, ], ]; diff --git a/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilderQueryBuilderTest.php b/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilderQueryBuilderTest.php index ce326b5437..a72c0e266f 100644 --- a/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilderQueryBuilderTest.php +++ b/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilderQueryBuilderTest.php @@ -20,8 +20,8 @@ public static function getFilteringCriteriaQueryData(): iterable { yield 'Language Code IN (eng-GB, eng-US), match always available' => [ new Criterion\LanguageCode(['eng-GB', 'eng-US']), - '(language.locale IN (:dcValue1)) OR (version.language_mask & 1 = 1)', - ['dcValue1' => ['eng-GB', 'eng-US']], + '(language.locale IN (:dcValue1)) OR (version.always_available = :dcValue2)', + ['dcValue1' => ['eng-GB', 'eng-US'], 'dcValue2' => true], ]; yield 'Language Code=pol-PL, don\'t match always available' => [ diff --git a/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/LogicalOperatorQueryBuilderQueryBuilderTest.php b/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/LogicalOperatorQueryBuilderQueryBuilderTest.php index 64d2480406..7994b17c4c 100644 --- a/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/LogicalOperatorQueryBuilderQueryBuilderTest.php +++ b/tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/LogicalOperatorQueryBuilderQueryBuilderTest.php @@ -32,8 +32,8 @@ public static function getFilteringCriteriaQueryData(): iterable new Criterion\LanguageCode('eng-GB'), ] ), - '(location.parent_node_id IN (:dcValue1)) AND ((language.locale IN (:dcValue2)) OR (version.language_mask & 1 = 1))', - ['dcValue1' => [1], 'dcValue2' => ['eng-GB']], + '(location.parent_node_id IN (:dcValue1)) AND ((language.locale IN (:dcValue2)) OR (version.always_available = :dcValue3))', + ['dcValue1' => [1], 'dcValue2' => ['eng-GB'], 'dcValue3' => true], ]; yield 'Language Code=eng-US OR Parent Location ID=2' => [ @@ -43,8 +43,8 @@ public static function getFilteringCriteriaQueryData(): iterable new Criterion\ParentLocationId(2), ] ), - '((language.locale IN (:dcValue1)) OR (version.language_mask & 1 = 1)) OR (location.parent_node_id IN (:dcValue2))', - ['dcValue1' => ['eng-GB'], 'dcValue2' => [2]], + '((language.locale IN (:dcValue1)) OR (version.always_available = :dcValue2)) OR (location.parent_node_id IN (:dcValue3))', + ['dcValue1' => ['eng-GB'], 'dcValue2' => true, 'dcValue3' => [2]], ]; yield 'NOT(Content ID=1 OR (Parent Location ID=2 AND Content ID = 1)' => [ diff --git a/tests/lib/Persistence/Legacy/TestCase.php b/tests/lib/Persistence/Legacy/TestCase.php index 3a02c42fa2..db85ec8935 100644 --- a/tests/lib/Persistence/Legacy/TestCase.php +++ b/tests/lib/Persistence/Legacy/TestCase.php @@ -184,7 +184,7 @@ static function ($row): string { protected function insertDatabaseFixture(string $file): void { try { - $fixtureImporter = new FixtureImporter($this->getDatabaseConnection()); + $fixtureImporter = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); $fixtureImporter->import((new FileFixtureFactory())->buildFixture($file)); } catch (DBALException $e) { self::fail('Database fixture import failed: ' . $e->getMessage()); @@ -199,7 +199,7 @@ protected function insertDatabaseFixture(string $file): void protected function insertSharedDatabaseFixture(): void { try { - $fixtureImporter = new FixtureImporter($this->getDatabaseConnection()); + $fixtureImporter = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); $fixtureImporter->import( new YamlFixture( __DIR__ . '/../../../integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml' diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index e149daf545..86f242ea8f 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php @@ -14,6 +14,7 @@ use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; use Ibexa\Core\Persistence\Legacy\Content\FieldHandler; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; @@ -109,6 +110,7 @@ protected function getContentMapperMock() $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->createMock(LanguageGateway::class), ] ) ->onlyMethods(['extractContentInfoFromRows']) diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index 03dcd118c2..b7f86729e7 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -16,6 +16,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; use Ibexa\Core\Persistence; use Ibexa\Core\Persistence\Legacy\Content\FieldHandler; +use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; @@ -231,6 +232,7 @@ protected function getContentMapperMock() $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), + $this->createMock(LanguageGateway::class), ] ) ->onlyMethods(['extractContentInfoFromRows']) From 51f5a0f8dec57bbf16bc6455aadaabfb63fda48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:35:41 +0100 Subject: [PATCH 02/54] IBX-11939: Added constants for the content translation table names --- .../Persistence/Legacy/Content/Gateway.php | 2 ++ .../Content/Gateway/DoctrineDatabase.php | 26 ++++++++++--------- .../Language/Gateway/DoctrineDatabase.php | 5 ++-- .../Location/Gateway/DoctrineDatabase.php | 2 +- .../Content/LanguageCodeQueryBuilder.php | 3 ++- .../Content/Doctrine/DoctrineGateway.php | 4 +-- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Gateway.php b/src/lib/Persistence/Legacy/Content/Gateway.php index 066d3bcabf..91d01b8aa2 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Gateway.php @@ -32,6 +32,8 @@ abstract class Gateway public const CONTENT_FIELD_TABLE = 'ibexa_content_field'; public const CONTENT_VERSION_TABLE = 'ibexa_content_version'; public const CONTENT_RELATION_TABLE = 'ibexa_content_relation'; + public const CONTENT_TRANSLATION_TABLE = 'ibexa_content_translation'; + public const CONTENT_VERSION_TRANSLATION_TABLE = 'ibexa_content_version_translation'; public const CONTENT_FIELD_SEQ = 'ibexa_content_field_id_seq'; diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index f150c5b3f8..db1664555f 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -232,7 +232,7 @@ private function insertContentTranslations( foreach (array_unique($languageCodes) as $languageCode) { $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; $this->connection->executeStatement( - 'INSERT INTO ibexa_content_translation (content_id, language_id) VALUES (:contentId, :languageId)', + 'INSERT INTO ' . self::CONTENT_TRANSLATION_TABLE . ' (content_id, language_id) VALUES (:contentId, :languageId)', ['contentId' => $contentId, 'languageId' => $languageId], ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] ); @@ -249,7 +249,7 @@ private function insertVersionTranslations( foreach (array_unique($languageCodes) as $languageCode) { $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; $this->connection->executeStatement( - 'INSERT INTO ibexa_content_version_translation (content_version_id, language_id) VALUES (:versionId, :languageId)', + 'INSERT INTO ' . self::CONTENT_VERSION_TRANSLATION_TABLE . ' (content_version_id, language_id) VALUES (:versionId, :languageId)', ['versionId' => $versionId, 'languageId' => $languageId], ['versionId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] ); @@ -266,15 +266,16 @@ private function addVersionTranslationsIfMissing( int $versionId, array $languageCodes ): void { + $translationTable = self::CONTENT_VERSION_TRANSLATION_TABLE; foreach (array_unique($languageCodes) as $languageCode) { $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; $this->connection->executeStatement( - 'INSERT INTO ibexa_content_version_translation (content_version_id, language_id) + "INSERT INTO {$translationTable} (content_version_id, language_id) SELECT :versionId, :languageId WHERE NOT EXISTS ( - SELECT 1 FROM ibexa_content_version_translation + SELECT 1 FROM {$translationTable} WHERE content_version_id = :versionId AND language_id = :languageId - )', + )", ['versionId' => $versionId, 'languageId' => $languageId], ['versionId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] ); @@ -293,7 +294,7 @@ private function replaceContentTranslations( array $languageCodes ): void { $this->connection->executeStatement( - 'DELETE FROM ibexa_content_translation WHERE content_id = :contentId', + 'DELETE FROM ' . self::CONTENT_TRANSLATION_TABLE . ' WHERE content_id = :contentId', ['contentId' => $contentId], ['contentId' => ParameterType::INTEGER] ); @@ -2208,7 +2209,7 @@ private function deleteTranslationFromContentObject( $languageId ) { $hasOtherLanguages = (bool)$this->connection->fetchOne( - 'SELECT 1 FROM ibexa_content_translation WHERE content_id = :contentId AND language_id != :languageId', + 'SELECT 1 FROM ' . self::CONTENT_TRANSLATION_TABLE . ' WHERE content_id = :contentId AND language_id != :languageId', ['contentId' => $contentId, 'languageId' => $languageId], ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] ); @@ -2233,7 +2234,7 @@ private function deleteTranslationFromContentObject( $query->executeStatement(); $this->connection->executeStatement( - 'DELETE FROM ibexa_content_translation WHERE content_id = :contentId AND language_id = :languageId', + 'DELETE FROM ' . self::CONTENT_TRANSLATION_TABLE . ' WHERE content_id = :contentId AND language_id = :languageId', ['contentId' => $contentId, 'languageId' => $languageId], ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER] ); @@ -2255,6 +2256,7 @@ private function deleteTranslationFromContentVersions( ) { $contentTable = Gateway::CONTENT_ITEM_TABLE; $versionTable = Gateway::CONTENT_VERSION_TABLE; + $versionTranslationTable = Gateway::CONTENT_VERSION_TRANSLATION_TABLE; $query = $this->connection->createQueryBuilder(); $query->update($versionTable) // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS @@ -2270,7 +2272,7 @@ private function deleteTranslationFromContentVersions( ->where('contentobject_id = :contentId') ->andWhere( // make sure removed translation is not the last one (incl. alwaysAvailable) - "EXISTS (SELECT 1 FROM ibexa_content_version_translation cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" + "EXISTS (SELECT 1 FROM {$versionTranslationTable} cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" ) ->setParameter('now', time()) ->setParameter('contentId', $contentId) @@ -2296,7 +2298,7 @@ private function deleteTranslationFromContentVersions( ->from($versionTable) ->where('contentobject_id = :contentId') ->andWhere( - "EXISTS (SELECT 1 FROM ibexa_content_version_translation cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" + "EXISTS (SELECT 1 FROM {$versionTranslationTable} cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" ) ->setParameter('contentId', $contentId) ->setParameter('languageId', $languageId) @@ -2321,10 +2323,10 @@ private function deleteTranslationFromContentVersions( $query->executeStatement(); - $deleteQuery = 'DELETE FROM ibexa_content_version_translation + $deleteQuery = "DELETE FROM {$versionTranslationTable} WHERE language_id = :languageId AND content_version_id IN ( - SELECT id FROM ibexa_content_version WHERE contentobject_id = :contentId' + SELECT id FROM {$versionTable} WHERE contentobject_id = :contentId" . (null !== $versionNo ? ' AND version = :versionNo' : '') . ')'; $deleteParams = ['contentId' => $contentId, 'languageId' => $languageId]; diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php index be70c79ed9..5f9f675ce9 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php @@ -17,6 +17,7 @@ use Ibexa\Contracts\Core\Persistence\Content\Language; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; use Ibexa\Core\Base\Exceptions\DatabaseException; +use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; use RuntimeException; @@ -219,7 +220,7 @@ private function countTableData( */ public function loadContentTranslations(array $contentIds): array { - return $this->loadTranslations('ibexa_content_translation', 'content_id', $contentIds); + return $this->loadTranslations(ContentGateway::CONTENT_TRANSLATION_TABLE, 'content_id', $contentIds); } /** @@ -229,7 +230,7 @@ public function loadContentTranslations(array $contentIds): array */ public function loadVersionTranslations(array $versionIds): array { - return $this->loadTranslations('ibexa_content_version_translation', 'content_version_id', $versionIds); + return $this->loadTranslations(ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, 'content_version_id', $versionIds); } /** diff --git a/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php index bf39b43185..e4d3b1ed0b 100644 --- a/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -1492,7 +1492,7 @@ private function appendContentItemTranslationsConstraint( $translationSubQuery = $this->connection->createQueryBuilder(); $translationSubQuery ->select('1') - ->from('ibexa_content_translation', 'ct') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') ->where( $translationSubQuery->expr()->and( 'ct.content_id = c.id', diff --git a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php index dd62180e2c..317e566ecf 100644 --- a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php +++ b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php @@ -14,6 +14,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LanguageCode; use Ibexa\Contracts\Core\Repository\Values\Filter\CriterionQueryBuilder; use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; +use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; /** @@ -38,7 +39,7 @@ public function buildQueryConstraint( $queryBuilder ->joinOnce( 'version', - 'ibexa_content_version_translation', + ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, 'version_translation', 'version_translation.content_version_id = version.id' ) diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index 3a66fcf586..95f63cf0db 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -223,7 +223,7 @@ private function bulkFetchVersionNames(FilteringQueryBuilder $query): array // the same defensive way LanguagePriorityConditionBuilder does for // ibexa_content_field.language_id. 'EXISTS ( - SELECT 1 FROM ibexa_content_version_translation cvt + SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id AND content_name.language_id IN (cvt.language_id, cvt.language_id + 1) )' @@ -266,7 +266,7 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array // available" bit (+1) that was never cleaned up retroactively - see the same // tolerance in bulkFetchVersionNames() above. 'EXISTS ( - SELECT 1 FROM ibexa_content_version_translation cvt + SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id AND content_field.language_id IN (cvt.language_id, cvt.language_id + 1) )' From 0c5ff9502b4bce74a30b225ed6269f28b3813b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:35:41 +0100 Subject: [PATCH 03/54] IBX-11939: Made the language translation commands invokable --- .../BackfillLanguageTranslationsCommand.php | 76 +++++-------------- .../VerifyLanguageTranslationsCommand.php | 76 ++++++------------- 2 files changed, 45 insertions(+), 107 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index 3d219f54d7..af08f5349d 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -15,9 +15,8 @@ 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\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -37,9 +36,17 @@ */ #[AsCommand( name: 'ibexa:languages:backfill-translations', - description: 'Backfills the language translation tables from the legacy language bitmask columns' + description: 'Backfills the language translation tables from the legacy language bitmask columns', + help: <<<'EOT' + The command %command.name% populates "ibexa_content_translation", + "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" from the existing + "language_mask"/"lang_mask" bitmask columns. It is idempotent - already-backfilled rows are + skipped - so it is safe to re-run, including after a partial/interrupted run. + + Run ibexa:languages:verify-translations afterward to confirm the backfill is complete. + EOT, )] -final class BackfillLanguageTranslationsCommand extends Command +final class BackfillLanguageTranslationsCommand { private const int DEFAULT_BATCH_SIZE = 5000; @@ -54,58 +61,17 @@ final class BackfillLanguageTranslationsCommand extends Command self::TABLE_URL_ALIAS, ]; - public function __construct(private readonly Connection $connection) - { - parent::__construct(); - } + public function __construct(private readonly Connection $connection) {} - protected function configure(): void - { - $this - ->addOption( - 'table', - 't', - InputOption::VALUE_OPTIONAL, - sprintf( - 'Which table to backfill: one of "%s", or "%s" for all of them.', - implode('", "', self::VALID_TABLES), - self::TABLE_ALL - ), - self::TABLE_ALL - ) - ->addOption( - 'batch-size', - null, - InputOption::VALUE_OPTIONAL, - 'Number of primary-key values processed per batch.', - (string)self::DEFAULT_BATCH_SIZE - ) - ->addOption( - 'dry-run', - null, - InputOption::VALUE_NONE, - 'Report how many rows would be inserted per batch without writing anything.' - ) - ->setHelp( - <<%command.name% populates "ibexa_content_translation", -"ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" from the existing -"language_mask"/"lang_mask" bitmask columns. It is idempotent - already-backfilled rows are -skipped - so it is safe to re-run, including after a partial/interrupted run. - -Run ibexa:languages:verify-translations afterward to confirm the backfill is complete. -EOT - ); - } - - protected function execute( - InputInterface $input, - OutputInterface $output + 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 { - $table = $input->getOption('table'); - $batchSize = (int)$input->getOption('batch-size'); - $dryRun = (bool)$input->getOption('dry-run'); - if ($batchSize < 1) { throw new InvalidArgumentException('batch-size', 'must be a positive integer.'); } @@ -129,7 +95,7 @@ protected function execute( $this->backfillTable($singleTable, $batchSize, $dryRun, $output); } - return self::SUCCESS; + return Command::SUCCESS; } private function backfillTable( diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index fa8f164d37..986dd20516 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -15,9 +15,8 @@ use Ibexa\Bundle\RepositoryInstaller\Migration\DropLanguageBitmaskColumnsMigration; 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\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -38,9 +37,20 @@ */ #[AsCommand( name: 'ibexa:languages:verify-translations', - description: 'Verifies the language translation tables against the legacy language bitmask columns' + description: 'Verifies the language translation tables against the legacy language bitmask columns', + help: <<<'EOT' + The command %command.name% compares "ibexa_content_translation", + "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" against the + "language_mask"/"lang_mask" columns they were backfilled from, reporting: + - missing: a language bit set in the mask with no corresponding translation row + - orphaned: a translation row whose bit is no longer set in the mask + + Exits non-zero if any drift is found and --fix was not passed. Run this after + ibexa:languages:backfill-translations, and again before relying on the translation + tables for anything - a clean report here is the precondition for every later migration step. + EOT, )] -final class VerifyLanguageTranslationsCommand extends Command +final class VerifyLanguageTranslationsCommand { private const string TABLE_CONTENT = 'content'; private const string TABLE_CONTENT_VERSION = 'content_version'; @@ -159,53 +169,15 @@ private function buildQueries( }; } - public function __construct(private readonly Connection $connection) - { - parent::__construct(); - } - - protected function configure(): void - { - $this - ->addOption( - 'table', - 't', - InputOption::VALUE_OPTIONAL, - sprintf( - 'Which table to verify: one of "%s", or "%s" for all of them.', - implode('", "', self::VALID_TABLES), - self::TABLE_ALL - ), - self::TABLE_ALL - ) - ->addOption( - 'fix', - null, - InputOption::VALUE_NONE, - 'Insert missing rows and delete orphaned rows to bring the translation table back in sync.' - ) - ->setHelp( - <<%command.name% compares "ibexa_content_translation", -"ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" against the -"language_mask"/"lang_mask" columns they were backfilled from, reporting: - - missing: a language bit set in the mask with no corresponding translation row - - orphaned: a translation row whose bit is no longer set in the mask + public function __construct(private readonly Connection $connection) {} -Exits non-zero if any drift is found and --fix was not passed. Run this after -ibexa:languages:backfill-translations, and again before relying on the translation -tables for anything - a clean report here is the precondition for every later migration step. -EOT - ); - } - - protected function execute( - InputInterface $input, - OutputInterface $output + public function __invoke( + OutputInterface $output, + #[Option(description: 'Which table to verify: one of "content", "content_version", "url_alias", or "all" for all of them.', shortcut: 't')] + string $table = self::TABLE_ALL, + #[Option(description: 'Insert missing rows and delete orphaned rows to bring the translation table back in sync.')] + bool $fix = false, ): int { - $table = $input->getOption('table'); - $fix = (bool)$input->getOption('fix'); - $tables = $table === self::TABLE_ALL ? self::VALID_TABLES : [$table]; foreach ($tables as $singleTable) { if (!isset(self::SOURCE_TABLES[$singleTable])) { @@ -229,18 +201,18 @@ protected function execute( if ($clean) { $output->writeln('All checked translation tables are in sync with their language masks.'); - return self::SUCCESS; + return Command::SUCCESS; } if ($fix) { $output->writeln('Drift found and fixed.'); - return self::SUCCESS; + return Command::SUCCESS; } $output->writeln('Drift found. Re-run with --fix to correct it.'); - return self::FAILURE; + return Command::FAILURE; } private function verifyTable( From 0299c11507452c2995961c8913517bd71da19c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:35:42 +0100 Subject: [PATCH 04/54] IBX-11939: Typed FixtureImporter's constant and promoted its properties --- .../Test/Persistence/Fixture/FixtureImporter.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 94629a63dd..c13027c3b6 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -25,14 +25,10 @@ */ final class FixtureImporter { - private Connection $connection; - - private SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass; - /** * Join tables referencing "ibexa_content_language" (ON DELETE RESTRICT), keyed to the table owning their rows. */ - private const LANGUAGE_TRANSLATION_TABLES = [ + private const array LANGUAGE_TRANSLATION_TABLES = [ 'ibexa_content_translation' => 'ibexa_content', 'ibexa_content_version_translation' => 'ibexa_content_version', 'ibexa_url_alias_ml_translation' => 'ibexa_url_alias_ml', @@ -45,12 +41,9 @@ final class FixtureImporter private static array $existingColumnsByTable = []; public function __construct( - Connection $connection, - ?SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass = null - ) { - $this->connection = $connection; - $this->schemaAssetsFilterBypass = $schemaAssetsFilterBypass ?? new SchemaAssetsFilterBypass(); - } + private readonly Connection $connection, + private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass = new SchemaAssetsFilterBypass() + ) {} /** * @throws Exception From b3a1968d9fe7319f521b7003fb299976fa6a2d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:52:46 +0100 Subject: [PATCH 05/54] IBX-11939: Moved the always_available backfill into the chunked BackfillLanguageTranslationsMigration --- ...ContentAlwaysAvailableColumnsMigration.php | 51 +-------- .../BackfillLanguageTranslationsMigration.php | 61 +++++----- ...kfillLanguageTranslationsMigrationTest.php | 105 ++++++++++++++++++ 3 files changed, 142 insertions(+), 75 deletions(-) create mode 100644 tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php diff --git a/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php index ce83b07f5a..5d667374dd 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php @@ -15,23 +15,7 @@ use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Adds "always_available" boolean columns to "ibexa_content" and "ibexa_content_version", - * backfilled from bit 0 of their "language_mask" column (step 1 of the language bitmask - * migration). "language_mask" itself is left untouched by this migration - only the - * always-available flag moves off the bitmask; the mask keeps carrying language-membership bits - * until later steps introduce dedicated translation tables. - * - * Each column is checked and queued independently, and the backfill is unconditional whenever - * anything is still missing: on MySQL, each `ALTER TABLE`/`UPDATE` auto-commits independently, so a - * failure partway through (e.g. after adding "ibexa_content.always_available" but before adding it - * to "ibexa_content_version", or before either backfill runs) must not make a retry mistake "the - * first column already exists" for "this migration already fully ran" and silently skip the rest. - * The backfill UPDATE is idempotent (derived only from "language_mask", which this migration never - * modifies), so re-running it whenever anything else is still missing is always safe. - * - * Guarded via the connection's schema manager rather than the injected $schema, because - * TaggedMigrationsRunner (the "ibexa:install" path) invokes up() with an empty Schema, so - * $schema->hasTable()/hasColumn() would always report false there. + * Adds "always_available" columns to "ibexa_content" and "ibexa_content_version". */ final class AddContentAlwaysAvailableColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface { @@ -41,7 +25,7 @@ final class AddContentAlwaysAvailableColumnsMigration extends AbstractSqlMigrati public function getDescription(): string { - return 'Adds "always_available" columns to "ibexa_content" and "ibexa_content_version", backfilled from the language mask'; + return 'Adds "always_available" columns to "ibexa_content" and "ibexa_content_version"'; } public static function getTargetVersion(): string @@ -64,27 +48,11 @@ public function up(Schema $schema): void return; } - $hasContentColumn = $schemaManager->introspectTable(self::CONTENT_TABLE) - ->hasColumn(self::ALWAYS_AVAILABLE_COLUMN); - $hasContentVersionColumn = $schemaManager->introspectTable(self::CONTENT_VERSION_TABLE) - ->hasColumn(self::ALWAYS_AVAILABLE_COLUMN); - - if ($hasContentColumn && $hasContentVersionColumn) { - // Already fully applied - avoid an unconditional full-table backfill re-scan once this - // migration has genuinely completed. - return; - } - - if (!$hasContentColumn) { - $this->addSql($this->buildAddColumnSql(self::CONTENT_TABLE)); - } - - if (!$hasContentVersionColumn) { - $this->addSql($this->buildAddColumnSql(self::CONTENT_VERSION_TABLE)); + foreach ([self::CONTENT_TABLE, self::CONTENT_VERSION_TABLE] as $table) { + if (!$schemaManager->introspectTable($table)->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { + $this->addSql($this->buildAddColumnSql($table)); + } } - - $this->addSql($this->buildBackfillSql(self::CONTENT_TABLE)); - $this->addSql($this->buildBackfillSql(self::CONTENT_VERSION_TABLE)); } private function buildAddColumnSql(string $table): string @@ -97,11 +65,4 @@ private function buildAddColumnSql(string $table): string return "ALTER TABLE {$table} ADD COLUMN " . self::ALWAYS_AVAILABLE_COLUMN . " {$columnDefinition}"; } - - private function buildBackfillSql(string $table): string - { - $trueLiteral = $this->isPostgreSQL() ? 'true' : '1'; - - return "UPDATE {$table} SET " . self::ALWAYS_AVAILABLE_COLUMN . " = {$trueLiteral} WHERE (language_mask & 1) = 1"; - } } diff --git a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php index 0f69d1abf0..680ecb43ed 100644 --- a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php @@ -16,32 +16,7 @@ use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Backfills "ibexa_content_translation", "ibexa_content_version_translation" and - * "ibexa_url_alias_ml_translation" from the legacy "language_mask"/"lang_mask" bitmask columns - * (step 2 of the language bitmask migration), so DropLanguageBitmaskColumnsMigration can safely - * drop those columns afterward. - * - * Chunked by primary-key range via repeated {@see addSql()} calls, and executed non-transactionally - * ({@see isTransactional()}), rather than as a single `INSERT ... SELECT` - "ibexa_content"/ - * "ibexa_content_version"/"ibexa_url_alias_ml" can hold tens of millions of rows on a mature - * install, and one giant statement in one transaction risks an enormous undo log/WAL. With each - * chunk committed independently, a failed/interrupted run only has to redo the (idempotent, cheap - - * "INSERT IGNORE"/"ON CONFLICT DO NOTHING") already-completed chunks on retry, not roll everything - * back. This still uses `addSql()` rather than executing directly, so `--dry-run` previews it like - * any other migration instead of silently writing anyway. - * - * The decomposition needs no PHP-side bit-walking or a recursive CTE: "ibexa_content_language" - * already contains every valid bit value, so joining against it with a bitwise AND does the - * decomposition in SQL directly. - * - * The manual `ibexa:languages:backfill-translations`/`ibexa:languages:verify-translations` commands - * remain available for a dry-run preview or manual repair, but running them separately is no longer - * a required step before the drop migration - this migration already does the same job as part of - * the standard migration sequence, during the same maintenance window. - * - * Guarded via the connection's schema manager rather than the injected $schema, because - * TaggedMigrationsRunner (the "ibexa:install" path) invokes up() with an empty Schema, so - * $schema->hasTable()/hasColumn() would always report false there. + * Backfills "always_available" and the language translation tables from the legacy language bitmask columns. */ final class BackfillLanguageTranslationsMigration extends AbstractSqlMigration implements IbexaMigrationInterface { @@ -49,7 +24,7 @@ final class BackfillLanguageTranslationsMigration extends AbstractSqlMigration i public function getDescription(): string { - return 'Backfills the language translation tables from the legacy language bitmask columns'; + return 'Backfills "always_available" and the language translation tables from the legacy language bitmask columns'; } public static function getTargetVersion(): string @@ -77,6 +52,9 @@ public function up(Schema $schema): void return; } + $this->backfillAlwaysAvailable('ibexa_content'); + $this->backfillAlwaysAvailable('ibexa_content_version'); + $this->backfillTable( 'ibexa_content', 'language_mask', @@ -108,11 +86,36 @@ public function up(Schema $schema): void ); } + private function backfillAlwaysAvailable(string $sourceTable): void + { + $this->addChunkedSql( + $sourceTable, + 'language_mask', + 'id', + "UPDATE {$sourceTable} SET always_available = ((language_mask & 1) = 1) + WHERE id BETWEEN :from AND :to AND always_available <> ((language_mask & 1) = 1)" + ); + } + private function backfillTable( string $sourceTable, string $maskColumn, string $pkColumn, string $insertSqlTemplate + ): void { + $this->addChunkedSql( + $sourceTable, + $maskColumn, + $pkColumn, + sprintf($insertSqlTemplate, $this->insertIgnoreKeyword(), $this->onConflictClause()) + ); + } + + private function addChunkedSql( + string $sourceTable, + string $maskColumn, + string $pkColumn, + string $sql ): void { $schemaManager = $this->connection->createSchemaManager(); if ( @@ -137,12 +140,10 @@ private function backfillTable( $minId = (int)$range['min_id']; $maxId = (int)$range['max_id']; - $insertSql = sprintf($insertSqlTemplate, $this->insertIgnoreKeyword(), $this->onConflictClause()); - for ($from = $minId; $from <= $maxId; $from += self::BATCH_SIZE) { $to = min($from + self::BATCH_SIZE - 1, $maxId); $this->addSql( - $insertSql, + $sql, ['from' => $from, 'to' => $to], ['from' => ParameterType::INTEGER, 'to' => ParameterType::INTEGER] ); diff --git a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php new file mode 100644 index 0000000000..111f552b75 --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php @@ -0,0 +1,105 @@ +insertDatabaseFixture( + __DIR__ . '/../../../lib/Persistence/Legacy/Content/_fixtures/languages.php' + ); + + $connection = $this->getDatabaseConnection(); + foreach ([1 => 2, 2 => 7] as $id => $languageMask) { + $connection->insert('ibexa_content', [ + 'id' => $id, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => 2, + 'language_mask' => $languageMask, + 'name' => 'Content ' . $id, + 'owner_id' => 14, + 'remote_id' => 'content-' . $id, + ]); + $connection->insert('ibexa_content_version', [ + 'id' => $id, + 'contentobject_id' => $id, + 'version' => 1, + 'initial_language_id' => 2, + 'language_mask' => $languageMask, + ]); + } + } + + public function testBackfillsAlwaysAvailableAndTranslations(): void + { + $this->runMigration(); + + $this->assertBackfilled(); + } + + public function testRerunAfterAnInterruptedRunCompletesTheBackfill(): void + { + $this->runMigration(); + $this->getDatabaseConnection()->executeStatement( + 'UPDATE ibexa_content_version SET always_available = :alwaysAvailable', + ['alwaysAvailable' => false], + ['alwaysAvailable' => ParameterType::BOOLEAN] + ); + + $this->runMigration(); + + $this->assertBackfilled(); + } + + private function runMigration(): void + { + $connection = $this->getDatabaseConnection(); + $migration = new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext()); + $migration->up(new Schema()); + + foreach ($migration->getSql() as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + } + + private function assertBackfilled(): void + { + $connection = $this->getDatabaseConnection(); + + foreach (['ibexa_content', 'ibexa_content_version'] as $table) { + self::assertEquals( + [1 => 0, 2 => 1], + $connection->fetchAllKeyValue("SELECT id, always_available FROM {$table} ORDER BY id"), + $table + ); + } + + self::assertEquals( + [[1, 2], [2, 2], [2, 4]], + $connection->fetchAllNumeric('SELECT content_id, language_id FROM ibexa_content_translation ORDER BY content_id, language_id') + ); + self::assertEquals( + [[1, 2], [2, 2], [2, 4]], + $connection->fetchAllNumeric('SELECT content_version_id, language_id FROM ibexa_content_version_translation ORDER BY content_version_id, language_id') + ); + } +} From 96e8ee52a454dcb2238c2edfd3e721e25d4ee2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:52:46 +0100 Subject: [PATCH 06/54] IBX-11939: Covered always_available in the language translation commands --- .../BackfillLanguageTranslationsCommand.php | 49 ++++++++++++------- .../VerifyLanguageTranslationsCommand.php | 46 +++++++++-------- ...ackfillLanguageTranslationsCommandTest.php | 34 +++++++++++++ 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index af08f5349d..bd0a0a7f41 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -20,27 +20,16 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Backfills "ibexa_content_translation", "ibexa_content_version_translation" and - * "ibexa_url_alias_ml_translation" from the legacy "language_mask"/"lang_mask" bitmask columns - * (step 2 of the language bitmask migration). - * - * A standard upgrade no longer needs to run this manually: {@see BackfillLanguageTranslationsMigration} - * (in ibexa/core's RepositoryInstaller bundle) does the same chunked, idempotent backfill as part of - * the regular `doctrine:migrations:migrate` sequence, before the migration that drops these columns. - * This command remains available for a `--dry-run` preview of what a pending upgrade would do, or - * for manual repair (together with `ibexa:languages:verify-translations`) outside of a migration run. - * - * The decomposition needs no PHP-side bit-walking or a recursive CTE: "ibexa_content_language" - * already contains every valid bit value, so joining against it with a bitwise AND does the - * decomposition in SQL directly. + * Backfills "always_available" and the language translation tables from the legacy language bitmask columns. */ #[AsCommand( name: 'ibexa:languages:backfill-translations', - description: 'Backfills the language translation tables from the legacy language bitmask columns', + description: 'Backfills "always_available" and the language translation tables from the legacy language bitmask columns', help: <<<'EOT' The command %command.name% populates "ibexa_content_translation", "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" from the existing - "language_mask"/"lang_mask" bitmask columns. It is idempotent - already-backfilled rows are + "language_mask"/"lang_mask" bitmask columns, and sets "always_available" on "ibexa_content" + and "ibexa_content_version" from bit 0 of "language_mask". It is idempotent - already-backfilled rows are skipped - so it is safe to re-run, including after a partial/interrupted run. Run ibexa:languages:verify-translations afterward to confirm the backfill is complete. @@ -104,7 +93,7 @@ private function backfillTable( bool $dryRun, OutputInterface $output ): void { - [$sourceTable, $pkColumn, $maskColumn, $insertSql] = match ($table) { + [$sourceTable, $pkColumn, $maskColumn, $insertSql, $alwaysAvailableColumn] = match ($table) { self::TABLE_CONTENT => [ 'ibexa_content', 'id', @@ -113,6 +102,7 @@ private function backfillTable( 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', @@ -122,6 +112,7 @@ private function backfillTable( 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', @@ -131,6 +122,7 @@ private function backfillTable( 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.parent BETWEEN :from AND :to %s', + null, ], default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), }; @@ -166,33 +158,52 @@ private function backfillTable( $output->writeln("Backfilling {$sourceTable} ({$pkColumn} {$minId}..{$maxId}, batch size {$batchSize})..."); $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); + $flagged = 0; if ($dryRun) { $inserted = (int)$this->connection->fetchOne( $this->buildDryRunCountSql($table, $languageTable), ['from' => $from, 'to' => $to] ); + if ($alwaysAvailableColumn !== null) { + $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]); + if ($alwaysAvailableColumn !== null) { + $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)%s', $from, $to, $inserted, $dryRun ? ' (dry-run)' : ''), + 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( - '%s%s: %d row(s) %s.', + '%s%s: %d row(s) %s, %d always-available flag(s) %s.', $dryRun ? '[dry-run] ' : '', $sourceTable, $totalInserted, - $dryRun ? 'would be inserted' : 'inserted' + $dryRun ? 'would be inserted' : 'inserted', + $totalFlagged, + $dryRun ? 'would be updated' : 'updated' )); } diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index 986dd20516..bd9fd6a9fc 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -11,8 +11,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Ibexa\Bundle\RepositoryInstaller\Migration\BackfillLanguageTranslationsMigration; -use Ibexa\Bundle\RepositoryInstaller\Migration\DropLanguageBitmaskColumnsMigration; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\Option; @@ -20,30 +18,18 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Verifies that "ibexa_content_translation", "ibexa_content_version_translation" and - * "ibexa_url_alias_ml_translation" agree with the legacy "language_mask"/"lang_mask" bitmask - * columns they were backfilled from (step 2 of the language bitmask migration). - * - * A standard upgrade no longer needs to run this manually - {@see BackfillLanguageTranslationsMigration} - * backfills as part of the regular migration sequence, and {@see DropLanguageBitmaskColumnsMigration} - * refuses to drop the mask columns if any row wasn't backfilled. This command remains available - * for manual verification/repair (via `--fix`) outside of a migration run. - * - * Checks both directions with plain NOT EXISTS correlated subqueries rather than EXCEPT/MINUS, so - * the same SQL runs unchanged on MySQL, PostgreSQL and SQLite: - * - missing: a bit set in the mask with no corresponding translation row - * - orphaned: a translation row whose bit is no longer set in the mask (or the mask/language - * row it pointed to is gone) + * Verifies "always_available" and the language translation tables against the legacy language bitmask columns. */ #[AsCommand( name: 'ibexa:languages:verify-translations', - description: 'Verifies the language translation tables against the legacy language bitmask columns', + description: 'Verifies "always_available" and the language translation tables against the legacy language bitmask columns', help: <<<'EOT' The command %command.name% compares "ibexa_content_translation", "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation" against the "language_mask"/"lang_mask" columns they were backfilled from, reporting: - missing: a language bit set in the mask with no corresponding translation row - orphaned: a translation row whose bit is no longer set in the mask + - wrong always-available flag: an "always_available" value that doesn't match bit 0 of the mask Exits non-zero if any drift is found and --fix was not passed. Run this after ibexa:languages:backfill-translations, and again before relying on the translation @@ -74,6 +60,12 @@ final class VerifyLanguageTranslationsCommand self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask'], ]; + /** @var array */ + private const array ALWAYS_AVAILABLE_COLUMNS = [ + self::TABLE_CONTENT => 'always_available', + self::TABLE_CONTENT_VERSION => 'always_available', + ]; + /** * @return array{missing: string, orphaned: string, fixMissing: string, fixOrphaned: string} */ @@ -236,20 +228,27 @@ private function verifyTable( $languageTable = $this->resolveLanguageTableName($schemaManager); $queries = $this->buildQueries($table, $languageTable); + $alwaysAvailableColumn = self::ALWAYS_AVAILABLE_COLUMNS[$table] ?? null; + $alwaysAvailableMismatch = "{$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)"; + $missing = (int)$this->connection->fetchOne($queries['missing']); $orphaned = (int)$this->connection->fetchOne($queries['orphaned']); + $mismatched = $alwaysAvailableColumn === null + ? 0 + : (int)$this->connection->fetchOne("SELECT COUNT(*) FROM {$sourceTable} WHERE {$alwaysAvailableMismatch}"); - if ($missing === 0 && $orphaned === 0) { + if ($missing === 0 && $orphaned === 0 && $mismatched === 0) { $output->writeln("{$table}: in sync."); return true; } $output->writeln(sprintf( - '%s: %d missing, %d orphaned row(s).', + '%s: %d missing, %d orphaned row(s), %d wrong always-available flag(s).', $table, $missing, - $orphaned + $orphaned, + $mismatched )); if (!$fix) { @@ -266,6 +265,13 @@ private function verifyTable( $output->writeln(" deleted {$deleted} orphaned row(s)."); } + if ($mismatched > 0) { + $updated = $this->connection->executeStatement( + "UPDATE {$sourceTable} SET {$alwaysAvailableColumn} = (({$maskColumn} & 1) = 1) WHERE {$alwaysAvailableMismatch}" + ); + $output->writeln(" fixed {$updated} always-available flag(s)."); + } + return true; } diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 95ef486468..1909914c9c 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -109,6 +109,8 @@ public function testBackfillPopulatesTranslationTablesFromMasks(): void ) ) ); + self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); + self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content_version')); } public function testBackfillIsIdempotent(): void @@ -188,6 +190,26 @@ public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void ); } + public function testVerifyDetectsWrongAlwaysAvailableFlagsAndFixesThem(): void + { + $connection = $this->getDatabaseConnection(); + (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) + ->execute(['--table' => 'content']); + $connection->update('ibexa_content', ['always_available' => 0], ['id' => 2]); + + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $exitCode = $tester->execute(['--table' => 'content']); + + self::assertSame(1, $exitCode); + self::assertStringContainsString('1 wrong always-available flag(s)', $tester->getDisplay()); + + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); + + self::assertSame(0, $fixExitCode); + self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); + } + /** * Both commands are explicitly documented as usable standalone, outside of a migration run - * but a schema that already completed the language bitmask migration (or a fresh install, @@ -257,6 +279,18 @@ private function restorePreMigrationSchema(Connection $connection): void $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); } + /** + * @return array + */ + private function fetchAlwaysAvailable(string $table): array + { + $rows = $this->getDatabaseConnection()->fetchAllKeyValue( + "SELECT id, always_available FROM {$table} ORDER BY id" + ); + + return array_map(static fn (mixed $value): bool => (bool)$value, $rows); + } + /** * @return list */ From f2e43bee8b1ff07cbdd96b83209bde6ad720c7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 15:54:13 +0100 Subject: [PATCH 07/54] IBX-11939: Chunked the URL alias translations backfill by id --- .../BackfillLanguageTranslationsCommand.php | 6 +-- .../BackfillLanguageTranslationsMigration.php | 4 +- ...kfillLanguageTranslationsMigrationTest.php | 45 ++++++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index bd0a0a7f41..2cc1825eb7 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -116,12 +116,12 @@ private function backfillTable( ], self::TABLE_URL_ALIAS => [ 'ibexa_url_alias_ml', - 'parent', + '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.parent BETWEEN :from AND :to %s', + WHERE u.id BETWEEN :from AND :to %s', null, ], default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), @@ -235,7 +235,7 @@ private function buildDryRunCountSql( )", 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.parent BETWEEN :from AND :to + 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 diff --git a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php index 680ecb43ed..10361f2bb4 100644 --- a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php @@ -78,11 +78,11 @@ public function up(Schema $schema): void $this->backfillTable( 'ibexa_url_alias_ml', 'lang_mask', - 'parent', + 'id', '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 ibexa_content_language l ON (u.lang_mask & l.id) = l.id - WHERE u.parent BETWEEN :from AND :to %s' + WHERE u.id BETWEEN :from AND :to %s' ); } diff --git a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php index 111f552b75..18f83ec3b6 100644 --- a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\Query\Query; use Ibexa\Bundle\RepositoryInstaller\Migration\BackfillLanguageTranslationsMigration; use Ibexa\Contracts\DoctrineMigrations\Migrations\MigrationRunContext; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; @@ -70,15 +71,55 @@ public function testRerunAfterAnInterruptedRunCompletesTheBackfill(): void $this->assertBackfilled(); } - private function runMigration(): void + public function testChunksUrlAliasesById(): void + { + $connection = $this->getDatabaseConnection(); + foreach ([1 => ['foo', 'acbd18db4cc2f85cedef654fccc4a4d8'], 5001 => ['bar', '37b51d194a7513e45b56f6524f2d51f2']] as $id => [$text, $textMd5]) { + $connection->insert('ibexa_url_alias_ml', [ + 'parent' => 0, + 'text_md5' => $textMd5, + 'id' => $id, + 'text' => $text, + 'action' => 'eznode:' . $id, + 'action_type' => 'eznode', + 'lang_mask' => 7, + ], ['lang_mask' => ParameterType::INTEGER]); + } + + $queries = $this->runMigration(); + + self::assertCount( + 2, + array_filter( + $queries, + static fn (Query $query): bool => str_contains($query->getStatement(), 'ibexa_url_alias_ml_translation') + ) + ); + self::assertEquals( + [[1, 2], [1, 4], [5001, 2], [5001, 4]], + $connection->fetchAllNumeric( + 'SELECT u.id, t.language_id FROM ibexa_url_alias_ml_translation t + JOIN ibexa_url_alias_ml u ON u.parent = t.parent AND u.text_md5 = t.text_md5 + ORDER BY u.id, t.language_id' + ) + ); + } + + /** + * @return Query[] + */ + private function runMigration(): array { $connection = $this->getDatabaseConnection(); $migration = new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext()); $migration->up(new Schema()); - foreach ($migration->getSql() as $query) { + $queries = $migration->getSql(); + foreach ($queries as $query) { $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); } + + return $queries; } private function assertBackfilled(): void From dbf1e50994321ead23c400ae2145de8cf9a83838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 16:07:53 +0100 Subject: [PATCH 08/54] IBX-11939: Deleted a translation only from versions that keep another one --- .../Content/Gateway/DoctrineDatabase.php | 90 +++++++------------ .../Content/Gateway/DoctrineDatabaseTest.php | 51 +++++++++++ 2 files changed, 84 insertions(+), 57 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index db1664555f..c0fa5c6397 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -2257,86 +2257,62 @@ private function deleteTranslationFromContentVersions( $contentTable = Gateway::CONTENT_ITEM_TABLE; $versionTable = Gateway::CONTENT_VERSION_TABLE; $versionTranslationTable = Gateway::CONTENT_VERSION_TRANSLATION_TABLE; - $query = $this->connection->createQueryBuilder(); - $query->update($versionTable) - // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS - ->set('language_mask', 'language_mask & ~ ' . $languageId) - ->set('modified', ':now') - // update initial_language_id only if it matches removed translation languageId - ->set( - 'initial_language_id', - 'CASE WHEN initial_language_id = :languageId ' . - "THEN (SELECT initial_language_id AS main_language_id FROM $contentTable c WHERE c.id = :contentId) " . - 'ELSE initial_language_id END' - ) - ->where('contentobject_id = :contentId') - ->andWhere( - // make sure removed translation is not the last one (incl. alwaysAvailable) - "EXISTS (SELECT 1 FROM {$versionTranslationTable} cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" - ) - ->setParameter('now', time()) - ->setParameter('contentId', $contentId) - ->setParameter('languageId', $languageId) - ; - - if (null !== $versionNo) { - $query - ->andWhere('version = :versionNo') - ->setParameter('versionNo', $versionNo) - ; - } - // Checked as its own query rather than via the UPDATE's affected-row count: MySQL's PDO - // driver reports "rows changed", not "rows matched", by default - if a version's - // "modified"/"initial_language_id" happen to already hold the values being set (e.g. two - // operations landing within the same time() second), MySQL reports 0 affected rows even - // though the WHERE/EXISTS clause matched, which would incorrectly look like "no other - // translation exists" here. - $hasOtherLanguagesQuery = $this->connection->createQueryBuilder(); - $hasOtherLanguagesQuery - ->select('1') + $versionIdsQuery = $this->connection->createQueryBuilder(); + $versionIdsQuery + ->select('id') ->from($versionTable) ->where('contentobject_id = :contentId') ->andWhere( + // make sure removed translation is not the last one "EXISTS (SELECT 1 FROM {$versionTranslationTable} cvt WHERE cvt.content_version_id = {$versionTable}.id AND cvt.language_id != :languageId)" ) - ->setParameter('contentId', $contentId) - ->setParameter('languageId', $languageId) + ->setParameter('contentId', $contentId, ParameterType::INTEGER) + ->setParameter('languageId', $languageId, ParameterType::INTEGER) ; if (null !== $versionNo) { - $hasOtherLanguagesQuery + $versionIdsQuery ->andWhere('version = :versionNo') - ->setParameter('versionNo', $versionNo) + ->setParameter('versionNo', $versionNo, ParameterType::INTEGER) ; } - $hasOtherLanguages = (bool)$hasOtherLanguagesQuery->executeQuery()->fetchOne(); + $versionIds = array_map('intval', $versionIdsQuery->executeQuery()->fetchFirstColumn()); // most likely somehow it was the last remaining translation - if (!$hasOtherLanguages) { + if ($versionIds === []) { throw new BadStateException( '$languageCode', 'The provided translation is the only translation in this version' ); } + $query = $this->connection->createQueryBuilder(); + $query->update($versionTable) + // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS + ->set('language_mask', 'language_mask & ~ ' . $languageId) + ->set('modified', ':now') + // update initial_language_id only if it matches removed translation languageId + ->set( + 'initial_language_id', + 'CASE WHEN initial_language_id = :languageId ' . + "THEN (SELECT initial_language_id AS main_language_id FROM $contentTable c WHERE c.id = :contentId) " . + 'ELSE initial_language_id END' + ) + ->where($query->expr()->in('id', ':versionIds')) + ->setParameter('now', time()) + ->setParameter('contentId', $contentId) + ->setParameter('languageId', $languageId) + ->setParameter('versionIds', $versionIds, ArrayParameterType::INTEGER) + ; $query->executeStatement(); - $deleteQuery = "DELETE FROM {$versionTranslationTable} - WHERE language_id = :languageId - AND content_version_id IN ( - SELECT id FROM {$versionTable} WHERE contentobject_id = :contentId" - . (null !== $versionNo ? ' AND version = :versionNo' : '') . ')'; - - $deleteParams = ['contentId' => $contentId, 'languageId' => $languageId]; - $deleteTypes = ['contentId' => ParameterType::INTEGER, 'languageId' => ParameterType::INTEGER]; - if (null !== $versionNo) { - $deleteParams['versionNo'] = $versionNo; - $deleteTypes['versionNo'] = ParameterType::INTEGER; - } - - $this->connection->executeStatement($deleteQuery, $deleteParams, $deleteTypes); + $this->connection->executeStatement( + "DELETE FROM {$versionTranslationTable} WHERE language_id = :languageId AND content_version_id IN (:versionIds)", + ['languageId' => $languageId, 'versionIds' => $versionIds], + ['languageId' => ParameterType::INTEGER, 'versionIds' => ArrayParameterType::INTEGER] + ); } /** diff --git a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php index ab10faafe6..c4917b80c8 100644 --- a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php @@ -1455,6 +1455,57 @@ public function testDeleteRelationWithCompositeBitmask(): void /** * @throws \Doctrine\DBAL\Exception */ + public function testDeleteTranslationFromContentKeepsVersionsWithOnlyThatTranslation(): void + { + $connection = $this->getDatabaseConnection(); + $connection->insert(Gateway::CONTENT_ITEM_TABLE, [ + 'id' => 1, + 'content_type_id' => 1, + 'current_version' => 2, + 'initial_language_id' => 2, + 'language_mask' => 10, + 'name' => 'Foo', + 'owner_id' => 14, + 'remote_id' => 'foo', + ]); + foreach ([2, 8] as $languageId) { + $connection->insert(Gateway::CONTENT_TRANSLATION_TABLE, ['content_id' => 1, 'language_id' => $languageId]); + } + foreach ([1 => [8], 2 => [2, 8]] as $versionId => $languageIds) { + $connection->insert(Gateway::CONTENT_VERSION_TABLE, [ + 'id' => $versionId, + 'contentobject_id' => 1, + 'version' => $versionId, + 'initial_language_id' => $languageIds[0], + 'language_mask' => array_sum($languageIds), + ]); + foreach ($languageIds as $languageId) { + $connection->insert( + Gateway::CONTENT_VERSION_TRANSLATION_TABLE, + ['content_version_id' => $versionId, 'language_id' => $languageId] + ); + } + } + + $this->getDatabaseGateway()->deleteTranslationFromContent(1, 'ger-DE'); + + self::assertQueryResult( + [['content_version_id' => 1, 'language_id' => 8], ['content_version_id' => 2, 'language_id' => 2]], + $connection->createQueryBuilder() + ->select('content_version_id', 'language_id') + ->from(Gateway::CONTENT_VERSION_TRANSLATION_TABLE) + ->orderBy('content_version_id') + ->addOrderBy('language_id') + ); + self::assertQueryResult( + [['id' => 1, 'language_mask' => 8], ['id' => 2, 'language_mask' => 2]], + $connection->createQueryBuilder() + ->select('id', 'language_mask') + ->from(Gateway::CONTENT_VERSION_TABLE) + ->orderBy('id') + ); + } + public function testUpdateAlwaysAvailableFlagRemove(): void { $this->insertDatabaseFixture( From dbb28fb41e1bb8a21731e34f49e43a8cd8c427e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 16:20:58 +0100 Subject: [PATCH 09/54] IBX-11939: Joined the version languages in the Filter instead of loading them by id --- .../Content/Doctrine/DoctrineGateway.php | 42 +++++++++---------- .../storage_engines/legacy/filter.yaml | 1 - .../Filtering/ContentFilteringTest.php | 30 +++++++++++++ 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index 95f63cf0db..3c04f71cf1 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -15,7 +15,6 @@ use Ibexa\Contracts\Core\Persistence\Filter\SortClauseVisitor; use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Filter\Gateway\Gateway; use Traversable; @@ -60,8 +59,7 @@ public function __construct( private readonly Connection $connection, private readonly CriterionVisitor $criterionVisitor, private readonly SortClauseVisitor $sortClauseVisitor, - private readonly CountQueryBuilder $countQueryBuilder, - private readonly LanguageGateway $languageGateway + private readonly CountQueryBuilder $countQueryBuilder ) {} /** @@ -281,36 +279,38 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array } /** - * Bulk-fetches, for the same query constraints, which languages each matched content version is - * translated into - avoids the N+1 that would result from calling - * {@see LanguageGateway::loadVersionTranslations()} once per row in the data mapper instead. - * - * Deliberately reuses that same gateway method (batched with every matching version id at once) - * rather than reimplementing the query as a join against the main criteria query, like - * {@see bulkFetchVersionNames()}/{@see bulkFetchFieldValues()} above do: other callers (e.g. the - * Legacy Search Engine) also load translations through this same shared method, batched with - * their own, differently-sized id lists - reusing it here, rather than a bespoke query, is what - * guarantees every caller agrees on each version's language order. + * Fetches, for the same query constraints, the languages of each matched content version. * * @return array Content version id => language ids */ private function bulkFetchVersionTranslations(FilteringQueryBuilder $query): array { $query - // completely reset SELECT part to get only needed data - ->select('version.id AS content_version_id') + ->select('version.id AS content_version_id', 'version_languages.language_id') ->distinct() - // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints + ->joinOnce( + 'version', + ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, + 'version_languages', + 'version_languages.content_version_id = version.id' + ) ->setMaxResults(null) ->setFirstResult(0) ->resetOrderBy(); - $versionIds = array_map( - 'intval', - $query->executeQuery()->fetchFirstColumn() - ); + $translations = []; + foreach ($query->executeQuery()->iterateAssociative() as $row) { + $translations[(int)$row['content_version_id']][] = (int)$row['language_id']; + } - return $this->languageGateway->loadVersionTranslations($versionIds); + return array_map( + static function (array $languageIds): array { + sort($languageIds); + + return $languageIds; + }, + $translations + ); } private function getColumns(): Traversable diff --git a/src/lib/Resources/settings/storage_engines/legacy/filter.yaml b/src/lib/Resources/settings/storage_engines/legacy/filter.yaml index d90f1376a5..00ca79e951 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/filter.yaml +++ b/src/lib/Resources/settings/storage_engines/legacy/filter.yaml @@ -44,7 +44,6 @@ services: Ibexa\Core\Persistence\Legacy\Filter\Gateway\Content\Doctrine\DoctrineGateway: arguments: $connection: '@ibexa.persistence.connection' - $languageGateway: '@ibexa.persistence.legacy.language.gateway' Ibexa\Core\Persistence\Legacy\Filter\Handler\ContentFilteringHandler: arguments: diff --git a/tests/integration/Core/Repository/Filtering/ContentFilteringTest.php b/tests/integration/Core/Repository/Filtering/ContentFilteringTest.php index e837301b55..d1e549044e 100644 --- a/tests/integration/Core/Repository/Filtering/ContentFilteringTest.php +++ b/tests/integration/Core/Repository/Filtering/ContentFilteringTest.php @@ -422,6 +422,36 @@ public function testPagination(): void } } + /** + * @throws ForbiddenException + * @throws NotFoundException + * @throws UnauthorizedException + */ + public function testFindLoadsAllLanguagesOfEachVersion(): void + { + $parentFolder = $this->createFolder(['eng-US' => 'Parent Folder'], 2); + $parentLocationId = $parentFolder->getContentInfo()->getMainLocationId(); + self::assertNotNull($parentLocationId); + for ($itemNo = 1; $itemNo <= 3; ++$itemNo) { + $this->createFolder( + ['eng-US' => "Child no #{$itemNo}", 'eng-GB' => "Child no #{$itemNo} (GB)"], + $parentLocationId + ); + } + + $filter = new Filter(new Criterion\ParentLocationId($parentLocationId)); + $filter + ->andWithCriterion(new Criterion\LanguageCode(['eng-GB'], false)) + ->sliceBy(2, 0); + $contentList = $this->find($filter); + + self::assertSame(3, $contentList->getTotalCount()); + self::assertCount(2, $contentList); + foreach ($contentList as $content) { + self::assertEqualsCanonicalizing(['eng-US', 'eng-GB'], $content->getVersionInfo()->getLanguageCodes()); + } + } + /** * @throws ForbiddenException * @throws NotFoundException From 20b4faa5e8e87b36ffc27da53a15a718d826c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 16:36:32 +0100 Subject: [PATCH 10/54] IBX-11939: Loaded the version languages in the content handlers and passed them to the Mapper --- .../Persistence/Legacy/Content/Gateway.php | 18 +++++ .../Content/Gateway/DoctrineDatabase.php | 47 +++++++++++++ .../Content/Gateway/ExceptionConversion.php | 18 +++++ .../Persistence/Legacy/Content/Handler.php | 25 +++++-- .../Legacy/Content/Language/Gateway.php | 21 ------ .../Language/Gateway/DoctrineDatabase.php | 66 ------------------- .../Language/Gateway/ExceptionConversion.php | 18 ----- src/lib/Persistence/Legacy/Content/Mapper.php | 28 +++----- .../Legacy/Content/TreeHandler.php | 5 +- .../Type/ContentUpdater/Action/AddField.php | 8 ++- .../ContentUpdater/Action/RemoveField.php | 8 ++- .../storage_engines/legacy/content.yml | 1 - .../Legacy/Content/ContentHandlerTest.php | 28 +++++--- .../Persistence/Legacy/Content/MapperTest.php | 48 ++++---------- .../Legacy/Content/TreeHandlerTest.php | 10 ++- .../ContentUpdater/Action/AddFieldTest.php | 4 +- .../ContentUpdater/Action/RemoveFieldTest.php | 4 +- 17 files changed, 173 insertions(+), 184 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Gateway.php b/src/lib/Persistence/Legacy/Content/Gateway.php index 91d01b8aa2..046c72ee94 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Gateway.php @@ -495,6 +495,24 @@ abstract public function getContentIdsByContentTypeId(int $contentTypeId): array */ abstract public function loadVersionedNameData(array $rows): array; + /** + * Loads the languages of the given Content items. + * + * @param int[] $contentIds + * + * @return array Content id => language ids + */ + abstract public function loadContentTranslations(array $contentIds): array; + + /** + * Loads the languages of the given Content versions. + * + * @param int[] $versionIds + * + * @return array Version id => language ids + */ + abstract public function loadVersionTranslations(array $versionIds): array; + /** * Bulk-copy all relations meta data for a copied Content item. * diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index c0fa5c6397..1adadd6e3f 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -2038,6 +2038,53 @@ public function loadVersionedNameData(array $rows): array return $query->executeQuery()->fetchAllAssociative(); } + public function loadContentTranslations(array $contentIds): array + { + return $this->loadTranslations(self::CONTENT_TRANSLATION_TABLE, 'content_id', $contentIds); + } + + public function loadVersionTranslations(array $versionIds): array + { + return $this->loadTranslations(self::CONTENT_VERSION_TRANSLATION_TABLE, 'content_version_id', $versionIds); + } + + /** + * @param int[] $ids + * + * @return array + */ + private function loadTranslations( + string $tableName, + string $idColumn, + array $ids + ): array { + if (empty($ids)) { + return []; + } + + $query = $this->connection->createQueryBuilder(); + $rows = $query + ->select($idColumn, 'language_id') + ->from($tableName) + ->where( + $query->expr()->in( + $idColumn, + $query->createNamedParameter(array_values(array_unique($ids)), ArrayParameterType::INTEGER, ':ids') + ) + ) + ->orderBy($idColumn) + ->addOrderBy('language_id') + ->executeQuery() + ->fetchAllAssociative(); + + $translations = []; + foreach ($rows as $row) { + $translations[(int)$row[$idColumn]][] = (int)$row['language_id']; + } + + return $translations; + } + /** * @throws Exception */ diff --git a/src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php index f14956634e..bad1db353c 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php @@ -569,6 +569,24 @@ public function loadVersionedNameData(array $rows): array } } + public function loadContentTranslations(array $contentIds): array + { + try { + return $this->innerGateway->loadContentTranslations($contentIds); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } + + public function loadVersionTranslations(array $versionIds): array + { + try { + return $this->innerGateway->loadVersionTranslations($versionIds); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } + public function copyRelations( int $originalContentId, int $copiedContentId, diff --git a/src/lib/Persistence/Legacy/Content/Handler.php b/src/lib/Persistence/Legacy/Content/Handler.php index 0154f5d3ed..0a99762e3f 100644 --- a/src/lib/Persistence/Legacy/Content/Handler.php +++ b/src/lib/Persistence/Legacy/Content/Handler.php @@ -358,6 +358,7 @@ public function load( 'id' => $id, 'version' => $rows[0]['content_version_version'], ]]), + $this->loadVersionTranslations($rows), 'content_', $translations ); @@ -392,6 +393,7 @@ public function loadContentList( // group name data per Content Id $nameData = $this->contentGateway->loadVersionedNameData(array_values($idVersionPairs)); + $versionLanguageIds = $this->loadVersionTranslations($rawList); $contentItemNameData = []; foreach ($nameData as $nameDataRow) { $contentId = $nameDataRow['content_name_contentobject_id']; @@ -413,6 +415,7 @@ public function loadContentList( $contentList = $this->mapper->extractContentFromRows( $contentItemsRow, $contentItemNameData[$contentId], + $versionLanguageIds, 'content_', $translations ); @@ -500,7 +503,8 @@ public function loadVersionInfo( $versionInfo = $this->mapper->extractVersionInfoListFromRows( $rows, - $this->contentGateway->loadVersionedNameData([['id' => $contentId, 'version' => $rows[0]['content_version_version']]]) + $this->contentGateway->loadVersionedNameData([['id' => $contentId, 'version' => $rows[0]['content_version_version']]]), + $this->loadVersionTranslations($rows) ); $versionInfo = reset($versionInfo); @@ -558,7 +562,7 @@ static function ($row): array { ); $nameRows = $this->contentGateway->loadVersionedNameData($idVersionPairs); - return $this->mapper->extractVersionInfoListFromRows($rows, $nameRows); + return $this->mapper->extractVersionInfoListFromRows($rows, $nameRows, $this->loadVersionTranslations($rows)); } public function loadDraftListForUser( @@ -582,7 +586,7 @@ static function (array $row): array { ); $nameRows = $this->contentGateway->loadVersionedNameData($idVersionPairs); - return $this->mapper->extractVersionInfoListFromRows($rows, $nameRows); + return $this->mapper->extractVersionInfoListFromRows($rows, $nameRows, $this->loadVersionTranslations($rows)); } /** @@ -1031,7 +1035,8 @@ static function (array $row): array { $versionInfoList = $this->mapper->extractVersionInfoListFromRows( $rows, - $this->contentGateway->loadVersionedNameData($mappedRows) + $this->contentGateway->loadVersionedNameData($mappedRows), + $this->loadVersionTranslations($rows) ); $versionInfoListById = []; @@ -1041,4 +1046,16 @@ static function (array $row): array { return $versionInfoListById; } + + /** + * @param array> $rows + * + * @return array + */ + private function loadVersionTranslations(array $rows): array + { + return $this->contentGateway->loadVersionTranslations( + array_map(static fn (array $row): int => (int)$row['content_version_id'], $rows) + ); + } } diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway.php b/src/lib/Persistence/Legacy/Content/Language/Gateway.php index 581dc421db..eba63900a7 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway.php @@ -89,25 +89,4 @@ abstract public function deleteLanguage(int $id): void; * Check whether a language may be deleted. */ abstract public function canDeleteLanguage(int $id): bool; - - /** - * Loads which languages each of the given Content ids is translated into, from - * "ibexa_content_translation" (the relational replacement for "ibexa_content.language_mask"). - * - * @param int[] $contentIds - * - * @return array Content id => language ids - */ - abstract public function loadContentTranslations(array $contentIds): array; - - /** - * Loads which languages each of the given Content Version ids is translated into, from - * "ibexa_content_version_translation" (the relational replacement for - * "ibexa_content_version.language_mask"). - * - * @param int[] $versionIds - * - * @return array Version id => language ids - */ - abstract public function loadVersionTranslations(array $versionIds): array; } diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php index 5f9f675ce9..c23b3b884f 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php @@ -17,7 +17,6 @@ use Ibexa\Contracts\Core\Persistence\Content\Language; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; use Ibexa\Core\Base\Exceptions\DatabaseException; -use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; use RuntimeException; @@ -213,71 +212,6 @@ private function countTableData( return (int)$query->executeQuery()->fetchOne(); } - /** - * @param int[] $contentIds - * - * @return array - */ - public function loadContentTranslations(array $contentIds): array - { - return $this->loadTranslations(ContentGateway::CONTENT_TRANSLATION_TABLE, 'content_id', $contentIds); - } - - /** - * @param int[] $versionIds - * - * @return array - */ - public function loadVersionTranslations(array $versionIds): array - { - return $this->loadTranslations(ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, 'content_version_id', $versionIds); - } - - /** - * @param int[] $ids - * - * @return array - */ - private function loadTranslations( - string $tableName, - string $idColumn, - array $ids - ): array { - if (empty($ids)) { - return []; - } - - // Explicit ORDER BY, not just "no ORDER BY happens to come out consistently": without one, - // PostgreSQL (unlike MySQL/InnoDB's PK-clustered storage) can pick a different scan - // strategy - and therefore a different per-id row order - depending on how many ids are in - // this call's IN() list. Different call sites batch different numbers of ids at once (e.g. - // the Legacy Search Engine loads a whole result page in one call, while another caller might - // batch differently), so relying on incidental order would make language_id ordering - // inconsistent between them on Postgres specifically, even though every call goes through - // this exact same method. - $query = $this->connection->createQueryBuilder(); - $rows = $query - ->select($idColumn, 'language_id') - ->from($tableName) - ->where( - $query->expr()->in( - $idColumn, - $query->createNamedParameter($ids, ArrayParameterType::INTEGER, ':ids') - ) - ) - ->orderBy($idColumn) - ->addOrderBy('language_id') - ->executeQuery() - ->fetchAllAssociative(); - - $translations = []; - foreach ($rows as $row) { - $translations[(int)$row[$idColumn]][] = (int)$row['language_id']; - } - - return $translations; - } - private function getDatabasePlatform(): AbstractPlatform { try { diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php index 953818c355..9ea2ae27a7 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/ExceptionConversion.php @@ -96,22 +96,4 @@ public function canDeleteLanguage(int $id): bool throw DatabaseException::wrap($e); } } - - public function loadContentTranslations(array $contentIds): array - { - try { - return $this->innerGateway->loadContentTranslations($contentIds); - } catch (DBALException | PDOException $e) { - throw DatabaseException::wrap($e); - } - } - - public function loadVersionTranslations(array $versionIds): array - { - try { - return $this->innerGateway->loadVersionTranslations($versionIds); - } catch (DBALException | PDOException $e) { - throw DatabaseException::wrap($e); - } - } } diff --git a/src/lib/Persistence/Legacy/Content/Mapper.php b/src/lib/Persistence/Legacy/Content/Mapper.php index ae56715388..b24cac8635 100644 --- a/src/lib/Persistence/Legacy/Content/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Mapper.php @@ -23,8 +23,6 @@ use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** @@ -73,22 +71,18 @@ class Mapper private FieldTypeAliasResolverInterface $fieldTypeAliasResolver; - private LanguageGateway $languageGateway; - public function __construct( Registry $converterRegistry, LanguageHandler $languageHandler, ContentTypeHandler $contentTypeHandler, EventDispatcherInterface $eventDispatcher, - FieldTypeAliasResolverInterface $fieldTypeAliasResolver, - LanguageGateway $languageGateway + FieldTypeAliasResolverInterface $fieldTypeAliasResolver ) { $this->converterRegistry = $converterRegistry; $this->languageHandler = $languageHandler; $this->contentTypeHandler = $contentTypeHandler; $this->eventDispatcher = $eventDispatcher; $this->fieldTypeAliasResolver = $fieldTypeAliasResolver; - $this->languageGateway = $languageGateway; } /** @@ -221,6 +215,7 @@ public function convertToStorageValue(Field $field) * * @param array> $rows * @param array> $nameRows + * @param array $versionLanguageIds * @param string $prefix * @param array|null $translations * @@ -229,6 +224,7 @@ public function convertToStorageValue(Field $field) public function extractContentFromRows( array $rows, array $nameRows, + array $versionLanguageIds, string $prefix = 'content_', ?array $translations = null ): array { @@ -245,10 +241,6 @@ public function extractContentFromRows( $versionInfos = []; $fields = []; - $versionLanguageIds = $this->languageGateway->loadVersionTranslations( - array_unique(array_map(static fn (array $row): int => (int)$row["{$prefix}version_id"], $rows)) - ); - $fieldDefinitions = $this->loadCachedVersionFieldDefinitionsPerLanguage( $rows, $prefix, @@ -357,8 +349,7 @@ private function buildContentObjects( * @phpstan-param TRawContentRow[] $rows * * @param string[]|null $translations - * @param array $versionLanguageIds Version id => language ids, as returned by - * {@see Gateway::loadVersionTranslations()} + * @param array $versionLanguageIds * * @phpstan-return TVersionedLanguageFieldDefinitionsMap * @@ -463,8 +454,7 @@ public function extractContentInfoFromRows( * * @param array $row * @param array $names - * @param int[] $languageIds Language ids this version is translated into, as returned by - * {@see Gateway::loadVersionTranslations()} + * @param int[] $languageIds * * @return VersionInfo */ @@ -509,11 +499,14 @@ private function extractVersionInfoFromRow( * @phpstan-param TRawContentRow[] $rows * @phpstan-param TRawContentRow[] $nameRows * + * @param array $versionLanguageIds + * * @return VersionInfo[] */ public function extractVersionInfoListFromRows( array $rows, - array $nameRows + array $nameRows, + array $versionLanguageIds ): array { $nameData = []; foreach ($nameRows as $row) { @@ -522,9 +515,6 @@ public function extractVersionInfoListFromRows( } $allLanguages = $this->loadAllLanguagesWithIdKey(); - $versionLanguageIds = $this->languageGateway->loadVersionTranslations( - array_unique(array_map(static fn (array $row): int => (int)$row['content_version_id'], $rows)) - ); $versionInfoList = []; foreach ($rows as $row) { $versionId = $row['content_id'] . '_' . $row['content_version_version']; diff --git a/src/lib/Persistence/Legacy/Content/TreeHandler.php b/src/lib/Persistence/Legacy/Content/TreeHandler.php index 833edb0313..1c9f6bad5e 100644 --- a/src/lib/Persistence/Legacy/Content/TreeHandler.php +++ b/src/lib/Persistence/Legacy/Content/TreeHandler.php @@ -153,7 +153,10 @@ static function ($row) use ($contentId): array { return $this->contentMapper->extractVersionInfoListFromRows( $rows, - $nameRows + $nameRows, + $this->contentGateway->loadVersionTranslations( + array_map(static fn (array $row): int => (int)$row['content_version_id'], $rows) + ) ); } diff --git a/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddField.php b/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddField.php index d2dfe30b16..c50a12e016 100644 --- a/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddField.php +++ b/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddField.php @@ -90,7 +90,13 @@ static function ($versionNo) use ($contentId): array { foreach ($versionNumbers as $versionNo) { $contentRows = $this->contentGateway->load($contentId, $versionNo); - $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows); + $contentList = $this->contentMapper->extractContentFromRows( + $contentRows, + $nameRows, + $this->contentGateway->loadVersionTranslations( + array_map(static fn (array $row): int => (int)$row['content_version_id'], $contentRows) + ) + ); $content = $contentList[0]; $languageCodeSet = []; diff --git a/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveField.php b/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveField.php index 54f332ac7a..4207aef452 100644 --- a/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveField.php +++ b/src/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveField.php @@ -76,7 +76,13 @@ static function ($versionNo) use ($contentId): array { foreach ($versionNumbers as $versionNo) { $contentRows = $this->contentGateway->load($contentId, $versionNo); - $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows); + $contentList = $this->contentMapper->extractContentFromRows( + $contentRows, + $nameRows, + $this->contentGateway->loadVersionTranslations( + array_map(static fn (array $row): int => (int)$row['content_version_id'], $contentRows) + ) + ); $content = $contentList[0]; $versionFieldIdSet = []; diff --git a/src/lib/Resources/settings/storage_engines/legacy/content.yml b/src/lib/Resources/settings/storage_engines/legacy/content.yml index 5a15664274..4c9885041e 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content.yml @@ -12,7 +12,6 @@ services: - '@ibexa.spi.persistence.legacy.content_type.handler' - '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' - - '@ibexa.persistence.legacy.language.gateway' Ibexa\Core\Persistence\Legacy\Content\Mapper\ResolveVirtualFieldSubscriber: arguments: diff --git a/tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php b/tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php index 34bae717bf..dd81fd38c1 100644 --- a/tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/ContentHandlerTest.php @@ -240,7 +240,7 @@ public function testPublishFirstVersion(): void ) ); - $contentRows = [['content_version_version' => 1]]; + $contentRows = [['content_version_id' => 1, 'content_version_version' => 1]]; $gatewayMock->expects($this->once()) ->method('load') @@ -322,7 +322,7 @@ public function testPublish(): void ->method('setStatus') ->with(23, VersionInfo::STATUS_ARCHIVED, 1); - $contentRows = [['content_version_version' => 2]]; + $contentRows = [['content_version_id' => 2, 'content_version_version' => 2]]; $gatewayMock->expects($this->once()) ->method('load') @@ -478,7 +478,7 @@ public function testLoad(): void $mapperMock = $this->getMapperMock(); $fieldHandlerMock = $this->getFieldHandlerMock(); - $contentRows = [['content_version_version' => 2]]; + $contentRows = [['content_version_id' => 2, 'content_version_version' => 2]]; $gatewayMock->expects($this->once()) ->method('load') @@ -523,8 +523,8 @@ public function testLoadContentList(): void $mapperMock = $this->getMapperMock(); $fieldHandlerMock = $this->getFieldHandlerMock(); $contentRows = [ - ['content_id' => 2, 'content_version_version' => 2], - ['content_id' => 3, 'content_version_version' => 1], + ['content_id' => 2, 'content_version_id' => 22, 'content_version_version' => 2], + ['content_id' => 3, 'content_version_id' => 31, 'content_version_version' => 1], ]; $gatewayMock->expects($this->once()) ->method('loadContentList') @@ -541,6 +541,12 @@ public function testLoadContentList(): void ->with(self::equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]])) ->willReturn($nameDataRows); + $versionLanguageIds = [22 => [2], 31 => [2, 4]]; + $gatewayMock->expects($this->once()) + ->method('loadVersionTranslations') + ->with([22, 31]) + ->willReturn($versionLanguageIds); + $expected = [ 2 => $this->getContentFixtureForDraft(2, 2), 3 => $this->getContentFixtureForDraft(3, 1), @@ -551,9 +557,11 @@ public function testLoadContentList(): void ->willReturnCallback(static function ( array $rows, array $nameRows, + array $languageIds, string $prefix = 'content_', ?array $translations = null - ) use ($extractContentFromRowsMatcher, $contentRows, $nameDataRows, $expected): array { + ) use ($extractContentFromRowsMatcher, $contentRows, $nameDataRows, $versionLanguageIds, $expected): array { + self::assertSame($versionLanguageIds, $languageIds); if ($extractContentFromRowsMatcher->numberOfInvocations() === 1) { self::assertSame([$contentRows[0]], $rows); self::assertSame([$nameDataRows[0]], $nameRows); @@ -1038,7 +1046,7 @@ public function getCreateStructFixture() public function testLoadDraftsForUser(): void { $handler = $this->getContentHandler(); - $rows = [['content_version_contentobject_id' => 42, 'content_version_version' => 2]]; + $rows = [['content_version_id' => 2, 'content_version_contentobject_id' => 42, 'content_version_version' => 2]]; $gatewayMock = $this->getGatewayMock(); $mapperMock = $this->getMapperMock(); @@ -1152,7 +1160,7 @@ public function testDeleteVersion(): void $locationHandlerMock = $this->getLocationGatewayMock(); $fieldHandlerMock = $this->getFieldHandlerMock(); - $rows = [['content_version_version' => 2]]; + $rows = [['content_version_id' => 2, 'content_version_version' => 2]]; // Load VersionInfo to delete fields $gatewayMock->expects($this->once()) @@ -1494,8 +1502,8 @@ public function testLoadVersionInfoList(): void ]); $versionRows = [ - ['content_id' => 2, 'content_version_version' => 2], - ['content_id' => 3, 'content_version_version' => 1], + ['content_id' => 2, 'content_version_id' => 22, 'content_version_version' => 2], + ['content_id' => 3, 'content_version_id' => 31, 'content_version_version' => 1], ]; $gatewayMock->expects($this->once()) diff --git a/tests/lib/Persistence/Legacy/Content/MapperTest.php b/tests/lib/Persistence/Legacy/Content/MapperTest.php index 140fd95c2c..f54d6125ec 100644 --- a/tests/lib/Persistence/Legacy/Content/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/MapperTest.php @@ -24,7 +24,6 @@ use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry; use Ibexa\Core\Persistence\Legacy\Content\Gateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Handler; use Ibexa\Core\Persistence\Legacy\Content\Mapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper\ResolveVirtualFieldSubscriber; @@ -160,7 +159,6 @@ public function testConvertToStorageValue(): void $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub(), ); $res = $mapper->convertToStorageValue($field); @@ -195,9 +193,8 @@ public function testExtractContentFromRows(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub($rowsFixture), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); $expected = [$this->getContentExtractReference()]; @@ -236,9 +233,8 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub($rowsFixture), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); $expectedContent = $this->getContentExtractReference(); // Virtual "eznumber" fields (no data rows for this field definition at all) are @@ -298,9 +294,8 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub($rowsFixture), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); $expectedContent = $this->getContentExtractReference(); $expectedContent->fields = array_values( @@ -345,9 +340,8 @@ public function testExtractContentFromRowsMultipleVersions(): void $contentTypeHandlerMock, $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub($rowsFixture), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); self::assertCount( 2, @@ -512,7 +506,6 @@ public function testExtractContentInfoFromRow( $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub(), ); self::assertEquals($contentInfoReference, $mapper->extractContentInfoFromRow($fixtures, $prefix)); } @@ -673,43 +666,26 @@ protected function getMapper($valueConverter = null) $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->getLanguageGatewayStub(), ); } /** - * Builds a Language Gateway stub whose loadVersionTranslations() collects the distinct set of - * real (non-always-available) language ids each version's fields are written in from $rows - - * the relational replacement for decoding "content_version_language_mask". - * - * These fixtures predate "content_field_language_id" always being a pure id - some rows still - * carry the legacy "indicator" encoding (id with the always-available bit folded in), so mask - * it off the same way decoding "content_version_language_mask" used to (implicitly, by never - * testing bit 0). - * * @param array> $rows + * + * @return array */ - protected function getLanguageGatewayStub( - array $rows = [], - string $prefix = 'content_' - ): LanguageGateway { + private function getVersionLanguageIds(array $rows): array + { $versionLanguageIds = []; foreach ($rows as $row) { - $versionId = (int)$row["{$prefix}version_id"]; - $languageId = (int)$row["{$prefix}field_language_id"] & ~1; - if (!isset($versionLanguageIds[$versionId])) { - $versionLanguageIds[$versionId] = []; - } - if (!in_array($languageId, $versionLanguageIds[$versionId], true)) { + $versionId = (int)$row['content_version_id']; + $languageId = (int)$row['content_field_language_id'] & ~1; + if (!in_array($languageId, $versionLanguageIds[$versionId] ?? [], true)) { $versionLanguageIds[$versionId][] = $languageId; } } - $gateway = $this->createMock(LanguageGateway::class); - $gateway->method('loadVersionTranslations')->willReturn($versionLanguageIds); - $gateway->method('loadContentTranslations')->willReturn([]); - - return $gateway; + return $versionLanguageIds; } /** diff --git a/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php b/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php index f2c27ef7e0..61b1bee059 100644 --- a/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php @@ -52,7 +52,7 @@ public function testListVersions(): void ->expects($this->once()) ->method('listVersions') ->with(self::equalTo(23)) - ->will($this->returnValue([['content_version_version' => 2]])); + ->will($this->returnValue([['content_version_id' => 5, 'content_version_version' => 2]])); $this->getContentGatewayMock() ->expects($this->once()) @@ -60,10 +60,16 @@ public function testListVersions(): void ->with(self::equalTo([['id' => 23, 'version' => 2]])) ->will($this->returnValue([])); + $this->getContentGatewayMock() + ->expects($this->once()) + ->method('loadVersionTranslations') + ->with([5]) + ->willReturn([5 => [2]]); + $this->getContentMapperMock() ->expects($this->once()) ->method('extractVersionInfoListFromRows') - ->with(self::equalTo([['content_version_version' => 2]]), []) + ->with(self::equalTo([['content_version_id' => 5, 'content_version_version' => 2]]), [], [5 => [2]]) ->will($this->returnValue([new VersionInfo()])); $versions = $this->getTreeHandler()->listVersions(23); diff --git a/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddFieldTest.php b/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddFieldTest.php index 9066da8387..150e39c431 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddFieldTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/AddFieldTest.php @@ -198,7 +198,7 @@ public function testApplyMultipleVersionsSingleTranslation(): void ->expects($extractMatcher) ->method('extractContentFromRows') ->willReturnCallback(static function (...$parameters) use ($extractMatcher, $content1, $content2): array { - self::assertSame([[], [], 'content_', null], $parameters); + self::assertSame([[], [], [], 'content_', null], $parameters); return $extractMatcher->numberOfInvocations() === 1 ? [$content1] : [$content2]; }); @@ -255,7 +255,7 @@ public function testApplyMultipleVersionsMultipleTranslations(): void ->expects($extractMatcher) ->method('extractContentFromRows') ->willReturnCallback(static function (...$parameters) use ($extractMatcher, $content1, $content2): array { - self::assertSame([[], [], 'content_', null], $parameters); + self::assertSame([[], [], [], 'content_', null], $parameters); return $extractMatcher->numberOfInvocations() === 1 ? [$content1] : [$content2]; }); diff --git a/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveFieldTest.php b/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveFieldTest.php index 17e9f830b1..43660fb470 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveFieldTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/ContentUpdater/Action/RemoveFieldTest.php @@ -129,7 +129,7 @@ public function testApplyMultipleVersionsSingleTranslation(): void ->expects($extractMatcher) ->method('extractContentFromRows') ->willReturnCallback(static function (...$parameters) use ($extractMatcher, $content1, $content2): array { - self::assertSame([[], [], 'content_', null], $parameters); + self::assertSame([[], [], [], 'content_', null], $parameters); return $extractMatcher->numberOfInvocations() === 1 ? [$content1] : [$content2]; }); @@ -190,7 +190,7 @@ public function testApplyMultipleVersionsMultipleTranslations(): void ->expects($extractMatcher) ->method('extractContentFromRows') ->willReturnCallback(static function (...$parameters) use ($extractMatcher, $content1, $content2): array { - self::assertSame([[], [], 'content_', null], $parameters); + self::assertSame([[], [], [], 'content_', null], $parameters); return $extractMatcher->numberOfInvocations() === 1 ? [$content1] : [$content2]; }); From 7ff1c451f38c20ef761840d6c0624f083457db21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 09:37:48 +0100 Subject: [PATCH 11/54] IBX-11939: Removed the leftover Language\Gateway mock from the search handler tests --- tests/lib/Search/Legacy/Content/HandlerContentSortTest.php | 2 -- tests/lib/Search/Legacy/Content/HandlerContentTest.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index 86f242ea8f..e149daf545 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php @@ -14,7 +14,6 @@ use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; use Ibexa\Core\Persistence\Legacy\Content\FieldHandler; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; @@ -110,7 +109,6 @@ protected function getContentMapperMock() $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->createMock(LanguageGateway::class), ] ) ->onlyMethods(['extractContentInfoFromRows']) diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index b7f86729e7..03dcd118c2 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -16,7 +16,6 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; use Ibexa\Core\Persistence; use Ibexa\Core\Persistence\Legacy\Content\FieldHandler; -use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; @@ -232,7 +231,6 @@ protected function getContentMapperMock() $this->getContentTypeHandler(), $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), - $this->createMock(LanguageGateway::class), ] ) ->onlyMethods(['extractContentInfoFromRows']) From 5f50b0b5a3739a0c159e6158e76b7011cb16875c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 10:56:27 +0100 Subject: [PATCH 12/54] IBX-13142: Looked up the language table past the schema assets filter in the language translation commands --- .../BackfillLanguageTranslationsCommand.php | 30 +++++++----- .../VerifyLanguageTranslationsCommand.php | 30 +++++++----- src/bundle/Core/Resources/config/services.yml | 2 + ...ackfillLanguageTranslationsCommandTest.php | 47 +++++++++++++------ 4 files changed, 71 insertions(+), 38 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index 2cc1825eb7..b774cfacbe 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -9,10 +9,9 @@ namespace Ibexa\Bundle\Core\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\AbstractSchemaManager; use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformName; use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformResolver; +use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\Option; @@ -50,7 +49,10 @@ final class BackfillLanguageTranslationsCommand self::TABLE_URL_ALIAS, ]; - public function __construct(private readonly Connection $connection) {} + public function __construct( + private readonly Connection $connection, + private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass + ) {} public function __invoke( OutputInterface $output, @@ -131,14 +133,17 @@ private function backfillTable( // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never // had it to begin with - in both cases there is nothing left to backfill, and the mask-based // queries below would otherwise fail outright with "no such column"/"undefined column". - $schemaManager = $this->connection->createSchemaManager(); - if (!$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn)) { + $hasMaskColumn = $this->schemaAssetsFilterBypass->call( + $this->connection, + fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) + ); + if (!$hasMaskColumn) { $output->writeln("{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill."); return; } - $languageTable = $this->resolveLanguageTableName($schemaManager); + $languageTable = $this->resolveLanguageTableName(); // 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 @@ -250,14 +255,15 @@ private function buildDryRunCountSql( * rename happens later, in RenameLanguageTableMigration. When run manually/standalone * after the full sequence (or against a fresh install, which starts from the renamed schema), * the table is already "ibexa_language". - * - * @param AbstractSchemaManager $schemaManager */ - private function resolveLanguageTableName(AbstractSchemaManager $schemaManager): string + private function resolveLanguageTableName(): string { - return $schemaManager->tablesExist(['ibexa_content_language']) - ? 'ibexa_content_language' - : 'ibexa_language'; + $legacyTableExists = $this->schemaAssetsFilterBypass->call( + $this->connection, + fn (): bool => $this->connection->createSchemaManager()->tablesExist(['ibexa_content_language']) + ); + + return $legacyTableExists ? 'ibexa_content_language' : 'ibexa_language'; } private function insertIgnoreKeyword(): string diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index bd9fd6a9fc..ba7c045df3 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -9,8 +9,7 @@ namespace Ibexa\Bundle\Core\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\Option; @@ -161,7 +160,10 @@ private function buildQueries( }; } - public function __construct(private readonly Connection $connection) {} + public function __construct( + private readonly Connection $connection, + private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass + ) {} public function __invoke( OutputInterface $output, @@ -218,14 +220,17 @@ private function verifyTable( // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never // had it to begin with - in both cases there is nothing left to verify, and the mask-based // queries below would otherwise fail outright with "no such column"/"undefined column". - $schemaManager = $this->connection->createSchemaManager(); - if (!$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn)) { + $hasMaskColumn = $this->schemaAssetsFilterBypass->call( + $this->connection, + fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) + ); + if (!$hasMaskColumn) { $output->writeln("{$table}: {$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to verify."); return true; } - $languageTable = $this->resolveLanguageTableName($schemaManager); + $languageTable = $this->resolveLanguageTableName(); $queries = $this->buildQueries($table, $languageTable); $alwaysAvailableColumn = self::ALWAYS_AVAILABLE_COLUMNS[$table] ?? null; @@ -282,13 +287,14 @@ private function verifyTable( * RenameLanguageTableMigration. When run manually/standalone after the full sequence * (or against a fresh install, which starts from the renamed schema), the table is already * "ibexa_language". - * - * @param AbstractSchemaManager $schemaManager */ - private function resolveLanguageTableName(AbstractSchemaManager $schemaManager): string + private function resolveLanguageTableName(): string { - return $schemaManager->tablesExist(['ibexa_content_language']) - ? 'ibexa_content_language' - : 'ibexa_language'; + $legacyTableExists = $this->schemaAssetsFilterBypass->call( + $this->connection, + fn (): bool => $this->connection->createSchemaManager()->tablesExist(['ibexa_content_language']) + ); + + return $legacyTableExists ? 'ibexa_content_language' : 'ibexa_language'; } } diff --git a/src/bundle/Core/Resources/config/services.yml b/src/bundle/Core/Resources/config/services.yml index d077cc25cf..0626d186aa 100644 --- a/src/bundle/Core/Resources/config/services.yml +++ b/src/bundle/Core/Resources/config/services.yml @@ -293,12 +293,14 @@ services: Ibexa\Bundle\Core\Command\BackfillLanguageTranslationsCommand: arguments: $connection: '@ibexa.persistence.connection' + $schemaAssetsFilterBypass: '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' tags: - { name: console.command } Ibexa\Bundle\Core\Command\VerifyLanguageTranslationsCommand: arguments: $connection: '@ibexa.persistence.connection' + $schemaAssetsFilterBypass: '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' tags: - { name: console.command } diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 1909914c9c..9fb8f53766 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\ParameterType; use Ibexa\Bundle\Core\Command\BackfillLanguageTranslationsCommand; use Ibexa\Bundle\Core\Command\VerifyLanguageTranslationsCommand; +use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; use PHPUnit\Framework\Attributes\CoversClass; use Symfony\Component\Console\Tester\CommandTester; @@ -86,7 +87,7 @@ protected function setUp(): void public function testBackfillPopulatesTranslationTablesFromMasks(): void { - $exitCode = (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) + $exitCode = (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()))) ->execute(['--table' => 'all']) ; @@ -115,7 +116,7 @@ public function testBackfillPopulatesTranslationTablesFromMasks(): void public function testBackfillIsIdempotent(): void { - $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); (new CommandTester($command))->execute(['--table' => 'content']); (new CommandTester($command))->execute(['--table' => 'content']); @@ -127,7 +128,7 @@ public function testBackfillIsIdempotent(): void public function testBackfillDryRunDoesNotWrite(): void { - $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); (new CommandTester($command))->execute(['--table' => 'content', '--dry-run' => true]); self::assertSame([], $this->fetchPairs('ibexa_content_translation', 'content_id')); @@ -136,12 +137,12 @@ public function testBackfillDryRunDoesNotWrite(): void public function testBackfillDryRunReportsNothingRemainingAfterRealBackfill(): void { $connection = $this->getDatabaseConnection(); - (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) + (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) ->execute(['--table' => 'content']); // A dry-run preview after a real backfill must report that nothing is left to insert - not // recount every mask-derived pair as if none of them already existed. - $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $tester->execute(['--table' => 'content', '--dry-run' => true]); self::assertStringContainsString('0 row(s) would be inserted', $tester->getDisplay()); @@ -154,10 +155,10 @@ public function testBackfillDryRunReportsNothingRemainingAfterRealBackfill(): vo public function testVerifyReportsCleanAfterBackfill(): void { - (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) + (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()))) ->execute(['--table' => 'all']); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($this->getDatabaseConnection())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass())); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); @@ -174,13 +175,13 @@ public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void // Orphaned: language 4 is not part of content 1's mask (2). $connection->insert('ibexa_content_translation', ['content_id' => 1, 'language_id' => 4]); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $exitCode = $tester->execute(['--table' => 'content']); self::assertSame(1, $exitCode); self::assertStringContainsString('1 missing, 1 orphaned', $tester->getDisplay()); - $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); self::assertSame(0, $fixExitCode); @@ -193,23 +194,41 @@ public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void public function testVerifyDetectsWrongAlwaysAvailableFlagsAndFixesThem(): void { $connection = $this->getDatabaseConnection(); - (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) + (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) ->execute(['--table' => 'content']); $connection->update('ibexa_content', ['always_available' => 0], ['id' => 2]); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $exitCode = $tester->execute(['--table' => 'content']); self::assertSame(1, $exitCode); self::assertStringContainsString('1 wrong always-available flag(s)', $tester->getDisplay()); - $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); self::assertSame(0, $fixExitCode); self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); } + public function testVerifyFindsTheLanguageTableBehindASchemaAssetsFilter(): void + { + $connection = $this->getDatabaseConnection(); + (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) + ->execute(['--table' => 'content']); + + $configuration = $connection->getConfiguration(); + $previousFilter = $configuration->getSchemaAssetsFilter(); + $configuration->setSchemaAssetsFilter(static fn (): bool => false); + try { + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + + self::assertSame(0, $tester->execute(['--table' => 'content'])); + } finally { + $configuration->setSchemaAssetsFilter($previousFilter); + } + } + /** * Both commands are explicitly documented as usable standalone, outside of a migration run - * but a schema that already completed the language bitmask migration (or a fresh install, @@ -224,7 +243,7 @@ public function testBackfillReportsNothingToDoOnAnAlreadyMigratedSchema(): void $this->simulateFullyMigratedSchema($connection); try { - $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); @@ -240,7 +259,7 @@ public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void $this->simulateFullyMigratedSchema($connection); try { - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); From 8a396226c1280ad18068dde2a0b7a3639e5b93ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 11:10:27 +0100 Subject: [PATCH 13/54] IBX-13142: Fed the Mapper tests the version languages their fixtures' masks encoded --- .../Persistence/Legacy/Content/MapperTest.php | 46 ++--------- .../extract_content_from_rows_result.php | 82 +------------------ 2 files changed, 9 insertions(+), 119 deletions(-) diff --git a/tests/lib/Persistence/Legacy/Content/MapperTest.php b/tests/lib/Persistence/Legacy/Content/MapperTest.php index f54d6125ec..f407c90a1b 100644 --- a/tests/lib/Persistence/Legacy/Content/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/MapperTest.php @@ -185,7 +185,7 @@ public function testExtractContentFromRows(): void 'ibexa_image', 'ibexa_datetime', 'ibexa_keyword', - ], null); + ], count($rowsFixture) - 1); $mapper = new Mapper( $reg, @@ -194,7 +194,7 @@ public function testExtractContentFromRows(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expected = [$this->getContentExtractReference()]; @@ -225,7 +225,7 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void 'ibexa_datetime', 'ibexa_keyword', 'eznumber', - ], null); + ], count($rowsFixture) - 1); $mapper = new Mapper( $reg, @@ -234,23 +234,12 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expectedContent = $this->getContentExtractReference(); - // Virtual "eznumber" fields (no data rows for this field definition at all) are - // synthesized once per recognized language - eng-US right after the real field rows, - // eng-GB at the very end after the eng-GB virtual fields for pre-existing definitions. - array_splice($expectedContent->fields, 9, 0, [ - new Field([ - 'type' => 'eznumber', - 'languageCode' => 'eng-US', - 'value' => new FieldValue(), - 'versionNo' => 2, - ]), - ]); $expectedContent->fields[] = new Field([ 'type' => 'eznumber', - 'languageCode' => 'eng-GB', + 'languageCode' => 'eng-US', 'value' => new FieldValue(), 'versionNo' => 2, ]); @@ -286,7 +275,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { 'ibexa_image', 'ibexa_datetime', 'ibexa_keyword', - ], null); + ], count($rowsFixture) - 2); $mapper = new Mapper( $reg, @@ -295,7 +284,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expectedContent = $this->getContentExtractReference(); $expectedContent->fields = array_values( @@ -341,7 +330,7 @@ public function testExtractContentFromRowsMultipleVersions(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, $this->getVersionLanguageIds($rowsFixture)); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [439 => [2], 674 => [2]]); self::assertCount( 2, @@ -669,25 +658,6 @@ protected function getMapper($valueConverter = null) ); } - /** - * @param array> $rows - * - * @return array - */ - private function getVersionLanguageIds(array $rows): array - { - $versionLanguageIds = []; - foreach ($rows as $row) { - $versionId = (int)$row['content_version_id']; - $languageId = (int)$row['content_field_language_id'] & ~1; - if (!in_array($languageId, $versionLanguageIds[$versionId] ?? [], true)) { - $versionLanguageIds[$versionId][] = $languageId; - } - } - - return $versionLanguageIds; - } - /** * Returns a FieldValue converter registry mock. * diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php index 2d9b76ab2a..727fd2b185 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_result.php @@ -23,7 +23,7 @@ $versionInfo->creationDate = 1313061317; $versionInfo->status = 1; $versionInfo->initialLanguageCode = 'eng-US'; -$versionInfo->languageCodes = ['eng-US', 'eng-GB']; +$versionInfo->languageCodes = ['eng-US']; $versionInfo->contentInfo = new ContentInfo(); $versionInfo->contentInfo->id = 226; @@ -122,84 +122,4 @@ $content->fields[] = $field; -$field = new Field(); -$field->id = 4000; -$field->fieldDefinitionId = 193; -$field->type = 'ibexa_keyword'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 183; -$field->type = 'ibexa_string'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 184; -$field->type = 'ibexa_string'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 185; -$field->type = 'ibexa_author'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 188; -$field->type = 'ibexa_boolean'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 189; -$field->type = 'ibexa_image'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 191; -$field->type = 'ibexa_datetime'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - -$field = new Field(); -$field->id = 0; -$field->fieldDefinitionId = 192; -$field->type = 'ibexa_datetime'; -$field->value = new FieldValue(); -$field->languageCode = 'eng-GB'; -$field->versionNo = 2; - -$content->fields[] = $field; - return $content; From 04e7e78a7eb37dd8e99f78fc5fb3ca591f37ebd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 11:25:27 +0100 Subject: [PATCH 14/54] IBX-13142: Removed outdated comments from the language join table code --- .../BackfillLanguageTranslationsCommand.php | 11 ------- .../VerifyLanguageTranslationsCommand.php | 12 -------- .../AddLanguageTranslationTablesMigration.php | 30 ++----------------- .../Content/Doctrine/DoctrineGateway.php | 7 ----- ...ackfillLanguageTranslationsCommandTest.php | 5 +--- 5 files changed, 3 insertions(+), 62 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index b774cfacbe..38afd970fb 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -129,10 +129,6 @@ private function backfillTable( default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), }; - // The mask column is dropped once a schema has fully completed the language bitmask - // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never - // had it to begin with - in both cases there is nothing left to backfill, and the mask-based - // queries below would otherwise fail outright with "no such column"/"undefined column". $hasMaskColumn = $this->schemaAssetsFilterBypass->call( $this->connection, fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) @@ -249,13 +245,6 @@ private function buildDryRunCountSql( }; } - /** - * Not yet renamed to "ibexa_language" at the point in the real migration sequence where this - * command's logic normally runs (as part of BackfillLanguageTranslationsMigration) - that - * rename happens later, in RenameLanguageTableMigration. When run manually/standalone - * after the full sequence (or against a fresh install, which starts from the renamed schema), - * the table is already "ibexa_language". - */ private function resolveLanguageTableName(): string { $legacyTableExists = $this->schemaAssetsFilterBypass->call( diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index ba7c045df3..69df583a95 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -216,10 +216,6 @@ private function verifyTable( ): bool { [$sourceTable, $maskColumn] = self::SOURCE_TABLES[$table]; - // The mask column is dropped once a schema has fully completed the language bitmask - // migration (DropLanguageBitmaskColumnsMigration), and a fresh install's schema.yaml never - // had it to begin with - in both cases there is nothing left to verify, and the mask-based - // queries below would otherwise fail outright with "no such column"/"undefined column". $hasMaskColumn = $this->schemaAssetsFilterBypass->call( $this->connection, fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) @@ -280,14 +276,6 @@ private function verifyTable( return true; } - /** - * Not yet renamed to "ibexa_language" at the point in the real migration sequence where this - * command's logic normally runs (as part of BackfillLanguageTranslationsMigration/ - * DropLanguageBitmaskColumnsMigration) - that rename happens later, in - * RenameLanguageTableMigration. When run manually/standalone after the full sequence - * (or against a fresh install, which starts from the renamed schema), the table is already - * "ibexa_language". - */ private function resolveLanguageTableName(): string { $legacyTableExists = $this->schemaAssetsFilterBypass->call( diff --git a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php index 89fe520380..e75bcf0605 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php @@ -17,39 +17,13 @@ use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Creates "ibexa_content_translation", "ibexa_content_version_translation" and - * "ibexa_url_alias_ml_translation" - the relational replacement for the - * "language_mask"/"lang_mask" columns on "ibexa_content", "ibexa_content_version" and - * "ibexa_url_alias_ml" (step 2 of the language bitmask migration). - * - * Purely additive: tables are created empty and stay empty until - * "ibexa:languages:backfill-translations" populates them, and nothing reads them yet - the mask - * columns remain authoritative until later steps switch read paths over and eventually drop them. - * - * On SQLite, each table's foreign keys are embedded directly in its own `CREATE TABLE IF NOT - * EXISTS` statement (SQLite has no separate `ALTER TABLE ... ADD CONSTRAINT`), so the table and its - * constraints are always created atomically together - a table existing at all means it's complete. - * - * On MySQL/PostgreSQL, `CREATE TABLE`/`ADD CONSTRAINT` are separate statements that each commit - * independently, so a failure partway through (e.g. after creating "ibexa_content_translation" but - * before its constraints, or before the other two tables) must not make a retry mistake "the first - * table already exists" for "everything already ran" and silently skip the rest - each of the 6 - * foreign keys across the 3 tables is checked and queued independently. - * - * Guarded via the connection's schema manager rather than the injected $schema, because - * TaggedMigrationsRunner (the "ibexa:install" path) invokes up() with an empty Schema, so - * $schema->hasTable() would always report false there. + * Creates "ibexa_content_translation", "ibexa_content_version_translation" and "ibexa_url_alias_ml_translation". */ final class AddLanguageTranslationTablesMigration extends AbstractSqlMigration implements IbexaMigrationInterface { private const string CONTENT_TABLE = 'ibexa_content'; - /** - * Not yet renamed to "ibexa_language" at this point in the migration sequence - that rename - * happens later, in {@see RenameLanguageTableMigration}. - * - * @var array> - */ + /** @var array> */ private const array FOREIGN_KEYS = [ 'ibexa_content_translation' => [ 'ibexa_content_translation_content_fk' => 'FOREIGN KEY (content_id) REFERENCES ibexa_content (id) ON DELETE CASCADE ON UPDATE CASCADE', diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index 3c04f71cf1..ecd3470570 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -216,10 +216,6 @@ private function bulkFetchVersionNames(FilteringQueryBuilder $query): array (string)$query->expr()->and( 'content.id = content_name.contentobject_id', 'version.version = content_name.content_version', - // content_name.language_id may still carry a stray pre-migration "always - // available" bit (+1) that was never cleaned up retroactively - tolerate it - // the same defensive way LanguagePriorityConditionBuilder does for - // ibexa_content_field.language_id. 'EXISTS ( SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id @@ -260,9 +256,6 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array (string)$query->expr()->and( 'content.id = content_field.contentobject_id', 'version.version = content_field.version', - // content_field.language_id may still carry a stray pre-migration "always - // available" bit (+1) that was never cleaned up retroactively - see the same - // tolerance in bulkFetchVersionNames() above. 'EXISTS ( SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 9fb8f53766..83e8a212c7 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -270,10 +270,7 @@ public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void } /** - * Undoes setUp()'s pre-migration simulation: renames the language table to its final name and - * drops the mask columns, matching the state a schema is in once DropLanguageBitmaskColumnsMigration - * and RenameLanguageTableMigration have both run (or a fresh install, which never had - * them at all). + * Renames the language table to "ibexa_language" and drops the mask columns, like a fully migrated schema. */ private function simulateFullyMigratedSchema(Connection $connection): void { From 178bee7591698dca3bd1d7b832b5c87b3c309477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 15:04:43 +0100 Subject: [PATCH 15/54] IBX-13142: Replaced the deprecated introspectTable() calls with introspectTableByUnquotedName() --- .../Command/BackfillLanguageTranslationsCommand.php | 2 +- .../Command/VerifyLanguageTranslationsCommand.php | 2 +- .../AddContentAlwaysAvailableColumnsMigration.php | 2 +- .../AddLanguageTranslationTablesMigration.php | 2 +- .../BackfillLanguageTranslationsMigration.php | 11 ++++++++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index 38afd970fb..1b7c61fe68 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -131,7 +131,7 @@ private function backfillTable( $hasMaskColumn = $this->schemaAssetsFilterBypass->call( $this->connection, - fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) + fn (): bool => $this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn) ); if (!$hasMaskColumn) { $output->writeln("{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill."); diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index 69df583a95..fbe24b4d44 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -218,7 +218,7 @@ private function verifyTable( $hasMaskColumn = $this->schemaAssetsFilterBypass->call( $this->connection, - fn (): bool => $this->connection->createSchemaManager()->introspectTable($sourceTable)->hasColumn($maskColumn) + fn (): bool => $this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn) ); if (!$hasMaskColumn) { $output->writeln("{$table}: {$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to verify."); diff --git a/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php index 5d667374dd..6ca662b925 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php @@ -49,7 +49,7 @@ public function up(Schema $schema): void } foreach ([self::CONTENT_TABLE, self::CONTENT_VERSION_TABLE] as $table) { - if (!$schemaManager->introspectTable($table)->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { + if (!$schemaManager->introspectTableByUnquotedName($table)->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { $this->addSql($this->buildAddColumnSql($table)); } } diff --git a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php index e75bcf0605..a1560069be 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php @@ -104,7 +104,7 @@ private function findMissingForeignKeys(AbstractSchemaManager $schemaManager): a foreach (self::FOREIGN_KEYS as $table => $foreignKeys) { $existingTable = $schemaManager->tablesExist([$table]) - ? $schemaManager->introspectTable($table) + ? $schemaManager->introspectTableByUnquotedName($table) : null; foreach ($foreignKeys as $constraintName => $definition) { diff --git a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php index 10361f2bb4..17321e2f81 100644 --- a/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php @@ -86,6 +86,9 @@ public function up(Schema $schema): void ); } + /** + * @param non-empty-string $sourceTable + */ private function backfillAlwaysAvailable(string $sourceTable): void { $this->addChunkedSql( @@ -97,6 +100,9 @@ private function backfillAlwaysAvailable(string $sourceTable): void ); } + /** + * @param non-empty-string $sourceTable + */ private function backfillTable( string $sourceTable, string $maskColumn, @@ -111,6 +117,9 @@ private function backfillTable( ); } + /** + * @param non-empty-string $sourceTable + */ private function addChunkedSql( string $sourceTable, string $maskColumn, @@ -120,7 +129,7 @@ private function addChunkedSql( $schemaManager = $this->connection->createSchemaManager(); if ( !$schemaManager->tablesExist([$sourceTable]) - || !$schemaManager->introspectTable($sourceTable)->hasColumn($maskColumn) + || !$schemaManager->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn) ) { // Column already dropped (re-running after a prior upgrade already completed this // step), or a fresh install whose schema.yaml never had it. From e3183abc04c68f2908138277594f304d34e7983b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 17:26:01 +0100 Subject: [PATCH 16/54] IBX-13142: Removed the language table name lookup, as the table keeps its name --- .../BackfillLanguageTranslationsCommand.php | 14 +++----------- .../Command/VerifyLanguageTranslationsCommand.php | 14 +++----------- .../Test/Persistence/Fixture/FixtureImporter.php | 9 +-------- .../BackfillLanguageTranslationsCommandTest.php | 13 +++++-------- 4 files changed, 12 insertions(+), 38 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index 1b7c61fe68..a186dbf74e 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -36,6 +36,8 @@ )] final class BackfillLanguageTranslationsCommand { + private const string LANGUAGE_TABLE = 'ibexa_content_language'; + private const int DEFAULT_BATCH_SIZE = 5000; private const string TABLE_CONTENT = 'content'; @@ -139,7 +141,7 @@ private function backfillTable( return; } - $languageTable = $this->resolveLanguageTableName(); + $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 @@ -245,16 +247,6 @@ private function buildDryRunCountSql( }; } - private function resolveLanguageTableName(): string - { - $legacyTableExists = $this->schemaAssetsFilterBypass->call( - $this->connection, - fn (): bool => $this->connection->createSchemaManager()->tablesExist(['ibexa_content_language']) - ); - - return $legacyTableExists ? 'ibexa_content_language' : 'ibexa_language'; - } - private function insertIgnoreKeyword(): string { return match ($this->resolvePlatformName()) { diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index fbe24b4d44..4306bb4e2e 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -37,6 +37,8 @@ )] final class VerifyLanguageTranslationsCommand { + private const string LANGUAGE_TABLE = 'ibexa_content_language'; + private const string TABLE_CONTENT = 'content'; private const string TABLE_CONTENT_VERSION = 'content_version'; private const string TABLE_URL_ALIAS = 'url_alias'; @@ -226,7 +228,7 @@ private function verifyTable( return true; } - $languageTable = $this->resolveLanguageTableName(); + $languageTable = self::LANGUAGE_TABLE; $queries = $this->buildQueries($table, $languageTable); $alwaysAvailableColumn = self::ALWAYS_AVAILABLE_COLUMNS[$table] ?? null; @@ -275,14 +277,4 @@ private function verifyTable( return true; } - - private function resolveLanguageTableName(): string - { - $legacyTableExists = $this->schemaAssetsFilterBypass->call( - $this->connection, - fn (): bool => $this->connection->createSchemaManager()->tablesExist(['ibexa_content_language']) - ); - - return $legacyTableExists ? 'ibexa_content_language' : 'ibexa_language'; - } } diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index c13027c3b6..608fd6a5e9 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -52,14 +52,7 @@ public function import(Fixture $fixture): void { $data = $fixture->load(); - // Fixtures (e.g. ibexa/test-core's own bundled baseline, which this package doesn't - // control) predate tables being renamed/dropped over time (e.g. ibexa_content_language - // becoming ibexa_language) - silently skip tables that no longer exist, same as - // getExistingColumns() already does for individual columns below. - $tablesList = array_values(array_filter( - array_keys($data), - fn (string $table): bool => $this->tableExists($table) - )); + $tablesList = array_keys($data); $detachedTranslations = []; if (!$fixture instanceof AppendOnlyFixture) { $detachedTranslations = $this->detachLanguageTranslations($tablesList); diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 83e8a212c7..dc4e2620a4 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -211,7 +211,7 @@ public function testVerifyDetectsWrongAlwaysAvailableFlagsAndFixesThem(): void self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); } - public function testVerifyFindsTheLanguageTableBehindASchemaAssetsFilter(): void + public function testVerifyFindsTheMaskColumnsBehindASchemaAssetsFilter(): void { $connection = $this->getDatabaseConnection(); (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) @@ -232,10 +232,9 @@ public function testVerifyFindsTheLanguageTableBehindASchemaAssetsFilter(): void /** * Both commands are explicitly documented as usable standalone, outside of a migration run - * but a schema that already completed the language bitmask migration (or a fresh install, - * which starts from that same final state) has neither the "ibexa_content_language" name nor - * the mask columns these commands' queries otherwise assume. Without a guard, that crashes with - * a raw "no such table"/"no such column" DB exception instead of reporting there is nothing to - * do. + * which starts from that same final state) has none of the mask columns these commands' queries + * otherwise assume. Without a guard, that crashes with a raw "no such column" DB exception + * instead of reporting there is nothing to do. */ public function testBackfillReportsNothingToDoOnAnAlreadyMigratedSchema(): void { @@ -270,11 +269,10 @@ public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void } /** - * Renames the language table to "ibexa_language" and drops the mask columns, like a fully migrated schema. + * Drops the mask columns, like a fully migrated schema. */ private function simulateFullyMigratedSchema(Connection $connection): void { - $connection->executeStatement('ALTER TABLE ibexa_content_language RENAME TO ibexa_language'); // SQLite can't drop a column an index still covers $connection->executeStatement('DROP INDEX ibexa_content_lmask'); $connection->executeStatement('DROP INDEX ibexa_url_alias_ml_text_lang'); @@ -289,7 +287,6 @@ private function simulateFullyMigratedSchema(Connection $connection): void */ private function restorePreMigrationSchema(Connection $connection): void { - $connection->executeStatement('ALTER TABLE ibexa_language RENAME TO ibexa_content_language'); $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); $connection->executeStatement('ALTER TABLE ibexa_content_version ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); From 6957c1fba992dbfc8e5871a0b9856bb17d24fe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 17 Nov 2026 11:42:07 +0100 Subject: [PATCH 17/54] IBX-13142: Dropped the schema assets filter bypass from the language join table code IBX-13070 removed SchemaAssetsFilterBypass together with the filter it lifted, so the language translation commands and FixtureImporter introspect the connection directly again. --- .../BackfillLanguageTranslationsCommand.php | 12 ++----- .../VerifyLanguageTranslationsCommand.php | 12 ++----- src/bundle/Core/Resources/config/services.yml | 2 -- .../Persistence/Fixture/FixtureImporter.php | 20 ++--------- .../Test/Repository/SetupFactory/Legacy.php | 2 +- ...ackfillLanguageTranslationsCommandTest.php | 33 +++++++++---------- .../Resources/services/fixture-services.yaml | 1 - .../BinaryBaseStorageGatewayTest.php | 3 +- tests/integration/Core/TestKernel.php | 13 -------- .../UserStorageGatewayTestCase.php | 3 +- tests/lib/Persistence/Legacy/TestCase.php | 4 +-- 11 files changed, 27 insertions(+), 78 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index a186dbf74e..fef42ec53d 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -11,7 +11,6 @@ use Doctrine\DBAL\Connection; use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformName; use Ibexa\Contracts\DoctrineSchema\Database\DatabasePlatformResolver; -use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\Option; @@ -51,10 +50,7 @@ final class BackfillLanguageTranslationsCommand self::TABLE_URL_ALIAS, ]; - public function __construct( - private readonly Connection $connection, - private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass - ) {} + public function __construct(private readonly Connection $connection) {} public function __invoke( OutputInterface $output, @@ -131,11 +127,7 @@ private function backfillTable( default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), }; - $hasMaskColumn = $this->schemaAssetsFilterBypass->call( - $this->connection, - fn (): bool => $this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn) - ); - if (!$hasMaskColumn) { + if (!$this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn)) { $output->writeln("{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill."); return; diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index 4306bb4e2e..79ccf1bedf 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -9,7 +9,6 @@ namespace Ibexa\Bundle\Core\Command; use Doctrine\DBAL\Connection; -use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\Option; @@ -162,10 +161,7 @@ private function buildQueries( }; } - public function __construct( - private readonly Connection $connection, - private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass - ) {} + public function __construct(private readonly Connection $connection) {} public function __invoke( OutputInterface $output, @@ -218,11 +214,7 @@ private function verifyTable( ): bool { [$sourceTable, $maskColumn] = self::SOURCE_TABLES[$table]; - $hasMaskColumn = $this->schemaAssetsFilterBypass->call( - $this->connection, - fn (): bool => $this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn) - ); - if (!$hasMaskColumn) { + if (!$this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn)) { $output->writeln("{$table}: {$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to verify."); return true; diff --git a/src/bundle/Core/Resources/config/services.yml b/src/bundle/Core/Resources/config/services.yml index 0626d186aa..d077cc25cf 100644 --- a/src/bundle/Core/Resources/config/services.yml +++ b/src/bundle/Core/Resources/config/services.yml @@ -293,14 +293,12 @@ services: Ibexa\Bundle\Core\Command\BackfillLanguageTranslationsCommand: arguments: $connection: '@ibexa.persistence.connection' - $schemaAssetsFilterBypass: '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' tags: - { name: console.command } Ibexa\Bundle\Core\Command\VerifyLanguageTranslationsCommand: arguments: $connection: '@ibexa.persistence.connection' - $schemaAssetsFilterBypass: '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' tags: - { name: console.command } diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 608fd6a5e9..430b3efda0 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -15,8 +15,6 @@ use Doctrine\DBAL\Schema\Column; use Ibexa\Contracts\Core\Test\Persistence\AppendOnlyFixture; use Ibexa\Contracts\Core\Test\Persistence\Fixture; -use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; -use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; /** * Database fixture importer. @@ -40,10 +38,7 @@ final class FixtureImporter /** @var array */ private static array $existingColumnsByTable = []; - public function __construct( - private readonly Connection $connection, - private readonly SchemaAssetsFilterBypassInterface $schemaAssetsFilterBypass = new SchemaAssetsFilterBypass() - ) {} + public function __construct(private readonly Connection $connection) {} /** * @throws Exception @@ -278,20 +273,9 @@ private function backfillLanguageBitmaskColumns(array $nonEmptyTablesData): void } } - /** - * tablesExist() goes through AbstractSchemaManager::listTableNames(), which is filtered by - * whatever schema assets filter is configured on the connection (e.g. - * ManagedTablesSchemaAssetFilter, which hides every table not backed by a registered ORM - * entity - i.e. all of Ibexa's own legacy/join tables). Bypass it, same as - * LegacySchemaImporter does, or this always reports these tables as absent and every backfill - * below silently no-ops. - */ private function tableExists(string $table): bool { - return $this->schemaAssetsFilterBypass->call( - $this->connection, - fn (): bool => $this->connection->createSchemaManager()->tablesExist([$table]) - ); + return $this->connection->createSchemaManager()->tablesExist([$table]); } /** diff --git a/src/contracts/Test/Repository/SetupFactory/Legacy.php b/src/contracts/Test/Repository/SetupFactory/Legacy.php index 8b542d2ac2..391474c383 100644 --- a/src/contracts/Test/Repository/SetupFactory/Legacy.php +++ b/src/contracts/Test/Repository/SetupFactory/Legacy.php @@ -164,7 +164,7 @@ public function insertData(): void $connection = $this->getDatabaseConnection(); $this->cleanupVarDir($this->getInitialVarDir()); - $fixtureImporter = new FixtureImporter($connection, new SchemaAssetsFilterBypass()); + $fixtureImporter = new FixtureImporter($connection); $fixtureImporter->import($this->getInitialDataFixture()); } diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index dc4e2620a4..0fb80553f8 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -12,7 +12,6 @@ use Doctrine\DBAL\ParameterType; use Ibexa\Bundle\Core\Command\BackfillLanguageTranslationsCommand; use Ibexa\Bundle\Core\Command\VerifyLanguageTranslationsCommand; -use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; use PHPUnit\Framework\Attributes\CoversClass; use Symfony\Component\Console\Tester\CommandTester; @@ -87,7 +86,7 @@ protected function setUp(): void public function testBackfillPopulatesTranslationTablesFromMasks(): void { - $exitCode = (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()))) + $exitCode = (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) ->execute(['--table' => 'all']) ; @@ -116,7 +115,7 @@ public function testBackfillPopulatesTranslationTablesFromMasks(): void public function testBackfillIsIdempotent(): void { - $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); (new CommandTester($command))->execute(['--table' => 'content']); (new CommandTester($command))->execute(['--table' => 'content']); @@ -128,7 +127,7 @@ public function testBackfillIsIdempotent(): void public function testBackfillDryRunDoesNotWrite(): void { - $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $command = new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()); (new CommandTester($command))->execute(['--table' => 'content', '--dry-run' => true]); self::assertSame([], $this->fetchPairs('ibexa_content_translation', 'content_id')); @@ -137,12 +136,12 @@ public function testBackfillDryRunDoesNotWrite(): void public function testBackfillDryRunReportsNothingRemainingAfterRealBackfill(): void { $connection = $this->getDatabaseConnection(); - (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) + (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) ->execute(['--table' => 'content']); // A dry-run preview after a real backfill must report that nothing is left to insert - not // recount every mask-derived pair as if none of them already existed. - $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); $tester->execute(['--table' => 'content', '--dry-run' => true]); self::assertStringContainsString('0 row(s) would be inserted', $tester->getDisplay()); @@ -155,10 +154,10 @@ public function testBackfillDryRunReportsNothingRemainingAfterRealBackfill(): vo public function testVerifyReportsCleanAfterBackfill(): void { - (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()))) + (new CommandTester(new BackfillLanguageTranslationsCommand($this->getDatabaseConnection()))) ->execute(['--table' => 'all']); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($this->getDatabaseConnection(), new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($this->getDatabaseConnection())); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); @@ -175,13 +174,13 @@ public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void // Orphaned: language 4 is not part of content 1's mask (2). $connection->insert('ibexa_content_translation', ['content_id' => 1, 'language_id' => 4]); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); $exitCode = $tester->execute(['--table' => 'content']); self::assertSame(1, $exitCode); self::assertStringContainsString('1 missing, 1 orphaned', $tester->getDisplay()); - $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); self::assertSame(0, $fixExitCode); @@ -194,17 +193,17 @@ public function testVerifyDetectsMissingAndOrphanedRowsAndFixesThem(): void public function testVerifyDetectsWrongAlwaysAvailableFlagsAndFixesThem(): void { $connection = $this->getDatabaseConnection(); - (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) + (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) ->execute(['--table' => 'content']); $connection->update('ibexa_content', ['always_available' => 0], ['id' => 2]); - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); $exitCode = $tester->execute(['--table' => 'content']); self::assertSame(1, $exitCode); self::assertStringContainsString('1 wrong always-available flag(s)', $tester->getDisplay()); - $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $fixTester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); $fixExitCode = $fixTester->execute(['--table' => 'content', '--fix' => true]); self::assertSame(0, $fixExitCode); @@ -214,14 +213,14 @@ public function testVerifyDetectsWrongAlwaysAvailableFlagsAndFixesThem(): void public function testVerifyFindsTheMaskColumnsBehindASchemaAssetsFilter(): void { $connection = $this->getDatabaseConnection(); - (new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass()))) + (new CommandTester(new BackfillLanguageTranslationsCommand($connection))) ->execute(['--table' => 'content']); $configuration = $connection->getConfiguration(); $previousFilter = $configuration->getSchemaAssetsFilter(); $configuration->setSchemaAssetsFilter(static fn (): bool => false); try { - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); self::assertSame(0, $tester->execute(['--table' => 'content'])); } finally { @@ -242,7 +241,7 @@ public function testBackfillReportsNothingToDoOnAnAlreadyMigratedSchema(): void $this->simulateFullyMigratedSchema($connection); try { - $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new BackfillLanguageTranslationsCommand($connection)); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); @@ -258,7 +257,7 @@ public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void $this->simulateFullyMigratedSchema($connection); try { - $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection, new SchemaAssetsFilterBypass())); + $tester = new CommandTester(new VerifyLanguageTranslationsCommand($connection)); $exitCode = $tester->execute(['--table' => 'all']); self::assertSame(0, $exitCode); diff --git a/tests/bundle/Core/Resources/services/fixture-services.yaml b/tests/bundle/Core/Resources/services/fixture-services.yaml index a0620cb82a..dfe6d24f5c 100644 --- a/tests/bundle/Core/Resources/services/fixture-services.yaml +++ b/tests/bundle/Core/Resources/services/fixture-services.yaml @@ -17,4 +17,3 @@ services: public: true arguments: - '@doctrine.dbal.default_connection' - - '@Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface' diff --git a/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php b/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php index b5d840e19b..c39f717128 100644 --- a/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php +++ b/tests/integration/Core/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php @@ -16,7 +16,6 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture; use Ibexa\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway as BinaryBaseStorageGateway; use Ibexa\Core\FieldType\BinaryFile\BinaryFileStorage\Gateway\DoctrineStorage; -use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Integration\Core\BaseCoreFieldTypeIntegrationTestCase; /** @@ -28,7 +27,7 @@ protected function setUp(): void { parent::setUp(); - $importer = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $importer = new FixtureImporter($this->getDatabaseConnection()); $importer->import(new YamlFixture(__DIR__ . '/_fixtures/ibexa_binary_file.yaml')); } diff --git a/tests/integration/Core/TestKernel.php b/tests/integration/Core/TestKernel.php index 3b8a4fdec2..d789717031 100644 --- a/tests/integration/Core/TestKernel.php +++ b/tests/integration/Core/TestKernel.php @@ -16,11 +16,9 @@ use Ibexa\Contracts\Core\Repository\BookmarkService; use Ibexa\Contracts\Core\Repository\TrashService; use Ibexa\Contracts\Core\Test\IbexaTestKernel; -use Ibexa\Contracts\DoctrineSchema\SchemaAssetsFilterBypassInterface; use Ibexa\Contracts\Test\Core\IbexaTestKernel as BaseIbexaTestKernel; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; /** * Loads the same fixture set {@see IbexaTestKernel} (the package-internal @@ -50,17 +48,6 @@ public function registerContainerConfiguration(LoaderInterface $loader): void __DIR__ . '/Repository/_fixtures/Legacy/data/test_data.yaml', ]); }); - - $loader->load(static function (ContainerBuilder $container): void { - // ibexa/test-core's own fixture-services.yaml only passes a Connection to - // FixtureImporter - it predates the SchemaAssetsFilterBypassInterface argument this - // package's FixtureImporter gained for the language join-table backfill. Re-wire the - // shared definition here rather than waiting for it to catch up. - $container->getDefinition('test.ibexa.fixture_importer')->setArguments([ - new Reference('ibexa.persistence.connection'), - new Reference(SchemaAssetsFilterBypassInterface::class), - ]); - }); } public function registerBundles(): iterable diff --git a/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php b/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php index d8039fb9ba..27c57a522b 100644 --- a/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php +++ b/tests/integration/Core/User/UserStorage/UserStorageGatewayTestCase.php @@ -11,7 +11,6 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture; use Ibexa\Core\FieldType\User\UserStorage\Gateway; use Ibexa\Core\Repository\Values\User\User; -use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Integration\Core\BaseCoreFieldTypeIntegrationTestCase; use PHPUnit\Framework\Attributes\DataProvider; @@ -73,7 +72,7 @@ public function testCountUsersWithUnsupportedHashType( ?string $fixtureFilePath ): void { if (null !== $fixtureFilePath) { - $importer = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $importer = new FixtureImporter($this->getDatabaseConnection()); $importer->import(new YamlFixture($fixtureFilePath)); } diff --git a/tests/lib/Persistence/Legacy/TestCase.php b/tests/lib/Persistence/Legacy/TestCase.php index db85ec8935..3a02c42fa2 100644 --- a/tests/lib/Persistence/Legacy/TestCase.php +++ b/tests/lib/Persistence/Legacy/TestCase.php @@ -184,7 +184,7 @@ static function ($row): string { protected function insertDatabaseFixture(string $file): void { try { - $fixtureImporter = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $fixtureImporter = new FixtureImporter($this->getDatabaseConnection()); $fixtureImporter->import((new FileFixtureFactory())->buildFixture($file)); } catch (DBALException $e) { self::fail('Database fixture import failed: ' . $e->getMessage()); @@ -199,7 +199,7 @@ protected function insertDatabaseFixture(string $file): void protected function insertSharedDatabaseFixture(): void { try { - $fixtureImporter = new FixtureImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass()); + $fixtureImporter = new FixtureImporter($this->getDatabaseConnection()); $fixtureImporter->import( new YamlFixture( __DIR__ . '/../../../integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml' From 844b34ae447e37ea0db05e43ea74c2f2341666df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 20:45:04 +0100 Subject: [PATCH 18/54] IBX-11939: Moved the legacy search engine off the language bitmask ibexa_search_object_word_link gets language_id and is_main_and_always_available columns, filled from its mask. The field criteria and sort clause, the full-text and language code criteria and the language filter of content and location search use the join tables and those columns instead of arithmetic on the masks. The indexer keeps writing the word link mask until the bitmask is removed, and field language ids are compared without their always-available bit until it is stripped. --- phpstan-baseline.neon | 60 -------- .../Resources/config/doctrine_migrations.php | 5 + .../config/storage/legacy/schema.yaml | 2 + ...jectWordLinkLanguageIdColumnsMigration.php | 119 ++++++++++++++++ .../settings/search_engines/legacy.yml | 1 + .../legacy/criterion_handlers_common.yml | 10 +- .../search_engines/legacy/indexer.yml | 2 +- .../legacy/sort_clause_handlers_common.yml | 1 + .../Common/Gateway/CriterionHandler/Field.php | 12 +- .../Gateway/CriterionHandler/FieldBase.php | 91 ++---------- .../Gateway/CriterionHandler/FieldEmpty.php | 12 +- .../Gateway/CriterionHandler/FullText.php | 46 +++---- .../Gateway/CriterionHandler/LanguageCode.php | 55 ++++++-- .../LanguagePriorityConditionBuilder.php | 130 ++++++++++++++++++ .../Gateway/SortClauseHandler/Field.php | 86 ++---------- .../Content/Gateway/DoctrineDatabase.php | 73 ++++------ src/lib/Search/Legacy/Content/Handler.php | 42 ++++-- .../Location/Gateway/DoctrineDatabase.php | 95 ++++++------- .../WordIndexer/Gateway/DoctrineDatabase.php | 18 ++- .../WordIndexer/Repository/SearchIndex.php | 13 +- .../Legacy/Content/AbstractTestCase.php | 13 ++ .../Legacy/Content/HandlerContentSortTest.php | 11 +- .../Legacy/Content/HandlerContentTest.php | 21 ++- .../Content/HandlerLocationSortTest.php | 12 +- .../Legacy/Content/HandlerLocationTest.php | 28 +++- 25 files changed, 553 insertions(+), 405 deletions(-) create mode 100644 src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php create mode 100644 src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b42edb33fb..b41c7e117c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -17220,12 +17220,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/Field.php - - - message: '#^Cannot call method getBitAndComparisonExpression\(\) on Doctrine\\DBAL\\Platforms\\AbstractPlatform\|null\.$#' - identifier: method.nonObject - count: 8 - path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Common\\Gateway\\CriterionHandler\\FieldBase\:\:getFieldCondition\(\) has parameter \$languageSettings with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -17424,24 +17418,12 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/IsUserEnabled.php - - - message: '#^Cannot call method getBitAndComparisonExpression\(\) on Doctrine\\DBAL\\Platforms\\AbstractPlatform\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Common\\Gateway\\CriterionHandler\\LanguageCode\:\:handle\(\) has parameter \$languageSettings with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php - - - message: '#^Parameter \#1 \$languageCodes of method Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\:\:generateLanguageMaskFromLanguageCodes\(\) expects array\, array\\|bool\|float\|int\|string given\.$#' - identifier: argument.type - count: 1 - path: src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Common\\Gateway\\CriterionHandler\\LogicalAnd\:\:handle\(\) has parameter \$languageSettings with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -17658,12 +17640,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Factory/RandomSortClauseHandlerFactory.php - - - message: '#^Cannot call method getBitAndComparisonExpression\(\) on Doctrine\\DBAL\\Platforms\\AbstractPlatform\|null\.$#' - identifier: method.nonObject - count: 8 - path: src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Common\\Gateway\\SortClauseHandler\\Field\:\:applySelect\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -17850,12 +17826,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Gateway\\DoctrineDatabase\:\:getLanguageMask\(\) has parameter \$languageSettings with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Gateway\\DoctrineDatabase\:\:getQueryCondition\(\) has parameter \$languageFilter with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -17916,30 +17886,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Handler.php - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Handler\:\:extractMatchedLanguage\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/Search/Legacy/Content/Handler.php - - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Handler\:\:extractMatchedLanguage\(\) has parameter \$languageMask with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/Search/Legacy/Content/Handler.php - - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Handler\:\:extractMatchedLanguage\(\) has parameter \$languageSettings with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/Search/Legacy/Content/Handler.php - - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Handler\:\:extractMatchedLanguage\(\) has parameter \$mainLanguageId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/Search/Legacy/Content/Handler.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Handler\:\:indexContent\(\) has no return type specified\.$#' identifier: missingType.return @@ -18132,12 +18078,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php - - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Location\\Gateway\\DoctrineDatabase\:\:getLanguageMask\(\) has parameter \$languageFilter with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\Location\\Gateway\\DoctrineDatabase\:\:getTotalCount\(\) has parameter \$languageFilter with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/bundle/Core/Resources/config/doctrine_migrations.php b/src/bundle/Core/Resources/config/doctrine_migrations.php index e1c274671c..3780e65837 100644 --- a/src/bundle/Core/Resources/config/doctrine_migrations.php +++ b/src/bundle/Core/Resources/config/doctrine_migrations.php @@ -9,6 +9,7 @@ use Ibexa\Bundle\RepositoryInstaller\Migration\AddContentAlwaysAvailableColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddContentVersionUniqueIndexMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddLanguageTranslationTablesMigration; +use Ibexa\Bundle\RepositoryInstaller\Migration\AddSearchObjectWordLinkLanguageIdColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddUrlAliasMlLinkIndexMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\BackfillLanguageTranslationsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsMigration; @@ -91,6 +92,10 @@ ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); + $services->set(AddSearchObjectWordLinkLanguageIdColumnsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + $services->set(BackfillLanguageTranslationsMigration::class) ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index 6e34a1d916..eb49316970 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -532,6 +532,8 @@ tables: section_id: { type: integer, nullable: false, options: { default: '0' } } word_id: { type: integer, nullable: false, options: { default: '0' } } language_mask: { type: bigint, nullable: false, options: { default: '0' } } + language_id: { type: bigint, nullable: false, options: { default: '0' } } + is_main_and_always_available: { type: boolean, nullable: false, options: { default: false } } ibexa_search_word: indexes: ibexa_search_word_word_i: { fields: [word] } diff --git a/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php new file mode 100644 index 0000000000..865229d875 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php @@ -0,0 +1,119 @@ +hasTable()/hasColumn() would always report false there. + */ +final class AddSearchObjectWordLinkLanguageIdColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string TABLE = 'ibexa_search_object_word_link'; + private const string LANGUAGE_ID_COLUMN = 'language_id'; + private const string IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN = 'is_main_and_always_available'; + + public function getDescription(): string + { + return 'Adds "language_id" and "is_main_and_always_available" columns to "ibexa_search_object_word_link", backfilled from the language mask'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 03:00:00'); + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::TABLE])) { + return; + } + + $table = $schemaManager->introspectTable(self::TABLE); + $hasLanguageIdColumn = $table->hasColumn(self::LANGUAGE_ID_COLUMN); + $hasAlwaysAvailableColumn = $table->hasColumn(self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN); + + if ($hasLanguageIdColumn && $hasAlwaysAvailableColumn) { + // Already fully applied - avoid an unconditional full-table backfill re-scan once this + // migration has genuinely completed. + return; + } + + if (!$hasLanguageIdColumn) { + $this->addSql($this->buildAddLanguageIdColumnSql()); + } + + if (!$hasAlwaysAvailableColumn) { + $this->addSql($this->buildAddAlwaysAvailableColumnSql()); + } + + $this->addSql( + 'UPDATE ' . self::TABLE . ' SET ' . self::LANGUAGE_ID_COLUMN . ' = (language_mask & -2)' + ); + $this->addSql( + 'UPDATE ' . self::TABLE . ' SET ' . self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN . ' = ' . + ($this->isPostgreSQL() ? 'true' : '1') . ' WHERE (language_mask & 1) = 1' + ); + } + + private function buildAddLanguageIdColumnSql(): string + { + // BIGINT, like the other columns holding bitmask-era language ids: up to 2^62 + $columnDefinition = $this->isMySQL() || $this->isMariaDB() ? "BIGINT DEFAULT '0' NOT NULL" : 'BIGINT DEFAULT 0 NOT NULL'; + + return 'ALTER TABLE ' . self::TABLE . ' ADD COLUMN ' . self::LANGUAGE_ID_COLUMN . " {$columnDefinition}"; + } + + private function buildAddAlwaysAvailableColumnSql(): string + { + $columnDefinition = match (true) { + $this->isMySQL(), $this->isMariaDB() => "TINYINT(1) DEFAULT '0' NOT NULL", + $this->isPostgreSQL() => "BOOLEAN DEFAULT 'false' NOT NULL", + default => "BOOLEAN DEFAULT '0' NOT NULL", + }; + + return 'ALTER TABLE ' . self::TABLE . ' ADD COLUMN ' . self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN . + " {$columnDefinition}"; + } +} diff --git a/src/lib/Resources/settings/search_engines/legacy.yml b/src/lib/Resources/settings/search_engines/legacy.yml index a028246951..2c84f78a14 100644 --- a/src/lib/Resources/settings/search_engines/legacy.yml +++ b/src/lib/Resources/settings/search_engines/legacy.yml @@ -67,6 +67,7 @@ services: $locationMapper: '@Ibexa\Core\Persistence\Legacy\Content\Location\Mapper' $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' $mapper: '@ibexa.search.legacy.fulltext_mapper' + $contentGateway: '@ibexa.persistence.legacy.content.gateway' tags: - {name: ibexa.search.engine, alias: legacy} lazy: true diff --git a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml index 0ac5cfd9ae..24c799a948 100644 --- a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml +++ b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml @@ -44,12 +44,18 @@ services: $connection: '@ibexa.persistence.connection' $joinedTablesTracker: '@Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker' + Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder: + arguments: + $connection: '@ibexa.persistence.connection' + $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' + Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase: parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler abstract: true arguments: $contentTypeHandler: '@Ibexa\Contracts\Core\Persistence\Content\Type\Handler' $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' + $languagePriorityConditionBuilder: '@Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder' Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldValue\Handler: abstract: true @@ -142,7 +148,7 @@ services: parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler arguments: $processor: '@Ibexa\Core\Persistence\TransformationProcessor\PreprocessedBased' - $languageMaskGenerator: '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' $configuration: '%ibexa.search.legacy.criterion_handler.full_text.configuration%' tags: - {name: ibexa.search.legacy.gateway.criterion_handler.content} @@ -158,7 +164,7 @@ services: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\LanguageCode parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler arguments: - $maskGenerator: '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + $languageHandler: '@ibexa.spi.persistence.legacy.language.handler' tags: - {name: ibexa.search.legacy.gateway.criterion_handler.content} - {name: ibexa.search.legacy.gateway.criterion_handler.location} diff --git a/src/lib/Resources/settings/search_engines/legacy/indexer.yml b/src/lib/Resources/settings/search_engines/legacy/indexer.yml index 1cf7757994..c94fc0a8de 100644 --- a/src/lib/Resources/settings/search_engines/legacy/indexer.yml +++ b/src/lib/Resources/settings/search_engines/legacy/indexer.yml @@ -5,7 +5,7 @@ services: $typeHandler: '@Ibexa\Contracts\Core\Persistence\Content\Type\Handler' $transformationProcessor: '@Ibexa\Core\Persistence\TransformationProcessor\PreprocessedBased' $searchIndex: '@Ibexa\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex' - $languageMaskGenerator: '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' $fullTextSearchConfiguration: '%ibexa.search.legacy.criterion_handler.full_text.configuration%' Ibexa\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex: diff --git a/src/lib/Resources/settings/search_engines/legacy/sort_clause_handlers_common.yml b/src/lib/Resources/settings/search_engines/legacy/sort_clause_handlers_common.yml index 9be7888533..55548e1307 100644 --- a/src/lib/Resources/settings/search_engines/legacy/sort_clause_handlers_common.yml +++ b/src/lib/Resources/settings/search_engines/legacy/sort_clause_handlers_common.yml @@ -38,6 +38,7 @@ services: arguments: $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' $contentTypeHandler: '@Ibexa\Contracts\Core\Persistence\Content\Type\Handler' + $languagePriorityConditionBuilder: '@Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder' tags: - {name: ibexa.search.legacy.gateway.sort_clause_handler.content} - {name: ibexa.search.legacy.gateway.sort_clause_handler.location} diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/Field.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/Field.php index 47e20a180a..726371e6c9 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/Field.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/Field.php @@ -24,6 +24,7 @@ use Ibexa\Core\Persistence\TransformationProcessor; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldValue\Converter as FieldValueConverter; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; /** * Field criterion handler. @@ -58,9 +59,16 @@ public function __construct( Registry $fieldConverterRegistry, FieldValueConverter $fieldValueConverter, TransformationProcessor $transformationProcessor, - JoinedTablesTracker $joinedTablesTracker + JoinedTablesTracker $joinedTablesTracker, + LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { - parent::__construct($connection, $contentTypeHandler, $languageHandler, $joinedTablesTracker); + parent::__construct( + $connection, + $contentTypeHandler, + $languageHandler, + $joinedTablesTracker, + $languagePriorityConditionBuilder + ); $this->fieldConverterRegistry = $fieldConverterRegistry; $this->fieldValueConverter = $fieldValueConverter; diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php index 14c18b96b9..424004d7f5 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php @@ -9,7 +9,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Type\Handler as ContentTypeHandler; @@ -17,6 +16,7 @@ use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; /** * Base criterion handler for field criteria. @@ -37,6 +37,8 @@ abstract class FieldBase extends CriterionHandler */ protected $languageHandler; + private LanguagePriorityConditionBuilder $languagePriorityConditionBuilder; + /** * @throws Exception */ @@ -44,12 +46,14 @@ public function __construct( Connection $connection, ContentTypeHandler $contentTypeHandler, LanguageHandler $languageHandler, - JoinedTablesTracker $joinedTablesTracker + JoinedTablesTracker $joinedTablesTracker, + LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); $this->contentTypeHandler = $contentTypeHandler; $this->languageHandler = $languageHandler; + $this->languagePriorityConditionBuilder = $languagePriorityConditionBuilder; } /** @@ -63,85 +67,10 @@ protected function getFieldCondition( QueryBuilder $query, array $languageSettings ): string { - // 1. Use main language(s) by default - $expr = $query->expr(); - if (empty($languageSettings['languages'])) { - return $expr->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.initial_language_id', - 'f_def.language_id' - ), - $query->createNamedParameter(0, ParameterType::INTEGER) - ); - } - - // 2. Otherwise use prioritized languages - $leftSide = $this->dbPlatform->getBitAndComparisonExpression( - sprintf( - 'c.language_mask - %s', - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - 'f_def.language_id' - ) - ), - $query->createNamedParameter(1, ParameterType::INTEGER) - ); - $rightSide = $this->dbPlatform->getBitAndComparisonExpression( - 'f_def.language_id', - $query->createNamedParameter(1, ParameterType::INTEGER) - ); - - for ( - $index = count($languageSettings['languages']) - 1, - $multiplier = 2; - $index >= 0; - $index--, $multiplier *= 2 - ) { - $languageId = $this->languageHandler - ->loadByLanguageCode($languageSettings['languages'][$index])->id; - - $addToLeftSide = $this->dbPlatform->getBitAndComparisonExpression( - sprintf( - 'c.language_mask - %s', - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - 'f_def.language_id' - ) - ), - $languageId - ); - $addToRightSide = $this->dbPlatform->getBitAndComparisonExpression( - 'f_def.language_id', - $languageId - ); - - if ($multiplier > $languageId) { - $factor = $multiplier / $languageId; - for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++); - $factorTerm = ' << ' . $shift; - $addToLeftSide .= $factorTerm; - $addToRightSide .= $factorTerm; - } elseif ($multiplier < $languageId) { - $factor = $languageId / $multiplier; - for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++); - $factorTerm = ' >> ' . $shift; - $addToLeftSide .= $factorTerm; - $addToRightSide .= $factorTerm; - } - - $leftSide = "$leftSide + ($addToLeftSide)"; - $rightSide = "$rightSide + ($addToRightSide)"; - } - - return $expr->and( - $expr->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - 'f_def.language_id' - ), - $query->createNamedParameter(0, ParameterType::INTEGER) - ), - $expr->lt($leftSide, $rightSide) + return $this->languagePriorityConditionBuilder->buildCondition( + $query, + $languageSettings, + 'f_def.language_id' ); } diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldEmpty.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldEmpty.php index 6ffc65596f..dd662c574e 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldEmpty.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldEmpty.php @@ -23,6 +23,7 @@ use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; /** * Field criterion handler. @@ -47,9 +48,16 @@ public function __construct( LanguageHandler $languageHandler, Registry $fieldConverterRegistry, FieldTypeService $fieldTypeService, - JoinedTablesTracker $joinedTablesTracker + JoinedTablesTracker $joinedTablesTracker, + LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { - parent::__construct($connection, $contentTypeHandler, $languageHandler, $joinedTablesTracker); + parent::__construct( + $connection, + $contentTypeHandler, + $languageHandler, + $joinedTablesTracker, + $languagePriorityConditionBuilder + ); $this->fieldConverterRegistry = $fieldConverterRegistry; $this->fieldTypeService = $fieldTypeService; diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php index 1a35c11c52..30337418c5 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php @@ -7,18 +7,16 @@ namespace Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\QueryBuilder; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; -use Ibexa\Core\Base\Exceptions\DatabaseException; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\TransformationProcessor; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; @@ -79,7 +77,7 @@ class FullText extends CriterionHandler public function __construct( Connection $connection, protected TransformationProcessor $processor, - private readonly MaskGenerator $languageMaskGenerator, + private readonly LanguageHandler $languageHandler, JoinedTablesTracker $joinedTablesTracker, array $configuration = [] ) { @@ -220,20 +218,27 @@ public function handle( ); if (!empty($languageSettings['languages'])) { - $languageMask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - $languageSettings['languages'], - $languageSettings['useAlwaysAvailable'] ?? true + $languageIds = array_map( + fn (string $languageCode): int => $this->languageHandler->loadByLanguageCode($languageCode)->id, + $languageSettings['languages'] ); - $subSelect->andWhere( - $expr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'ibexa_search_object_word_link.language_mask', - $queryBuilder->createNamedParameter($languageMask, ParameterType::INTEGER) - ), - $queryBuilder->createNamedParameter(0, ParameterType::INTEGER) - ) + $languageCondition = $expr->in( + 'ibexa_search_object_word_link.language_id', + $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) ); + + if ($languageSettings['useAlwaysAvailable'] ?? true) { + $languageCondition = $expr->or( + $languageCondition, + $expr->eq( + 'ibexa_search_object_word_link.is_main_and_always_available', + $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN) + ) + ); + } + + $subSelect->andWhere($languageCondition); } return $expr->in( @@ -273,13 +278,4 @@ protected function getStopWordThresholdValue(): int // Calculate the int stopWordThresholdValue based on count (first column) * factor return $this->stopWordThresholdValue = (int)($count * $this->configuration['stopWordThresholdFactor']); } - - private function getDatabasePlatform(): AbstractPlatform - { - try { - return $this->connection->getDatabasePlatform(); - } catch (Exception $e) { - throw DatabaseException::wrap($e); - } - } } diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php index 187700bf76..2372470390 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php @@ -7,12 +7,17 @@ namespace Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; +use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; +use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; @@ -21,17 +26,17 @@ */ class LanguageCode extends CriterionHandler { - /** @var MaskGenerator */ - private $maskGenerator; + /** @var Handler */ + private $languageHandler; public function __construct( Connection $connection, - MaskGenerator $maskGenerator, + LanguageHandler $languageHandler, JoinedTablesTracker $joinedTablesTracker ) { parent::__construct($connection, $joinedTablesTracker); - $this->maskGenerator = $maskGenerator; + $this->languageHandler = $languageHandler; } public function accept(CriterionInterface $criterion): bool @@ -49,15 +54,37 @@ public function handle( array $languageSettings ) { /* @var $criterion \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LanguageCode */ - return $queryBuilder->expr()->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( - $criterion->value, - $criterion->matchAlwaysAvailable + $expr = $queryBuilder->expr(); + $languageCodes = array_map('strval', (array)$criterion->value); + $languages = iterator_to_array($this->languageHandler->loadListByLanguageCodes($languageCodes)); + if ($missing = array_diff($languageCodes, array_keys($languages))) { + throw new NotFoundException('Language', implode(', ', $missing)); + } + $languageIds = array_map(static fn ($language): int => $language->id, array_values($languages)); + + $translationSubQuery = $this->connection->createQueryBuilder(); + $translationSubQuery + ->select('1') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $translationSubQuery->expr()->and( + 'ct.content_id = c.id', + $translationSubQuery->expr()->in( + 'ct.language_id', + $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) ) - ), - '0' - ); + ); + + $condition = sprintf('EXISTS (%s)', $translationSubQuery->getSQL()); + + if ($criterion->matchAlwaysAvailable) { + return $expr->or( + $condition, + $expr->eq('c.always_available', $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN)) + ); + } + + return $condition; } } diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php new file mode 100644 index 0000000000..8aa3181f95 --- /dev/null +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -0,0 +1,130 @@ +connection->getDatabasePlatform()->getBitAndComparisonExpression( + $languageIdColumn, + (string)self::REMOVE_ALWAYS_AVAILABLE_BIT_OPERAND + ); + + if (empty($languageSettings['languages'])) { + return $query->expr()->eq($languageIdColumn, $mainLanguageIdColumn); + } + + $languageIds = array_map( + fn (string $languageCode): int => $this->languageHandler->loadByLanguageCode($languageCode)->id, + $languageSettings['languages'] + ); + + $priorityCase = 'CASE ct.language_id'; + foreach ($languageIds as $priority => $languageId) { + $priorityCase .= sprintf( + ' WHEN %s THEN %d', + $query->createNamedParameter($languageId, ParameterType::INTEGER), + $priority + ); + } + $priorityCase .= ' END'; + + $subQuery = $this->connection->createQueryBuilder(); + $subQuery + ->select('ct.language_id') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $subQuery->expr()->and( + sprintf('ct.content_id = %s', $contentIdColumn), + $subQuery->expr()->in( + 'ct.language_id', + $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ) + ->orderBy($priorityCase) + ->setMaxResults(1); + + $priorityMatch = $query->expr()->eq($languageIdColumn, sprintf('(%s)', $subQuery->getSQL())); + + if (!($languageSettings['useAlwaysAvailable'] ?? true)) { + return $priorityMatch; + } + + // Content has none of the requested priority languages: an always-available Content falls + // back to matching its main language, same as the empty-$languageSettings branch above. + $hasRequestedLanguageSubQuery = $this->connection->createQueryBuilder(); + $hasRequestedLanguageSubQuery + ->select('1') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $hasRequestedLanguageSubQuery->expr()->and( + sprintf('ct.content_id = %s', $contentIdColumn), + $hasRequestedLanguageSubQuery->expr()->in( + 'ct.language_id', + $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); + + $alwaysAvailableFallback = $query->expr()->and( + sprintf('NOT EXISTS (%s)', $hasRequestedLanguageSubQuery->getSQL()), + $alwaysAvailableColumn, + $query->expr()->eq($languageIdColumn, $mainLanguageIdColumn) + ); + + return (string)$query->expr()->or($priorityMatch, $alwaysAvailableFallback); + } +} diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php b/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php index 7b283db1ef..921c435912 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php @@ -16,6 +16,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\Target\FieldTarget; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Persistence\Legacy\Content\Gateway; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler; /** @@ -37,15 +38,19 @@ class Field extends SortClauseHandler */ protected $contentTypeHandler; + private LanguagePriorityConditionBuilder $languagePriorityConditionBuilder; + public function __construct( Connection $connection, LanguageHandler $languageHandler, - ContentTypeHandler $contentTypeHandler + ContentTypeHandler $contentTypeHandler, + LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection); $this->languageHandler = $languageHandler; $this->contentTypeHandler = $contentTypeHandler; + $this->languagePriorityConditionBuilder = $languagePriorityConditionBuilder; } /** @@ -161,81 +166,10 @@ protected function getFieldCondition( array $languageSettings, $fieldTableName ) { - // 1. Use main language(s) by default - if (empty($languageSettings['languages'])) { - return $query->expr()->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.initial_language_id', - $fieldTableName . '.language_id' - ), - $query->createNamedParameter(0, ParameterType::INTEGER) - ); - } - - // 2. Otherwise use prioritized languages - $leftSide = $this->dbPlatform->getBitAndComparisonExpression( - sprintf( - 'c.language_mask - %s', - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - $fieldTableName . '.language_id' - ) - ), - $query->createNamedParameter(1, ParameterType::INTEGER) - ); - $rightSide = $this->dbPlatform->getBitAndComparisonExpression( - $fieldTableName . '.language_id', - $query->createNamedParameter(1, ParameterType::INTEGER) - ); - - for ($index = count( - $languageSettings['languages'] - ) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2) { - $languageId = $this->languageHandler - ->loadByLanguageCode($languageSettings['languages'][$index])->id; - - $addToLeftSide = $this->dbPlatform->getBitAndComparisonExpression( - sprintf( - 'c.language_mask - %s', - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - $fieldTableName . '.language_id' - ) - ), - $query->createNamedParameter($languageId, ParameterType::INTEGER) - ); - $addToRightSide = $this->dbPlatform->getBitAndComparisonExpression( - $fieldTableName . '.language_id', - $query->createNamedParameter($languageId, ParameterType::INTEGER) - ); - - if ($multiplier > $languageId) { - $factor = $multiplier / $languageId; - for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++); - $factorTerm = ' << ' . $shift; - $addToLeftSide .= $factorTerm; - $addToRightSide .= $factorTerm; - } elseif ($multiplier < $languageId) { - $factor = $languageId / $multiplier; - for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++); - $factorTerm = ' >> ' . $shift; - $addToLeftSide .= $factorTerm; - $addToRightSide .= $factorTerm; - } - - $leftSide = "$leftSide + ($addToLeftSide)"; - $rightSide = "$rightSide + ($addToRightSide)"; - } - - return $query->expr()->and( - $query->expr()->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - $fieldTableName . '.language_id' - ), - $query->createNamedParameter(0, ParameterType::INTEGER) - ), - $query->expr()->lt($leftSide, $rightSide) + return $this->languagePriorityConditionBuilder->buildCondition( + $query, + $languageSettings, + $fieldTableName . '.language_id' ); } } diff --git a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php index 41a1d3a073..2bdcd06e25 100644 --- a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php @@ -7,14 +7,11 @@ namespace Ibexa\Core\Search\Legacy\Content\Gateway; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; -use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; @@ -33,9 +30,6 @@ final class DoctrineDatabase extends Gateway /** @var Connection */ private $connection; - /** @var AbstractPlatform */ - private $dbPlatform; - /** * Criteria converter. * @@ -57,9 +51,6 @@ final class DoctrineDatabase extends Gateway */ private $languageHandler; - /** - * @throws Exception - */ public function __construct( Connection $connection, CriteriaConverter $criteriaConverter, @@ -67,7 +58,6 @@ public function __construct( LanguageHandler $languageHandler ) { $this->connection = $connection; - $this->dbPlatform = $connection->getDatabasePlatform(); $this->criteriaConverter = $criteriaConverter; $this->sortClauseConverter = $sortClauseConverter; $this->languageHandler = $languageHandler; @@ -99,29 +89,6 @@ public function find( ]; } - /** - * Generates a language mask from the given $languageSettings. - * - * @param array $languageSettings - * - * @return int - * - * @throws NotFoundException - */ - private function getLanguageMask(array $languageSettings): int - { - $mask = 0; - if ($languageSettings['useAlwaysAvailable']) { - $mask |= 1; - } - - foreach ($languageSettings['languages'] as $languageCode) { - $mask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; - } - - return $mask; - } - /** * @param array $languageFilter * @@ -149,20 +116,32 @@ private function getQueryCondition( // If not main-languages query if (!empty($languageFilter['languages'])) { - $condition = $expr->and( - $condition, - $expr->gt( - $this->dbPlatform->getBitAndComparisonExpression( - 'c.language_mask', - $query->createNamedParameter( - $this->getLanguageMask($languageFilter), - ParameterType::INTEGER, - ':language_mask' - ) - ), - $query->createNamedParameter(0, ParameterType::INTEGER, ':zero') - ) + $languageIds = array_map( + fn (string $languageCode): int => $this->languageHandler->loadByLanguageCode($languageCode)->id, + $languageFilter['languages'] ); + + $translationExistsSubQuery = $this->connection->createQueryBuilder(); + $translationExistsSubQuery + ->select('1') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $translationExistsSubQuery->expr()->and( + 'ct.content_id = c.id', + $translationExistsSubQuery->expr()->in( + 'ct.language_id', + $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); + + $languageCondition = sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); + + if (!empty($languageFilter['useAlwaysAvailable'])) { + $languageCondition = $expr->or($languageCondition, 'c.always_available'); + } + + $condition = $expr->and($condition, $languageCondition); } return $condition; diff --git a/src/lib/Search/Legacy/Content/Handler.php b/src/lib/Search/Legacy/Content/Handler.php index c8a8d99aa7..214592037b 100644 --- a/src/lib/Search/Legacy/Content/Handler.php +++ b/src/lib/Search/Legacy/Content/Handler.php @@ -21,6 +21,7 @@ use Ibexa\Contracts\Core\Search\VersatileHandler as SearchHandlerInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\NotFoundException; +use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content\Location\Gateway as LocationGateway; @@ -101,6 +102,8 @@ class Handler implements SearchHandlerInterface */ protected $mapper; + private ContentGateway $contentGateway; + public function __construct( Gateway $gateway, LocationGateway $locationGateway, @@ -108,7 +111,8 @@ public function __construct( ContentMapper $contentMapper, LocationMapper $locationMapper, LanguageHandler $languageHandler, - FullTextMapper $mapper + FullTextMapper $mapper, + ContentGateway $contentGateway ) { $this->gateway = $gateway; $this->locationGateway = $locationGateway; @@ -117,6 +121,7 @@ public function __construct( $this->locationMapper = $locationMapper; $this->languageHandler = $languageHandler; $this->mapper = $mapper; + $this->contentGateway = $contentGateway; } public function findContent( @@ -152,14 +157,19 @@ public function findContent( 'main_tree_' ); + $contentTranslations = $this->contentGateway->loadContentTranslations( + array_map(static fn (ContentInfo $contentInfo): int => $contentInfo->id, $contentInfoList) + ); + foreach ($contentInfoList as $index => $contentInfo) { /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $contentInfo; $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $data['rows'][$index]['language_mask'], + $contentTranslations[$contentInfo->id] ?? [], $data['rows'][$index]['initial_language_id'], - $languageFilter + $languageFilter, + (bool)$data['rows'][$index]['always_available'] ); $result->searchHits[] = $searchHit; @@ -168,22 +178,27 @@ public function findContent( return $result; } + /** + * @param int[] $languageIds + * @param array{languages?: string[]} $languageSettings + */ protected function extractMatchedLanguage( - $languageMask, - $mainLanguageId, - $languageSettings - ) { + array $languageIds, + int $mainLanguageId, + array $languageSettings, + bool $alwaysAvailable = false + ): ?string { $languageList = !empty($languageSettings['languages']) ? $this->languageHandler->loadListByLanguageCodes($languageSettings['languages']) : []; foreach ($languageList as $language) { - if ($languageMask & $language->id) { + if (in_array($language->id, $languageIds, true)) { return $language->languageCode; } } - if ($languageMask & 1 || empty($languageSettings['languages'])) { + if ($alwaysAvailable || empty($languageSettings['languages'])) { return $this->languageHandler->load($mainLanguageId)->languageCode; } @@ -241,14 +256,19 @@ public function findLocations( $result->totalCount = $data['count'] !== null ? (int)$data['count'] : null; $locationList = $this->locationMapper->createLocationsFromRows($data['rows']); + $contentTranslations = $this->contentGateway->loadContentTranslations( + array_map(static fn (Location $location): int => $location->contentId, $locationList) + ); + foreach ($locationList as $index => $location) { /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $location; $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $data['rows'][$index]['language_mask'], + $contentTranslations[$location->contentId] ?? [], $data['rows'][$index]['initial_language_id'], - $languageFilter + $languageFilter, + (bool)$data['rows'][$index]['always_available'] ); $result->searchHits[] = $searchHit; diff --git a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php index 3e17642a2d..63df2b2e78 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -7,15 +7,14 @@ namespace Ibexa\Core\Search\Legacy\Content\Location\Gateway; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; -use Ibexa\Core\Base\Exceptions\DatabaseException; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; @@ -62,7 +61,7 @@ public function find( $selectQuery = $this->connection->createQueryBuilder(); $selectQuery->select( 't.*', - 'c.language_mask', + 'c.always_available', 'c.initial_language_id' ); @@ -109,18 +108,7 @@ public function find( // If not main-languages query if (!empty($languageFilter['languages'])) { - $selectQuery->andWhere( - $selectQuery->expr()->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'c.language_mask', - $selectQuery->createNamedParameter( - $this->getLanguageMask($languageFilter), - ParameterType::INTEGER - ) - ), - $selectQuery->createNamedParameter(0, ParameterType::INTEGER) - ) - ); + $selectQuery->andWhere($this->buildTranslationCondition($selectQuery, $languageFilter)); } if ($sortClauses !== null) { @@ -185,18 +173,7 @@ private function getTotalCount( // If not main-languages query if (!empty($languageFilter['languages'])) { - $query->andWhere( - $query->expr()->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'c.language_mask', - $query->createNamedParameter( - $this->getLanguageMask($languageFilter), - ParameterType::INTEGER - ) - ), - $query->createNamedParameter(0, ParameterType::INTEGER) - ) - ); + $query->andWhere($this->buildTranslationCondition($query, $languageFilter)); } $statement = $query->executeQuery(); @@ -205,38 +182,50 @@ private function getTotalCount( } /** - * Generates a language mask from the given $languageFilter. + * Builds the "content is translated into one of the requested languages, or it's + * always-available" condition shared by find() and getTotalCount() - kept as one place so the + * two queries can't drift out of sync on the always-available fallback. + * + * @param QueryBuilder $queryBuilder + * @param array{languages?: string[], useAlwaysAvailable?: bool} $languageFilter * * @throws NotFoundException */ - private function getLanguageMask(array $languageFilter): int - { - if (!isset($languageFilter['languages'])) { - $languageFilter['languages'] = []; - } + private function buildTranslationCondition( + $queryBuilder, + array $languageFilter + ): string { + $languageIds = array_map( + fn (string $languageCode): int => $this->languageHandler->loadByLanguageCode($languageCode)->id, + $languageFilter['languages'] ?? [] + ); - if (!isset($languageFilter['useAlwaysAvailable'])) { - $languageFilter['useAlwaysAvailable'] = true; - } + $translationExistsSubQuery = $this->connection->createQueryBuilder(); + $translationExistsSubQuery + ->select('1') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $translationExistsSubQuery->expr()->and( + 'ct.content_id = c.id', + $translationExistsSubQuery->expr()->in( + 'ct.language_id', + $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); - $mask = 0; - if ($languageFilter['useAlwaysAvailable']) { - $mask |= 1; - } + $translationCondition = sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); - foreach ($languageFilter['languages'] as $languageCode) { - $mask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; + if ($languageFilter['useAlwaysAvailable'] ?? true) { + $translationCondition = $queryBuilder->expr()->or( + $translationCondition, + $queryBuilder->expr()->eq( + 'c.always_available', + $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN) + ) + ); } - return $mask; - } - - private function getDatabasePlatform(): AbstractPlatform - { - try { - return $this->connection->getDatabasePlatform(); - } catch (Exception $e) { - throw DatabaseException::wrap($e); - } + return $translationCondition; } } diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php index 82959d47a4..f852bf6300 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php @@ -8,8 +8,8 @@ namespace Ibexa\Core\Search\Legacy\Content\WordIndexer\Gateway; use Doctrine\DBAL\Connection; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Type\Handler as SPITypeHandler; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\TransformationProcessor; use Ibexa\Core\Search\Legacy\Content\FullTextData; use Ibexa\Core\Search\Legacy\Content\FullTextValue; @@ -58,8 +58,8 @@ class DoctrineDatabase extends Gateway */ protected $searchIndex; - /** @var MaskGenerator */ - private $languageMaskGenerator; + /** @var LanguageHandler */ + private $languageHandler; /** * Full text search configuration options. @@ -73,7 +73,7 @@ public function __construct( SPITypeHandler $typeHandler, TransformationProcessor $transformationProcessor, SearchIndex $searchIndex, - MaskGenerator $languageMaskGenerator, + LanguageHandler $languageHandler, array $fullTextSearchConfiguration ) { $this->connection = $connection; @@ -81,7 +81,7 @@ public function __construct( $this->transformationProcessor = $transformationProcessor; $this->searchIndex = $searchIndex; $this->fullTextSearchConfiguration = $fullTextSearchConfiguration; - $this->languageMaskGenerator = $languageMaskGenerator; + $this->languageHandler = $languageHandler; } /** @@ -259,10 +259,7 @@ private function indexWords( $languageCode = $indexArray[$i]['language_code']; $wordId = $wordIDArray[$indexWord]; $isMainAndAlwaysAvailable = $indexArray[$i]['is_main_and_always_available']; - $languageMask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - [$languageCode], - $isMainAndAlwaysAvailable - ); + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; if (isset($indexArray[$i + 1])) { $nextIndexWord = $indexArray[$i + 1]['Word']; @@ -285,7 +282,8 @@ private function indexWords( $fullTextData->sectionId, $identifier, $integerValue, - $languageMask + $languageId, + $isMainAndAlwaysAvailable ); $prevWordId = $wordId; ++$placement; diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php index 4d1397f626..6915a71869 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php @@ -131,7 +131,8 @@ public function addObjectWordLink( int $sectionId, string $identifier, int $integerValue, - int $languageMask + int $languageId, + bool $isMainAndAlwaysAvailable ): void { $query = $this->connection->createQueryBuilder(); $query @@ -181,9 +182,17 @@ public function addObjectWordLink( ParameterType::INTEGER ), 'language_mask' => $query->createPositionalParameter( - $languageMask, + $languageId | ($isMainAndAlwaysAvailable ? 1 : 0), ParameterType::INTEGER ), + 'language_id' => $query->createPositionalParameter( + $languageId, + ParameterType::INTEGER + ), + 'is_main_and_always_available' => $query->createPositionalParameter( + $isMainAndAlwaysAvailable, + ParameterType::BOOLEAN + ), ] ); diff --git a/tests/lib/Search/Legacy/Content/AbstractTestCase.php b/tests/lib/Search/Legacy/Content/AbstractTestCase.php index ada9f8fea8..256fa84060 100644 --- a/tests/lib/Search/Legacy/Content/AbstractTestCase.php +++ b/tests/lib/Search/Legacy/Content/AbstractTestCase.php @@ -113,6 +113,19 @@ protected function getContentTypeHandler(): SPIContentTypeHandler return $this->contentTypeHandler; } + protected function getContentGateway(): Gateway + { + $connection = $this->getDatabaseConnection(); + + return new Gateway\DoctrineDatabase( + $connection, + $this->getSharedGateway(), + new Gateway\DoctrineDatabase\QueryBuilder($connection), + $this->getLanguageHandler(), + $this->getLanguageMaskGenerator() + ); + } + protected function getConverterRegistry() { if (!isset($this->converterRegistry)) { diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index e149daf545..341a3aace9 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php @@ -72,7 +72,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\SortClauseHandler\Field( $connection, $this->getLanguageHandler(), - $this->getContentTypeHandler() + $this->getContentTypeHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), @@ -84,13 +88,14 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), $this->getContentMapperMock(), self::createStub(LocationMapper::class), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()) + $this->getFullTextMapper($this->getContentTypeHandler()), + $this->getContentGateway() ); } diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index 03dcd118c2..bde28083e4 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -135,7 +135,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\CriterionHandler\FullText( $connection, $transformationProcessor, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker, $fullTextSearchConfiguration ), @@ -162,7 +162,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $compositeValueHandler ), $transformationProcessor, - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new Content\Common\Gateway\CriterionHandler\ObjectStateId( $connection, @@ -170,7 +174,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ), new Content\Common\Gateway\CriterionHandler\LanguageCode( $connection, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker ), new Content\Gateway\CriterionHandler\Visibility( @@ -189,7 +193,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), @@ -206,13 +214,14 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), $this->getContentMapperMock(), self::createStub(LocationMapper::class), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()) + $this->getFullTextMapper($this->getContentTypeHandler()), + $this->getContentGateway() ); } diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php index 8bf28dded3..1987a773d7 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php @@ -89,7 +89,11 @@ protected function getContentSearchHandler() new CommonSortClauseHandler\Field( $connection, $this->getLanguageHandler(), - $this->getContentTypeHandler() + $this->getContentTypeHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), @@ -100,13 +104,14 @@ protected function getContentSearchHandler() $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), self::createStub(ContentMapper::class), $this->getLocationMapperMock(), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()) + $this->getFullTextMapper($this->getContentTypeHandler()), + $this->getContentGateway() ); } @@ -133,6 +138,7 @@ static function ($rows): array { if (!isset($locations[$locationId])) { $locations[$locationId] = new SPILocation(); $locations[$locationId]->id = $locationId; + $locations[$locationId]->contentId = (int)$row['contentobject_id']; } } diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php index 3e5d4d55fd..ad2f373f42 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php @@ -118,18 +118,22 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $compositeValueHandler ), $transformationProcessor, - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\FullText( $connection, $transformationProcessor, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker, $fullTextSearchConfiguration ), new CommonCriterionHandler\LanguageCode( $connection, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker ), new CommonCriterionHandler\LogicalAnd($connection, $joinedTablesTracker), @@ -139,7 +143,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\MatchAll($connection, $joinedTablesTracker), new CommonCriterionHandler\ObjectStateId($connection, $joinedTablesTracker), @@ -147,7 +155,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\RemoteId($connection, $joinedTablesTracker), new CommonCriterionHandler\SectionId($connection, $joinedTablesTracker), @@ -167,13 +179,14 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $transformationProcessor, new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), self::createStub(ContentMapper::class), $this->getLocationMapperMock(), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()) + $this->getFullTextMapper($this->getContentTypeHandler()), + $this->getContentGateway() ); } @@ -200,6 +213,7 @@ static function ($rows): array { if (!isset($locations[$locationId])) { $locations[$locationId] = new SPILocation(); $locations[$locationId]->id = $locationId; + $locations[$locationId]->contentId = (int)$row['contentobject_id']; } } From 9c5d93fcf0214848c825d8c6444985af2dc2c2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 11:43:57 +0100 Subject: [PATCH 19/54] IBX-13142: Backfilled the search word links in chunks, also on a rerun --- ...jectWordLinkLanguageIdColumnsMigration.php | 77 +++++++++--------- ...WordLinkLanguageIdColumnsMigrationTest.php | 78 +++++++++++++++++++ 2 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php diff --git a/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php index 865229d875..98e6cd3d58 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php @@ -9,41 +9,22 @@ namespace Ibexa\Bundle\RepositoryInstaller\Migration; use DateTimeImmutable; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Schema; use Ibexa\Contracts\DoctrineMigrations\Migrations\AbstractSqlMigration; use Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationInterface; use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Adds "language_id" and "is_main_and_always_available" columns to - * "ibexa_search_object_word_link", backfilled from its "language_mask" column (part of step 5 of - * the language bitmask migration). Unlike other multilingual tables, this one only ever stored a - * single language id per row (OR-ed with the always-available bit), so the replacement is a plain - * id column plus a boolean flag rather than a join table. "language_mask" itself is dropped later, - * once every write path has stopped populating it - see DropLanguageBitmaskColumnsMigration. - * - * Existing search index rows are backfilled here for consistency with every other step of this - * migration, but the recommended (and, for a fully corrected index, mandatory) follow-up is a full - * search reindex - the word-splitting/normalization logic itself is untouched, but this guarantees - * newly indexed content never round-trips through the legacy bitmask columns. - * - * The two columns (and their backfills) are checked and queued independently: on MySQL, each - * `ALTER TABLE`/`UPDATE` auto-commits independently, so a failure after adding "language_id" but - * before adding "is_main_and_always_available" (or before either backfill runs) must not make a - * retry mistake "the first column already exists" for "this migration already fully ran" and - * silently skip the rest. Each backfill UPDATE is idempotent (derived only from "language_mask", - * which this migration never modifies), so re-running it whenever anything else is still missing is - * always safe. - * - * Guarded via the connection's schema manager rather than the injected $schema, because - * TaggedMigrationsRunner (the "ibexa:install" path) invokes up() with an empty Schema, so - * $schema->hasTable()/hasColumn() would always report false there. + * Adds "language_id" and "is_main_and_always_available" to "ibexa_search_object_word_link", backfilled from "language_mask". */ final class AddSearchObjectWordLinkLanguageIdColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface { private const string TABLE = 'ibexa_search_object_word_link'; private const string LANGUAGE_ID_COLUMN = 'language_id'; private const string IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN = 'is_main_and_always_available'; + private const string LANGUAGE_MASK_COLUMN = 'language_mask'; + private const int BATCH_SIZE = 5000; public function getDescription(): string { @@ -60,6 +41,11 @@ public static function getCreationDate(): DateTimeImmutable return new DateTimeImmutable('2026-10-19 03:00:00'); } + public function isTransactional(): bool + { + return false; + } + public function up(Schema $schema): void { $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); @@ -71,30 +57,41 @@ public function up(Schema $schema): void } $table = $schemaManager->introspectTable(self::TABLE); - $hasLanguageIdColumn = $table->hasColumn(self::LANGUAGE_ID_COLUMN); - $hasAlwaysAvailableColumn = $table->hasColumn(self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN); - if ($hasLanguageIdColumn && $hasAlwaysAvailableColumn) { - // Already fully applied - avoid an unconditional full-table backfill re-scan once this - // migration has genuinely completed. - return; - } - - if (!$hasLanguageIdColumn) { + if (!$table->hasColumn(self::LANGUAGE_ID_COLUMN)) { $this->addSql($this->buildAddLanguageIdColumnSql()); } - if (!$hasAlwaysAvailableColumn) { + if (!$table->hasColumn(self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN)) { $this->addSql($this->buildAddAlwaysAvailableColumnSql()); } - $this->addSql( - 'UPDATE ' . self::TABLE . ' SET ' . self::LANGUAGE_ID_COLUMN . ' = (language_mask & -2)' - ); - $this->addSql( - 'UPDATE ' . self::TABLE . ' SET ' . self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN . ' = ' . - ($this->isPostgreSQL() ? 'true' : '1') . ' WHERE (language_mask & 1) = 1' - ); + if (!$table->hasColumn(self::LANGUAGE_MASK_COLUMN)) { + return; + } + + $range = $this->connection->fetchAssociative('SELECT MIN(id) AS min_id, MAX(id) AS max_id FROM ' . self::TABLE); + if ($range === false || $range['min_id'] === null) { + return; + } + + $languageId = '(' . self::LANGUAGE_MASK_COLUMN . ' & -2)'; + $isMainAndAlwaysAvailable = '((' . self::LANGUAGE_MASK_COLUMN . ' & 1) = 1)'; + $sql = 'UPDATE ' . self::TABLE + . ' SET ' . self::LANGUAGE_ID_COLUMN . " = {$languageId}, " + . self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN . " = {$isMainAndAlwaysAvailable}" + . ' WHERE id BETWEEN :from AND :to' + . ' AND (' . self::LANGUAGE_ID_COLUMN . " <> {$languageId} OR " + . self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN . " <> {$isMainAndAlwaysAvailable})"; + + $maxId = (int)$range['max_id']; + for ($from = (int)$range['min_id']; $from <= $maxId; $from += self::BATCH_SIZE) { + $this->addSql( + $sql, + ['from' => $from, 'to' => min($from + self::BATCH_SIZE - 1, $maxId)], + ['from' => ParameterType::INTEGER, 'to' => ParameterType::INTEGER] + ); + } } private function buildAddLanguageIdColumnSql(): string diff --git a/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php new file mode 100644 index 0000000000..1b2f9ed14b --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php @@ -0,0 +1,78 @@ + 3, 5001 => 4] as $id => $languageMask) { + $this->getDatabaseConnection()->insert( + 'ibexa_search_object_word_link', + ['id' => $id, 'identifier' => '', 'language_mask' => $languageMask], + ['language_mask' => ParameterType::INTEGER] + ); + } + } + + public function testBackfillsTheColumnsInChunksById(): void + { + self::assertCount(2, $this->runMigration()); + $this->assertBackfilled(); + } + + public function testRerunAfterAnInterruptedRunCompletesTheBackfill(): void + { + $this->runMigration(); + $this->getDatabaseConnection()->executeStatement('UPDATE ibexa_search_object_word_link SET language_id = 0'); + + $this->runMigration(); + + $this->assertBackfilled(); + } + + /** + * @return Query[] + */ + private function runMigration(): array + { + $connection = $this->getDatabaseConnection(); + $migration = new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext()); + $migration->up(new Schema()); + + $queries = $migration->getSql(); + foreach ($queries as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + + return $queries; + } + + private function assertBackfilled(): void + { + self::assertEquals( + [[1, 2, 1], [5001, 4, 0]], + $this->getDatabaseConnection()->fetchAllNumeric( + 'SELECT id, language_id, is_main_and_always_available FROM ibexa_search_object_word_link ORDER BY id' + ) + ); + } +} From 36f7baf6231fad24ccf89983091f30bdd8b498de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 12:00:30 +0100 Subject: [PATCH 20/54] IBX-13142: Matched the field language with a single COALESCE in legacy search --- .../LanguagePriorityConditionBuilder.php | 51 ++++--------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php index 8aa3181f95..402589b96c 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -16,18 +16,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; /** - * Builds the "does $languageIdColumn hold the highest-priority translation this Content actually - * has" condition shared by the Legacy Search Engine's field criterion (FieldBase) and field sort - * clause (SortClauseHandler\Field). - * - * Historically this was expressed as bit-shift arithmetic directly on "c.language_mask" and - * "$languageIdColumn" - a trick that only works because language ids are exact powers of two, with - * no incremental replacement possible. The relational form instead asks "which of Content's actual - * translations (via ibexa_content_translation) ranks highest in the requested priority list", via a - * correlated `ORDER BY CASE ... LIMIT 1` subquery, and requires $languageIdColumn to equal that - * pick. If none of Content's translations are in the priority list, and the caller allowed the - * always-available fallback (the default), an always-available Content instead matches on its main - * language - mirroring the original arithmetic's use of "c.language_mask"'s bit 0. + * Builds the condition matching the field language a Content is shown in for a language priority list. * * @internal */ @@ -45,7 +34,7 @@ public function __construct( ) {} /** - * @param array{languages?: string[], useAlwaysAvailable?: bool} $languageSettings + * @param array{languages?: string[]} $languageSettings */ public function buildCondition( QueryBuilder $query, @@ -97,34 +86,14 @@ public function buildCondition( ->orderBy($priorityCase) ->setMaxResults(1); - $priorityMatch = $query->expr()->eq($languageIdColumn, sprintf('(%s)', $subQuery->getSQL())); - - if (!($languageSettings['useAlwaysAvailable'] ?? true)) { - return $priorityMatch; - } - - // Content has none of the requested priority languages: an always-available Content falls - // back to matching its main language, same as the empty-$languageSettings branch above. - $hasRequestedLanguageSubQuery = $this->connection->createQueryBuilder(); - $hasRequestedLanguageSubQuery - ->select('1') - ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') - ->where( - $hasRequestedLanguageSubQuery->expr()->and( - sprintf('ct.content_id = %s', $contentIdColumn), - $hasRequestedLanguageSubQuery->expr()->in( - 'ct.language_id', - $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) - ) - ) - ); - - $alwaysAvailableFallback = $query->expr()->and( - sprintf('NOT EXISTS (%s)', $hasRequestedLanguageSubQuery->getSQL()), - $alwaysAvailableColumn, - $query->expr()->eq($languageIdColumn, $mainLanguageIdColumn) + return $query->expr()->eq( + $languageIdColumn, + sprintf( + 'COALESCE((%s), CASE WHEN %s THEN %s END)', + $subQuery->getSQL(), + $alwaysAvailableColumn, + $mainLanguageIdColumn + ) ); - - return (string)$query->expr()->or($priorityMatch, $alwaysAvailableFallback); } } From 6315ec24a928f5f87f6ba651e7d10a80f03b4ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 12:28:29 +0100 Subject: [PATCH 21/54] IBX-13142: Selected the matched translation with the legacy search rows instead of loading content translations --- .../settings/search_engines/legacy.yml | 3 +- .../LanguagePriorityConditionBuilder.php | 39 ++++++++++--- .../Content/Gateway/DoctrineDatabase.php | 5 +- src/lib/Search/Legacy/Content/Handler.php | 56 +++---------------- .../Location/Gateway/DoctrineDatabase.php | 7 ++- .../Legacy/Content/AbstractTestCase.php | 13 ----- .../Legacy/Content/HandlerContentSortTest.php | 9 ++- .../Legacy/Content/HandlerContentTest.php | 9 ++- .../Content/HandlerLocationSortTest.php | 9 ++- .../Legacy/Content/HandlerLocationTest.php | 9 ++- 10 files changed, 73 insertions(+), 86 deletions(-) diff --git a/src/lib/Resources/settings/search_engines/legacy.yml b/src/lib/Resources/settings/search_engines/legacy.yml index 2c84f78a14..7b3503d393 100644 --- a/src/lib/Resources/settings/search_engines/legacy.yml +++ b/src/lib/Resources/settings/search_engines/legacy.yml @@ -21,6 +21,7 @@ services: $criteriaConverter: '@ibexa.search.legacy.gateway.criteria_converter.content' $sortClauseConverter: '@ibexa.search.legacy.gateway.sort_clause_converter.content' $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' + $languagePriorityConditionBuilder: '@Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder' Ibexa\Core\Search\Legacy\Content\Gateway\ExceptionConversion: class: Ibexa\Core\Search\Legacy\Content\Gateway\ExceptionConversion @@ -38,6 +39,7 @@ services: $criteriaConverter: '@ibexa.search.legacy.gateway.criteria_converter.location' $sortClauseConverter: '@ibexa.search.legacy.gateway.sort_clause_converter.location' $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' + $languagePriorityConditionBuilder: '@Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder' Ibexa\Core\Search\Legacy\Content\Location\Gateway\ExceptionConversion: class: Ibexa\Core\Search\Legacy\Content\Location\Gateway\ExceptionConversion @@ -67,7 +69,6 @@ services: $locationMapper: '@Ibexa\Core\Persistence\Legacy\Content\Location\Mapper' $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' $mapper: '@ibexa.search.legacy.fulltext_mapper' - $contentGateway: '@ibexa.persistence.legacy.content.gateway' tags: - {name: ibexa.search.engine, alias: legacy} lazy: true diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php index 402589b96c..654467d88d 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -51,8 +51,32 @@ public function buildCondition( (string)self::REMOVE_ALWAYS_AVAILABLE_BIT_OPERAND ); + return $query->expr()->eq( + $languageIdColumn, + $this->buildMatchedLanguageExpression( + $query, + $languageSettings, + $contentIdColumn, + $mainLanguageIdColumn, + $alwaysAvailableColumn + ) + ); + } + + /** + * Builds the expression for the id of the language a Content is shown in for a language priority list. + * + * @param array{languages?: string[]} $languageSettings + */ + public function buildMatchedLanguageExpression( + QueryBuilder $query, + array $languageSettings, + string $contentIdColumn = 'c.id', + string $mainLanguageIdColumn = 'c.initial_language_id', + string $alwaysAvailableColumn = 'c.always_available' + ): string { if (empty($languageSettings['languages'])) { - return $query->expr()->eq($languageIdColumn, $mainLanguageIdColumn); + return $mainLanguageIdColumn; } $languageIds = array_map( @@ -86,14 +110,11 @@ public function buildCondition( ->orderBy($priorityCase) ->setMaxResults(1); - return $query->expr()->eq( - $languageIdColumn, - sprintf( - 'COALESCE((%s), CASE WHEN %s THEN %s END)', - $subQuery->getSQL(), - $alwaysAvailableColumn, - $mainLanguageIdColumn - ) + return sprintf( + 'COALESCE((%s), CASE WHEN %s THEN %s END)', + $subQuery->getSQL(), + $alwaysAvailableColumn, + $mainLanguageIdColumn ); } } diff --git a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php index 2bdcd06e25..c722b4dfed 100644 --- a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php @@ -18,6 +18,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; use Ibexa\Core\Search\Legacy\Content\Gateway; use RuntimeException; @@ -55,7 +56,8 @@ public function __construct( Connection $connection, CriteriaConverter $criteriaConverter, SortClauseConverter $sortClauseConverter, - LanguageHandler $languageHandler + LanguageHandler $languageHandler, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { $this->connection = $connection; $this->criteriaConverter = $criteriaConverter; @@ -200,6 +202,7 @@ private function getContentInfoList( $query = $this->connection->createQueryBuilder(); $query->select( 'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id', + $this->languagePriorityConditionBuilder->buildMatchedLanguageExpression($query, $languageFilter) . ' AS matched_language_id', ); if ($sort !== null) { diff --git a/src/lib/Search/Legacy/Content/Handler.php b/src/lib/Search/Legacy/Content/Handler.php index 214592037b..c8c1d1bb76 100644 --- a/src/lib/Search/Legacy/Content/Handler.php +++ b/src/lib/Search/Legacy/Content/Handler.php @@ -21,7 +21,6 @@ use Ibexa\Contracts\Core\Search\VersatileHandler as SearchHandlerInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\NotFoundException; -use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content\Location\Gateway as LocationGateway; @@ -102,8 +101,6 @@ class Handler implements SearchHandlerInterface */ protected $mapper; - private ContentGateway $contentGateway; - public function __construct( Gateway $gateway, LocationGateway $locationGateway, @@ -111,8 +108,7 @@ public function __construct( ContentMapper $contentMapper, LocationMapper $locationMapper, LanguageHandler $languageHandler, - FullTextMapper $mapper, - ContentGateway $contentGateway + FullTextMapper $mapper ) { $this->gateway = $gateway; $this->locationGateway = $locationGateway; @@ -121,7 +117,6 @@ public function __construct( $this->locationMapper = $locationMapper; $this->languageHandler = $languageHandler; $this->mapper = $mapper; - $this->contentGateway = $contentGateway; } public function findContent( @@ -157,20 +152,11 @@ public function findContent( 'main_tree_' ); - $contentTranslations = $this->contentGateway->loadContentTranslations( - array_map(static fn (ContentInfo $contentInfo): int => $contentInfo->id, $contentInfoList) - ); - foreach ($contentInfoList as $index => $contentInfo) { /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $contentInfo; - $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $contentTranslations[$contentInfo->id] ?? [], - $data['rows'][$index]['initial_language_id'], - $languageFilter, - (bool)$data['rows'][$index]['always_available'] - ); + $searchHit->matchedTranslation = $this->extractMatchedLanguage($data['rows'][$index]['matched_language_id']); $result->searchHits[] = $searchHit; } @@ -179,30 +165,15 @@ public function findContent( } /** - * @param int[] $languageIds - * @param array{languages?: string[]} $languageSettings + * @param int|string|null $languageId */ - protected function extractMatchedLanguage( - array $languageIds, - int $mainLanguageId, - array $languageSettings, - bool $alwaysAvailable = false - ): ?string { - $languageList = !empty($languageSettings['languages']) ? - $this->languageHandler->loadListByLanguageCodes($languageSettings['languages']) : - []; - - foreach ($languageList as $language) { - if (in_array($language->id, $languageIds, true)) { - return $language->languageCode; - } - } - - if ($alwaysAvailable || empty($languageSettings['languages'])) { - return $this->languageHandler->load($mainLanguageId)->languageCode; + protected function extractMatchedLanguage($languageId): ?string + { + if ($languageId === null) { + return null; } - return null; + return $this->languageHandler->load((int)$languageId)->languageCode; } public function findSingle( @@ -256,20 +227,11 @@ public function findLocations( $result->totalCount = $data['count'] !== null ? (int)$data['count'] : null; $locationList = $this->locationMapper->createLocationsFromRows($data['rows']); - $contentTranslations = $this->contentGateway->loadContentTranslations( - array_map(static fn (Location $location): int => $location->contentId, $locationList) - ); - foreach ($locationList as $index => $location) { /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $location; - $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $contentTranslations[$location->contentId] ?? [], - $data['rows'][$index]['initial_language_id'], - $languageFilter, - (bool)$data['rows'][$index]['always_available'] - ); + $searchHit->matchedTranslation = $this->extractMatchedLanguage($data['rows'][$index]['matched_language_id']); $result->searchHits[] = $searchHit; } diff --git a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php index 63df2b2e78..acd50fa31b 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -18,6 +18,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; use Ibexa\Core\Search\Legacy\Content\Location\Gateway; use RuntimeException; @@ -37,7 +38,8 @@ public function __construct( private readonly Connection $connection, private readonly CriteriaConverter $criteriaConverter, private readonly SortClauseConverter $sortClauseConverter, - private readonly LanguageHandler $languageHandler + private readonly LanguageHandler $languageHandler, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) {} public function find( @@ -61,8 +63,7 @@ public function find( $selectQuery = $this->connection->createQueryBuilder(); $selectQuery->select( 't.*', - 'c.always_available', - 'c.initial_language_id' + $this->languagePriorityConditionBuilder->buildMatchedLanguageExpression($selectQuery, $languageFilter) . ' AS matched_language_id' ); if ($sortClauses !== null) { diff --git a/tests/lib/Search/Legacy/Content/AbstractTestCase.php b/tests/lib/Search/Legacy/Content/AbstractTestCase.php index 256fa84060..ada9f8fea8 100644 --- a/tests/lib/Search/Legacy/Content/AbstractTestCase.php +++ b/tests/lib/Search/Legacy/Content/AbstractTestCase.php @@ -113,19 +113,6 @@ protected function getContentTypeHandler(): SPIContentTypeHandler return $this->contentTypeHandler; } - protected function getContentGateway(): Gateway - { - $connection = $this->getDatabaseConnection(); - - return new Gateway\DoctrineDatabase( - $connection, - $this->getSharedGateway(), - new Gateway\DoctrineDatabase\QueryBuilder($connection), - $this->getLanguageHandler(), - $this->getLanguageMaskGenerator() - ); - } - protected function getConverterRegistry() { if (!isset($this->converterRegistry)) { diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index 341a3aace9..64f8854261 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php @@ -80,7 +80,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), self::createStub(LocationGateway::class), new Content\WordIndexer\Gateway\DoctrineDatabase( @@ -94,8 +98,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentMapperMock(), self::createStub(LocationMapper::class), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()), - $this->getContentGateway() + $this->getFullTextMapper($this->getContentTypeHandler()) ); } diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index bde28083e4..eebdcbeae3 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -206,7 +206,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\SortClauseHandler\ContentId($connection), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), self::createStub(LocationGateway::class), new Content\WordIndexer\Gateway\DoctrineDatabase( @@ -220,8 +224,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentMapperMock(), self::createStub(LocationMapper::class), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()), - $this->getContentGateway() + $this->getFullTextMapper($this->getContentTypeHandler()) ); } diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php index 1987a773d7..1f9e92c497 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php @@ -97,7 +97,11 @@ protected function getContentSearchHandler() ), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), new Content\WordIndexer\Gateway\DoctrineDatabase( $this->getDatabaseConnection(), @@ -110,8 +114,7 @@ protected function getContentSearchHandler() self::createStub(ContentMapper::class), $this->getLocationMapperMock(), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()), - $this->getContentGateway() + $this->getFullTextMapper($this->getContentTypeHandler()) ); } diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php index ad2f373f42..9da71481d0 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php @@ -172,7 +172,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new CommonSortClauseHandler\ContentId($connection), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new Content\Common\Gateway\LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), new Content\WordIndexer\Gateway\DoctrineDatabase( $this->getDatabaseConnection(), @@ -185,8 +189,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = self::createStub(ContentMapper::class), $this->getLocationMapperMock(), $this->getLanguageHandler(), - $this->getFullTextMapper($this->getContentTypeHandler()), - $this->getContentGateway() + $this->getFullTextMapper($this->getContentTypeHandler()) ); } From 29b9ea899918a31125fe267b00be103c8a37a75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 12:36:07 +0100 Subject: [PATCH 22/54] IBX-13142: Built the content translation condition in one place in legacy search --- .../legacy/criterion_handlers_common.yml | 3 +- .../Gateway/CriterionHandler/LanguageCode.php | 36 ++++------------ .../LanguagePriorityConditionBuilder.php | 41 +++++++++++++++++++ .../Content/Gateway/DoctrineDatabase.php | 25 +++-------- .../Location/Gateway/DoctrineDatabase.php | 33 +++------------ .../Legacy/Content/HandlerContentTest.php | 3 +- .../Legacy/Content/HandlerLocationTest.php | 3 +- 7 files changed, 65 insertions(+), 79 deletions(-) diff --git a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml index 24c799a948..3094c9eb53 100644 --- a/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml +++ b/src/lib/Resources/settings/search_engines/legacy/criterion_handlers_common.yml @@ -164,7 +164,8 @@ services: class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\LanguageCode parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler arguments: - $languageHandler: '@ibexa.spi.persistence.legacy.language.handler' + $languageHandler: '@Ibexa\Contracts\Core\Persistence\Content\Language\Handler' + $languagePriorityConditionBuilder: '@Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder' tags: - {name: ibexa.search.legacy.gateway.criterion_handler.content} - {name: ibexa.search.legacy.gateway.criterion_handler.location} diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php index 2372470390..82922d52ee 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php @@ -7,9 +7,7 @@ namespace Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; @@ -17,9 +15,9 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Persistence\Doctrine\JoinedTablesTracker; -use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; /** * LanguageCode criterion handler. @@ -32,7 +30,8 @@ class LanguageCode extends CriterionHandler public function __construct( Connection $connection, LanguageHandler $languageHandler, - JoinedTablesTracker $joinedTablesTracker + JoinedTablesTracker $joinedTablesTracker, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); @@ -62,29 +61,10 @@ public function handle( } $languageIds = array_map(static fn ($language): int => $language->id, array_values($languages)); - $translationSubQuery = $this->connection->createQueryBuilder(); - $translationSubQuery - ->select('1') - ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') - ->where( - $translationSubQuery->expr()->and( - 'ct.content_id = c.id', - $translationSubQuery->expr()->in( - 'ct.language_id', - $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) - ) - ) - ); - - $condition = sprintf('EXISTS (%s)', $translationSubQuery->getSQL()); - - if ($criterion->matchAlwaysAvailable) { - return $expr->or( - $condition, - $expr->eq('c.always_available', $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN)) - ); - } - - return $condition; + return $this->languagePriorityConditionBuilder->buildTranslationCondition( + $queryBuilder, + $languageIds, + $criterion->matchAlwaysAvailable + ); } } diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php index 654467d88d..8742ea1f6d 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -117,4 +117,45 @@ public function buildMatchedLanguageExpression( $mainLanguageIdColumn ); } + + /** + * Builds the condition matching Content translated into any of the given languages. + * + * @param int[] $languageIds + */ + public function buildTranslationCondition( + QueryBuilder $query, + array $languageIds, + bool $matchAlwaysAvailable, + string $contentIdColumn = 'c.id', + string $alwaysAvailableColumn = 'c.always_available' + ): string { + $subQuery = $this->connection->createQueryBuilder(); + $subQuery + ->select('1') + ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') + ->where( + $subQuery->expr()->and( + sprintf('ct.content_id = %s', $contentIdColumn), + $subQuery->expr()->in( + 'ct.language_id', + $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); + + $condition = sprintf('EXISTS (%s)', $subQuery->getSQL()); + + if (!$matchAlwaysAvailable) { + return $condition; + } + + return (string)$query->expr()->or( + $condition, + $query->expr()->eq( + $alwaysAvailableColumn, + $query->createNamedParameter(true, ParameterType::BOOLEAN) + ) + ); + } } diff --git a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php index c722b4dfed..0313e4d914 100644 --- a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php @@ -7,7 +7,6 @@ namespace Ibexa\Core\Search\Legacy\Content\Gateway; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; @@ -123,25 +122,11 @@ private function getQueryCondition( $languageFilter['languages'] ); - $translationExistsSubQuery = $this->connection->createQueryBuilder(); - $translationExistsSubQuery - ->select('1') - ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') - ->where( - $translationExistsSubQuery->expr()->and( - 'ct.content_id = c.id', - $translationExistsSubQuery->expr()->in( - 'ct.language_id', - $query->createNamedParameter($languageIds, ArrayParameterType::INTEGER) - ) - ) - ); - - $languageCondition = sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); - - if (!empty($languageFilter['useAlwaysAvailable'])) { - $languageCondition = $expr->or($languageCondition, 'c.always_available'); - } + $languageCondition = $this->languagePriorityConditionBuilder->buildTranslationCondition( + $query, + $languageIds, + !empty($languageFilter['useAlwaysAvailable']) + ); $condition = $expr->and($condition, $languageCondition); } diff --git a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php index acd50fa31b..c0b6e80d6f 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -7,7 +7,6 @@ namespace Ibexa\Core\Search\Legacy\Content\Location\Gateway; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; @@ -201,32 +200,10 @@ private function buildTranslationCondition( $languageFilter['languages'] ?? [] ); - $translationExistsSubQuery = $this->connection->createQueryBuilder(); - $translationExistsSubQuery - ->select('1') - ->from(ContentGateway::CONTENT_TRANSLATION_TABLE, 'ct') - ->where( - $translationExistsSubQuery->expr()->and( - 'ct.content_id = c.id', - $translationExistsSubQuery->expr()->in( - 'ct.language_id', - $queryBuilder->createNamedParameter($languageIds, ArrayParameterType::INTEGER) - ) - ) - ); - - $translationCondition = sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); - - if ($languageFilter['useAlwaysAvailable'] ?? true) { - $translationCondition = $queryBuilder->expr()->or( - $translationCondition, - $queryBuilder->expr()->eq( - 'c.always_available', - $queryBuilder->createNamedParameter(true, ParameterType::BOOLEAN) - ) - ); - } - - return $translationCondition; + return $this->languagePriorityConditionBuilder->buildTranslationCondition( + $queryBuilder, + $languageIds, + $languageFilter['useAlwaysAvailable'] ?? true + ); } } diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index eebdcbeae3..db39a2a238 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -175,7 +175,8 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\CriterionHandler\LanguageCode( $connection, $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new Content\Gateway\CriterionHandler\Visibility( $connection, diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php index 9da71481d0..70f849550b 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php @@ -134,7 +134,8 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new CommonCriterionHandler\LanguageCode( $connection, $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new Content\Common\Gateway\LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new CommonCriterionHandler\LogicalAnd($connection, $joinedTablesTracker), new CommonCriterionHandler\LogicalNot($connection, $joinedTablesTracker), From a111c1a097a7565756f93a6fdcf9c99540196da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:08:45 +0100 Subject: [PATCH 23/54] IBX-13142: Promoted the constructor properties and declared strict types in the legacy search classes --- phpstan-baseline.neon | 6 -- .../Gateway/CriterionHandler/FieldBase.php | 26 +------ .../Gateway/CriterionHandler/LanguageCode.php | 7 +- .../LanguagePriorityConditionBuilder.php | 6 +- .../Gateway/SortClauseHandler/Field.php | 26 +------ .../Content/Gateway/DoctrineDatabase.php | 48 +++--------- src/lib/Search/Legacy/Content/Handler.php | 73 ++----------------- .../Location/Gateway/DoctrineDatabase.php | 3 +- .../WordIndexer/Gateway/DoctrineDatabase.php | 67 +++-------------- .../Legacy/Content/HandlerContentSortTest.php | 5 +- .../Legacy/Content/HandlerContentTest.php | 9 ++- .../Content/HandlerLocationSortTest.php | 5 +- .../Legacy/Content/HandlerLocationTest.php | 11 +-- 13 files changed, 57 insertions(+), 235 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b41c7e117c..bac7a17c2b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -18222,12 +18222,6 @@ parameters: count: 1 path: src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php - - - message: '#^Property Ibexa\\Core\\Search\\Legacy\\Content\\WordIndexer\\Gateway\\DoctrineDatabase\:\:\$fullTextSearchConfiguration type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php - - message: '#^Method Ibexa\\Core\\Search\\Legacy\\Content\\WordIndexer\\Repository\\SearchIndex\:\:getContentObjectWords\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php index 424004d7f5..ebdf25ffdb 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php @@ -23,37 +23,17 @@ */ abstract class FieldBase extends CriterionHandler { - /** - * Content type handler. - * - * @var ContentTypeHandler - */ - protected $contentTypeHandler; - - /** - * Language handler. - * - * @var LanguageHandler - */ - protected $languageHandler; - - private LanguagePriorityConditionBuilder $languagePriorityConditionBuilder; - /** * @throws Exception */ public function __construct( Connection $connection, - ContentTypeHandler $contentTypeHandler, - LanguageHandler $languageHandler, + protected ContentTypeHandler $contentTypeHandler, + protected LanguageHandler $languageHandler, JoinedTablesTracker $joinedTablesTracker, - LanguagePriorityConditionBuilder $languagePriorityConditionBuilder + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); - - $this->contentTypeHandler = $contentTypeHandler; - $this->languageHandler = $languageHandler; - $this->languagePriorityConditionBuilder = $languagePriorityConditionBuilder; } /** diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php index 82922d52ee..06c47ea26d 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php @@ -24,18 +24,13 @@ */ class LanguageCode extends CriterionHandler { - /** @var Handler */ - private $languageHandler; - public function __construct( Connection $connection, - LanguageHandler $languageHandler, + private readonly LanguageHandler $languageHandler, JoinedTablesTracker $joinedTablesTracker, private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); - - $this->languageHandler = $languageHandler; } public function accept(CriterionInterface $criterion): bool diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php index 8742ea1f6d..bc288d3a1c 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -20,7 +20,7 @@ * * @internal */ -final class LanguagePriorityConditionBuilder +final readonly class LanguagePriorityConditionBuilder { /** * Pre-computed integer constant which, when combined with a bit-wise AND, removes the @@ -29,8 +29,8 @@ final class LanguagePriorityConditionBuilder private const int REMOVE_ALWAYS_AVAILABLE_BIT_OPERAND = -2; public function __construct( - private readonly Connection $connection, - private readonly LanguageHandler $languageHandler + private Connection $connection, + private LanguageHandler $languageHandler ) {} /** diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php b/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php index 921c435912..9d1da01d68 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php @@ -24,33 +24,13 @@ */ class Field extends SortClauseHandler { - /** - * Language handler. - * - * @var LanguageHandler - */ - protected $languageHandler; - - /** - * Content type handler. - * - * @var ContentTypeHandler - */ - protected $contentTypeHandler; - - private LanguagePriorityConditionBuilder $languagePriorityConditionBuilder; - public function __construct( Connection $connection, - LanguageHandler $languageHandler, - ContentTypeHandler $contentTypeHandler, - LanguagePriorityConditionBuilder $languagePriorityConditionBuilder + protected LanguageHandler $languageHandler, + protected ContentTypeHandler $contentTypeHandler, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection); - - $this->languageHandler = $languageHandler; - $this->contentTypeHandler = $contentTypeHandler; - $this->languagePriorityConditionBuilder = $languagePriorityConditionBuilder; } /** diff --git a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php index 0313e4d914..4a49d2eee4 100644 --- a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php @@ -4,6 +4,7 @@ * @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\Core\Search\Legacy\Content\Gateway; @@ -27,42 +28,13 @@ */ final class DoctrineDatabase extends Gateway { - /** @var Connection */ - private $connection; - - /** - * Criteria converter. - * - * @var CriteriaConverter - */ - private $criteriaConverter; - - /** - * Sort clause converter. - * - * @var SortClauseConverter - */ - private $sortClauseConverter; - - /** - * Language handler. - * - * @var LanguageHandler - */ - private $languageHandler; - public function __construct( - Connection $connection, - CriteriaConverter $criteriaConverter, - SortClauseConverter $sortClauseConverter, - LanguageHandler $languageHandler, + private readonly Connection $connection, + private readonly CriteriaConverter $criteriaConverter, + private readonly SortClauseConverter $sortClauseConverter, + private readonly LanguageHandler $languageHandler, private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder - ) { - $this->connection = $connection; - $this->criteriaConverter = $criteriaConverter; - $this->sortClauseConverter = $sortClauseConverter; - $this->languageHandler = $languageHandler; - } + ) {} public function find( CriterionInterface $criterion, @@ -101,9 +73,9 @@ private function getQueryCondition( CriterionInterface $filter, QueryBuilder $query, array $languageFilter - ) { + ): string { $expr = $query->expr(); - $condition = $expr->and( + $condition = (string)$expr->and( $this->criteriaConverter->convertCriteria($query, $filter, $languageFilter), $expr->eq( 'c.status', @@ -128,7 +100,7 @@ private function getQueryCondition( !empty($languageFilter['useAlwaysAvailable']) ); - $condition = $expr->and($condition, $languageCondition); + $condition = (string)$expr->and($condition, $languageCondition); } return $condition; @@ -206,7 +178,7 @@ private function getContentInfoList( 'c', LocationGateway::CONTENT_TREE_TABLE, 'main_tree', - $query->expr()->and( + (string)$query->expr()->and( 'main_tree.contentobject_id = c.id', 'main_tree.main_node_id = main_tree.node_id' ) diff --git a/src/lib/Search/Legacy/Content/Handler.php b/src/lib/Search/Legacy/Content/Handler.php index c8c1d1bb76..0e450a7cc5 100644 --- a/src/lib/Search/Legacy/Content/Handler.php +++ b/src/lib/Search/Legacy/Content/Handler.php @@ -52,72 +52,15 @@ */ class Handler implements SearchHandlerInterface { - /** - * Content locator gateway. - * - * @var Gateway - */ - protected $gateway; - - /** - * Location locator gateway. - * - * @var LocationGateway - */ - protected $locationGateway; - - /** - * Word indexer gateway. - * - * @var WordIndexerGateway - */ - protected $indexerGateway; - - /** - * Content mapper. - * - * @var ContentMapper - */ - protected $contentMapper; - - /** - * Location locationMapper. - * - * @var LocationMapper - */ - protected $locationMapper; - - /** - * Language handler. - * - * @var LanguageHandler - */ - protected $languageHandler; - - /** - * FullText mapper. - * - * @var FullTextMapper - */ - protected $mapper; - public function __construct( - Gateway $gateway, - LocationGateway $locationGateway, - WordIndexerGateway $indexerGateway, - ContentMapper $contentMapper, - LocationMapper $locationMapper, - LanguageHandler $languageHandler, - FullTextMapper $mapper - ) { - $this->gateway = $gateway; - $this->locationGateway = $locationGateway; - $this->indexerGateway = $indexerGateway; - $this->contentMapper = $contentMapper; - $this->locationMapper = $locationMapper; - $this->languageHandler = $languageHandler; - $this->mapper = $mapper; - } + protected Gateway $gateway, + protected LocationGateway $locationGateway, + protected WordIndexerGateway $indexerGateway, + protected ContentMapper $contentMapper, + protected LocationMapper $locationMapper, + protected LanguageHandler $languageHandler, + protected FullTextMapper $mapper + ) {} public function findContent( Query $query, diff --git a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php index c0b6e80d6f..ca08cc34eb 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -186,13 +186,12 @@ private function getTotalCount( * always-available" condition shared by find() and getTotalCount() - kept as one place so the * two queries can't drift out of sync on the always-available fallback. * - * @param QueryBuilder $queryBuilder * @param array{languages?: string[], useAlwaysAvailable?: bool} $languageFilter * * @throws NotFoundException */ private function buildTranslationCondition( - $queryBuilder, + QueryBuilder $queryBuilder, array $languageFilter ): string { $languageIds = array_map( diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php index f852bf6300..773e3ddeb0 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php @@ -4,6 +4,7 @@ * @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\Core\Search\Legacy\Content\WordIndexer\Gateway; @@ -28,61 +29,14 @@ class DoctrineDatabase extends Gateway */ public const DB_INT_MAX = 2147483647; - /** @var Connection */ - protected $connection; - - /** - * Persistence content type handler. - * - * Need this for being able to pick fields that are searchable. - * - * @var SPITypeHandler - */ - protected $typeHandler; - - /** - * Transformation processor. - * - * Need this for being able to transform text to searchable value - * - * @var TransformationProcessor - */ - protected $transformationProcessor; - - /** - * LegacySearchService. - * - * Need this for queries on ezsearch* tables - * - * @var SearchIndex - */ - protected $searchIndex; - - /** @var LanguageHandler */ - private $languageHandler; - - /** - * Full text search configuration options. - * - * @var array - */ - protected $fullTextSearchConfiguration; - public function __construct( - Connection $connection, - SPITypeHandler $typeHandler, - TransformationProcessor $transformationProcessor, - SearchIndex $searchIndex, - LanguageHandler $languageHandler, - array $fullTextSearchConfiguration - ) { - $this->connection = $connection; - $this->typeHandler = $typeHandler; - $this->transformationProcessor = $transformationProcessor; - $this->searchIndex = $searchIndex; - $this->fullTextSearchConfiguration = $fullTextSearchConfiguration; - $this->languageHandler = $languageHandler; - } + protected Connection $connection, + protected SPITypeHandler $typeHandler, + protected TransformationProcessor $transformationProcessor, + protected SearchIndex $searchIndex, + private readonly LanguageHandler $languageHandler, + protected array $fullTextSearchConfiguration + ) {} /** * Index search engine full text data corresponding to content object field values. @@ -105,7 +59,8 @@ public function index(FullTextData $fullTextData) $this->remove($fullTextData->id); foreach ($fullTextData->values as $fullTextValue) { /** @var FullTextValue $fullTextValue */ - if (is_numeric(trim($fullTextValue->value))) { + $value = (string)$fullTextValue->value; + if (is_numeric(trim($value))) { $integerValue = (int)$fullTextValue->value; if ($integerValue > self::DB_INT_MAX) { $integerValue = 0; @@ -114,7 +69,7 @@ public function index(FullTextData $fullTextData) $integerValue = 0; } $text = $this->transformationProcessor->transform( - $fullTextValue->value, + $value, !empty($fullTextValue->transformationRules) ? $fullTextValue->transformationRules : $this->fullTextSearchConfiguration['commands'] diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index 64f8854261..fe6c6d39f7 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php @@ -17,6 +17,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Handler; use Ibexa\Core\Search\Legacy\Content\Location\Gateway as LocationGateway; @@ -73,7 +74,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getLanguageHandler(), $this->getContentTypeHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -81,7 +82,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ] ), $this->getLanguageHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $this->getDatabaseConnection(), $this->getLanguageHandler() ) diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index db39a2a238..57993ace90 100644 --- a/tests/lib/Search/Legacy/Content/HandlerContentTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerContentTest.php @@ -19,6 +19,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; use Ibexa\Core\Persistence\Legacy\Content\Mapper as ContentMapper; use Ibexa\Core\Search\Legacy\Content; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Handler; use Ibexa\Core\Search\Legacy\Content\Location\Gateway as LocationGateway; @@ -163,7 +164,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ), $transformationProcessor, $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -176,7 +177,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getLanguageHandler(), $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) + new LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new Content\Gateway\CriterionHandler\Visibility( $connection, @@ -195,7 +196,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getLanguageHandler(), $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -208,7 +209,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ] ), $this->getLanguageHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $this->getDatabaseConnection(), $this->getLanguageHandler() ) diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php index 1f9e92c497..78404fb038 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php @@ -18,6 +18,7 @@ use Ibexa\Core\Search\Legacy\Content; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler as CommonCriterionHandler; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler as CommonSortClauseHandler; use Ibexa\Core\Search\Legacy\Content\Gateway as ContentGateway; @@ -90,7 +91,7 @@ protected function getContentSearchHandler() $connection, $this->getLanguageHandler(), $this->getContentTypeHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -98,7 +99,7 @@ protected function getContentSearchHandler() ] ), $this->getLanguageHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $this->getDatabaseConnection(), $this->getLanguageHandler() ) diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php index 70f849550b..fcfccea7f2 100644 --- a/tests/lib/Search/Legacy/Content/HandlerLocationTest.php +++ b/tests/lib/Search/Legacy/Content/HandlerLocationTest.php @@ -18,6 +18,7 @@ use Ibexa\Core\Search\Legacy\Content; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler as CommonCriterionHandler; +use Ibexa\Core\Search\Legacy\Content\Common\Gateway\LanguagePriorityConditionBuilder; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler as CommonSortClauseHandler; use Ibexa\Core\Search\Legacy\Content\Gateway as ContentGateway; @@ -119,7 +120,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ), $transformationProcessor, $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -135,7 +136,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getLanguageHandler(), $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) + new LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new CommonCriterionHandler\LogicalAnd($connection, $joinedTablesTracker), new CommonCriterionHandler\LogicalNot($connection, $joinedTablesTracker), @@ -145,7 +146,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getLanguageHandler(), $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -157,7 +158,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getLanguageHandler(), $joinedTablesTracker, - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $connection, $this->getLanguageHandler() ) @@ -174,7 +175,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ] ), $this->getLanguageHandler(), - new Content\Common\Gateway\LanguagePriorityConditionBuilder( + new LanguagePriorityConditionBuilder( $this->getDatabaseConnection(), $this->getLanguageHandler() ) From cb447f0313ce634e80d7c7a237496cb9833bd1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 15:04:46 +0100 Subject: [PATCH 24/54] IBX-13142: Replaced the deprecated introspectTable() calls with introspectTableByUnquotedName() --- .../AddSearchObjectWordLinkLanguageIdColumnsMigration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php index 98e6cd3d58..86512dffde 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php @@ -56,7 +56,7 @@ public function up(Schema $schema): void return; } - $table = $schemaManager->introspectTable(self::TABLE); + $table = $schemaManager->introspectTableByUnquotedName(self::TABLE); if (!$table->hasColumn(self::LANGUAGE_ID_COLUMN)) { $this->addSql($this->buildAddLanguageIdColumnSql()); From eabc420ef6f4f08bc6cc71d175f80a6e8c4a51bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 17 Nov 2026 11:55:35 +0100 Subject: [PATCH 25/54] IBX-13142: Dropped strict types from the word indexer gateway ReindexCommand passes the --content-ids values as strings, and the untyped remove() hands them on to SearchIndex's int parameters, which strict types turned into a TypeError for deleted or unpublished content. --- .../Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php index 773e3ddeb0..4f3c4f1e97 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php @@ -4,7 +4,6 @@ * @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\Core\Search\Legacy\Content\WordIndexer\Gateway; From 923066a27ec9a41f5c56007784a056954a35fd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 20:45:04 +0100 Subject: [PATCH 26/54] IBX-11939: Moved URL aliases off the language bitmask ibexa_url_alias_ml gets an is_always_available column, and an alias's languages come from ibexa_url_alias_ml_translation instead of lang_mask, in cleandata.sql too. The gateway keeps lang_mask in step with them until the bitmask is removed. --- data/mysql/cleandata.sql | 66 +-- data/postgresql/cleandata.sql | 66 +-- phpstan-baseline.neon | 24 -- .../Resources/config/doctrine_migrations.php | 5 + .../config/storage/legacy/schema.yaml | 1 + ...UrlAliasAlwaysAvailableColumnMigration.php | 95 +++++ .../Persistence/Fixture/FixtureImporter.php | 5 + .../Legacy/Content/UrlAlias/Gateway.php | 34 +- .../UrlAlias/Gateway/DoctrineDatabase.php | 398 ++++++++++++------ .../UrlAlias/Gateway/ExceptionConversion.php | 15 +- .../Legacy/Content/UrlAlias/Handler.php | 104 +++-- .../Legacy/Content/UrlAlias/Mapper.php | 50 ++- .../storage_engines/legacy/url_alias.yml | 6 +- .../Legacy/UrlAliasGatewayTest.php | 6 +- .../Core/Repository/URLAliasServiceTest.php | 3 - .../UrlAlias/Gateway/DoctrineDatabaseTest.php | 92 ++-- .../Content/UrlAlias/UrlAliasHandlerTest.php | 26 +- .../Content/UrlAlias/UrlAliasMapperTest.php | 71 +++- 18 files changed, 726 insertions(+), 341 deletions(-) create mode 100644 src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php diff --git a/data/mysql/cleandata.sql b/data/mysql/cleandata.sql index bdd26ad126..3dc90c8fa1 100644 --- a/data/mysql/cleandata.sql +++ b/data/mysql/cleandata.sql @@ -280,32 +280,46 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `lang_mask`, `link`, `parent`, `text`, `text_md5`) -VALUES ('nop:','nop',1,17,0,0,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), - ('eznode:43','eznode',1,9,0,1,3,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), - ('nop:','nop',1,3,0,0,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), - ('eznode:5','eznode',1,2,0,1,3,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), - ('eznode:2','eznode',1,1,0,1,3,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), - ('eznode:14','eznode',1,6,0,1,3,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), - ('eznode:44','eznode',1,10,0,1,3,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), - ('eznode:12','eznode',1,4,0,1,3,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), - ('eznode:13','eznode',1,5,0,1,3,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), - ('nop:','nop',1,11,0,0,1,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), - ('eznode:12','eznode',1,26,0,0,1,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), - ('eznode:14','eznode',1,29,0,0,1,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), - ('nop:','nop',1,7,0,0,1,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), - ('eznode:13','eznode',1,27,0,0,1,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), - ('eznode:44','eznode',1,30,0,0,1,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), - ('eznode:15','eznode',1,8,0,1,3,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), - ('eznode:15','eznode',1,28,0,0,0,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), - ('eznode:53','eznode',1,20,0,1,3,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,19,0,1,3,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,18,0,1,3,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), - ('eznode:45','eznode',1,12,0,1,3,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), - ('eznode:45','eznode',1,31,0,0,1,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), - ('eznode:53','eznode',1,34,0,0,1,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,33,0,0,1,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,32,0,0,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); +INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `lang_mask`, `is_always_available`, `link`, `parent`, `text`, `text_md5`) +VALUES ('nop:','nop',1,17,0,0,1,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), + ('eznode:43','eznode',1,9,0,1,3,1,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), + ('nop:','nop',1,3,0,0,1,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), + ('eznode:5','eznode',1,2,0,1,3,1,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), + ('eznode:2','eznode',1,1,0,1,3,1,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), + ('eznode:14','eznode',1,6,0,1,3,1,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), + ('eznode:44','eznode',1,10,0,1,3,1,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), + ('eznode:12','eznode',1,4,0,1,3,1,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), + ('eznode:13','eznode',1,5,0,1,3,1,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), + ('nop:','nop',1,11,0,0,1,1,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), + ('eznode:12','eznode',1,26,0,0,1,1,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), + ('eznode:14','eznode',1,29,0,0,1,1,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), + ('nop:','nop',1,7,0,0,1,1,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), + ('eznode:13','eznode',1,27,0,0,1,1,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), + ('eznode:44','eznode',1,30,0,0,1,1,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), + ('eznode:15','eznode',1,8,0,1,3,1,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), + ('eznode:15','eznode',1,28,0,0,0,0,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), + ('eznode:53','eznode',1,20,0,1,3,1,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,19,0,1,3,1,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,18,0,1,3,1,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), + ('eznode:45','eznode',1,12,0,1,3,1,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), + ('eznode:45','eznode',1,31,0,0,1,1,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), + ('eznode:53','eznode',1,34,0,0,1,1,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,33,0,0,1,1,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,32,0,0,1,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); + +INSERT INTO `ibexa_url_alias_ml_translation` (`parent`, `text_md5`, `language_id`) +VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), + (0,'9bc65c2abec141778ffaa729489f3e87',2), + (0,'d41d8cd98f00b204e9800998ecf8427e',2), + (2,'a147e136bfa717592f2bd70bd4b53b17',2), + (2,'c2803c3fa1b0b5423237b4e018cae755',2), + (2,'e57843d836e3af8ab611fde9e2139b3a',2), + (2,'f89fad7f8a3abc8c09e1deb46a420007',2), + (5,'5a9d7b0ec93173ef4fedee023209cb61',2), + (9,'2e5bc8831f7ae6a29530e7f1bbf2de9c',2), + (9,'45b963397aa40d4a0063e0d85e4fe7a1',2), + (9,'59b514174bffe4ae402b3d63aad79fe0',2), + (10,'ccb62ebca03a31272430bc414bd5cd5b',2); INSERT INTO `ibexa_url_alias_ml_incr` (`id`) VALUES (1), diff --git a/data/postgresql/cleandata.sql b/data/postgresql/cleandata.sql index 360dab6304..6193fbd2e7 100644 --- a/data/postgresql/cleandata.sql +++ b/data/postgresql/cleandata.sql @@ -280,32 +280,46 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "lang_mask", "link", "parent", "text", "text_md5") -VALUES ('nop:','nop',1,17,0,0,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), - ('eznode:43','eznode',1,9,0,1,3,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), - ('nop:','nop',1,3,0,0,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), - ('eznode:5','eznode',1,2,0,1,3,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), - ('eznode:2','eznode',1,1,0,1,3,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), - ('eznode:14','eznode',1,6,0,1,3,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), - ('eznode:44','eznode',1,10,0,1,3,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), - ('eznode:12','eznode',1,4,0,1,3,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), - ('eznode:13','eznode',1,5,0,1,3,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), - ('nop:','nop',1,11,0,0,1,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), - ('eznode:12','eznode',1,26,0,0,1,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), - ('eznode:14','eznode',1,29,0,0,1,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), - ('nop:','nop',1,7,0,0,1,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), - ('eznode:13','eznode',1,27,0,0,1,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), - ('eznode:44','eznode',1,30,0,0,1,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), - ('eznode:15','eznode',1,8,0,1,3,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), - ('eznode:15','eznode',1,28,0,0,0,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), - ('eznode:53','eznode',1,20,0,1,3,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,19,0,1,3,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,18,0,1,3,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), - ('eznode:45','eznode',1,12,0,1,3,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), - ('eznode:45','eznode',1,31,0,0,1,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), - ('eznode:53','eznode',1,34,0,0,1,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,33,0,0,1,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,32,0,0,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); +INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "lang_mask", "is_always_available", "link", "parent", "text", "text_md5") +VALUES ('nop:','nop',1,17,0,0,1,TRUE,17,0,'media2','50e2736330de124f6edea9b008556fe6'), + ('eznode:43','eznode',1,9,0,1,3,TRUE,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), + ('nop:','nop',1,3,0,0,1,TRUE,3,0,'users2','86425c35a33507d479f71ade53a669aa'), + ('eznode:5','eznode',1,2,0,1,3,TRUE,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), + ('eznode:2','eznode',1,1,0,1,3,TRUE,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), + ('eznode:14','eznode',1,6,0,1,3,TRUE,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), + ('eznode:44','eznode',1,10,0,1,3,TRUE,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), + ('eznode:12','eznode',1,4,0,1,3,TRUE,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), + ('eznode:13','eznode',1,5,0,1,3,TRUE,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), + ('nop:','nop',1,11,0,0,1,TRUE,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), + ('eznode:12','eznode',1,26,0,0,1,TRUE,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), + ('eznode:14','eznode',1,29,0,0,1,TRUE,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), + ('nop:','nop',1,7,0,0,1,TRUE,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), + ('eznode:13','eznode',1,27,0,0,1,TRUE,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), + ('eznode:44','eznode',1,30,0,0,1,TRUE,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), + ('eznode:15','eznode',1,8,0,1,3,TRUE,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), + ('eznode:15','eznode',1,28,0,0,0,FALSE,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), + ('eznode:53','eznode',1,20,0,1,3,TRUE,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,19,0,1,3,TRUE,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,18,0,1,3,TRUE,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), + ('eznode:45','eznode',1,12,0,1,3,TRUE,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), + ('eznode:45','eznode',1,31,0,0,1,TRUE,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), + ('eznode:53','eznode',1,34,0,0,1,TRUE,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,33,0,0,1,TRUE,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,32,0,0,1,TRUE,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); + +INSERT INTO "ibexa_url_alias_ml_translation" ("parent", "text_md5", "language_id") +VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), + (0,'9bc65c2abec141778ffaa729489f3e87',2), + (0,'d41d8cd98f00b204e9800998ecf8427e',2), + (2,'a147e136bfa717592f2bd70bd4b53b17',2), + (2,'c2803c3fa1b0b5423237b4e018cae755',2), + (2,'e57843d836e3af8ab611fde9e2139b3a',2), + (2,'f89fad7f8a3abc8c09e1deb46a420007',2), + (5,'5a9d7b0ec93173ef4fedee023209cb61',2), + (9,'2e5bc8831f7ae6a29530e7f1bbf2de9c',2), + (9,'45b963397aa40d4a0063e0d85e4fe7a1',2), + (9,'59b514174bffe4ae402b3d63aad79fe0',2), + (10,'ccb62ebca03a31272430bc414bd5cd5b',2); INSERT INTO "ibexa_url_alias_ml_incr" ("id") VALUES (1), diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bac7a17c2b..f7d2fc2104 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12648,24 +12648,6 @@ parameters: count: 1 path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php - - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Gateway\\DoctrineDatabase\:\:updateRow\(\) has parameter \$values with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php - - - - message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(int\)\: bool\)\|null, Closure\(mixed\)\: int given\.$#' - identifier: argument.type - count: 1 - path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php - - - - message: '#^Variable \$connection in PHPDoc tag @var does not match assigned variable \$query\.$#' - identifier: varTag.differentVariable - count: 1 - path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php - - message: '#^Dead catch \- PDOException is never thrown in the try block\.$#' identifier: catch.neverThrown @@ -34146,12 +34128,6 @@ parameters: count: 1 path: tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php - - - message: '#^Property Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\UrlAliasHandlerTest\:\:\$languageMaskGenerator \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php - - message: '#^Property Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\UrlAliasHandlerTest\:\:\$locationGateway \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway\) in isset\(\) is not nullable\.$#' identifier: isset.property diff --git a/src/bundle/Core/Resources/config/doctrine_migrations.php b/src/bundle/Core/Resources/config/doctrine_migrations.php index 3780e65837..04691f6550 100644 --- a/src/bundle/Core/Resources/config/doctrine_migrations.php +++ b/src/bundle/Core/Resources/config/doctrine_migrations.php @@ -10,6 +10,7 @@ use Ibexa\Bundle\RepositoryInstaller\Migration\AddContentVersionUniqueIndexMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddLanguageTranslationTablesMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddSearchObjectWordLinkLanguageIdColumnsMigration; +use Ibexa\Bundle\RepositoryInstaller\Migration\AddUrlAliasAlwaysAvailableColumnMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\AddUrlAliasMlLinkIndexMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\BackfillLanguageTranslationsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsMigration; @@ -96,6 +97,10 @@ ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); + $services->set(AddUrlAliasAlwaysAvailableColumnMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + $services->set(BackfillLanguageTranslationsMigration::class) ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index eb49316970..eb11a0e309 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -619,6 +619,7 @@ tables: lang_mask: { type: bigint, nullable: false, options: { default: '0' } } link: { type: integer, nullable: false, options: { default: '0' } } text: { type: text, nullable: false, length: 0 } + is_always_available: { type: boolean, nullable: false, options: { default: false } } ibexa_url_alias_ml_incr: id: id: { type: integer, nullable: false, options: { autoincrement: true } } diff --git a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php new file mode 100644 index 0000000000..3bccb6f19f --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php @@ -0,0 +1,95 @@ +hasTable()/hasColumn() would always report false there. + */ +final class AddUrlAliasAlwaysAvailableColumnMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string TABLE = 'ibexa_url_alias_ml'; + private const string ALWAYS_AVAILABLE_COLUMN = 'is_always_available'; + private const string LANGUAGE_MASK_COLUMN = 'lang_mask'; + + public function getDescription(): string + { + return 'Adds "is_always_available" column to "ibexa_url_alias_ml", backfilled from the language mask'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 04:00:00'); + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::TABLE])) { + return; + } + + $table = $schemaManager->introspectTable(self::TABLE); + + if (!$table->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { + $columnDefinition = match (true) { + $this->isMySQL(), $this->isMariaDB() => "TINYINT(1) DEFAULT '0' NOT NULL", + $this->isPostgreSQL() => "BOOLEAN DEFAULT 'false' NOT NULL", + default => "BOOLEAN DEFAULT '0' NOT NULL", + }; + + $this->addSql( + 'ALTER TABLE ' . self::TABLE . ' ADD COLUMN ' . self::ALWAYS_AVAILABLE_COLUMN . " {$columnDefinition}" + ); + } + + if (!$table->hasColumn(self::LANGUAGE_MASK_COLUMN)) { + return; + } + + $trueLiteral = $this->isPostgreSQL() ? 'true' : '1'; + + $this->addSql( + 'UPDATE ' . self::TABLE . ' SET ' . self::ALWAYS_AVAILABLE_COLUMN . + " = {$trueLiteral} WHERE (" . self::LANGUAGE_MASK_COLUMN . ' & 1) = 1' + ); + } +} diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 430b3efda0..37921ea865 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -238,6 +238,11 @@ private function backfillLanguageBitmaskColumns(array $nonEmptyTablesData): void continue; } $mask = (int)$row['lang_mask']; + $this->connection->executeStatement( + 'UPDATE ibexa_url_alias_ml SET is_always_available = :alwaysAvailable WHERE parent = :parent AND text_md5 = :textMd5', + ['alwaysAvailable' => ($mask & 1) === 1, 'parent' => $row['parent'], 'textMd5' => $row['text_md5']], + ['alwaysAvailable' => ParameterType::BOOLEAN, 'parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] + ); foreach ($this->extractLanguageIds($mask, $validLanguageIds) as $languageId) { $this->connection->executeStatement( 'INSERT INTO ibexa_url_alias_ml_translation (parent, text_md5, language_id) VALUES (:parent, :textMd5, :languageId)', diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php index ca8f74d772..9d145c7971 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php @@ -22,6 +22,8 @@ abstract class Gateway public const TABLE = 'ibexa_url_alias_ml'; + public const TRANSLATION_TABLE = 'ibexa_url_alias_ml_translation'; + public const INCR_TABLE = 'ibexa_url_alias_ml_incr'; public const INCR_TABLE_SEQ = 'ibexa_url_alias_ml_incr_id_seq'; @@ -73,7 +75,9 @@ abstract public function isRootEntry(int $id): bool; /** * Update single row data matched by composite primary key. * - * @param array $values associative array with column names as keys and column values as values + * @param array $values associative array with column names as keys and column values as + * values - "language_ids" (int[]) is a pseudo-column: it replaces the row's + * translations in "ibexa_url_alias_ml_translation" instead of mapping to a real column. */ abstract public function updateRow( int $parentId, @@ -84,7 +88,7 @@ abstract public function updateRow( /** * Insert new row into urlalias_ml table. * - * @param array $values + * @param array $values see {@see updateRow()} for the "language_ids" pseudo-column */ abstract public function insertRow(array $values): int; @@ -100,8 +104,8 @@ abstract public function loadRow( * Downgrade autogenerated entry matched by given $action and $languageId and negatively matched by * composite primary key. * - * If language mask of the found entry is composite (meaning it consists of multiple language ids) given - * $languageId will be removed from mask. Otherwise entry will be marked as history. + * If the found entry carries more than one language, $languageId is removed from its set of + * translations. Otherwise entry will be marked as history. */ abstract public function cleanupAfterPublish( string $action, @@ -112,14 +116,16 @@ abstract public function cleanupAfterPublish( ): void; /** - * Archive entry with $action by $languageMask. + * Archive entries with $action carrying any of $languageIds. * - * Used when swapping Location aliases, this ensures that given $languageMask matches a + * Used when swapping Location aliases, this ensures that given $languageIds match a * single entry (database row). + * + * @param int[] $languageIds */ abstract public function historizeBeforeSwap( string $action, - int $languageMask + array $languageIds ): void; /** @@ -150,6 +156,18 @@ abstract public function reparent( */ abstract public function loadPathData(int $id): array; + /** + * Loads the real (non-always-available) language ids a specific alias row is translated + * into, from "ibexa_url_alias_ml_translation" - the relational replacement for decoding + * "lang_mask". + * + * @return int[] + */ + abstract public function loadTranslationLanguageIds( + int $parent, + string $textMD5 + ): array; + /** * Load path data identified by given ordered array of hierarchy data. * @@ -214,7 +232,7 @@ abstract public function getNextId(): int; abstract public function getLocationContentMainLanguageId(int $locationId): int; /** - * Remove languageId of removed translation from lang_mask and deletes single language rows for multiple Locations. + * Removes $languageId's translation rows for multiple Locations. * * @param string[] $actions actions for which to perform the update */ diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index 8e03d43fcf..844b01b380 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -15,11 +15,12 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Query\QueryBuilder; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\UrlAlias\Handler; use Ibexa\Core\Base\Exceptions\BadStateException; use Ibexa\Core\Base\Exceptions\DatabaseException; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway; use Psr\Log\LoggerInterface; @@ -53,6 +54,7 @@ final class DoctrineDatabase extends Gateway 'text' => ParameterType::STRING, 'parent' => ParameterType::INTEGER, 'text_md5' => ParameterType::STRING, + 'is_always_available' => ParameterType::BOOLEAN, ]; private string $table; @@ -61,7 +63,7 @@ final class DoctrineDatabase extends Gateway public function __construct( private Connection $connection, - private LanguageMaskGenerator $languageMaskGenerator, + private LanguageHandler $languageHandler, ?LoggerInterface $logger = null ) { $this->logger = $logger ?? new NullLogger(); @@ -103,14 +105,14 @@ public function loadLocationEntries( 'link', 'is_alias', 'alias_redirects', - 'lang_mask', + 'is_always_available', 'is_original', 'parent', 'text', 'text_md5', 'action' ) - ->from($this->connection->quoteSingleIdentifier($this->table)) + ->from($this->connection->quoteSingleIdentifier($this->table), 'u') ->where( $expr->eq( 'action', @@ -135,15 +137,7 @@ public function loadLocationEntries( ; if (null !== $languageId) { - $query->andWhere( - $expr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'lang_mask', - $query->createPositionalParameter($languageId, ParameterType::INTEGER) - ), - '0' - ) - ); + $query->andWhere($this->buildTranslationExistsCondition($query, 'u.parent', 'u.text_md5', [$languageId])); } $statement = $query->executeQuery(); @@ -167,12 +161,12 @@ public function listGlobalEntries( 'link', 'is_alias', 'alias_redirects', - 'lang_mask', + 'is_always_available', 'is_original', 'parent', 'text_md5' ) - ->from($this->connection->quoteSingleIdentifier($this->table)) + ->from($this->connection->quoteSingleIdentifier($this->table), 'u') ->where( $expr->eq( 'action_type', @@ -200,21 +194,8 @@ public function listGlobalEntries( ->setFirstResult($offset); if (isset($languageCode)) { - $query->andWhere( - $expr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'lang_mask', - $query->createPositionalParameter( - $this->languageMaskGenerator->generateLanguageIndicator( - $languageCode, - false - ), - ParameterType::INTEGER - ) - ), - '0' - ) - ); + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; + $query->andWhere($this->buildTranslationExistsCondition($query, 'u.parent', 'u.text_md5', [$languageId])); } $statement = $query->executeQuery(); @@ -259,10 +240,9 @@ public function cleanupAfterPublish( $query ->select( 'parent', - 'text_md5', - 'lang_mask' + 'text_md5' ) - ->from($this->connection->quoteSingleIdentifier($this->table)) + ->from($this->connection->quoteSingleIdentifier($this->table), 'u') // 1) Autogenerated aliases that match action and language... ->where( $expr->eq( @@ -282,15 +262,7 @@ public function cleanupAfterPublish( $query->createPositionalParameter(0, ParameterType::INTEGER) ) ) - ->andWhere( - $expr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'lang_mask', - $query->createPositionalParameter($languageId, ParameterType::INTEGER) - ), - '0' - ) - ) + ->andWhere($this->buildTranslationExistsCondition($query, 'u.parent', 'u.text_md5', [$languageId])) // 2) ...but not newly published entry ->andWhere( sprintf( @@ -314,10 +286,9 @@ public function cleanupAfterPublish( if (!empty($row)) { $this->archiveUrlAliasForDeletedTranslation( - (int)$row['lang_mask'], - (int)$languageId, (int)$row['parent'], $row['text_md5'], + (int)$languageId, (int)$newId ); } @@ -326,19 +297,24 @@ public function cleanupAfterPublish( /** * Archive (remove or historize) obsolete URL aliases (for translations that were removed). * - * @param int $languageMask all languages bit mask - * @param int $languageId removed language Id - * @param string $textMD5 checksum + * If the alias still carries other real (non-always-available) languages besides the removed + * one, only that language's translation row is removed; otherwise the whole entry is obsolete + * and gets historized instead. */ private function archiveUrlAliasForDeletedTranslation( - int $languageMask, - int $languageId, int $parent, string $textMD5, + int $languageId, int $linkId ): void { - // If language mask is composite (consists of multiple languages) then remove given language from entry - if ($languageMask & ~($languageId | 1)) { + $hasOtherLanguages = (bool)$this->connection->fetchOne( + 'SELECT 1 FROM ' . self::TRANSLATION_TABLE . ' + WHERE parent = :parent AND text_md5 = :textMd5 AND language_id != :languageId', + ['parent' => $parent, 'textMd5' => $textMD5, 'languageId' => $languageId], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING, 'languageId' => ParameterType::INTEGER] + ); + + if ($hasOtherLanguages) { $this->removeTranslation($parent, $textMD5, $languageId); } else { // Otherwise mark entry as history @@ -346,13 +322,18 @@ private function archiveUrlAliasForDeletedTranslation( } } + /** + * @param int[] $languageIds real (non-always-available) language ids the swapped entry carries + */ public function historizeBeforeSwap( string $action, - int $languageMask + array $languageIds ): void { + $tableName = $this->connection->quoteSingleIdentifier($this->table); + $query = $this->connection->createQueryBuilder(); $query - ->update($this->connection->quoteSingleIdentifier($this->table)) + ->update($tableName) ->set( 'is_original', $query->createPositionalParameter(0, ParameterType::INTEGER) @@ -374,16 +355,7 @@ public function historizeBeforeSwap( 'is_original', $query->createPositionalParameter(1, ParameterType::INTEGER) ), - $query->expr()->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'lang_mask', - $query->createPositionalParameter( - $languageMask & ~1, - ParameterType::INTEGER - ) - ), - '0' - ) + $this->buildTranslationExistsCondition($query, "{$tableName}.parent", "{$tableName}.text_md5", $languageIds) ) ); @@ -441,48 +413,25 @@ private function historize( } /** - * Update single row data matched by composite primary key. - * - * Removes given $languageId from entry's language mask + * Removes given $languageId from entry's set of translations. */ private function removeTranslation( int $parentId, string $textMD5, int $languageId ): void { - $query = $this->connection->createQueryBuilder(); - $query - ->update($this->connection->quoteSingleIdentifier($this->table)) - ->set( - 'lang_mask', - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'lang_mask', - $query->createPositionalParameter( - ~$languageId, - ParameterType::INTEGER - ) - ) - ) - ->where( - $query->expr()->eq( - 'parent', - $query->createPositionalParameter( - $parentId, - ParameterType::INTEGER - ) - ) - ) - ->andWhere( - $query->expr()->eq( - 'text_md5', - $query->createPositionalParameter( - $textMD5, - ParameterType::STRING - ) - ) - ) - ; - $query->executeStatement(); + $this->connection->executeStatement( + 'UPDATE ' . $this->connection->quoteSingleIdentifier($this->table) . ' + SET lang_mask = lang_mask & ~ ' . $languageId . ' + WHERE parent = :parent AND text_md5 = :textMd5', + ['parent' => $parentId, 'textMd5' => $textMD5], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] + ); + $this->connection->executeStatement( + 'DELETE FROM ' . self::TRANSLATION_TABLE . ' WHERE parent = :parent AND text_md5 = :textMd5 AND language_id = :languageId', + ['parent' => $parentId, 'textMd5' => $textMD5, 'languageId' => $languageId], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING, 'languageId' => ParameterType::INTEGER] + ); } public function historizeId( @@ -555,11 +504,21 @@ public function reparent( $query->executeStatement(); } + /** + * @param array $values associative array with column names as keys and column + * values as values - "language_ids" (int[]) is a pseudo-column: it does not map to a + * real table column, and instead replaces the row's translations in + * "ibexa_url_alias_ml_translation". + */ public function updateRow( int $parentId, string $textMD5, array $values ): void { + $languageIds = $values['language_ids'] ?? null; + unset($values['language_ids']); + $values = $this->withLanguageMask($values, $languageIds, $parentId, $textMD5); + $query = $this->connection->createQueryBuilder(); $query->update($this->connection->quoteSingleIdentifier($this->table)); foreach ($values as $columnName => $value) { @@ -586,6 +545,10 @@ public function updateRow( ) ); $query->executeStatement(); + + if (null !== $languageIds) { + $this->syncUrlAliasTranslations($parentId, $textMD5, $languageIds); + } } public function insertRow(array $values): int @@ -640,6 +603,10 @@ private function doInsertRow(array $values): int $values['is_original'] = 1; } + $languageIds = $values['language_ids'] ?? null; + unset($values['language_ids']); + $values = $this->withLanguageMask($values, $languageIds); + $query = $this->connection->createQueryBuilder(); $query->insert($this->connection->quoteSingleIdentifier($this->table)); foreach ($values as $columnName => $value) { @@ -654,9 +621,77 @@ private function doInsertRow(array $values): int } $query->executeStatement(); + if (null !== $languageIds) { + $this->syncUrlAliasTranslations((int)$values['parent'], (string)$values['text_md5'], $languageIds); + } + return (int)$values['id']; } + /** + * Keeps the legacy "lang_mask" in step with the row's translations and "is_always_available", + * for as long as the language bitmask is still around. + * + * @param array $values + * @param int[]|null $languageIds + * + * @return array + */ + private function withLanguageMask( + array $values, + ?array $languageIds, + ?int $parentId = null, + ?string $textMD5 = null + ): array { + if (null === $languageIds && !array_key_exists('is_always_available', $values)) { + return $values; + } + + $existing = null !== $parentId && null !== $textMD5; + $languageIds ??= $existing ? $this->loadTranslationLanguageIds($parentId, $textMD5) : []; + $alwaysAvailable = array_key_exists('is_always_available', $values) + ? (bool)$values['is_always_available'] + : $existing && (bool)$this->connection->fetchOne( + 'SELECT is_always_available FROM ' . $this->connection->quoteSingleIdentifier($this->table) + . ' WHERE parent = :parent AND text_md5 = :textMd5', + ['parent' => $parentId, 'textMd5' => $textMD5], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] + ); + + $languageMask = $alwaysAvailable ? 1 : 0; + foreach ($languageIds as $languageId) { + $languageMask |= (int)$languageId; + } + $values['lang_mask'] = $languageMask; + + return $values; + } + + /** + * Replaces $parentId/$textMD5's rows in "ibexa_url_alias_ml_translation" with $languageIds. + * + * @param int[] $languageIds + */ + private function syncUrlAliasTranslations( + int $parentId, + string $textMD5, + array $languageIds + ): void { + $this->connection->executeStatement( + 'DELETE FROM ' . self::TRANSLATION_TABLE . ' WHERE parent = :parent AND text_md5 = :textMd5', + ['parent' => $parentId, 'textMd5' => $textMD5], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] + ); + + foreach ($languageIds as $languageId) { + $this->connection->executeStatement( + 'INSERT INTO ' . self::TRANSLATION_TABLE . ' (parent, text_md5, language_id) VALUES (:parent, :textMd5, :languageId)', + ['parent' => $parentId, 'textMd5' => $textMD5, 'languageId' => $languageId], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING, 'languageId' => ParameterType::INTEGER] + ); + } + } + public function getNextId(): int { $query = $this->connection->createQueryBuilder(); @@ -809,7 +844,8 @@ public function loadPathData(int $id): array $query = $this->connection->createQueryBuilder(); $query->select( 'parent', - 'lang_mask', + 'text_md5', + 'is_always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) @@ -882,7 +918,9 @@ public function loadPathDataByHierarchy(array $hierarchyData): array $query->select( 'action', - 'lang_mask', + 'parent', + 'text_md5', + 'is_always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) @@ -1064,12 +1102,28 @@ public function bulkRemoveTranslation( ->setParameter('actions', $actions, ArrayParameterType::STRING); $query->executeStatement(); - // cleanup: delete single language rows (including alwaysAvailable) + $this->connection->executeStatement( + 'DELETE FROM ' . self::TRANSLATION_TABLE . ' + WHERE language_id = :languageId + AND EXISTS ( + SELECT 1 FROM ' . $this->connection->quoteSingleIdentifier($this->table) . ' u + WHERE u.parent = ' . self::TRANSLATION_TABLE . '.parent + AND u.text_md5 = ' . self::TRANSLATION_TABLE . '.text_md5 + AND u.action IN (:actions) + )', + ['languageId' => $languageId, 'actions' => $actions], + ['languageId' => ParameterType::INTEGER, 'actions' => ArrayParameterType::STRING] + ); + + // cleanup: delete rows left with no real (non-always-available) language at all + $tableName = $this->connection->quoteSingleIdentifier($this->table); $query = $this->connection->createQueryBuilder(); $query - ->delete($this->connection->quoteSingleIdentifier($this->table)) + ->delete($tableName) ->where('action IN (:actions)') - ->andWhere('lang_mask IN (0, 1)') + ->andWhere( + 'NOT EXISTS (SELECT 1 FROM ' . self::TRANSLATION_TABLE . " ut WHERE ut.parent = {$tableName}.parent AND ut.text_md5 = {$tableName}.text_md5)" + ) ->setParameter('actions', $actions, ArrayParameterType::STRING); $query->executeStatement(); } @@ -1091,16 +1145,10 @@ public function archiveUrlAliasesForDeletedTranslations( $languageIds ); - // remove specific languages from a bit mask + // remove each row's actually-present removed languages foreach ($rows as $row) { - // filter mask to reduce the number of calls to storage engine - $rowLanguageMask = (int)$row['lang_mask']; - $languageIdsToBeRemoved = array_filter( - $languageIds, - static function ($languageId) use ($rowLanguageMask): int { - return $languageId & $rowLanguageMask; - } - ); + $rowLanguageIds = $this->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']); + $languageIdsToBeRemoved = array_intersect($languageIds, $rowLanguageIds); if (empty($languageIdsToBeRemoved)) { continue; @@ -1112,16 +1160,35 @@ static function ($languageId) use ($rowLanguageMask): int { : (int)$row['id']; foreach ($languageIdsToBeRemoved as $languageId) { $this->archiveUrlAliasForDeletedTranslation( - (int)$row['lang_mask'], - (int)$languageId, (int)$row['parent'], $row['text_md5'], + (int)$languageId, $linkToId ); } } } + public function loadTranslationLanguageIds( + int $parent, + string $textMD5 + ): array { + // Explicit ORDER BY: UrlAlias::$languageCodes' element order is observable (e.g. asserted + // directly in URLAliasServiceTest), so it must not depend on however this table's rows + // happened to be inserted - which itself can shift whenever an upstream write path's own + // language-iteration order changes, even though this query is otherwise untouched. + return array_map( + 'intval', + $this->connection->fetchFirstColumn( + 'SELECT language_id FROM ' . self::TRANSLATION_TABLE . ' + WHERE parent = :parent AND text_md5 = :textMd5 + ORDER BY language_id', + ['parent' => $parent, 'textMd5' => $textMD5], + ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] + ) + ); + } + /** * Load list of aliases for given $locationId matching any of the specified Languages. * @@ -1131,22 +1198,18 @@ private function loadLocationEntriesMatchingMultipleLanguages( int $locationId, array $languageIds ): array { - // note: alwaysAvailable for this use case is not relevant - $languageMask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageIds( - $languageIds, - false - ); - - /** @var Connection $connection */ $query = $this->connection->createQueryBuilder(); $query - ->select('id', 'lang_mask', 'parent', 'text_md5') - ->from($this->connection->quoteSingleIdentifier($this->table)) - ->where('action = :action') + ->select('id', 'parent', 'text_md5') + ->from($this->connection->quoteSingleIdentifier($this->table), 'u') + ->where( + $query->expr()->eq( + 'action', + $query->createPositionalParameter('eznode:' . $locationId, ParameterType::STRING) + ) + ) // fetch rows matching any of the given Languages - ->andWhere('lang_mask & :languageMask <> 0') - ->setParameter('action', 'eznode:' . $locationId) - ->setParameter('languageMask', $languageMask); + ->andWhere($this->buildTranslationExistsCondition($query, 'u.parent', 'u.text_md5', $languageIds)); $statement = $query->executeQuery(); @@ -1270,12 +1333,13 @@ public function repairBrokenUrlAliasesForLocation(int $locationId): void ->setParameter('action', "eznode:{$locationId}"); foreach ($urlAliasesData as $urlAliasData) { - if ($urlAliasData['is_original'] === 1 || !isset($originalUrlAliases[$urlAliasData['lang_mask']])) { + $languageSetKey = $this->buildLanguageSetKey((int)$urlAliasData['parent'], $urlAliasData['text_md5']); + if ($urlAliasData['is_original'] === 1 || !isset($originalUrlAliases[$languageSetKey])) { // ignore non-archived entries and deleted Translations continue; } - $originalUrlAlias = $originalUrlAliases[$urlAliasData['lang_mask']]; + $originalUrlAlias = $originalUrlAliases[$languageSetKey]; if ($urlAliasData['link'] === $originalUrlAlias['link']) { // ignore correct entries to avoid unnecessary updates @@ -1379,9 +1443,9 @@ public function getAllChildrenAliases(int $parentId): array } /** - * Filter from the given result set original (current) only URL aliases and index them by language_mask. - * - * Note: each language_mask can have one URL Alias. + * Filter from the given result set original (current) only URL aliases and index them by their + * real (non-always-available) language id set - the relational replacement for indexing by + * "lang_mask" (each distinct language set can have one URL Alias). * * @param array $urlAliasesData */ @@ -1395,8 +1459,28 @@ static function ($urlAliasData): bool { } ); - // return language_mask-indexed array - return array_column($originalUrlAliases, null, 'lang_mask'); + $keyedUrlAliases = []; + foreach ($originalUrlAliases as $urlAliasData) { + $languageSetKey = $this->buildLanguageSetKey((int)$urlAliasData['parent'], $urlAliasData['text_md5']); + $keyedUrlAliases[$languageSetKey] = $urlAliasData; + } + + return $keyedUrlAliases; + } + + /** + * Builds a stable identity key for the real (non-always-available) language id set a specific + * alias row is translated into - used to match an archived alias row to the still-current alias + * row covering the same languages. + */ + private function buildLanguageSetKey( + int $parent, + string $textMD5 + ): string { + $languageIds = $this->loadTranslationLanguageIds($parent, $textMD5); + sort($languageIds); + + return implode(',', $languageIds); } /** @@ -1439,7 +1523,6 @@ private function getUrlAliasesForLocation(int $locationId): array ->select( 't1.id', 't1.is_original', - 't1.lang_mask', 't1.link', 't1.parent', // show existing parent only if its row exists, special case for root parent @@ -1500,4 +1583,47 @@ private function getDatabasePlatform(): AbstractPlatform throw DatabaseException::wrap($e); } } + + /** + * Builds an "at least one of $languageIds is a real translation of this row" condition against + * "ibexa_url_alias_ml_translation", correlated via $parentColumn/$textMd5Column (must be + * qualified with $query's own table alias) - the relational replacement for bitwise-AND-ing a + * row's "lang_mask". + * + * $parentColumn/$textMd5Column must be alias-qualified (e.g. "u.parent"), never bare column + * names - "ibexa_url_alias_ml_translation" has its own same-named columns, so an unqualified + * reference inside the subquery would resolve to its own column (the innermost scope), silently + * turning the correlation into a tautology instead of a real join back to the outer row. + * + * @param int[] $languageIds + */ + private function buildTranslationExistsCondition( + QueryBuilder $query, + string $parentColumn, + string $textMd5Column, + array $languageIds + ): string { + if (empty($languageIds)) { + // No language can ever match an empty set - mirrors the old mask check being + // vacuously false for a zero mask. + return '1 = 0'; + } + + $translationExistsSubQuery = $this->connection->createQueryBuilder(); + $translationExistsSubQuery + ->select('1') + ->from(self::TRANSLATION_TABLE, 'ut') + ->where( + $translationExistsSubQuery->expr()->and( + "ut.parent = {$parentColumn}", + "ut.text_md5 = {$textMd5Column}", + $translationExistsSubQuery->expr()->in( + 'ut.language_id', + $query->createPositionalParameter($languageIds, ArrayParameterType::INTEGER) + ) + ) + ); + + return sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); + } } diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php index 298ca0e43f..98d989b642 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php @@ -90,10 +90,10 @@ public function cleanupAfterPublish( public function historizeBeforeSwap( string $action, - int $languageMask + array $languageIds ): void { try { - $this->innerGateway->historizeBeforeSwap($action, $languageMask); + $this->innerGateway->historizeBeforeSwap($action, $languageIds); } catch (DBALException | PDOException $e) { throw DatabaseException::wrap($e); } @@ -216,6 +216,17 @@ public function loadPathData(int $id): array } } + public function loadTranslationLanguageIds( + int $parent, + string $textMD5 + ): array { + try { + return $this->innerGateway->loadTranslationLanguageIds($parent, $textMD5); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } + public function loadPathDataByHierarchy(array $hierarchyData): array { try { diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php index 6a1d23a092..6ccfab30fe 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -19,7 +19,6 @@ use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\CachingHandler; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\DTO\SwappedLocationProperties; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\DTO\UrlAliasForSwappedLocation; @@ -96,13 +95,6 @@ class Handler implements UrlAliasHandlerInterface */ protected $contentGateway; - /** - * Language mask generator. - * - * @var MaskGenerator - */ - protected $maskGenerator; - /** @var TransactionHandler */ private $transactionHandler; @@ -115,7 +107,6 @@ class Handler implements UrlAliasHandlerInterface * @param LanguageHandler $languageHandler * @param SlugConverter $slugConverter * @param ContentGateway $contentGateway - * @param MaskGenerator $maskGenerator * @param TransactionHandler $transactionHandler */ public function __construct( @@ -125,7 +116,6 @@ public function __construct( LanguageHandler $languageHandler, SlugConverter $slugConverter, ContentGateway $contentGateway, - MaskGenerator $maskGenerator, TransactionHandler $transactionHandler ) { $this->gateway = $gateway; @@ -134,7 +124,6 @@ public function __construct( $this->languageHandler = $languageHandler; $this->slugConverter = $slugConverter; $this->contentGateway = $contentGateway; - $this->maskGenerator = $maskGenerator; $this->transactionHandler = $transactionHandler; } @@ -184,7 +173,7 @@ private function internalPublishUrlAliasForLocation( $parentId = $this->getRealAliasId($parentLocationId); $name = $this->slugConverter->convert($name, 'location_' . $locationId); $uniqueCounter = $this->slugConverter->getUniqueCounterValue($name, $parentId == 0); - $languageMask = $languageId | (int)$alwaysAvailable; + $languageIds = [$languageId]; $action = 'eznode:' . $locationId; $cleanup = false; @@ -215,7 +204,8 @@ private function internalPublishUrlAliasForLocation( 'link' => $newId, 'parent' => $parentId, 'action' => $action, - 'lang_mask' => $languageMask, + 'language_ids' => $languageIds, + 'is_always_available' => $alwaysAvailable, 'text' => $newText, 'text_md5' => $newTextMD5, ] @@ -254,8 +244,11 @@ private function internalPublishUrlAliasForLocation( $cleanup = true; $newId = $existingLocationEntry['id']; if ($existingLocationEntry['id'] == $row['id']) { - // If we are reusing existing location entry merge existing language mask - $languageMask |= ($row['lang_mask'] & ~1); + // If we are reusing existing location entry merge its existing real languages + $languageIds = array_unique(array_merge( + $languageIds, + $this->gateway->loadTranslationLanguageIds($parentId, $newTextMD5) + )); } } elseif ($newId === null) { // Use reused row ID only if publishing normally, else use given $newId @@ -269,7 +262,8 @@ private function internalPublishUrlAliasForLocation( 'action' => $action, // In case when NOP row was reused 'action_type' => 'eznode', - 'lang_mask' => $languageMask, + 'language_ids' => $languageIds, + 'is_always_available' => $alwaysAvailable, // Updating text ensures that letter case changes are stored 'text' => $newText, // Set "id" and "link" for case when reusable entry is history @@ -456,13 +450,15 @@ protected function createUrlAlias( // If nothing was returned perform insert if ($isPathNew || empty($row)) { - $data['lang_mask'] = $languageId | (int)$alwaysAvailable; + $data['language_ids'] = [$languageId]; + $data['is_always_available'] = $alwaysAvailable; $id = $this->gateway->insertRow($data); } elseif ($row['action'] === Gateway::NOP_ACTION || (int)$row['is_original'] === 0) { // Row exists, check if it is reusable. There are 2 cases when this is possible: // 1. NOP entry // 2. history entry - $data['lang_mask'] = $languageId | (int)$alwaysAvailable; + $data['language_ids'] = [$languageId]; + $data['is_always_available'] = $alwaysAvailable; // If history is reused move link to id $data['link'] = $id = $row['id']; $this->gateway->updateRow( @@ -473,11 +469,15 @@ protected function createUrlAlias( } elseif ( $row['action'] === $action && (int)$row['is_alias'] === 1 && - 0 === ((int)$row['lang_mask'] & $languageId) + !in_array($languageId, $this->gateway->loadTranslationLanguageIds($parentId, $topElementMD5), true) ) { // add another language to the same custom alias $data['link'] = $id = $row['id']; - $data['lang_mask'] = $row['lang_mask'] | $languageId | (int)$alwaysAvailable; + $data['language_ids'] = array_unique(array_merge( + $this->gateway->loadTranslationLanguageIds($parentId, $topElementMD5), + [$languageId] + )); + $data['is_always_available'] = $alwaysAvailable || (bool)$row['is_always_available']; $this->gateway->updateRow( $parentId, $topElementMD5, @@ -511,7 +511,8 @@ protected function insertNopEntry( ) { return $this->gateway->insertRow( [ - 'lang_mask' => 1, + 'language_ids' => [], + 'is_always_available' => true, 'action' => Gateway::NOP_ACTION, 'parent' => $parentId, 'text' => $text, @@ -765,8 +766,8 @@ public function locationSwapped( $names1 = $this->getNamesForAllLanguages($contentInfo1); $names2 = $this->getNamesForAllLanguages($contentInfo2); - $location1->isAlwaysAvailable = $this->maskGenerator->isAlwaysAvailable($contentInfo1['language_mask']); - $location2->isAlwaysAvailable = $this->maskGenerator->isAlwaysAvailable($contentInfo2['language_mask']); + $location1->isAlwaysAvailable = (bool)$contentInfo1['always_available']; + $location2->isAlwaysAvailable = (bool)$contentInfo2['always_available']; $languages = $this->languageHandler->loadAll(); @@ -794,8 +795,18 @@ public function locationSwapped( } } - $this->internalPublishCustomUrlAliasForLocation($location1, $contentInfo1['language_mask']); - $this->internalPublishCustomUrlAliasForLocation($location2, $contentInfo2['language_mask']); + $contentTranslations = $this->contentGateway->loadContentTranslations( + [(int)$contentInfo1['id'], (int)$contentInfo2['id']] + ); + + $this->internalPublishCustomUrlAliasForLocation( + $location1, + $contentTranslations[(int)$contentInfo1['id']] ?? [] + ); + $this->internalPublishCustomUrlAliasForLocation( + $location2, + $contentTranslations[(int)$contentInfo2['id']] ?? [] + ); } /** @@ -840,11 +851,17 @@ private function historizeBeforeSwap( $location2Entries ) { foreach ($location1Entries as $row) { - $this->gateway->historizeBeforeSwap($row['action'], $row['lang_mask']); + $this->gateway->historizeBeforeSwap( + $row['action'], + $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) + ); } foreach ($location2Entries as $row) { - $this->gateway->historizeBeforeSwap($row['action'], $row['lang_mask']); + $this->gateway->historizeBeforeSwap( + $row['action'], + $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) + ); } } @@ -960,8 +977,12 @@ private function getLocationEntryInLanguage( ) { $entries = array_filter( $locationEntries, - static function (array $row) use ($languageId): bool { - return (bool) ($row['lang_mask'] & $languageId); + function (array $row) use ($languageId): bool { + return in_array( + $languageId, + $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']), + true + ); } ); @@ -1029,6 +1050,7 @@ protected function copySubtree( $newIdsMap[$oldParentAliasId] = $this->gateway->getNextId(); } + $row['language_ids'] = $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']); $row['action'] = $actionMap[$row['action']]; $row['parent'] = $newParentAliasId; $row['id'] = $row['link'] = $newIdsMap[$oldParentAliasId]; @@ -1073,6 +1095,8 @@ public function locationDeleted($locationId): array $action = 'eznode:' . $locationId; $entry = $this->gateway->loadAutogeneratedEntry($action); $entryId = $entry['id']; + // captured before removeSubtree() deletes the row (and cascades its translation rows away) + $entry['language_ids'] = $this->gateway->loadTranslationLanguageIds((int)$entry['parent'], $entry['text_md5']); $this->removeSubtree($entryId, $action, $entry['is_original']); @@ -1233,21 +1257,30 @@ private function insertAliasEntryAsNop(array $aliasEntry): void } /** - * Internal publish custom aliases method, accepting language mask to set correct language mask on url aliases - * new alias ID (used when swapping Locations). + * Internal publish custom aliases method, accepting the swapped Location's Content's real + * (non-always-available) language ids to set the correct languages on url aliases new alias ID + * (used when swapping Locations). + * + * $contentLanguageIds are the new Content's own real translation languages (from + * ibexa_content_translation) - $location->isAlwaysAvailable (set from the always_available + * column by locationSwapped()) is combined separately, since always-available is no longer part + * of a language id set. + * + * @param int[] $contentLanguageIds */ private function internalPublishCustomUrlAliasForLocation( SwappedLocationProperties $location, - int $languageMask + array $contentLanguageIds ) { foreach ($location->entries as $entry) { if ((int)$entry['is_alias'] === 0) { continue; } - $mask = (int)$entry['lang_mask'] & $languageMask; + $entryLanguageIds = $this->gateway->loadTranslationLanguageIds((int)$entry['parent'], $entry['text_md5']); + $intersectedLanguageIds = array_intersect($entryLanguageIds, $contentLanguageIds); - if ($mask <= 1) { + if (empty($intersectedLanguageIds) && !$location->isAlwaysAvailable) { continue; } @@ -1258,7 +1291,8 @@ private function internalPublishCustomUrlAliasForLocation( 'id' => (int)$entry['id'], 'is_original' => 1, 'is_alias' => 1, - 'lang_mask' => $mask, + 'language_ids' => $intersectedLanguageIds, + 'is_always_available' => $location->isAlwaysAvailable, ] ); } diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php index 2e5aa37a02..3a44157b29 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -7,29 +7,39 @@ namespace Ibexa\Core\Persistence\Legacy\Content\UrlAlias; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\UrlAlias; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; /** * UrlAlias Mapper. */ class Mapper { - /** - * Language mask generator. - * - * @var LanguageMaskGenerator - */ - protected $languageMaskGenerator; + private Gateway $gateway; + + private LanguageHandler $languageHandler; + + public function __construct( + Gateway $gateway, + LanguageHandler $languageHandler + ) { + $this->gateway = $gateway; + $this->languageHandler = $languageHandler; + } /** - * Creates a new UrlWildcard Handler. + * @param int[] $languageIds * - * @param LanguageMaskGenerator $languageMaskGenerator + * @return string[] */ - public function __construct(LanguageMaskGenerator $languageMaskGenerator) + private function loadLanguageCodes(array $languageIds): array { - $this->languageMaskGenerator = $languageMaskGenerator; + $languageCodes = []; + foreach ($this->languageHandler->loadList($languageIds) as $language) { + $languageCodes[] = $language->languageCode; + } + + return $languageCodes; } /** @@ -46,8 +56,10 @@ public function extractUrlAliasFromData($data) list($type, $destination) = $this->matchTypeAndDestination($data['action']); $urlAlias->id = $this->generateIdentityKey((int)$data['parent'], $data['text_md5']); $urlAlias->pathData = $this->normalizePathData($data['raw_path_data']); - $urlAlias->languageCodes = $this->languageMaskGenerator->extractLanguageCodesFromMask($data['lang_mask']); - $urlAlias->alwaysAvailable = $this->languageMaskGenerator->isAlwaysAvailable($data['lang_mask']); + $urlAlias->languageCodes = $this->loadLanguageCodes( + $this->gateway->loadTranslationLanguageIds((int)$data['parent'], $data['text_md5']) + ); + $urlAlias->alwaysAvailable = (bool)$data['is_always_available']; $urlAlias->isHistory = isset($data['is_path_history']) ? $data['is_path_history'] : !$data['is_original']; $urlAlias->isCustom = (bool)$data['is_alias']; $urlAlias->forward = $data['is_alias'] && $data['alias_redirects']; @@ -83,12 +95,12 @@ public function extractUrlAliasListFromData(array $rows) */ public function extractLanguageCodesFromData(array $rows): array { - $languageMask = 0; + $languageIds = []; foreach ($rows as $row) { - $languageMask |= $row['lang_mask']; + $languageIds[] = $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']); } - return $this->languageMaskGenerator->extractLanguageCodesFromMask($languageMask); + return $this->loadLanguageCodes(array_unique(array_merge([], ...$languageIds))); } public function generateIdentityKey( @@ -167,8 +179,10 @@ protected function normalizePathDataRow( array &$pathElementData, array $row ) { - $languageCodes = $this->languageMaskGenerator->extractLanguageCodesFromMask($row['lang_mask']); - $pathElementData['always-available'] = $this->languageMaskGenerator->isAlwaysAvailable($row['lang_mask']); + $languageCodes = $this->loadLanguageCodes( + $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) + ); + $pathElementData['always-available'] = (bool)$row['is_always_available']; if (!empty($languageCodes)) { foreach ($languageCodes as $languageCode) { $pathElementData['translations'][$languageCode] = $row['text']; diff --git a/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml b/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml index b8781afa6e..51ce44e7bb 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml @@ -3,7 +3,7 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway\DoctrineDatabase arguments: - '@ibexa.api.storage_engine.legacy.connection' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + - '@ibexa.spi.persistence.legacy.language.handler' - '@?logger' Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway\ExceptionConversion: @@ -18,7 +18,8 @@ services: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper: class: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper arguments: - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + - '@ibexa.persistence.legacy.url_alias.gateway' + - '@ibexa.spi.persistence.legacy.language.handler' Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Handler: class: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Handler @@ -29,6 +30,5 @@ services: - '@ibexa.spi.persistence.legacy.language.handler' - '@Ibexa\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter' - '@ibexa.persistence.legacy.content.gateway' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' - '@Ibexa\Core\Persistence\Legacy\TransactionHandler' lazy: true diff --git a/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php b/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php index d2409bcdc0..137d024b1c 100644 --- a/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php +++ b/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php @@ -13,7 +13,6 @@ use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Handler as LanguageHandler; use Ibexa\Core\Persistence\Legacy\Content\Language\Mapper as LanguageMapper; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway\DoctrineDatabase; use Ibexa\Tests\Integration\Core\RepositoryTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -58,7 +57,7 @@ private function createGateway(Connection $connection): DoctrineDatabase new LanguageMapper() ); - return new DoctrineDatabase($connection, new LanguageMaskGenerator($languageHandler)); + return new DoctrineDatabase($connection, $languageHandler); } /** @@ -68,7 +67,8 @@ private function getUrlAliasValues(): array { return [ 'action' => 'nop:', - 'lang_mask' => 3, + 'language_ids' => [2], + 'is_always_available' => true, 'link' => 1, 'parent' => 0, 'text' => self::TEXT, diff --git a/tests/integration/Core/Repository/URLAliasServiceTest.php b/tests/integration/Core/Repository/URLAliasServiceTest.php index 8dda58f18e..0e9c16195c 100644 --- a/tests/integration/Core/Repository/URLAliasServiceTest.php +++ b/tests/integration/Core/Repository/URLAliasServiceTest.php @@ -1718,7 +1718,6 @@ private function insertBrokenUrlAliasTableFixtures(Connection $connection): int 'id' => 9997, 'is_alias' => 0, 'is_original' => 1, - 'lang_mask' => 3, 'link' => 9997, 'parent' => 0, 'text' => 'my-location', @@ -1732,7 +1731,6 @@ private function insertBrokenUrlAliasTableFixtures(Connection $connection): int 'id' => 9998, 'is_alias' => 1, 'is_original' => 1, - 'lang_mask' => 2, 'link' => 9995, 'parent' => 0, 'text' => 'my-alias1', @@ -1746,7 +1744,6 @@ private function insertBrokenUrlAliasTableFixtures(Connection $connection): int 'id' => 9999, 'is_alias' => 0, 'is_original' => 1, - 'lang_mask' => 3, 'link' => 9999, 'parent' => 9995, 'text' => 'my-alias2', diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index 5ee707838b..d9aa0159fa 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php @@ -10,7 +10,6 @@ use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Handler as LanguageHandler; use Ibexa\Core\Persistence\Legacy\Content\Language\Mapper as LanguageMapper; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway\DoctrineDatabase; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; @@ -29,6 +28,30 @@ class DoctrineDatabaseTest extends TestCase */ protected $gateway; + /** + * "ibexa_content_language" is never seeded by these fixtures (this test suite predates the + * gateway needing real Language rows at all) - FixtureImporter's language-mask backfill (see + * Ibexa\Contracts\Core\Test\Persistence\Fixture\FixtureImporter) needs at least one row per + * language id/bit actually used across the fixtures' "lang_mask" values (1, 2, 4, 8 cover every + * fixture in this directory) or it silently backfills nothing - seed it before loading the + * fixture (not part of the fixture's own table list, so it survives import()'s truncation). + */ + protected function insertDatabaseFixture(string $file): void + { + $connection = $this->getDatabaseConnection(); + // Some tests call insertDatabaseFixture() more than once (e.g. to layer a second fixture) - + // reset first so re-seeding these fixed ids doesn't violate the primary key. + $connection->executeStatement('DELETE FROM ibexa_content_language'); + foreach ([2, 4, 8, 16] as $languageId) { + $connection->executeStatement( + 'INSERT INTO ibexa_content_language (id, locale, name, disabled) VALUES (:id, :locale, :name, 0)', + ['id' => $languageId, 'locale' => "lang-{$languageId}", 'name' => "Language {$languageId}"] + ); + } + + parent::insertDatabaseFixture($file); + } + /** * Test for the loadUrlAliasData() method. */ @@ -61,7 +84,6 @@ public function testLoadUrlaliasData(): void 'ibexa_url_alias_ml0_is_original' => '1', 'ibexa_url_alias_ml0_action' => 'eznode:314', 'ibexa_url_alias_ml0_action_type' => 'eznode', - 'ibexa_url_alias_ml0_lang_mask' => '2', 'ibexa_url_alias_ml0_text' => 'jedan', 'ibexa_url_alias_ml0_parent' => '0', 'ibexa_url_alias_ml0_text_md5' => '6896260129051a949051c3847c34466f', @@ -72,10 +94,13 @@ public function testLoadUrlaliasData(): void 'is_original' => '1', 'action' => 'eznode:315', 'action_type' => 'eznode', - 'lang_mask' => '3', 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'ibexa_url_alias_ml0_is_always_available' => '0', + 'is_always_available' => '1', + 'ibexa_url_alias_ml0_lang_mask' => '2', + 'lang_mask' => '3', ], $row ); @@ -102,7 +127,6 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'ibexa_url_alias_ml0_is_original' => '1', 'ibexa_url_alias_ml0_action' => 'eznode:314', 'ibexa_url_alias_ml0_action_type' => 'eznode', - 'ibexa_url_alias_ml0_lang_mask' => '3', 'ibexa_url_alias_ml0_text' => 'jedan', 'ibexa_url_alias_ml0_parent' => '0', 'ibexa_url_alias_ml0_text_md5' => '6896260129051a949051c3847c34466f', @@ -113,10 +137,13 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'is_original' => '1', 'action' => 'eznode:315', 'action_type' => 'eznode', - 'lang_mask' => '6', 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'ibexa_url_alias_ml0_is_always_available' => '1', + 'is_always_available' => '0', + 'ibexa_url_alias_ml0_lang_mask' => '3', + 'lang_mask' => '6', ], $row ); @@ -132,7 +159,7 @@ public static function providerForTestLoadPathData(): array 2, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], ], ], @@ -140,11 +167,11 @@ public static function providerForTestLoadPathData(): array 3, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], [ - ['parent' => '2', 'lang_mask' => '5', 'text' => 'two'], - ['parent' => '2', 'lang_mask' => '3', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva'], ], ], ], @@ -152,16 +179,16 @@ public static function providerForTestLoadPathData(): array 4, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], [ - ['parent' => '2', 'lang_mask' => '5', 'text' => 'two'], - ['parent' => '2', 'lang_mask' => '3', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva'], ], [ - ['parent' => '3', 'lang_mask' => '9', 'text' => 'drei'], - ['parent' => '3', 'lang_mask' => '5', 'text' => 'three'], - ['parent' => '3', 'lang_mask' => '3', 'text' => 'tri'], + ['parent' => '3', 'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', 'is_always_available' => true, 'text' => 'drei'], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => true, 'text' => 'three'], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => true, 'text' => 'tri'], ], ], ], @@ -197,7 +224,7 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 2, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], ], ], @@ -205,10 +232,10 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 3, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], [ - ['parent' => '2', 'lang_mask' => '6', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva'], ], ], ], @@ -216,14 +243,14 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 4, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], ], [ - ['parent' => '2', 'lang_mask' => '6', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva'], ], [ - ['parent' => '3', 'lang_mask' => '4', 'text' => 'three'], - ['parent' => '3', 'lang_mask' => '2', 'text' => 'tri'], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => false, 'text' => 'three'], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => false, 'text' => 'tri'], ], ], ], @@ -348,13 +375,19 @@ public function testCleanupAfterPublishRemovesLanguage( $gateway = $this->getGateway(); $loadedRow = $gateway->loadRow($parentId, $textMD5); + $languageIdsBefore = $gateway->loadTranslationLanguageIds($parentId, $textMD5); $gateway->cleanupAfterPublish($action, $languageId, 42, $parentId, 'jabberwocky'); $reloadedRow = $gateway->loadRow($parentId, $textMD5); + $languageIdsAfter = $gateway->loadTranslationLanguageIds($parentId, $textMD5); $loadedRow['lang_mask'] = $loadedRow['lang_mask'] & ~$languageId; - self::assertEquals($reloadedRow, $loadedRow); + self::assertEquals($loadedRow, $reloadedRow); + self::assertEquals( + array_values(array_diff($languageIdsBefore, [$languageId])), + array_values($languageIdsAfter) + ); } /** @@ -382,6 +415,7 @@ public function testReparent(): void 'parent' => '42', 'text' => 'dva', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'is_always_available' => '1', ], $gateway->loadRow(42, 'c67ed9a09ab136fae610b6a087d82e21') ); @@ -485,14 +519,10 @@ public function testArchiveUrlAliasesForDeletedTranslations( } // check results - $languageMask = 0; - foreach ($removedLanguageIds as $languageId) { - $languageMask |= $languageId; - } foreach ($gateway->loadLocationEntries($locationId) as $row) { - self::assertNotEquals(0, (int) $row['lang_mask']); - self::assertNotEquals(1, (int) $row['lang_mask']); - self::assertEquals(0, (int) $row['lang_mask'] & $languageMask); + $languageIds = $gateway->loadTranslationLanguageIds((int) $row['parent'], $row['text_md5']); + self::assertNotEmpty($languageIds); + self::assertEmpty(array_intersect($languageIds, $removedLanguageIds)); } } @@ -508,7 +538,7 @@ protected function getGateway(): DoctrineDatabase ); $this->gateway = new DoctrineDatabase( $this->getDatabaseConnection(), - new LanguageMaskGenerator($languageHandler) + $languageHandler ); } diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index 27a488034e..543837b5ec 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -5266,9 +5266,6 @@ protected function countRows(): int /** @var LanguageHandler */ protected $languageHandler; - /** @var LanguageMaskGenerator */ - protected $languageMaskGenerator; - /** * @param array $methods * @@ -5285,7 +5282,6 @@ protected function getPartlyMockedHandler(array $methods) self::createStub(LanguageHandler::class), self::createStub(SlugConverter::class), self::createStub(Gateway::class), - self::createStub(LanguageMaskGenerator::class), self::createStub(TransactionHandler::class), ] ) @@ -5301,12 +5297,11 @@ protected function getPartlyMockedHandler(array $methods) protected function getHandler(): Handler { $languageHandler = $this->getLanguageHandler(); - $languageMaskGenerator = $this->getLanguageMaskGenerator(); $gateway = new DoctrineDatabase( $this->getDatabaseConnection(), - $languageMaskGenerator + $languageHandler ); - $mapper = new Mapper($languageMaskGenerator); + $mapper = new Mapper($gateway, $languageHandler); $slugConverter = new SlugConverter( $this->getProcessor(), ['transformation' => 'urlalias'] @@ -5317,7 +5312,7 @@ protected function getHandler(): Handler $this->getSharedGateway(), new ContentGateway\QueryBuilder($connection), $languageHandler, - $languageMaskGenerator, + new LanguageMaskGenerator($languageHandler), new FieldTypeAliasResolver(new FieldTypeAliasRegistry()) ); @@ -5328,7 +5323,6 @@ protected function getHandler(): Handler $languageHandler, $slugConverter, $contentGateway, - $languageMaskGenerator, self::createStub(TransactionHandler::class) ); } @@ -5347,20 +5341,6 @@ protected function getLanguageHandler(): LanguageHandler return $this->languageHandler; } - /** - * @return LanguageMaskGenerator - */ - protected function getLanguageMaskGenerator() - { - if (!isset($this->languageMaskGenerator)) { - $this->languageMaskGenerator = new LanguageMaskGenerator( - $this->getLanguageHandler() - ); - } - - return $this->languageMaskGenerator; - } - /** * @return LocationGateway */ diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php index 3e4857035a..9f5afd89fc 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php @@ -8,7 +8,7 @@ namespace Ibexa\Tests\Core\Persistence\Legacy\Content\UrlAlias; use Ibexa\Contracts\Core\Persistence\Content\UrlAlias; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; +use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper; use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -26,22 +26,32 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '100', + 'text_md5' => 'path-root_us', 'lang_mask' => 2, + 'is_always_available' => false, 'text' => 'root_us', ], [ + 'parent' => '100', + 'text_md5' => 'path-root_gb', 'lang_mask' => 4, + 'is_always_available' => false, 'text' => 'root_gb', ], ], 1 => [ [ + 'parent' => '101', + 'text_md5' => 'path-one', 'lang_mask' => 4, + 'is_always_available' => false, 'text' => 'one', ], ], ], 'lang_mask' => 5, + 'is_always_available' => true, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '0', @@ -53,12 +63,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '102', + 'text_md5' => 'path-two', 'lang_mask' => 3, + 'is_always_available' => true, 'text' => 'two', ], ], ], 'lang_mask' => 3, + 'is_always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -70,12 +84,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '103', + 'text_md5' => 'path-three', 'lang_mask' => 6, + 'is_always_available' => false, 'text' => 'three', ], ], ], 'lang_mask' => 6, + 'is_always_available' => false, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '1', @@ -87,12 +105,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '104', + 'text_md5' => 'path-four', 'lang_mask' => 1, + 'is_always_available' => true, 'text' => 'four', ], ], ], 'lang_mask' => 1, + 'is_always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -104,12 +126,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '105', + 'text_md5' => 'path-drei', 'lang_mask' => 8, + 'is_always_available' => false, 'text' => 'drei', ], ], ], 'lang_mask' => 8, + 'is_always_available' => false, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -288,8 +314,47 @@ public function testExtractLanguageCodesFromData(): void protected function getMapper() { $languageHandler = $this->getLanguageHandler(); - $languageMaskGenerator = new LanguageMaskGenerator($languageHandler); - return new Mapper($languageMaskGenerator); + $languageIdsByRow = []; + foreach ($this->fixture as $row) { + $languageIdsByRow[$row['parent'] . ':' . $row['text_md5']] + = $this->extractLanguageIdsFromMask($row['lang_mask']); + foreach ($row['raw_path_data'] as $pathLevel) { + foreach ($pathLevel as $pathRow) { + $languageIdsByRow[$pathRow['parent'] . ':' . $pathRow['text_md5']] + = $this->extractLanguageIdsFromMask($pathRow['lang_mask']); + } + } + } + + $gateway = $this->createMock(Gateway::class); + $gateway->method('loadTranslationLanguageIds')->willReturnCallback( + static function ( + int $parent, + string $textMd5 + ) use ($languageIdsByRow): array { + return $languageIdsByRow["{$parent}:{$textMd5}"] ?? []; + } + ); + + return new Mapper($gateway, $languageHandler); + } + + /** + * Decodes the fixture's legacy bitmask values into real (non-always-available) language ids, + * for driving the {@see Gateway::loadTranslationLanguageIds()} mock. + * + * @return int[] + */ + private function extractLanguageIdsFromMask(int $mask): array + { + $languageIds = []; + for ($languageId = 2; $languageId <= $mask; $languageId *= 2) { + if (($mask & $languageId) === $languageId) { + $languageIds[] = $languageId; + } + } + + return $languageIds; } } From e6e2fc23367237b8c44f18c20e42516180c0fb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 09:42:19 +0100 Subject: [PATCH 27/54] IBX-11939: Covered is_always_available in the language translation commands --- .../BackfillLanguageTranslationsCommand.php | 28 ++++++++----------- .../VerifyLanguageTranslationsCommand.php | 25 ++++++----------- ...ackfillLanguageTranslationsCommandTest.php | 1 + 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index fef42ec53d..90d3a82217 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -27,7 +27,8 @@ The command %command.name% 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" - and "ibexa_content_version" from bit 0 of "language_mask". It is idempotent - already-backfilled rows are + and "ibexa_content_version" and "is_always_available" on "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 ibexa:languages:verify-translations afterward to confirm the backfill is complete. @@ -122,7 +123,7 @@ private function backfillTable( 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', - null, + 'is_always_available', ], default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), }; @@ -160,27 +161,22 @@ private function backfillTable( for ($from = $minId; $from <= $maxId; $from += $batchSize) { $to = min($from + $batchSize - 1, $maxId); - $flagged = 0; if ($dryRun) { $inserted = (int)$this->connection->fetchOne( $this->buildDryRunCountSql($table, $languageTable), ['from' => $from, 'to' => $to] ); - if ($alwaysAvailableColumn !== null) { - $flagged = (int)$this->connection->fetchOne( - "SELECT COUNT(*) FROM {$sourceTable} WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}", - ['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]); - if ($alwaysAvailableColumn !== null) { - $flagged = $this->connection->executeStatement( - "UPDATE {$sourceTable} SET {$alwaysAvailableColumn} = (({$maskColumn} & 1) = 1) - WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}", - ['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; diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index 79ccf1bedf..4a221539b8 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -27,7 +27,7 @@ "language_mask"/"lang_mask" columns they were backfilled from, reporting: - missing: a language bit set in the mask with no corresponding translation row - orphaned: a translation row whose bit is no longer set in the mask - - wrong always-available flag: an "always_available" value that doesn't match bit 0 of the mask + - wrong always-available flag: an "always_available"/"is_always_available" value that doesn't match bit 0 of the mask Exits non-zero if any drift is found and --fix was not passed. Run this after ibexa:languages:backfill-translations, and again before relying on the translation @@ -50,20 +50,14 @@ final class VerifyLanguageTranslationsCommand ]; /** - * Table => [source table carrying the legacy mask, mask column]. + * Table => [source table carrying the legacy mask, mask column, always-available column]. * - * @var array + * @var array */ private const array SOURCE_TABLES = [ - self::TABLE_CONTENT => ['ibexa_content', 'language_mask'], - self::TABLE_CONTENT_VERSION => ['ibexa_content_version', 'language_mask'], - self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask'], - ]; - - /** @var array */ - private const array ALWAYS_AVAILABLE_COLUMNS = [ - self::TABLE_CONTENT => 'always_available', - self::TABLE_CONTENT_VERSION => 'always_available', + self::TABLE_CONTENT => ['ibexa_content', 'language_mask', 'always_available'], + self::TABLE_CONTENT_VERSION => ['ibexa_content_version', 'language_mask', 'always_available'], + self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask', 'is_always_available'], ]; /** @@ -212,7 +206,7 @@ private function verifyTable( bool $fix, OutputInterface $output ): bool { - [$sourceTable, $maskColumn] = self::SOURCE_TABLES[$table]; + [$sourceTable, $maskColumn, $alwaysAvailableColumn] = self::SOURCE_TABLES[$table]; if (!$this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn)) { $output->writeln("{$table}: {$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to verify."); @@ -223,14 +217,11 @@ private function verifyTable( $languageTable = self::LANGUAGE_TABLE; $queries = $this->buildQueries($table, $languageTable); - $alwaysAvailableColumn = self::ALWAYS_AVAILABLE_COLUMNS[$table] ?? null; $alwaysAvailableMismatch = "{$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)"; $missing = (int)$this->connection->fetchOne($queries['missing']); $orphaned = (int)$this->connection->fetchOne($queries['orphaned']); - $mismatched = $alwaysAvailableColumn === null - ? 0 - : (int)$this->connection->fetchOne("SELECT COUNT(*) FROM {$sourceTable} WHERE {$alwaysAvailableMismatch}"); + $mismatched = (int)$this->connection->fetchOne("SELECT COUNT(*) FROM {$sourceTable} WHERE {$alwaysAvailableMismatch}"); if ($missing === 0 && $orphaned === 0 && $mismatched === 0) { $output->writeln("{$table}: in sync."); diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 0fb80553f8..b1064e8f9f 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -111,6 +111,7 @@ public function testBackfillPopulatesTranslationTablesFromMasks(): void ); self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content_version')); + self::assertTrue((bool)$this->getDatabaseConnection()->fetchOne('SELECT is_always_available FROM ibexa_url_alias_ml')); } public function testBackfillIsIdempotent(): void From 1e0ee7aa508f2f873d1820f75b82d5cc759ba975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 09:43:48 +0100 Subject: [PATCH 28/54] IBX-11939: Chunked the URL alias always-available backfill by id --- ...UrlAliasAlwaysAvailableColumnMigration.php | 49 +++++++++---------- ...liasAlwaysAvailableColumnMigrationTest.php | 49 +++++++++++++++++++ 2 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php diff --git a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php index 3bccb6f19f..03c9c1483e 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php @@ -9,38 +9,21 @@ namespace Ibexa\Bundle\RepositoryInstaller\Migration; use DateTimeImmutable; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Schema; use Ibexa\Contracts\DoctrineMigrations\Migrations\AbstractSqlMigration; use Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationInterface; use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Adds an "is_always_available" boolean column to "ibexa_url_alias_ml", backfilled from bit 0 of - * its "lang_mask" column (part of step 6 of the language bitmask migration). "lang_mask" itself is - * left untouched by this migration - only the always-available flag moves off the bitmask; the mask - * keeps carrying language-membership bits until Step 7 introduces - * "ibexa_url_alias_ml_translation" writes/reads and drops the mask column entirely. - * - * The column add and its backfill are treated as two independent steps rather than one all-or- - * nothing unit: on MySQL, `ALTER TABLE`/`UPDATE` each auto-commit independently, so if the column - * add succeeds but the backfill fails, a retry must still backfill even though the column already - * exists - the column's presence alone is not proof the backfill ever completed. The backfill - * UPDATE is idempotent (derived only from "lang_mask", which this migration never modifies), so - * re-running it whenever this migration's up() executes at all is always safe. - * - * A schema installed through the SchemaBuilderEvent already has the column and no "lang_mask" left - * to backfill from, so the backfill is skipped there (a later "ibexa:doctrine:migrations:migrate" - * runs every migration over that schema). - * - * Guarded via the connection's schema manager rather than the injected $schema, because - * TaggedMigrationsRunner (the "ibexa:install" path) invokes up() with an empty Schema, so - * $schema->hasTable()/hasColumn() would always report false there. + * Adds an "is_always_available" column to "ibexa_url_alias_ml", backfilled from bit 0 of "lang_mask". */ final class AddUrlAliasAlwaysAvailableColumnMigration extends AbstractSqlMigration implements IbexaMigrationInterface { private const string TABLE = 'ibexa_url_alias_ml'; private const string ALWAYS_AVAILABLE_COLUMN = 'is_always_available'; private const string LANGUAGE_MASK_COLUMN = 'lang_mask'; + private const int BATCH_SIZE = 5000; public function getDescription(): string { @@ -57,6 +40,11 @@ public static function getCreationDate(): DateTimeImmutable return new DateTimeImmutable('2026-10-19 04:00:00'); } + public function isTransactional(): bool + { + return false; + } + public function up(Schema $schema): void { $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); @@ -85,11 +73,22 @@ public function up(Schema $schema): void return; } - $trueLiteral = $this->isPostgreSQL() ? 'true' : '1'; + $range = $this->connection->fetchAssociative('SELECT MIN(id) AS min_id, MAX(id) AS max_id FROM ' . self::TABLE); + if ($range === false || $range['min_id'] === null) { + return; + } - $this->addSql( - 'UPDATE ' . self::TABLE . ' SET ' . self::ALWAYS_AVAILABLE_COLUMN . - " = {$trueLiteral} WHERE (" . self::LANGUAGE_MASK_COLUMN . ' & 1) = 1' - ); + $maskBit = '((' . self::LANGUAGE_MASK_COLUMN . ' & 1) = 1)'; + $sql = 'UPDATE ' . self::TABLE . ' SET ' . self::ALWAYS_AVAILABLE_COLUMN . " = {$maskBit}" + . ' WHERE id BETWEEN :from AND :to AND ' . self::ALWAYS_AVAILABLE_COLUMN . " <> {$maskBit}"; + + $maxId = (int)$range['max_id']; + for ($from = (int)$range['min_id']; $from <= $maxId; $from += self::BATCH_SIZE) { + $this->addSql( + $sql, + ['from' => $from, 'to' => min($from + self::BATCH_SIZE - 1, $maxId)], + ['from' => ParameterType::INTEGER, 'to' => ParameterType::INTEGER] + ); + } } } diff --git a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php new file mode 100644 index 0000000000..6d42c9fa9b --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php @@ -0,0 +1,49 @@ +getDatabaseConnection(); + foreach ([1 => ['foo', 'acbd18db4cc2f85cedef654fccc4a4d8', 3], 5001 => ['bar', '37b51d194a7513e45b56f6524f2d51f2', 2]] as $id => [$text, $textMd5, $langMask]) { + $connection->insert('ibexa_url_alias_ml', [ + 'parent' => 0, + 'text_md5' => $textMd5, + 'id' => $id, + 'text' => $text, + 'action' => 'eznode:' . $id, + 'action_type' => 'eznode', + 'lang_mask' => $langMask, + ], ['lang_mask' => ParameterType::INTEGER]); + } + + $migration = new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext()); + $migration->up(new Schema()); + foreach ($migration->getSql() as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + + self::assertCount(2, $migration->getSql()); + self::assertEquals( + [1 => 1, 5001 => 0], + $connection->fetchAllKeyValue('SELECT id, is_always_available FROM ibexa_url_alias_ml ORDER BY id') + ); + } +} From 0a2ce8682b038cd9931cf237eed001021102ed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:04:09 +0100 Subject: [PATCH 29/54] IBX-13142: Loaded the URL alias languages for all returned rows in one query --- .../UrlAlias/Gateway/DoctrineDatabase.php | 87 +++++++++++++++++-- .../Legacy/Content/UrlAlias/Handler.php | 33 ++----- .../Legacy/Content/UrlAlias/Mapper.php | 22 ++--- .../storage_engines/legacy/url_alias.yml | 1 - .../UrlAlias/Gateway/DoctrineDatabaseTest.php | 38 ++++---- .../Content/UrlAlias/UrlAliasHandlerTest.php | 2 +- .../Content/UrlAlias/UrlAliasMapperTest.php | 31 ++----- 7 files changed, 119 insertions(+), 95 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index 844b01b380..e278de0f15 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -36,6 +36,8 @@ */ final class DoctrineDatabase extends Gateway { + private const int TRANSLATION_KEYS_BATCH_SIZE = 500; + /** * 2^30, since PHP_INT_MAX can cause overflows in DB systems, if PHP is run * on 64 bit systems. @@ -89,7 +91,7 @@ public function loadAllLocationEntries(int $locationId): array ->setParameter('action', "eznode:{$locationId}", ParameterType::STRING) ->setParameter('is_original', 1, ParameterType::INTEGER); - return $query->executeQuery()->fetchAllAssociative(); + return $this->withLanguageIds($query->executeQuery()->fetchAllAssociative()); } public function loadLocationEntries( @@ -142,7 +144,7 @@ public function loadLocationEntries( $statement = $query->executeQuery(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function listGlobalEntries( @@ -199,7 +201,7 @@ public function listGlobalEntries( } $statement = $query->executeQuery(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function isRootEntry(int $id): bool @@ -738,7 +740,7 @@ public function loadRow( $result = $query->executeQuery()->fetchAssociative(); - return false !== $result ? $result : []; + return false !== $result ? $this->withLanguageIds([$result])[0] : []; } public function loadUrlAliasData(array $urlHashes): array @@ -790,7 +792,7 @@ static function (string $columnName) use ($tableAlias): string { $result = $query->executeQuery()->fetchAssociative(); - return false !== $result ? $result : []; + return false !== $result ? $this->withLanguageIds([$result])[0] : []; } public function loadAutogeneratedEntry( @@ -833,7 +835,7 @@ public function loadAutogeneratedEntry( $entry = $query->executeQuery()->fetchAssociative(); - return false !== $entry ? $entry : []; + return false !== $entry ? $this->withLanguageIds([$entry])[0] : []; } public function loadPathData(int $id): array @@ -882,7 +884,7 @@ public function loadPathData(int $id): array array_unshift($pathData, $rows); } - return $pathData; + return $this->withLanguageIdsInPathData($pathData); } public function loadPathDataByHierarchy(array $hierarchyData): array @@ -945,7 +947,7 @@ public function loadPathDataByHierarchy(array $hierarchyData): array $data[] = $rowsMap[$levelData['action']]; } - return $data; + return $this->withLanguageIdsInPathData($data); } public function removeCustomAlias( @@ -1063,7 +1065,7 @@ public function loadAutogeneratedEntries( $statement = $query->executeQuery(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function getLocationContentMainLanguageId(int $locationId): int @@ -1626,4 +1628,71 @@ private function buildTranslationExistsCondition( return sprintf('EXISTS (%s)', $translationExistsSubQuery->getSQL()); } + + /** + * Attaches each row's translation language ids as "language_ids". + * + * @param array> $rows + * + * @return array> + */ + private function withLanguageIds(array $rows): array + { + $languageIds = []; + foreach (array_chunk($this->getTranslationKeys($rows), self::TRANSLATION_KEYS_BATCH_SIZE) as $keys) { + $parameters = []; + $types = []; + foreach ($keys as [$parent, $textMD5]) { + array_push($parameters, $parent, $textMD5); + array_push($types, ParameterType::INTEGER, ParameterType::STRING); + } + + $result = $this->connection->executeQuery( + 'SELECT parent, text_md5, language_id FROM ' . self::TRANSLATION_TABLE + . ' WHERE (parent, text_md5) IN (' . implode(', ', array_fill(0, count($keys), '(?, ?)')) . ')' + . ' ORDER BY language_id', + $parameters, + $types + ); + foreach ($result->iterateAssociative() as $translation) { + $languageIds[$translation['parent'] . '-' . $translation['text_md5']][] = (int)$translation['language_id']; + } + } + + foreach ($rows as &$row) { + $row['language_ids'] = $languageIds[$row['parent'] . '-' . $row['text_md5']] ?? []; + } + + return $rows; + } + + /** + * @param array> $rows + * + * @return list + */ + private function getTranslationKeys(array $rows): array + { + $keys = []; + foreach ($rows as $row) { + $keys[$row['parent'] . '-' . $row['text_md5']] = [(int)$row['parent'], (string)$row['text_md5']]; + } + + return array_values($keys); + } + + /** + * @param array>> $pathData + * + * @return array>> + */ + private function withLanguageIdsInPathData(array $pathData): array + { + $rows = $this->withLanguageIds(array_merge([], ...$pathData)); + foreach ($pathData as $level => $levelRows) { + $pathData[$level] = array_splice($rows, 0, count($levelRows)); + } + + return $pathData; + } } diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php index 6ccfab30fe..14938d3779 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -247,7 +247,7 @@ private function internalPublishUrlAliasForLocation( // If we are reusing existing location entry merge its existing real languages $languageIds = array_unique(array_merge( $languageIds, - $this->gateway->loadTranslationLanguageIds($parentId, $newTextMD5) + $row['language_ids'] )); } } elseif ($newId === null) { @@ -469,14 +469,11 @@ protected function createUrlAlias( } elseif ( $row['action'] === $action && (int)$row['is_alias'] === 1 && - !in_array($languageId, $this->gateway->loadTranslationLanguageIds($parentId, $topElementMD5), true) + !in_array($languageId, $row['language_ids'], true) ) { // add another language to the same custom alias $data['link'] = $id = $row['id']; - $data['language_ids'] = array_unique(array_merge( - $this->gateway->loadTranslationLanguageIds($parentId, $topElementMD5), - [$languageId] - )); + $data['language_ids'] = array_unique(array_merge($row['language_ids'], [$languageId])); $data['is_always_available'] = $alwaysAvailable || (bool)$row['is_always_available']; $this->gateway->updateRow( $parentId, @@ -851,17 +848,11 @@ private function historizeBeforeSwap( $location2Entries ) { foreach ($location1Entries as $row) { - $this->gateway->historizeBeforeSwap( - $row['action'], - $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) - ); + $this->gateway->historizeBeforeSwap($row['action'], $row['language_ids']); } foreach ($location2Entries as $row) { - $this->gateway->historizeBeforeSwap( - $row['action'], - $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) - ); + $this->gateway->historizeBeforeSwap($row['action'], $row['language_ids']); } } @@ -977,12 +968,8 @@ private function getLocationEntryInLanguage( ) { $entries = array_filter( $locationEntries, - function (array $row) use ($languageId): bool { - return in_array( - $languageId, - $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']), - true - ); + static function (array $row) use ($languageId): bool { + return in_array($languageId, $row['language_ids'], true); } ); @@ -1050,7 +1037,6 @@ protected function copySubtree( $newIdsMap[$oldParentAliasId] = $this->gateway->getNextId(); } - $row['language_ids'] = $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']); $row['action'] = $actionMap[$row['action']]; $row['parent'] = $newParentAliasId; $row['id'] = $row['link'] = $newIdsMap[$oldParentAliasId]; @@ -1095,8 +1081,6 @@ public function locationDeleted($locationId): array $action = 'eznode:' . $locationId; $entry = $this->gateway->loadAutogeneratedEntry($action); $entryId = $entry['id']; - // captured before removeSubtree() deletes the row (and cascades its translation rows away) - $entry['language_ids'] = $this->gateway->loadTranslationLanguageIds((int)$entry['parent'], $entry['text_md5']); $this->removeSubtree($entryId, $action, $entry['is_original']); @@ -1277,8 +1261,7 @@ private function internalPublishCustomUrlAliasForLocation( continue; } - $entryLanguageIds = $this->gateway->loadTranslationLanguageIds((int)$entry['parent'], $entry['text_md5']); - $intersectedLanguageIds = array_intersect($entryLanguageIds, $contentLanguageIds); + $intersectedLanguageIds = array_intersect($entry['language_ids'], $contentLanguageIds); if (empty($intersectedLanguageIds) && !$location->isAlwaysAvailable) { continue; diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php index 3a44157b29..097feb21da 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -15,17 +15,9 @@ */ class Mapper { - private Gateway $gateway; - - private LanguageHandler $languageHandler; - public function __construct( - Gateway $gateway, - LanguageHandler $languageHandler - ) { - $this->gateway = $gateway; - $this->languageHandler = $languageHandler; - } + private readonly LanguageHandler $languageHandler + ) {} /** * @param int[] $languageIds @@ -56,9 +48,7 @@ public function extractUrlAliasFromData($data) list($type, $destination) = $this->matchTypeAndDestination($data['action']); $urlAlias->id = $this->generateIdentityKey((int)$data['parent'], $data['text_md5']); $urlAlias->pathData = $this->normalizePathData($data['raw_path_data']); - $urlAlias->languageCodes = $this->loadLanguageCodes( - $this->gateway->loadTranslationLanguageIds((int)$data['parent'], $data['text_md5']) - ); + $urlAlias->languageCodes = $this->loadLanguageCodes($data['language_ids']); $urlAlias->alwaysAvailable = (bool)$data['is_always_available']; $urlAlias->isHistory = isset($data['is_path_history']) ? $data['is_path_history'] : !$data['is_original']; $urlAlias->isCustom = (bool)$data['is_alias']; @@ -97,7 +87,7 @@ public function extractLanguageCodesFromData(array $rows): array { $languageIds = []; foreach ($rows as $row) { - $languageIds[] = $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']); + $languageIds[] = $row['language_ids']; } return $this->loadLanguageCodes(array_unique(array_merge([], ...$languageIds))); @@ -179,9 +169,7 @@ protected function normalizePathDataRow( array &$pathElementData, array $row ) { - $languageCodes = $this->loadLanguageCodes( - $this->gateway->loadTranslationLanguageIds((int)$row['parent'], $row['text_md5']) - ); + $languageCodes = $this->loadLanguageCodes($row['language_ids']); $pathElementData['always-available'] = (bool)$row['is_always_available']; if (!empty($languageCodes)) { foreach ($languageCodes as $languageCode) { diff --git a/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml b/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml index 51ce44e7bb..6bf7aeefbc 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml @@ -18,7 +18,6 @@ services: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper: class: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper arguments: - - '@ibexa.persistence.legacy.url_alias.gateway' - '@ibexa.spi.persistence.legacy.language.handler' Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Handler: diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index d9aa0159fa..fe81340c79 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php @@ -97,6 +97,7 @@ public function testLoadUrlaliasData(): void 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'language_ids' => [2], 'ibexa_url_alias_ml0_is_always_available' => '0', 'is_always_available' => '1', 'ibexa_url_alias_ml0_lang_mask' => '2', @@ -140,6 +141,7 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'language_ids' => [2, 4], 'ibexa_url_alias_ml0_is_always_available' => '1', 'is_always_available' => '0', 'ibexa_url_alias_ml0_lang_mask' => '3', @@ -159,7 +161,7 @@ public static function providerForTestLoadPathData(): array 2, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -167,11 +169,11 @@ public static function providerForTestLoadPathData(): array 3, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two'], - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two', 'language_ids' => [4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva', 'language_ids' => [2]], ], ], ], @@ -179,16 +181,16 @@ public static function providerForTestLoadPathData(): array 4, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two'], - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two', 'language_ids' => [4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva', 'language_ids' => [2]], ], [ - ['parent' => '3', 'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', 'is_always_available' => true, 'text' => 'drei'], - ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => true, 'text' => 'three'], - ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => true, 'text' => 'tri'], + ['parent' => '3', 'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', 'is_always_available' => true, 'text' => 'drei', 'language_ids' => [8]], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => true, 'text' => 'three', 'language_ids' => [4]], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => true, 'text' => 'tri', 'language_ids' => [2]], ], ], ], @@ -224,7 +226,7 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 2, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -232,10 +234,10 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 3, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], ], ], @@ -243,14 +245,14 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 4, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], [ - ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => false, 'text' => 'three'], - ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => false, 'text' => 'tri'], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => false, 'text' => 'three', 'language_ids' => [4]], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => false, 'text' => 'tri', 'language_ids' => [2]], ], ], ], @@ -382,6 +384,7 @@ public function testCleanupAfterPublishRemovesLanguage( $reloadedRow = $gateway->loadRow($parentId, $textMD5); $languageIdsAfter = $gateway->loadTranslationLanguageIds($parentId, $textMD5); $loadedRow['lang_mask'] = $loadedRow['lang_mask'] & ~$languageId; + $loadedRow['language_ids'] = array_values(array_diff($loadedRow['language_ids'], [$languageId])); self::assertEquals($loadedRow, $reloadedRow); self::assertEquals( @@ -416,6 +419,7 @@ public function testReparent(): void 'text' => 'dva', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => '1', + 'language_ids' => [2], ], $gateway->loadRow(42, 'c67ed9a09ab136fae610b6a087d82e21') ); diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index 543837b5ec..7e904e23ef 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -5301,7 +5301,7 @@ protected function getHandler(): Handler $this->getDatabaseConnection(), $languageHandler ); - $mapper = new Mapper($gateway, $languageHandler); + $mapper = new Mapper($languageHandler); $slugConverter = new SlugConverter( $this->getProcessor(), ['transformation' => 'urlalias'] diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php index 9f5afd89fc..39061f3bee 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php @@ -8,7 +8,6 @@ namespace Ibexa\Tests\Core\Persistence\Legacy\Content\UrlAlias; use Ibexa\Contracts\Core\Persistence\Content\UrlAlias; -use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper; use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -313,37 +312,19 @@ public function testExtractLanguageCodesFromData(): void */ protected function getMapper() { - $languageHandler = $this->getLanguageHandler(); - - $languageIdsByRow = []; - foreach ($this->fixture as $row) { - $languageIdsByRow[$row['parent'] . ':' . $row['text_md5']] - = $this->extractLanguageIdsFromMask($row['lang_mask']); - foreach ($row['raw_path_data'] as $pathLevel) { - foreach ($pathLevel as $pathRow) { - $languageIdsByRow[$pathRow['parent'] . ':' . $pathRow['text_md5']] - = $this->extractLanguageIdsFromMask($pathRow['lang_mask']); + foreach ($this->fixture as &$row) { + $row['language_ids'] = $this->extractLanguageIdsFromMask($row['lang_mask']); + foreach ($row['raw_path_data'] as &$pathLevel) { + foreach ($pathLevel as &$pathRow) { + $pathRow['language_ids'] = $this->extractLanguageIdsFromMask($pathRow['lang_mask']); } } } - $gateway = $this->createMock(Gateway::class); - $gateway->method('loadTranslationLanguageIds')->willReturnCallback( - static function ( - int $parent, - string $textMd5 - ) use ($languageIdsByRow): array { - return $languageIdsByRow["{$parent}:{$textMd5}"] ?? []; - } - ); - - return new Mapper($gateway, $languageHandler); + return new Mapper($this->getLanguageHandler()); } /** - * Decodes the fixture's legacy bitmask values into real (non-always-available) language ids, - * for driving the {@see Gateway::loadTranslationLanguageIds()} mock. - * * @return int[] */ private function extractLanguageIdsFromMask(int $mask): array From b743220a1a09ae9557287c13858f84b2ada26b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:12:56 +0100 Subject: [PATCH 30/54] IBX-13142: Restored swapped custom aliases only in the languages they share with the new content --- .../Legacy/Content/UrlAlias/Handler.php | 15 +++------- .../UrlAlias/Gateway/DoctrineDatabaseTest.php | 12 ++++++++ .../Content/UrlAlias/UrlAliasHandlerTest.php | 30 +++++++++++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php index 14938d3779..19cbaee514 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -1241,14 +1241,7 @@ private function insertAliasEntryAsNop(array $aliasEntry): void } /** - * Internal publish custom aliases method, accepting the swapped Location's Content's real - * (non-always-available) language ids to set the correct languages on url aliases new alias ID - * (used when swapping Locations). - * - * $contentLanguageIds are the new Content's own real translation languages (from - * ibexa_content_translation) - $location->isAlwaysAvailable (set from the always_available - * column by locationSwapped()) is combined separately, since always-available is no longer part - * of a language id set. + * Restores the swapped Location's custom aliases in the languages they share with its new Content. * * @param int[] $contentLanguageIds */ @@ -1261,9 +1254,9 @@ private function internalPublishCustomUrlAliasForLocation( continue; } - $intersectedLanguageIds = array_intersect($entry['language_ids'], $contentLanguageIds); + $intersectedLanguageIds = array_values(array_intersect($entry['language_ids'], $contentLanguageIds)); - if (empty($intersectedLanguageIds) && !$location->isAlwaysAvailable) { + if (empty($intersectedLanguageIds)) { continue; } @@ -1275,7 +1268,7 @@ private function internalPublishCustomUrlAliasForLocation( 'is_original' => 1, 'is_alias' => 1, 'language_ids' => $intersectedLanguageIds, - 'is_always_available' => $location->isAlwaysAvailable, + 'is_always_available' => (bool)$entry['is_always_available'] && $location->isAlwaysAvailable, ] ); } diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index fe81340c79..2366c4c146 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php @@ -398,6 +398,18 @@ public function testCleanupAfterPublishRemovesLanguage( * * @todo document */ + public function testArchiveUrlAliasesForDeletedTranslationsHistorizesRowLosingAllLanguages(): void + { + $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_multilang.php'); + $gateway = $this->getGateway(); + + $gateway->archiveUrlAliasesForDeletedTranslations(315, 2, [2, 4]); + + $row = $gateway->loadRow(2, 'c67ed9a09ab136fae610b6a087d82e21'); + self::assertEquals(0, $row['is_original']); + self::assertEquals(3, $row['link']); + } + public function testReparent(): void { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_simple.php'); diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index 7e904e23ef..248e3aac4f 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -8,6 +8,7 @@ namespace Ibexa\Tests\Core\Persistence\Legacy\Content\UrlAlias; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\ParameterType; use Ibexa\Contracts\Core\Persistence\Content\UrlAlias; use Ibexa\Contracts\Core\Persistence\TransactionHandler; use Ibexa\Contracts\Core\Repository\Exceptions\BadStateException; @@ -3148,6 +3149,35 @@ public function testPublishUrlAliasForLocationSkipsReservedWord( self::assertEquals(['kli-KR'], $urlAlias->languageCodes); } + public function testLocationSwappedKeepsCustomAliasWithoutCommonLanguageHistorized(): void + { + $handler = $this->getHandler(); + $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple.php'); + $connection = $this->getDatabaseConnection(); + $connection->insert(LanguageGateway::CONTENT_LANGUAGE_TABLE, ['id' => 4, 'locale' => 'eng-GB', 'name' => 'English (UK)', 'disabled' => 0]); + $connection->update(Gateway::CONTENT_ITEM_TABLE, ['always_available' => true], ['id' => 3], ['always_available' => ParameterType::BOOLEAN]); + $connection->insert(UrlAliasGateway::TABLE, [ + 'action' => 'eznode:316', + 'action_type' => 'eznode', + 'alias_redirects' => 1, + 'id' => 6, + 'is_alias' => 1, + 'is_original' => 1, + 'is_always_available' => 1, + 'link' => 6, + 'parent' => 0, + 'text' => 'custom', + 'text_md5' => '8b9035807842a4e4dbe009f3f1478127', + ], ['is_always_available' => ParameterType::BOOLEAN]); + $connection->insert(UrlAliasGateway::TRANSLATION_TABLE, ['parent' => 0, 'text_md5' => '8b9035807842a4e4dbe009f3f1478127', 'language_id' => 4]); + + $handler->locationSwapped(316, 314, 317, 315); + + $row = (new DoctrineDatabase($connection, $this->getLanguageHandler()))->loadRow(0, '8b9035807842a4e4dbe009f3f1478127'); + self::assertEquals(0, $row['is_original']); + self::assertSame([4], $row['language_ids']); + } + /** * Test for the locationSwapped() method. */ From c8cdb104ab819cf3ccd34a75bf2b402ec5aea375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:24:02 +0100 Subject: [PATCH 31/54] IBX-13142: Renamed the URL alias is_always_available column to always_available Same flag as always_available on ibexa_content and ibexa_content_version. --- data/mysql/cleandata.sql | 2 +- data/postgresql/cleandata.sql | 2 +- .../BackfillLanguageTranslationsCommand.php | 10 ++--- .../VerifyLanguageTranslationsCommand.php | 4 +- .../config/storage/legacy/schema.yaml | 2 +- ...UrlAliasAlwaysAvailableColumnMigration.php | 6 +-- .../Persistence/Fixture/FixtureImporter.php | 4 +- .../UrlAlias/Gateway/DoctrineDatabase.php | 20 ++++----- .../Legacy/Content/UrlAlias/Handler.php | 14 +++--- .../Legacy/Content/UrlAlias/Mapper.php | 4 +- ...ackfillLanguageTranslationsCommandTest.php | 2 +- ...liasAlwaysAvailableColumnMigrationTest.php | 2 +- .../Legacy/UrlAliasGatewayTest.php | 2 +- .../UrlAlias/Gateway/DoctrineDatabaseTest.php | 44 +++++++++---------- .../Content/UrlAlias/UrlAliasHandlerTest.php | 4 +- .../Content/UrlAlias/UrlAliasMapperTest.php | 24 +++++----- 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/data/mysql/cleandata.sql b/data/mysql/cleandata.sql index 3dc90c8fa1..0a8ff87f31 100644 --- a/data/mysql/cleandata.sql +++ b/data/mysql/cleandata.sql @@ -280,7 +280,7 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `lang_mask`, `is_always_available`, `link`, `parent`, `text`, `text_md5`) +INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `lang_mask`, `always_available`, `link`, `parent`, `text`, `text_md5`) VALUES ('nop:','nop',1,17,0,0,1,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), ('eznode:43','eznode',1,9,0,1,3,1,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), ('nop:','nop',1,3,0,0,1,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), diff --git a/data/postgresql/cleandata.sql b/data/postgresql/cleandata.sql index 6193fbd2e7..0d74db889f 100644 --- a/data/postgresql/cleandata.sql +++ b/data/postgresql/cleandata.sql @@ -280,7 +280,7 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "lang_mask", "is_always_available", "link", "parent", "text", "text_md5") +INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "lang_mask", "always_available", "link", "parent", "text", "text_md5") VALUES ('nop:','nop',1,17,0,0,1,TRUE,17,0,'media2','50e2736330de124f6edea9b008556fe6'), ('eznode:43','eznode',1,9,0,1,3,TRUE,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), ('nop:','nop',1,3,0,0,1,TRUE,3,0,'users2','86425c35a33507d479f71ade53a669aa'), diff --git a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php index 90d3a82217..c6a7cd90e7 100644 --- a/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -26,10 +26,10 @@ help: <<<'EOT' The command %command.name% 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" - and "ibexa_content_version" and "is_always_available" on "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. + "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 ibexa:languages:verify-translations afterward to confirm the backfill is complete. EOT, @@ -123,7 +123,7 @@ private function backfillTable( 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', - 'is_always_available', + 'always_available', ], default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), }; diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php index 4a221539b8..cf47052387 100644 --- a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -27,7 +27,7 @@ "language_mask"/"lang_mask" columns they were backfilled from, reporting: - missing: a language bit set in the mask with no corresponding translation row - orphaned: a translation row whose bit is no longer set in the mask - - wrong always-available flag: an "always_available"/"is_always_available" value that doesn't match bit 0 of the mask + - wrong always-available flag: an "always_available" value that doesn't match bit 0 of the mask Exits non-zero if any drift is found and --fix was not passed. Run this after ibexa:languages:backfill-translations, and again before relying on the translation @@ -57,7 +57,7 @@ final class VerifyLanguageTranslationsCommand private const array SOURCE_TABLES = [ self::TABLE_CONTENT => ['ibexa_content', 'language_mask', 'always_available'], self::TABLE_CONTENT_VERSION => ['ibexa_content_version', 'language_mask', 'always_available'], - self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask', 'is_always_available'], + self::TABLE_URL_ALIAS => ['ibexa_url_alias_ml', 'lang_mask', 'always_available'], ]; /** diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index eb11a0e309..2701bdd342 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -619,7 +619,7 @@ tables: lang_mask: { type: bigint, nullable: false, options: { default: '0' } } link: { type: integer, nullable: false, options: { default: '0' } } text: { type: text, nullable: false, length: 0 } - is_always_available: { type: boolean, nullable: false, options: { default: false } } + always_available: { type: boolean, nullable: false, options: { default: false } } ibexa_url_alias_ml_incr: id: id: { type: integer, nullable: false, options: { autoincrement: true } } diff --git a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php index 03c9c1483e..ddd6cc894f 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php @@ -16,18 +16,18 @@ use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform; /** - * Adds an "is_always_available" column to "ibexa_url_alias_ml", backfilled from bit 0 of "lang_mask". + * Adds an "always_available" column to "ibexa_url_alias_ml", backfilled from bit 0 of "lang_mask". */ final class AddUrlAliasAlwaysAvailableColumnMigration extends AbstractSqlMigration implements IbexaMigrationInterface { private const string TABLE = 'ibexa_url_alias_ml'; - private const string ALWAYS_AVAILABLE_COLUMN = 'is_always_available'; + private const string ALWAYS_AVAILABLE_COLUMN = 'always_available'; private const string LANGUAGE_MASK_COLUMN = 'lang_mask'; private const int BATCH_SIZE = 5000; public function getDescription(): string { - return 'Adds "is_always_available" column to "ibexa_url_alias_ml", backfilled from the language mask'; + return 'Adds "always_available" column to "ibexa_url_alias_ml", backfilled from the language mask'; } public static function getTargetVersion(): string diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 37921ea865..032650e6e6 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -149,7 +149,7 @@ private function getExistingColumns(string $table): array } /** - * Fixture data predates "always_available"/"is_always_available" becoming plain columns and + * Fixture data predates "always_available" becoming plain columns and * the "ibexa_content_translation"/"ibexa_content_version_translation"/ * "ibexa_url_alias_ml_translation" join tables - it only ever set "language_mask"/"lang_mask", * which import() now silently drops (see getExistingColumns()) since the column may no longer @@ -239,7 +239,7 @@ private function backfillLanguageBitmaskColumns(array $nonEmptyTablesData): void } $mask = (int)$row['lang_mask']; $this->connection->executeStatement( - 'UPDATE ibexa_url_alias_ml SET is_always_available = :alwaysAvailable WHERE parent = :parent AND text_md5 = :textMd5', + 'UPDATE ibexa_url_alias_ml SET always_available = :alwaysAvailable WHERE parent = :parent AND text_md5 = :textMd5', ['alwaysAvailable' => ($mask & 1) === 1, 'parent' => $row['parent'], 'textMd5' => $row['text_md5']], ['alwaysAvailable' => ParameterType::BOOLEAN, 'parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] ); diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index e278de0f15..e2df8999b8 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -56,7 +56,7 @@ final class DoctrineDatabase extends Gateway 'text' => ParameterType::STRING, 'parent' => ParameterType::INTEGER, 'text_md5' => ParameterType::STRING, - 'is_always_available' => ParameterType::BOOLEAN, + 'always_available' => ParameterType::BOOLEAN, ]; private string $table; @@ -107,7 +107,7 @@ public function loadLocationEntries( 'link', 'is_alias', 'alias_redirects', - 'is_always_available', + 'always_available', 'is_original', 'parent', 'text', @@ -163,7 +163,7 @@ public function listGlobalEntries( 'link', 'is_alias', 'alias_redirects', - 'is_always_available', + 'always_available', 'is_original', 'parent', 'text_md5' @@ -631,7 +631,7 @@ private function doInsertRow(array $values): int } /** - * Keeps the legacy "lang_mask" in step with the row's translations and "is_always_available", + * Keeps the legacy "lang_mask" in step with the row's translations and "always_available", * for as long as the language bitmask is still around. * * @param array $values @@ -645,16 +645,16 @@ private function withLanguageMask( ?int $parentId = null, ?string $textMD5 = null ): array { - if (null === $languageIds && !array_key_exists('is_always_available', $values)) { + if (null === $languageIds && !array_key_exists('always_available', $values)) { return $values; } $existing = null !== $parentId && null !== $textMD5; $languageIds ??= $existing ? $this->loadTranslationLanguageIds($parentId, $textMD5) : []; - $alwaysAvailable = array_key_exists('is_always_available', $values) - ? (bool)$values['is_always_available'] + $alwaysAvailable = array_key_exists('always_available', $values) + ? (bool)$values['always_available'] : $existing && (bool)$this->connection->fetchOne( - 'SELECT is_always_available FROM ' . $this->connection->quoteSingleIdentifier($this->table) + 'SELECT always_available FROM ' . $this->connection->quoteSingleIdentifier($this->table) . ' WHERE parent = :parent AND text_md5 = :textMd5', ['parent' => $parentId, 'textMd5' => $textMD5], ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] @@ -847,7 +847,7 @@ public function loadPathData(int $id): array $query->select( 'parent', 'text_md5', - 'is_always_available', + 'always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) @@ -922,7 +922,7 @@ public function loadPathDataByHierarchy(array $hierarchyData): array 'action', 'parent', 'text_md5', - 'is_always_available', + 'always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php index 19cbaee514..e303bcf78d 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -205,7 +205,7 @@ private function internalPublishUrlAliasForLocation( 'parent' => $parentId, 'action' => $action, 'language_ids' => $languageIds, - 'is_always_available' => $alwaysAvailable, + 'always_available' => $alwaysAvailable, 'text' => $newText, 'text_md5' => $newTextMD5, ] @@ -263,7 +263,7 @@ private function internalPublishUrlAliasForLocation( // In case when NOP row was reused 'action_type' => 'eznode', 'language_ids' => $languageIds, - 'is_always_available' => $alwaysAvailable, + 'always_available' => $alwaysAvailable, // Updating text ensures that letter case changes are stored 'text' => $newText, // Set "id" and "link" for case when reusable entry is history @@ -451,14 +451,14 @@ protected function createUrlAlias( // If nothing was returned perform insert if ($isPathNew || empty($row)) { $data['language_ids'] = [$languageId]; - $data['is_always_available'] = $alwaysAvailable; + $data['always_available'] = $alwaysAvailable; $id = $this->gateway->insertRow($data); } elseif ($row['action'] === Gateway::NOP_ACTION || (int)$row['is_original'] === 0) { // Row exists, check if it is reusable. There are 2 cases when this is possible: // 1. NOP entry // 2. history entry $data['language_ids'] = [$languageId]; - $data['is_always_available'] = $alwaysAvailable; + $data['always_available'] = $alwaysAvailable; // If history is reused move link to id $data['link'] = $id = $row['id']; $this->gateway->updateRow( @@ -474,7 +474,7 @@ protected function createUrlAlias( // add another language to the same custom alias $data['link'] = $id = $row['id']; $data['language_ids'] = array_unique(array_merge($row['language_ids'], [$languageId])); - $data['is_always_available'] = $alwaysAvailable || (bool)$row['is_always_available']; + $data['always_available'] = $alwaysAvailable || (bool)$row['always_available']; $this->gateway->updateRow( $parentId, $topElementMD5, @@ -509,7 +509,7 @@ protected function insertNopEntry( return $this->gateway->insertRow( [ 'language_ids' => [], - 'is_always_available' => true, + 'always_available' => true, 'action' => Gateway::NOP_ACTION, 'parent' => $parentId, 'text' => $text, @@ -1268,7 +1268,7 @@ private function internalPublishCustomUrlAliasForLocation( 'is_original' => 1, 'is_alias' => 1, 'language_ids' => $intersectedLanguageIds, - 'is_always_available' => (bool)$entry['is_always_available'] && $location->isAlwaysAvailable, + 'always_available' => (bool)$entry['always_available'] && $location->isAlwaysAvailable, ] ); } diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php index 097feb21da..dfabc702cc 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -49,7 +49,7 @@ public function extractUrlAliasFromData($data) $urlAlias->id = $this->generateIdentityKey((int)$data['parent'], $data['text_md5']); $urlAlias->pathData = $this->normalizePathData($data['raw_path_data']); $urlAlias->languageCodes = $this->loadLanguageCodes($data['language_ids']); - $urlAlias->alwaysAvailable = (bool)$data['is_always_available']; + $urlAlias->alwaysAvailable = (bool)$data['always_available']; $urlAlias->isHistory = isset($data['is_path_history']) ? $data['is_path_history'] : !$data['is_original']; $urlAlias->isCustom = (bool)$data['is_alias']; $urlAlias->forward = $data['is_alias'] && $data['alias_redirects']; @@ -170,7 +170,7 @@ protected function normalizePathDataRow( array $row ) { $languageCodes = $this->loadLanguageCodes($row['language_ids']); - $pathElementData['always-available'] = (bool)$row['is_always_available']; + $pathElementData['always-available'] = (bool)$row['always_available']; if (!empty($languageCodes)) { foreach ($languageCodes as $languageCode) { $pathElementData['translations'][$languageCode] = $row['text']; diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index b1064e8f9f..5ac964d28a 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -111,7 +111,7 @@ public function testBackfillPopulatesTranslationTablesFromMasks(): void ); self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content')); self::assertSame([1 => false, 2 => true], $this->fetchAlwaysAvailable('ibexa_content_version')); - self::assertTrue((bool)$this->getDatabaseConnection()->fetchOne('SELECT is_always_available FROM ibexa_url_alias_ml')); + self::assertTrue((bool)$this->getDatabaseConnection()->fetchOne('SELECT always_available FROM ibexa_url_alias_ml')); } public function testBackfillIsIdempotent(): void diff --git a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php index 6d42c9fa9b..a3c61b5750 100644 --- a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php @@ -43,7 +43,7 @@ public function testBackfillsTheFlagInChunksById(): void self::assertCount(2, $migration->getSql()); self::assertEquals( [1 => 1, 5001 => 0], - $connection->fetchAllKeyValue('SELECT id, is_always_available FROM ibexa_url_alias_ml ORDER BY id') + $connection->fetchAllKeyValue('SELECT id, always_available FROM ibexa_url_alias_ml ORDER BY id') ); } } diff --git a/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php b/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php index 137d024b1c..07bbb494e8 100644 --- a/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php +++ b/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php @@ -68,7 +68,7 @@ private function getUrlAliasValues(): array return [ 'action' => 'nop:', 'language_ids' => [2], - 'is_always_available' => true, + 'always_available' => true, 'link' => 1, 'parent' => 0, 'text' => self::TEXT, diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index 2366c4c146..89f94a9f82 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php @@ -98,8 +98,8 @@ public function testLoadUrlaliasData(): void 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'language_ids' => [2], - 'ibexa_url_alias_ml0_is_always_available' => '0', - 'is_always_available' => '1', + 'ibexa_url_alias_ml0_always_available' => '0', + 'always_available' => '1', 'ibexa_url_alias_ml0_lang_mask' => '2', 'lang_mask' => '3', ], @@ -142,8 +142,8 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'language_ids' => [2, 4], - 'ibexa_url_alias_ml0_is_always_available' => '1', - 'is_always_available' => '0', + 'ibexa_url_alias_ml0_always_available' => '1', + 'always_available' => '0', 'ibexa_url_alias_ml0_lang_mask' => '3', 'lang_mask' => '6', ], @@ -161,7 +161,7 @@ public static function providerForTestLoadPathData(): array 2, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -169,11 +169,11 @@ public static function providerForTestLoadPathData(): array 3, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two', 'language_ids' => [4]], - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva', 'language_ids' => [2]], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'always_available' => true, 'text' => 'two', 'language_ids' => [4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => true, 'text' => 'dva', 'language_ids' => [2]], ], ], ], @@ -181,16 +181,16 @@ public static function providerForTestLoadPathData(): array 4, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'is_always_available' => true, 'text' => 'two', 'language_ids' => [4]], - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => true, 'text' => 'dva', 'language_ids' => [2]], + ['parent' => '2', 'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', 'always_available' => true, 'text' => 'two', 'language_ids' => [4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => true, 'text' => 'dva', 'language_ids' => [2]], ], [ - ['parent' => '3', 'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', 'is_always_available' => true, 'text' => 'drei', 'language_ids' => [8]], - ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => true, 'text' => 'three', 'language_ids' => [4]], - ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => true, 'text' => 'tri', 'language_ids' => [2]], + ['parent' => '3', 'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', 'always_available' => true, 'text' => 'drei', 'language_ids' => [8]], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'always_available' => true, 'text' => 'three', 'language_ids' => [4]], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'always_available' => true, 'text' => 'tri', 'language_ids' => [2]], ], ], ], @@ -226,7 +226,7 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 2, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -234,10 +234,10 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 3, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], ], ], @@ -245,14 +245,14 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 4, [ [ - ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'is_always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'is_always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], [ - ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'is_always_available' => false, 'text' => 'three', 'language_ids' => [4]], - ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'is_always_available' => false, 'text' => 'tri', 'language_ids' => [2]], + ['parent' => '3', 'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', 'always_available' => false, 'text' => 'three', 'language_ids' => [4]], + ['parent' => '3', 'text_md5' => 'd2cfe69af2d64330670e08efb2c86df7', 'always_available' => false, 'text' => 'tri', 'language_ids' => [2]], ], ], ], @@ -430,7 +430,7 @@ public function testReparent(): void 'parent' => '42', 'text' => 'dva', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', - 'is_always_available' => '1', + 'always_available' => '1', 'language_ids' => [2], ], $gateway->loadRow(42, 'c67ed9a09ab136fae610b6a087d82e21') diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index 248e3aac4f..ce28c65e61 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -3163,12 +3163,12 @@ public function testLocationSwappedKeepsCustomAliasWithoutCommonLanguageHistoriz 'id' => 6, 'is_alias' => 1, 'is_original' => 1, - 'is_always_available' => 1, + 'always_available' => 1, 'link' => 6, 'parent' => 0, 'text' => 'custom', 'text_md5' => '8b9035807842a4e4dbe009f3f1478127', - ], ['is_always_available' => ParameterType::BOOLEAN]); + ], ['always_available' => ParameterType::BOOLEAN]); $connection->insert(UrlAliasGateway::TRANSLATION_TABLE, ['parent' => 0, 'text_md5' => '8b9035807842a4e4dbe009f3f1478127', 'language_id' => 4]); $handler->locationSwapped(316, 314, 317, 315); diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php index 39061f3bee..4f9060d086 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php @@ -28,14 +28,14 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '100', 'text_md5' => 'path-root_us', 'lang_mask' => 2, - 'is_always_available' => false, + 'always_available' => false, 'text' => 'root_us', ], [ 'parent' => '100', 'text_md5' => 'path-root_gb', 'lang_mask' => 4, - 'is_always_available' => false, + 'always_available' => false, 'text' => 'root_gb', ], ], @@ -44,13 +44,13 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '101', 'text_md5' => 'path-one', 'lang_mask' => 4, - 'is_always_available' => false, + 'always_available' => false, 'text' => 'one', ], ], ], 'lang_mask' => 5, - 'is_always_available' => true, + 'always_available' => true, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '0', @@ -65,13 +65,13 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '102', 'text_md5' => 'path-two', 'lang_mask' => 3, - 'is_always_available' => true, + 'always_available' => true, 'text' => 'two', ], ], ], 'lang_mask' => 3, - 'is_always_available' => true, + 'always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -86,13 +86,13 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '103', 'text_md5' => 'path-three', 'lang_mask' => 6, - 'is_always_available' => false, + 'always_available' => false, 'text' => 'three', ], ], ], 'lang_mask' => 6, - 'is_always_available' => false, + 'always_available' => false, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '1', @@ -107,13 +107,13 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '104', 'text_md5' => 'path-four', 'lang_mask' => 1, - 'is_always_available' => true, + 'always_available' => true, 'text' => 'four', ], ], ], 'lang_mask' => 1, - 'is_always_available' => true, + 'always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -128,13 +128,13 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'parent' => '105', 'text_md5' => 'path-drei', 'lang_mask' => 8, - 'is_always_available' => false, + 'always_available' => false, 'text' => 'drei', ], ], ], 'lang_mask' => 8, - 'is_always_available' => false, + 'always_available' => false, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', From 2ac98dcfe926e001e062559d8ffac1b2b1ce8ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:29:07 +0100 Subject: [PATCH 32/54] IBX-13142: Promoted the constructor properties and declared strict types in the URL alias handler and mapper --- phpstan-baseline.neon | 14 +--- .../Legacy/Content/UrlAlias/Handler.php | 84 +++---------------- .../Legacy/Content/UrlAlias/Mapper.php | 1 + 3 files changed, 12 insertions(+), 87 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f7d2fc2104..36be585d92 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12877,13 +12877,7 @@ parameters: path: src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php - - message: '#^Parameter \#1 \$languageCode of method Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\CachingHandler\:\:loadByLanguageCode\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php - - - - message: '#^Parameter \#1 \$parentId of method Ibexa\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Gateway\:\:removeCustomAlias\(\) expects int, string given\.$#' + message: '#^Parameter \#1 \$languageCode of method Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\:\:loadByLanguageCode\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -12894,12 +12888,6 @@ parameters: count: 3 path: src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php - - - message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Handler\:\:\$languageHandler \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\CachingHandler\) does not accept Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Mapper\:\:extractLanguageCodesFromData\(\) has parameter \$rows with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php index e303bcf78d..d79f6abb71 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -4,6 +4,7 @@ * @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\Core\Persistence\Legacy\Content\UrlAlias; @@ -18,7 +19,6 @@ use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\CachingHandler; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\DTO\SwappedLocationProperties; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\DTO\UrlAliasForSwappedLocation; @@ -53,79 +53,15 @@ class Handler implements UrlAliasHandlerInterface */ public const URL_ALIAS_ID_PATTERN = '/^\d+-[a-f0-9]{32}$/'; - /** - * UrlAlias Gateway. - * - * @var Gateway - */ - protected $gateway; - - /** - * Gateway for handling location data. - * - * @var LocationGateway - */ - protected $locationGateway; - - /** - * UrlAlias Mapper. - * - * @var Mapper - */ - protected $mapper; - - /** - * Caching language handler. - * - * @var CachingHandler - */ - protected $languageHandler; - - /** - * URL slug converter. - * - * @var SlugConverter - */ - protected $slugConverter; - - /** - * Gateway for handling content data. - * - * @var ContentGateway - */ - protected $contentGateway; - - /** @var TransactionHandler */ - private $transactionHandler; - - /** - * Creates a new UrlAlias Handler. - * - * @param Gateway $gateway - * @param Mapper $mapper - * @param LocationGateway $locationGateway - * @param LanguageHandler $languageHandler - * @param SlugConverter $slugConverter - * @param ContentGateway $contentGateway - * @param TransactionHandler $transactionHandler - */ public function __construct( - Gateway $gateway, - Mapper $mapper, - LocationGateway $locationGateway, - LanguageHandler $languageHandler, - SlugConverter $slugConverter, - ContentGateway $contentGateway, - TransactionHandler $transactionHandler - ) { - $this->gateway = $gateway; - $this->mapper = $mapper; - $this->locationGateway = $locationGateway; - $this->languageHandler = $languageHandler; - $this->slugConverter = $slugConverter; - $this->contentGateway = $contentGateway; - $this->transactionHandler = $transactionHandler; - } + protected Gateway $gateway, + protected Mapper $mapper, + protected LocationGateway $locationGateway, + protected LanguageHandler $languageHandler, + protected SlugConverter $slugConverter, + protected ContentGateway $contentGateway, + private TransactionHandler $transactionHandler + ) {} public function publishUrlAliasForLocation( $locationId, @@ -578,7 +514,7 @@ public function removeURLAliases(array $urlAliases): bool foreach ($urlAliases as $urlAlias) { if ($urlAlias->isCustom) { list($parentId, $textMD5) = explode('-', $urlAlias->id); - if (!$this->gateway->removeCustomAlias($parentId, $textMD5)) { + if (!$this->gateway->removeCustomAlias((int)$parentId, $textMD5)) { return false; } } diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php index dfabc702cc..d16f81307f 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -4,6 +4,7 @@ * @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\Core\Persistence\Legacy\Content\UrlAlias; From 35889e48af8bad3969e677251a267a9a804e134a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 15:04:50 +0100 Subject: [PATCH 33/54] IBX-13142: Replaced the deprecated introspectTable() calls with introspectTableByUnquotedName() --- .../Migration/AddUrlAliasAlwaysAvailableColumnMigration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php index ddd6cc894f..f5c4175fdb 100644 --- a/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php @@ -55,7 +55,7 @@ public function up(Schema $schema): void return; } - $table = $schemaManager->introspectTable(self::TABLE); + $table = $schemaManager->introspectTableByUnquotedName(self::TABLE); if (!$table->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { $columnDefinition = match (true) { From 5337aadfb22563a8684a69ec19a342c2f540ea24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 20:45:04 +0100 Subject: [PATCH 34/54] IBX-11939: Moved content types off the language bitmask Content types read their languages from ibexa_content_type_name instead of decoding the type's language_mask, and resolve language ids through the language handler instead of MaskGenerator. They keep writing the mask and the always-available bit of their name rows until the bitmask is removed. --- phpstan-baseline.neon | 6 -- .../Legacy/Content/Type/Gateway.php | 11 +++ .../Content/Type/Gateway/DoctrineDatabase.php | 67 +++++++++++++++---- .../Type/Gateway/ExceptionConversion.php | 9 +++ .../Legacy/Content/Type/Mapper.php | 53 ++++++++------- .../storage_engines/legacy/content_type.yml | 5 +- .../Type/Gateway/DoctrineDatabaseTest.php | 8 +-- .../Legacy/Content/Type/MapperTest.php | 45 ++++++++++--- .../Content/Type/_fixtures/map_load_type.php | 4 -- .../Legacy/Content/AbstractTestCase.php | 17 +++-- 10 files changed, 154 insertions(+), 71 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 36be585d92..937e499a1b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -33480,12 +33480,6 @@ parameters: count: 1 path: tests/lib/Persistence/Legacy/Content/Type/MapperTest.php - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Type\\MapperTest\:\:getMaskGeneratorMock\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/Persistence/Legacy/Content/Type/MapperTest.php - - message: '#^Call to an undefined method Ibexa\\Core\\Persistence\\Legacy\\Content\\Type\\ContentUpdater\:\:expects\(\)\.$#' identifier: method.notFound diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway.php b/src/lib/Persistence/Legacy/Content/Type/Gateway.php index 2891a033db..276569afaa 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway.php @@ -164,6 +164,17 @@ abstract public function loadTypeDataByRemoteId( int $status ): array; + /** + * Loads the language codes each of the given (Type id, status) pairs is translated into, from + * ibexa_content_type_name - the relational replacement for decoding + * ibexa_content_type.language_mask. + * + * @param array $typeIdStatusPairs + * + * @return array "{typeId}:{status}" => language codes + */ + abstract public function loadContentTypeTranslations(array $typeIdStatusPairs): array; + abstract public function countInstancesOfType(int $typeId): int; /** diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php index 3f287ff47f..935604558a 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Types\Types; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Type; use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; use Ibexa\Contracts\Core\Persistence\Content\Type\Group; @@ -25,7 +26,6 @@ use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\MultilingualStorageFieldDefinition; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition; use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway; @@ -103,7 +103,7 @@ final class DoctrineDatabase extends Gateway public function __construct( private readonly Connection $connection, private readonly SharedGateway $sharedGateway, - private readonly MaskGenerator $languageMaskGenerator, + private readonly LanguageHandler $languageHandler, private readonly CriterionVisitor\CriterionVisitor $criterionVisitor ) {} @@ -295,13 +295,9 @@ private function insertTypeNameData( ParameterType::INTEGER ), 'language_id' => $query->createPositionalParameter( - $this->languageMaskGenerator->generateLanguageIndicator( - $language, - $this->languageMaskGenerator->isLanguageAlwaysAvailable( - $language, - $languages - ) - ), + // the legacy "always available" bit stays until the language bitmask goes + $this->languageHandler->loadByLanguageCode($language)->id + | (($languages['always-available'] ?? null) === $language ? 1 : 0), ParameterType::INTEGER ), 'language_locale' => $query->createPositionalParameter( @@ -423,7 +419,7 @@ private function mapCommonContentTypeColumnsToQueryValuesAndTypes(Type $type): a 'contentobject_name' => [$type->nameSchema, ParameterType::STRING], 'is_container' => [(int)$type->isContainer, ParameterType::INTEGER], 'language_mask' => [ - $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( + $this->generateLanguageMask( $type->languageCodes, array_key_exists('always-available', $type->name) ), @@ -436,6 +432,23 @@ private function mapCommonContentTypeColumnsToQueryValuesAndTypes(Type $type): a ]; } + /** + * Keeps the legacy "language_mask" up to date for as long as the language bitmask is around. + * + * @param string[] $languageCodes + */ + private function generateLanguageMask( + array $languageCodes, + bool $alwaysAvailable + ): int { + $languageMask = $alwaysAvailable ? 1 : 0; + foreach ($languageCodes as $languageCode) { + $languageMask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; + } + + return $languageMask; + } + public function insertGroupAssignment( int $groupId, int $typeId, @@ -1039,6 +1052,35 @@ public function loadTypeDataByRemoteId( return $query->executeQuery()->fetchAllAssociative(); } + public function loadContentTypeTranslations(array $typeIdStatusPairs): array + { + if (empty($typeIdStatusPairs)) { + return []; + } + + $typeIds = array_unique(array_column($typeIdStatusPairs, 'id')); + $statuses = array_unique(array_column($typeIdStatusPairs, 'status')); + + $query = $this->connection->createQueryBuilder(); + $query + ->select('content_type_id', 'content_type_status', 'language_locale') + ->from(self::CONTENT_TYPE_NAME_TABLE) + ->where( + $query->expr()->in('content_type_id', $query->createNamedParameter($typeIds, ArrayParameterType::INTEGER)) + ) + ->andWhere( + $query->expr()->in('content_type_status', $query->createNamedParameter($statuses, ArrayParameterType::INTEGER)) + ); + + $translations = []; + foreach ($query->executeQuery()->fetchAllAssociative() as $row) { + $key = $row['content_type_id'] . ':' . $row['content_type_status']; + $translations[$key][] = $row['language_locale']; + } + + return $translations; + } + /** * Return a basic query to retrieve Type data. */ @@ -1065,7 +1107,6 @@ private function getLoadTypeQueryBuilder(): QueryBuilder 'c.always_available AS content_type_always_available', 'c.sort_field AS content_type_sort_field', 'c.sort_order AS content_type_sort_order', - 'c.language_mask AS content_type_language_mask', 'a.id AS content_type_field_definition_id', 'a.serialized_name_list AS content_type_field_definition_serialized_name_list', 'a.serialized_description_list AS content_type_field_definition_serialized_description_list', @@ -1404,9 +1445,7 @@ public function removeFieldDefinitionTranslation( string $languageCode, int $status ): void { - $languageId = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - [$languageCode] - ); + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; $deleteQuery = $this->connection->createQueryBuilder(); $deleteQuery diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php index 574e9baa3f..d37df9ab92 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php @@ -278,6 +278,15 @@ public function loadTypeDataByRemoteId( } } + public function loadContentTypeTranslations(array $typeIdStatusPairs): array + { + try { + return $this->innerGateway->loadContentTypeTranslations($typeIdStatusPairs); + } catch (DBALException | PDOException $e) { + throw DatabaseException::wrap($e); + } + } + public function loadTypesDataByFieldDefinitionIdentifier(string $identifier): array { try { diff --git a/src/lib/Persistence/Legacy/Content/Type/Mapper.php b/src/lib/Persistence/Legacy/Content/Type/Mapper.php index faf2a3fe35..3e44589e3e 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Type/Mapper.php @@ -7,6 +7,7 @@ namespace Ibexa\Core\Persistence\Legacy\Content\Type; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Type; use Ibexa\Contracts\Core\Persistence\Content\Type\CreateStruct; use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; @@ -15,7 +16,6 @@ use Ibexa\Contracts\Core\Persistence\Content\Type\UpdateStruct; use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\MultilingualStorageFieldDefinition; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition; @@ -33,25 +33,22 @@ class Mapper */ protected $converterRegistry; - /** @var MaskGenerator */ - private $maskGenerator; + private Gateway $gateway; + + private LanguageHandler $languageHandler; private StorageDispatcherInterface $storageDispatcher; - /** - * Creates a new content type mapper. - * - * @param ConverterRegistry $converterRegistry - * @param MaskGenerator $maskGenerator - */ public function __construct( ConverterRegistry $converterRegistry, - MaskGenerator $maskGenerator, + Gateway $gateway, + LanguageHandler $languageHandler, StorageDispatcherInterface $storageDispatcher, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver ) { $this->converterRegistry = $converterRegistry; - $this->maskGenerator = $maskGenerator; + $this->gateway = $gateway; + $this->languageHandler = $languageHandler; $this->storageDispatcher = $storageDispatcher; } @@ -134,10 +131,20 @@ public function extractTypesFromRows( $rowsByAttributeId[$attributeId][] = $row; } + $typeIdStatusPairs = []; + foreach ($rows as $row) { + $typeIdStatusPairs[$row['content_type_id'] . ':' . $row['content_type_status']] = [ + 'id' => (int)$row['content_type_id'], + 'status' => (int)$row['content_type_status'], + ]; + } + $typeTranslations = $this->gateway->loadContentTypeTranslations(array_values($typeIdStatusPairs)); + foreach ($rows as $row) { $typeId = (int)$row['content_type_id']; if (!isset($types[$typeId])) { - $types[$typeId] = $this->extractTypeFromRow($row); + $languageCodes = $typeTranslations[$row['content_type_id'] . ':' . $row['content_type_status']] ?? []; + $types[$typeId] = $this->extractTypeFromRow($row, $languageCodes); } $fieldId = (int)$row['content_type_field_definition_id']; @@ -185,11 +192,12 @@ public function extractMultilingualData(array $fieldDefinitionRows): array * Creates a Type from the data in $row. * * @param array $row - * - * @return Type + * @param string[] $languageCodes */ - protected function extractTypeFromRow(array $row) - { + protected function extractTypeFromRow( + array $row, + array $languageCodes = [] + ): Type { $type = new Type(); $type->id = (int)$row['content_type_id']; @@ -216,7 +224,7 @@ protected function extractTypeFromRow(array $row) $type->defaultAlwaysAvailable = ($row['content_type_always_available'] == 1); $type->sortField = (int)$row['content_type_sort_field']; $type->sortOrder = (int)$row['content_type_sort_order']; - $type->languageCodes = $this->maskGenerator->extractLanguageCodesFromMask((int)$row['content_type_language_mask']); + $type->languageCodes = $languageCodes; $type->groupIds = []; $type->fieldDefinitions = []; @@ -266,8 +274,7 @@ public function extractFieldFromRow( $field->isSearchable = (bool)$row['content_type_field_definition_is_searchable']; $field->position = (int)$row['content_type_field_definition_placement']; - $mainLanguageCode = $this->maskGenerator->extractLanguageCodesFromMask((int)$row['content_type_initial_language_id']); - $field->mainLanguageCode = array_shift($mainLanguageCode); + $field->mainLanguageCode = $this->languageHandler->load((int)$row['content_type_initial_language_id'])->languageCode; $this->toFieldDefinition($storageFieldDef, $field, $status); @@ -320,12 +327,12 @@ protected function extractStorageFieldFromRow( $storageFieldDef->serializedDataText = $row['content_type_field_definition_serialized_data_text']; foreach ($multilingualDataRow as $languageDataRow) { - $languageCodes = $this->maskGenerator->extractLanguageCodesFromMask((int)$languageDataRow['content_type_field_definition_multilingual_language_id']); + $multilingualLanguageId = (int)($languageDataRow['content_type_field_definition_multilingual_language_id'] ?? 0); - if (empty($languageCodes)) { + if ($multilingualLanguageId === 0) { continue; } - $languageCode = reset($languageCodes); + $languageCode = $this->languageHandler->load($multilingualLanguageId)->languageCode; $multilingualData = new MultilingualStorageFieldDefinition(); @@ -455,7 +462,7 @@ public function toStorageFieldDefinition( $multilingualData->name = $fieldDef->name[$languageCode]; $multilingualData->description = $fieldDef->description[$languageCode] ?? null; $multilingualData->languageId = - $this->maskGenerator->generateLanguageMaskFromLanguageCodes([$languageCode]); + $this->languageHandler->loadByLanguageCode($languageCode)->id; $storageFieldDef->multilingualData[$languageCode] = $multilingualData; } diff --git a/src/lib/Resources/settings/storage_engines/legacy/content_type.yml b/src/lib/Resources/settings/storage_engines/legacy/content_type.yml index 1fe117e080..ede412e529 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content_type.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content_type.yml @@ -18,7 +18,7 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase arguments: $sharedGateway: '@Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway' - $languageMaskGenerator: '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + $languageHandler: '@ibexa.spi.persistence.legacy.language.handler' $criterionVisitor: '@Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor' Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\ExceptionConversion: @@ -34,7 +34,8 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\Type\Mapper arguments: - '@Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + - '@ibexa.persistence.legacy.content_type.gateway' + - '@ibexa.spi.persistence.legacy.language.handler' - '@Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' diff --git a/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php index 693e8936ac..8e90b847e0 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php @@ -358,7 +358,7 @@ public function testLoadTypeData(): void $rows ); self::assertCount( - 50, + 49, $rows[0] ); @@ -386,7 +386,7 @@ public function testLoadTypeDataByIdentifier(): void $rows ); self::assertCount( - 50, + 49, $rows[0] ); } @@ -405,7 +405,7 @@ public function testLoadTypeDataByRemoteId(): void $rows ); self::assertCount( - 50, + 49, $rows[0] ); } @@ -1154,7 +1154,7 @@ protected function getGateway(): DoctrineDatabase $this->gateway = new DoctrineDatabase( $this->getDatabaseConnection(), $this->getSharedGateway(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getCriterionVisitor() ); } diff --git a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php index 8a4390b80d..4509c3761d 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php @@ -7,6 +7,8 @@ namespace Ibexa\Tests\Core\Persistence\Legacy\Content\Type; +use Ibexa\Contracts\Core\Persistence\Content\Language as LanguageValueObject; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\Location; use Ibexa\Contracts\Core\Persistence\Content\Type; use Ibexa\Contracts\Core\Persistence\Content\Type\CreateStruct; @@ -20,8 +22,8 @@ use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition; +use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway; use Ibexa\Core\Persistence\Legacy\Content\Type\Mapper; use Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; @@ -37,7 +39,8 @@ public function testCreateGroupFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -93,7 +96,8 @@ public function testTypeFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -114,7 +118,8 @@ public function testTypeFromUpdateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -204,7 +209,8 @@ public function testCreateStructFromType(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -272,7 +278,8 @@ public function testExtractGroupsFromRows(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -401,7 +408,8 @@ public function testToStorageFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -438,7 +446,8 @@ public function testToFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $storageDispatcher, $this->getFieldTypeAliasResolver(), ); @@ -456,7 +465,8 @@ protected function getNonConvertingMapper() $mapper = $this->getMockBuilder(Mapper::class) ->setConstructorArgs([ $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getContentTypeGatewayMock(), + $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ]) @@ -511,9 +521,22 @@ protected function getLoadGroupFixture() return require __DIR__ . '/_fixtures/map_load_group.php'; } - protected function getMaskGeneratorMock() + protected function getContentTypeGatewayMock(): Gateway { - return $this->createMock(MaskGenerator::class); + return $this->createMock(Gateway::class); + } + + protected function getLanguageHandlerMock(): LanguageHandler + { + $language = new LanguageValueObject(); + $language->id = 2; + $language->languageCode = 'eng-US'; + + $languageHandler = $this->createMock(LanguageHandler::class); + $languageHandler->method('load')->willReturn($language); + $languageHandler->method('loadByLanguageCode')->willReturn($language); + + return $languageHandler; } /** diff --git a/tests/lib/Persistence/Legacy/Content/Type/_fixtures/map_load_type.php b/tests/lib/Persistence/Legacy/Content/Type/_fixtures/map_load_type.php index a344ca1ede..8478ddde97 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/_fixtures/map_load_type.php +++ b/tests/lib/Persistence/Legacy/Content/Type/_fixtures/map_load_type.php @@ -16,7 +16,6 @@ 'content_type_identifier' => 'folder', 'content_type_initial_language_id' => '2', 'content_type_is_container' => '1', - 'content_type_language_mask' => '3', 'content_type_remote_id' => 'a3d405b81be900468eb153d774f4f0d2', 'content_type_serialized_description_list' => 'a:2:{i:0;s:0:"";s:16:"always-available";b:0;}', 'content_type_serialized_name_list' => 'a:2:{s:16:"always-available";s:6:"eng-US";s:6:"eng-US";s:6:"Folder";}', @@ -63,7 +62,6 @@ 'content_type_identifier' => 'folder', 'content_type_initial_language_id' => '2', 'content_type_is_container' => '1', - 'content_type_language_mask' => '3', 'content_type_remote_id' => 'a3d405b81be900468eb153d774f4f0d2', 'content_type_serialized_description_list' => 'a:2:{i:0;s:0:"";s:16:"always-available";b:0;}', 'content_type_serialized_name_list' => 'a:2:{s:16:"always-available";s:6:"eng-US";s:6:"eng-US";s:6:"Folder";}', @@ -110,7 +108,6 @@ 'content_type_identifier' => 'folder', 'content_type_initial_language_id' => '2', 'content_type_is_container' => '1', - 'content_type_language_mask' => '3', 'content_type_remote_id' => 'a3d405b81be900468eb153d774f4f0d2', 'content_type_serialized_description_list' => 'a:2:{i:0;s:0:"";s:16:"always-available";b:0;}', 'content_type_serialized_name_list' => 'a:2:{s:16:"always-available";s:6:"eng-US";s:6:"eng-US";s:6:"Folder";}', @@ -157,7 +154,6 @@ 'content_type_identifier' => 'folder', 'content_type_initial_language_id' => '2', 'content_type_is_container' => '1', - 'content_type_language_mask' => '3', 'content_type_remote_id' => 'a3d405b81be900468eb153d774f4f0d2', 'content_type_serialized_description_list' => '', 'content_type_serialized_name_list' => '', diff --git a/tests/lib/Search/Legacy/Content/AbstractTestCase.php b/tests/lib/Search/Legacy/Content/AbstractTestCase.php index ada9f8fea8..71aad22b7a 100644 --- a/tests/lib/Search/Legacy/Content/AbstractTestCase.php +++ b/tests/lib/Search/Legacy/Content/AbstractTestCase.php @@ -91,16 +91,19 @@ static function ($hit): mixed { protected function getContentTypeHandler(): SPIContentTypeHandler { if (!isset($this->contentTypeHandler)) { + $contentTypeGateway = new ContentTypeGateway( + $this->getDatabaseConnection(), + $this->getSharedGateway(), + $this->getLanguageHandler(), + $this->getCriterionVisitor() + ); + $this->contentTypeHandler = new ContentTypeHandler( - new ContentTypeGateway( - $this->getDatabaseConnection(), - $this->getSharedGateway(), - $this->getLanguageMaskGenerator(), - $this->getCriterionVisitor() - ), + $contentTypeGateway, new ContentTypeMapper( $this->getConverterRegistry(), - $this->getLanguageMaskGenerator(), + $contentTypeGateway, + $this->getLanguageHandler(), self::createStub(StorageDispatcherInterface::class), $this->getFieldTypeAliasResolver(), ), From 88d8e3b454bf00b896d1a01a646e3b5d682a251e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:31:56 +0100 Subject: [PATCH 35/54] IBX-13142: Loaded the content type translations in the handler instead of the mapper --- .../Legacy/Content/Type/Handler.php | 34 ++++++++++++++++--- .../Legacy/Content/Type/Mapper.php | 17 ++-------- .../storage_engines/legacy/content_type.yml | 1 - .../Legacy/Content/Type/MapperTest.php | 17 ++-------- .../Legacy/Content/AbstractTestCase.php | 15 ++++---- 5 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Type/Handler.php b/src/lib/Persistence/Legacy/Content/Type/Handler.php index a4fc972702..24a5ad9cb9 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Handler.php +++ b/src/lib/Persistence/Legacy/Content/Type/Handler.php @@ -188,14 +188,14 @@ public function loadContentTypes( $groupId, $status = 0 ) { - return $this->mapper->extractTypesFromRows( + return $this->extractTypesFromRows( $this->contentTypeGateway->loadTypesDataForGroup($groupId, $status) ); } public function loadContentTypeList(array $contentTypeIds): array { - return $this->mapper->extractTypesFromRows( + return $this->extractTypesFromRows( $this->contentTypeGateway->loadTypesListData($contentTypeIds), true ); @@ -206,7 +206,7 @@ public function findContentTypes( array $prioritizedLanguages = [] ): array { $rows = $this->contentTypeGateway->findContentTypes($query, $prioritizedLanguages); - $items = $this->mapper->extractTypesFromRows( + $items = $this->extractTypesFromRows( $rows['items'], true ); @@ -222,7 +222,7 @@ public function findContentTypes( */ public function loadContentTypesByFieldDefinitionIdentifier(string $identifier): array { - return $this->mapper->extractTypesFromRows( + return $this->extractTypesFromRows( $this->contentTypeGateway->loadTypesDataByFieldDefinitionIdentifier($identifier) ); } @@ -286,6 +286,30 @@ public function loadByRemoteId($remoteId) ); } + /** + * @param array> $rows + * + * @return Type[] + */ + private function extractTypesFromRows( + array $rows, + bool $keepTypeIdAsKey = false + ): array { + $typeIdStatusPairs = []; + foreach ($rows as $row) { + $typeIdStatusPairs[$row['content_type_id'] . ':' . $row['content_type_status']] = [ + 'id' => (int)$row['content_type_id'], + 'status' => (int)$row['content_type_status'], + ]; + } + + return $this->mapper->extractTypesFromRows( + $rows, + $keepTypeIdAsKey, + $this->contentTypeGateway->loadContentTypeTranslations(array_values($typeIdStatusPairs)) + ); + } + /** * Loads a single Type from $rows. * @@ -300,7 +324,7 @@ protected function loadFromRows( $typeIdentifier, $status ) { - $types = $this->mapper->extractTypesFromRows($rows); + $types = $this->extractTypesFromRows($rows); if (count($types) !== 1) { throw new Exception\TypeNotFound($typeIdentifier, $status); } diff --git a/src/lib/Persistence/Legacy/Content/Type/Mapper.php b/src/lib/Persistence/Legacy/Content/Type/Mapper.php index 3e44589e3e..ac7d2fda78 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Type/Mapper.php @@ -33,21 +33,17 @@ class Mapper */ protected $converterRegistry; - private Gateway $gateway; - private LanguageHandler $languageHandler; private StorageDispatcherInterface $storageDispatcher; public function __construct( ConverterRegistry $converterRegistry, - Gateway $gateway, LanguageHandler $languageHandler, StorageDispatcherInterface $storageDispatcher, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver ) { $this->converterRegistry = $converterRegistry; - $this->gateway = $gateway; $this->languageHandler = $languageHandler; $this->storageDispatcher = $storageDispatcher; } @@ -111,12 +107,14 @@ public function extractGroupsFromRows(array $rows) * * @param array $rows * @param bool $keepTypeIdAsKey + * @param array $typeTranslations "{typeId}:{status}" => language codes * * @return array (Type) */ public function extractTypesFromRows( array $rows, - bool $keepTypeIdAsKey = false + bool $keepTypeIdAsKey = false, + array $typeTranslations = [] ) { $types = []; $fields = []; @@ -131,15 +129,6 @@ public function extractTypesFromRows( $rowsByAttributeId[$attributeId][] = $row; } - $typeIdStatusPairs = []; - foreach ($rows as $row) { - $typeIdStatusPairs[$row['content_type_id'] . ':' . $row['content_type_status']] = [ - 'id' => (int)$row['content_type_id'], - 'status' => (int)$row['content_type_status'], - ]; - } - $typeTranslations = $this->gateway->loadContentTypeTranslations(array_values($typeIdStatusPairs)); - foreach ($rows as $row) { $typeId = (int)$row['content_type_id']; if (!isset($types[$typeId])) { diff --git a/src/lib/Resources/settings/storage_engines/legacy/content_type.yml b/src/lib/Resources/settings/storage_engines/legacy/content_type.yml index ede412e529..0696d80f60 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content_type.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content_type.yml @@ -34,7 +34,6 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\Type\Mapper arguments: - '@Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry' - - '@ibexa.persistence.legacy.content_type.gateway' - '@ibexa.spi.persistence.legacy.language.handler' - '@Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' diff --git a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php index 4509c3761d..5fb7319587 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php @@ -23,7 +23,6 @@ use Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter; use Ibexa\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldDefinition; -use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway; use Ibexa\Core\Persistence\Legacy\Content\Type\Mapper; use Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; @@ -39,7 +38,6 @@ public function testCreateGroupFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -96,7 +94,6 @@ public function testTypeFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -118,7 +115,6 @@ public function testTypeFromUpdateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -209,7 +205,6 @@ public function testCreateStructFromType(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -278,7 +273,6 @@ public function testExtractGroupsFromRows(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -314,7 +308,7 @@ public function testExtractTypesFromRowsSingle(): void $rows = $this->getLoadTypeFixture(); $mapper = $this->getNonConvertingMapper(); - $types = $mapper->extractTypesFromRows($rows); + $types = $mapper->extractTypesFromRows($rows, false, ['1:0' => ['eng-US']]); self::assertCount( 1, @@ -344,6 +338,7 @@ public function testExtractTypesFromRowsSingle(): void 'sortField' => 1, 'sortOrder' => 1, 'defaultAlwaysAvailable' => true, + 'languageCodes' => ['eng-US'], ], $types[0] ); @@ -408,7 +403,6 @@ public function testToStorageFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -446,7 +440,6 @@ public function testToFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $storageDispatcher, $this->getFieldTypeAliasResolver(), @@ -465,7 +458,6 @@ protected function getNonConvertingMapper() $mapper = $this->getMockBuilder(Mapper::class) ->setConstructorArgs([ $this->getConverterRegistryMock(), - $this->getContentTypeGatewayMock(), $this->getLanguageHandlerMock(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), @@ -521,11 +513,6 @@ protected function getLoadGroupFixture() return require __DIR__ . '/_fixtures/map_load_group.php'; } - protected function getContentTypeGatewayMock(): Gateway - { - return $this->createMock(Gateway::class); - } - protected function getLanguageHandlerMock(): LanguageHandler { $language = new LanguageValueObject(); diff --git a/tests/lib/Search/Legacy/Content/AbstractTestCase.php b/tests/lib/Search/Legacy/Content/AbstractTestCase.php index 71aad22b7a..0d5a0aca2c 100644 --- a/tests/lib/Search/Legacy/Content/AbstractTestCase.php +++ b/tests/lib/Search/Legacy/Content/AbstractTestCase.php @@ -91,18 +91,15 @@ static function ($hit): mixed { protected function getContentTypeHandler(): SPIContentTypeHandler { if (!isset($this->contentTypeHandler)) { - $contentTypeGateway = new ContentTypeGateway( - $this->getDatabaseConnection(), - $this->getSharedGateway(), - $this->getLanguageHandler(), - $this->getCriterionVisitor() - ); - $this->contentTypeHandler = new ContentTypeHandler( - $contentTypeGateway, + new ContentTypeGateway( + $this->getDatabaseConnection(), + $this->getSharedGateway(), + $this->getLanguageHandler(), + $this->getCriterionVisitor() + ), new ContentTypeMapper( $this->getConverterRegistry(), - $contentTypeGateway, $this->getLanguageHandler(), self::createStub(StorageDispatcherInterface::class), $this->getFieldTypeAliasResolver(), From cb5511faa6193060fb418831187814772a677a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:43:15 +0100 Subject: [PATCH 36/54] IBX-13142: Ordered the content type language codes by language id --- .../Legacy/Content/Type/Gateway/DoctrineDatabase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php index 935604558a..dadbebaebf 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php @@ -1070,7 +1070,8 @@ public function loadContentTypeTranslations(array $typeIdStatusPairs): array ) ->andWhere( $query->expr()->in('content_type_status', $query->createNamedParameter($statuses, ArrayParameterType::INTEGER)) - ); + ) + ->orderBy('language_id'); $translations = []; foreach ($query->executeQuery()->fetchAllAssociative() as $row) { From 161323dd594366e99cb9b40a843189274b79a4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:46:51 +0100 Subject: [PATCH 37/54] IBX-13142: Promoted the constructor properties and declared strict types in the content type mapper --- .../Legacy/Content/Type/Mapper.php | 24 ++++--------------- .../Legacy/Content/Type/MapperTest.php | 20 ++++++++-------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Type/Mapper.php b/src/lib/Persistence/Legacy/Content/Type/Mapper.php index ac7d2fda78..347f35ffb5 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Type/Mapper.php @@ -4,6 +4,7 @@ * @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\Core\Persistence\Legacy\Content\Type; @@ -26,27 +27,12 @@ */ class Mapper { - /** - * Converter registry. - * - * @var ConverterRegistry - */ - protected $converterRegistry; - - private LanguageHandler $languageHandler; - - private StorageDispatcherInterface $storageDispatcher; - public function __construct( - ConverterRegistry $converterRegistry, - LanguageHandler $languageHandler, - StorageDispatcherInterface $storageDispatcher, + protected ConverterRegistry $converterRegistry, + private LanguageHandler $languageHandler, + private StorageDispatcherInterface $storageDispatcher, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver - ) { - $this->converterRegistry = $converterRegistry; - $this->languageHandler = $languageHandler; - $this->storageDispatcher = $storageDispatcher; - } + ) {} /** * Creates a Group from its create struct. diff --git a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php index 5fb7319587..60532ec7b4 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/MapperTest.php @@ -38,7 +38,7 @@ public function testCreateGroupFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -94,7 +94,7 @@ public function testTypeFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -115,7 +115,7 @@ public function testTypeFromUpdateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -205,7 +205,7 @@ public function testCreateStructFromType(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -273,7 +273,7 @@ public function testExtractGroupsFromRows(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -403,7 +403,7 @@ public function testToStorageFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -440,7 +440,7 @@ public function testToFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $storageDispatcher, $this->getFieldTypeAliasResolver(), ); @@ -458,7 +458,7 @@ protected function getNonConvertingMapper() $mapper = $this->getMockBuilder(Mapper::class) ->setConstructorArgs([ $this->getConverterRegistryMock(), - $this->getLanguageHandlerMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ]) @@ -513,13 +513,13 @@ protected function getLoadGroupFixture() return require __DIR__ . '/_fixtures/map_load_group.php'; } - protected function getLanguageHandlerMock(): LanguageHandler + protected function getLanguageHandlerStub(): LanguageHandler { $language = new LanguageValueObject(); $language->id = 2; $language->languageCode = 'eng-US'; - $languageHandler = $this->createMock(LanguageHandler::class); + $languageHandler = self::createStub(LanguageHandler::class); $languageHandler->method('load')->willReturn($language); $languageHandler->method('loadByLanguageCode')->willReturn($language); From 5ebe47adab07071a6ee8ade8f0edc2c7ac26c5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 20:45:05 +0100 Subject: [PATCH 38/54] IBX-11939: Moved object states off MaskGenerator Object states resolve language ids through the language handler instead of MaskGenerator. They keep writing the masks and the always-available bit until the bitmask is removed. --- .../ObjectState/Gateway/DoctrineDatabase.php | 47 +++++++++++++++---- .../storage_engines/legacy/object_state.yml | 2 +- .../Gateway/DoctrineDatabaseTest.php | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php index 20f237e3b3..c7915e6b4e 100644 --- a/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php @@ -12,11 +12,11 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; +use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler; use Ibexa\Contracts\Core\Persistence\Content\ObjectState; use Ibexa\Contracts\Core\Persistence\Content\ObjectState\Group; use Ibexa\Contracts\Core\Persistence\Content\ObjectState\Handler; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway; /** @@ -30,7 +30,7 @@ final class DoctrineDatabase extends Gateway { public function __construct( private readonly Connection $connection, - private readonly MaskGenerator $maskGenerator + private readonly LanguageHandler $languageHandler ) {} public function loadObjectStateData(int $stateId): array @@ -156,7 +156,7 @@ public function insertObjectState( ParameterType::INTEGER ), 'default_language_id' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageIndicator( + $this->generateLanguageIndicator( $objectState->defaultLanguage, false ), @@ -167,7 +167,7 @@ public function insertObjectState( ParameterType::STRING ), 'language_mask' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( + $this->generateLanguageMask( $objectState->languageCodes, true ), @@ -219,7 +219,7 @@ private function updateObjectStateCommonFields( ->set( 'default_language_id', $query->createPositionalParameter( - $this->maskGenerator->generateLanguageIndicator( + $this->generateLanguageIndicator( $defaultLanguageCode, false ), @@ -236,7 +236,7 @@ private function updateObjectStateCommonFields( ->set( 'language_mask', $query->createPositionalParameter( - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( + $this->generateLanguageMask( $languageCodes, true ), @@ -369,7 +369,7 @@ public function insertObjectStateGroup(Group $objectStateGroup): void ->values( [ 'default_language_id' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageIndicator( + $this->generateLanguageIndicator( $objectStateGroup->defaultLanguage, false ), @@ -380,7 +380,7 @@ public function insertObjectStateGroup(Group $objectStateGroup): void ParameterType::STRING ), 'language_mask' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( + $this->generateLanguageMask( $objectStateGroup->languageCodes, true ), @@ -600,7 +600,7 @@ private function insertObjectStateTranslations(ObjectState $objectState): void ParameterType::STRING ), 'language_id' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageIndicator( + $this->generateLanguageIndicator( $languageCode, $languageCode === $objectState->defaultLanguage ), @@ -654,7 +654,7 @@ private function insertObjectStateGroupTranslations(Group $objectStateGroup): vo ) ; foreach ($objectStateGroup->languageCodes as $languageCode) { - $languageId = $this->maskGenerator->generateLanguageIndicator( + $languageId = $this->generateLanguageIndicator( $languageCode, $languageCode === $objectStateGroup->defaultLanguage ); @@ -759,4 +759,31 @@ private function insertContentStateAssignment( $query->executeStatement(); } + + /** + * The language id, with the legacy "always available" bit for as long as the language bitmask is around. + */ + private function generateLanguageIndicator( + string $languageCode, + bool $alwaysAvailable + ): int { + return $this->languageHandler->loadByLanguageCode($languageCode)->id | ($alwaysAvailable ? 1 : 0); + } + + /** + * Keeps the legacy "language_mask" up to date for as long as the language bitmask is around. + * + * @param string[] $languageCodes + */ + private function generateLanguageMask( + array $languageCodes, + bool $alwaysAvailable + ): int { + $languageMask = $alwaysAvailable ? 1 : 0; + foreach ($languageCodes as $languageCode) { + $languageMask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; + } + + return $languageMask; + } } diff --git a/src/lib/Resources/settings/storage_engines/legacy/object_state.yml b/src/lib/Resources/settings/storage_engines/legacy/object_state.yml index 48de1bfe90..850d1d2da8 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/object_state.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/object_state.yml @@ -3,7 +3,7 @@ services: class: Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway\DoctrineDatabase arguments: - '@ibexa.api.storage_engine.legacy.connection' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' + - '@ibexa.spi.persistence.legacy.language.handler' Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway\ExceptionConversion: class: Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway\ExceptionConversion diff --git a/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php index f364407932..7707ea5f6d 100644 --- a/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php @@ -511,7 +511,7 @@ protected function getDatabaseGateway(): DoctrineDatabase if (!isset($this->databaseGateway)) { $this->databaseGateway = new DoctrineDatabase( $this->getDatabaseConnection(), - $this->getLanguageMaskGenerator() + $this->getLanguageHandler() ); } From 7e1345d07ba799df13b33ca12c1065abb60dd84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 6 Nov 2026 20:45:05 +0100 Subject: [PATCH 39/54] IBX-11939: Removed the language bitmask Stops writing the masks and drops them, together with MaskGenerator. New languages get the id after the highest one instead of the next power of two, which lifts the limit of 62 languages, and the always-available bit is stripped from the language_id columns, after removing the stale object state translations eZ Publish left behind. --- data/mysql/cleandata.sql | 285 ++++++++-------- data/postgresql/cleandata.sql | 285 ++++++++-------- phpstan-baseline.neon | 102 ------ .../Resources/config/doctrine_migrations.php | 10 + .../config/storage/legacy/schema.yaml | 13 +- .../DropLanguageBitmaskColumnsMigration.php | 232 ++++++++++++++ ...ysAvailableBitFromLanguageIdsMigration.php | 154 +++++++++ ...-stale-object-state-translations-mysql.sql | 7 + ...e-object-state-translations-postgresql.sql | 6 + ...stale-object-state-translations-sqlite.sql | 14 + .../Persistence/Fixture/FixtureImporter.php | 32 ++ .../Content/Gateway/DoctrineDatabase.php | 268 +--------------- .../Legacy/Content/Language/Gateway.php | 18 +- .../Language/Gateway/DoctrineDatabase.php | 100 +++--- .../Legacy/Content/Language/MaskGenerator.php | 236 -------------- .../ObjectState/Gateway/DoctrineDatabase.php | 91 +----- .../Legacy/Content/ObjectState/Mapper.php | 6 +- .../Content/Type/Gateway/DoctrineDatabase.php | 29 +- .../UrlAlias/Gateway/DoctrineDatabase.php | 58 ---- .../DatabasePlatform/AbstractGateway.php | 22 -- .../DatabasePlatform/PostgresqlGateway.php | 25 +- .../Legacy/SharedGateway/Gateway.php | 5 - .../storage_engines/legacy/content.yml | 1 - .../storage_engines/legacy/language.yml | 4 - .../LanguagePriorityConditionBuilder.php | 13 - .../WordIndexer/Repository/SearchIndex.php | 4 - ...ackfillLanguageTranslationsCommandTest.php | 11 +- ...WordLinkLanguageIdColumnsMigrationTest.php | 3 + ...liasAlwaysAvailableColumnMigrationTest.php | 1 + ...kfillLanguageTranslationsMigrationTest.php | 3 + .../MaxLanguagesContentServiceTest.php | 19 ++ ...geServiceMaximumSupportedLanguagesTest.php | 49 +-- .../_fixtures/Legacy/data/test_data.yaml | 44 +-- .../Content/Gateway/DoctrineDatabaseTest.php | 140 +------- .../Language/Gateway/DoctrineDatabaseTest.php | 28 +- .../Content/Language/MaskGeneratorTest.php | 303 ------------------ .../Legacy/Content/LanguageAwareTestCase.php | 24 -- .../Gateway/DoctrineDatabaseTest.php | 50 +-- .../Legacy/Content/ObjectState/MapperTest.php | 4 +- .../Type/Gateway/DoctrineDatabaseTest.php | 5 +- .../UrlAlias/Gateway/DoctrineDatabaseTest.php | 6 - .../Content/UrlAlias/UrlAliasHandlerTest.php | 2 - ...ct_content_from_rows_multiple_versions.php | 8 +- 43 files changed, 919 insertions(+), 1801 deletions(-) create mode 100644 src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php create mode 100644 src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql create mode 100644 src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql delete mode 100644 src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php delete mode 100644 tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php diff --git a/data/mysql/cleandata.sql b/data/mysql/cleandata.sql index 0a8ff87f31..9baf07602c 100644 --- a/data/mysql/cleandata.sql +++ b/data/mysql/cleandata.sql @@ -1,16 +1,16 @@ -INSERT INTO `ibexa_object_state` (`default_language_id`, `group_id`, `id`, `identifier`, `language_mask`, `priority`) -VALUES (2, 2, 1, 'not_locked', 3, 0), - (2, 2, 2, 'locked', 3, 1); +INSERT INTO `ibexa_object_state` (`default_language_id`, `group_id`, `id`, `identifier`, `priority`) +VALUES (2, 2, 1, 'not_locked', 0), + (2, 2, 2, 'locked', 1); -INSERT INTO `ibexa_object_state_group` (`default_language_id`, `id`, `identifier`, `language_mask`) -VALUES (2,2,'ibexa_lock',3); +INSERT INTO `ibexa_object_state_group` (`default_language_id`, `id`, `identifier`) +VALUES (2,2,'ibexa_lock'); INSERT INTO `ibexa_object_state_group_language` (`contentobject_state_group_id`, `description`, `language_id`, `name`, `real_language_id`) -VALUES (2,'',3,'Lock',2); +VALUES (2,'',2,'Lock',2); INSERT INTO `ibexa_object_state_language` (`contentobject_state_id`, `description`, `language_id`, `name`) -VALUES (1,'',3,'Not locked'), - (2,'',3,'Locked'); +VALUES (1,'',2,'Not locked'), + (2,'',2,'Locked'); INSERT INTO `ibexa_object_state_link` (`contentobject_id`, `contentobject_state_id`) VALUES (1, 1), @@ -29,13 +29,13 @@ VALUES (1, 1), INSERT INTO `ibexa_content_language` (`disabled`, `id`, `locale`, `name`) VALUES (0, 2, 'eng-GB', 'English (United Kingdom)'); -INSERT INTO `ibexa_content_type` (`always_available`, `contentobject_name`, `created`, `creator_id`, `id`, `identifier`, `initial_language_id`, `is_container`, `language_mask`, `modified`, `modifier_id`, `remote_id`, `serialized_description_list`, `serialized_name_list`, `sort_field`, `sort_order`, `url_alias_name`, `status`) -VALUES (1,'',1024392098,14,1,'folder',2,1,2,1448831672,14,'a3d405b81be900468eb153d774f4f0d2','a:0:{}','a:1:{s:6:\"eng-GB\";s:6:\"Folder\";}',1,1,NULL,0), - (0,'',1024392098,14,2,'article',2,1,3,1082454989,14,'c15b600eb9198b1924063b5a68758232',NULL,'a:2:{s:6:\"eng-GB\";s:7:\"Article\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), - (1,'',1024392098,14,3,'user_group',2,1,3,1048494743,14,'25b4268cdcd01921b808a0d854b877ef',NULL,'a:2:{s:6:\"eng-GB\";s:10:\"User group\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), - (1,' ',1024392098,14,4,'user',2,0,3,1082018364,14,'40faa822edc579b02c25f6bb7beec3ad',NULL,'a:2:{s:6:\"eng-GB\";s:4:\"User\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), - (1,'',1031484992,14,5,'image',2,0,3,1048494784,14,'f6df12aa74e36230eb675f364fccd25a',NULL,'a:2:{s:6:\"eng-GB\";s:5:\"Image\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), - (1,'',1052385472,14,12,'file',2,0,3,1052385669,14,'637d58bfddf164627bdfd265733280a0',NULL,'a:2:{s:6:\"eng-GB\";s:4:\"File\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0); +INSERT INTO `ibexa_content_type` (`always_available`, `contentobject_name`, `created`, `creator_id`, `id`, `identifier`, `initial_language_id`, `is_container`, `modified`, `modifier_id`, `remote_id`, `serialized_description_list`, `serialized_name_list`, `sort_field`, `sort_order`, `url_alias_name`, `status`) +VALUES (1,'',1024392098,14,1,'folder',2,1,1448831672,14,'a3d405b81be900468eb153d774f4f0d2','a:0:{}','a:1:{s:6:\"eng-GB\";s:6:\"Folder\";}',1,1,NULL,0), + (0,'',1024392098,14,2,'article',2,1,1082454989,14,'c15b600eb9198b1924063b5a68758232',NULL,'a:2:{s:6:\"eng-GB\";s:7:\"Article\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), + (1,'',1024392098,14,3,'user_group',2,1,1048494743,14,'25b4268cdcd01921b808a0d854b877ef',NULL,'a:2:{s:6:\"eng-GB\";s:10:\"User group\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), + (1,' ',1024392098,14,4,'user',2,0,1082018364,14,'40faa822edc579b02c25f6bb7beec3ad',NULL,'a:2:{s:6:\"eng-GB\";s:4:\"User\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), + (1,'',1031484992,14,5,'image',2,0,1048494784,14,'f6df12aa74e36230eb675f364fccd25a',NULL,'a:2:{s:6:\"eng-GB\";s:5:\"Image\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0), + (1,'',1052385472,14,12,'file',2,0,1052385669,14,'637d58bfddf164627bdfd265733280a0',NULL,'a:2:{s:6:\"eng-GB\";s:4:\"File\";s:16:\"always-available\";s:6:\"eng-GB\";}',1,1,NULL,0); INSERT INTO `ibexa_content_type_field_definition` (`can_translate`, `category`, `content_type_id`, `data_float1`, `data_float2`, `data_float3`, `data_float4`, `data_int1`, `data_int2`, `data_int3`, `data_int4`, `data_text1`, `data_text2`, `data_text3`, `data_text4`, `data_text5`, `data_type_string`, `id`, `identifier`, `is_information_collector`, `is_required`, `is_searchable`, `is_thumbnail`, `placement`, `serialized_data_text`, `serialized_description_list`, `serialized_name_list`, `status`) VALUES (1,'',2,0,0,0,0,255,0,0,0,'New article','','','','','ibexa_string',1,'title',0,1,1,1,0,NULL,NULL,'a:2:{s:6:\"eng-GB\";s:5:\"Title\";s:16:\"always-available\";s:6:\"eng-GB\";}',0), @@ -73,30 +73,30 @@ VALUES (1, 0, 1, 'Content'), INSERT INTO `ibexa_content_type_name` (`content_type_id`, `content_type_status`, `language_id`, `language_locale`, `name`) VALUES (1, 0, 2, 'eng-GB', 'Folder'), - (2, 0, 3, 'eng-GB', 'Article'), - (3, 0, 3, 'eng-GB', 'User group'), - (4, 0, 3, 'eng-GB', 'User'), - (5, 0, 3, 'eng-GB', 'Image'), - (12, 0, 3, 'eng-GB', 'File'); + (2, 0, 2, 'eng-GB', 'Article'), + (3, 0, 2, 'eng-GB', 'User group'), + (4, 0, 2, 'eng-GB', 'User'), + (5, 0, 2, 'eng-GB', 'Image'), + (12, 0, 2, 'eng-GB', 'File'); INSERT INTO `ibexa_content_type_group` (`created`, `creator_id`, `id`, `modified`, `modifier_id`, `name`) VALUES (1031216928, 14, 1, 1033922106, 14, 'Content'), (1031216941, 14, 2, 1033922113, 14, 'Users'), (1032009743, 14, 3, 1033922120, 14, 'Media'); -INSERT INTO `ibexa_content` (`content_type_id`, `current_version`, `id`, `initial_language_id`, `language_mask`, `always_available`, `modified`, `name`, `owner_id`, `published`, `remote_id`, `section_id`, `status`) -VALUES (1,9,1,2,3,1,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), - (3,1,4,2,3,1,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), - (4,2,10,2,3,1,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), - (3,1,11,2,3,1,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), - (3,1,12,2,3,1,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), - (3,1,13,2,3,1,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), - (4,3,14,2,3,1,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), - (1,1,41,2,3,1,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), - (3,1,42,2,3,1,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), - (1,1,49,2,3,1,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), - (1,1,50,2,3,1,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), - (1,1,51,2,3,1,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); +INSERT INTO `ibexa_content` (`content_type_id`, `current_version`, `id`, `initial_language_id`, `always_available`, `modified`, `name`, `owner_id`, `published`, `remote_id`, `section_id`, `status`) +VALUES (1,9,1,2,1,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), + (3,1,4,2,1,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), + (4,2,10,2,1,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), + (3,1,11,2,1,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), + (3,1,12,2,1,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), + (3,1,13,2,1,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), + (4,3,14,2,1,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), + (1,1,41,2,1,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), + (3,1,42,2,1,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), + (1,1,49,2,1,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), + (1,1,50,2,1,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), + (1,1,51,2,1,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); INSERT INTO `ibexa_content_translation` (`content_id`, `language_id`) VALUES (1,2), @@ -113,60 +113,60 @@ VALUES (1,2), (51,2); INSERT INTO `ibexa_content_field` (`attribute_original_id`, `content_type_field_definition_id`, `contentobject_id`, `data_float`, `data_int`, `data_text`, `data_type_string`, `id`, `language_code`, `language_id`, `sort_key_int`, `sort_key_string`, `version`) -VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',3,0,'ibexa platform',9), - (0,119,1,NULL,NULL,'
You are now ready to start your project.
','ibexa_richtext',2,'eng-GB',3,0,'',9), - (0,7,4,NULL,NULL,'Main group','ibexa_string',7,'eng-GB',3,0,'',1), - (0,6,4,NULL,NULL,'Users','ibexa_string',8,'eng-GB',3,0,'',1), - (0,8,10,0,0,'Anonymous','ibexa_string',19,'eng-GB',3,0,'anonymous',2), - (0,9,10,0,0,'User','ibexa_string',20,'eng-GB',3,0,'user',2), - (0,12,10,0,0,'','ibexa_user',21,'eng-GB',3,0,'',2), - (0,6,11,0,0,'Guest accounts','ibexa_string',22,'eng-GB',3,0,'',1), - (0,7,11,0,0,'','ibexa_string',23,'eng-GB',3,0,'',1), - (0,6,12,0,0,'Administrator users','ibexa_string',24,'eng-GB',3,0,'',1), - (0,7,12,0,0,'','ibexa_string',25,'eng-GB',3,0,'',1), - (0,6,13,0,0,'Editors','ibexa_string',26,'eng-GB',3,0,'',1), - (0,7,13,0,0,'','ibexa_string',27,'eng-GB',3,0,'',1), - (0,8,14,0,0,'Administrator','ibexa_string',28,'eng-GB',3,0,'administrator',3), - (0,9,14,0,0,'User','ibexa_string',29,'eng-GB',3,0,'user',3), - (30,12,14,0,0,'','ibexa_user',30,'eng-GB',3,0,'',3), - (0,4,41,0,0,'Media','ibexa_string',98,'eng-GB',3,0,'',1), - (0,119,41,0,1045487555,'\n
\n','ibexa_richtext',99,'eng-GB',3,0,'',1), - (0,6,42,0,0,'Anonymous users','ibexa_string',100,'eng-GB',3,0,'anonymous users',1), - (0,7,42,0,0,'User group for the anonymous user','ibexa_string',101,'eng-GB',3,0,'user group for the anonymous user',1), - (0,155,1,NULL,NULL,'Ibexa Platform','ibexa_string',102,'eng-GB',3,0,'ibexa platform',9), - (0,155,41,0,0,'','ibexa_string',103,'eng-GB',3,0,'',1), - (0,156,1,NULL,NULL,'
This is the clean installation coming with Ibexa Platform.It''s a bare-bones setup of the Platform, an excellent foundation to build upon if you want to start your project from scratch.
','ibexa_richtext',104,'eng-GB',3,0,'',9), - (0,156,41,0,1045487555,'\n
\n','ibexa_richtext',105,'eng-GB',3,0,'',1), - (0,4,49,0,0,'Images','ibexa_string',142,'eng-GB',3,0,'images',1), - (0,155,49,0,0,'','ibexa_string',143,'eng-GB',3,0,'',1), - (0,119,49,0,1045487555,'\n
\n','ibexa_richtext',144,'eng-GB',3,0,'',1), - (0,156,49,0,1045487555,'\n
\n','ibexa_richtext',145,'eng-GB',3,0,'',1), - (0,4,50,0,0,'Files','ibexa_string',147,'eng-GB',3,0,'files',1), - (0,155,50,0,0,'','ibexa_string',148,'eng-GB',3,0,'',1), - (0,119,50,0,1045487555,'\n
\n','ibexa_richtext',149,'eng-GB',3,0,'',1), - (0,156,50,0,1045487555,'\n
\n','ibexa_richtext',150,'eng-GB',3,0,'',1), - (0,4,51,0,0,'Multimedia','ibexa_string',152,'eng-GB',3,0,'multimedia',1), - (0,155,51,0,0,'','ibexa_string',153,'eng-GB',3,0,'',1), - (0,119,51,0,1045487555,'\n
\n','ibexa_richtext',154,'eng-GB',3,0,'',1), - (0,156,51,0,1045487555,'\n
\n','ibexa_richtext',155,'eng-GB',3,0,'',1), - (0,179,10,0,0,'','ibexa_text',177,'eng-GB',3,0,'',2), - (0,179,14,0,0,'','ibexa_text',178,'eng-GB',3,0,'',3), - (0,180,10,0,0,'','ibexa_image',179,'eng-GB',3,0,'',2), - (0,180,14,0,0,'\n\n','ibexa_image',180,'eng-GB',3,0,'',3); +VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',2,0,'ibexa platform',9), + (0,119,1,NULL,NULL,'
You are now ready to start your project.
','ibexa_richtext',2,'eng-GB',2,0,'',9), + (0,7,4,NULL,NULL,'Main group','ibexa_string',7,'eng-GB',2,0,'',1), + (0,6,4,NULL,NULL,'Users','ibexa_string',8,'eng-GB',2,0,'',1), + (0,8,10,0,0,'Anonymous','ibexa_string',19,'eng-GB',2,0,'anonymous',2), + (0,9,10,0,0,'User','ibexa_string',20,'eng-GB',2,0,'user',2), + (0,12,10,0,0,'','ibexa_user',21,'eng-GB',2,0,'',2), + (0,6,11,0,0,'Guest accounts','ibexa_string',22,'eng-GB',2,0,'',1), + (0,7,11,0,0,'','ibexa_string',23,'eng-GB',2,0,'',1), + (0,6,12,0,0,'Administrator users','ibexa_string',24,'eng-GB',2,0,'',1), + (0,7,12,0,0,'','ibexa_string',25,'eng-GB',2,0,'',1), + (0,6,13,0,0,'Editors','ibexa_string',26,'eng-GB',2,0,'',1), + (0,7,13,0,0,'','ibexa_string',27,'eng-GB',2,0,'',1), + (0,8,14,0,0,'Administrator','ibexa_string',28,'eng-GB',2,0,'administrator',3), + (0,9,14,0,0,'User','ibexa_string',29,'eng-GB',2,0,'user',3), + (30,12,14,0,0,'','ibexa_user',30,'eng-GB',2,0,'',3), + (0,4,41,0,0,'Media','ibexa_string',98,'eng-GB',2,0,'',1), + (0,119,41,0,1045487555,'\n
\n','ibexa_richtext',99,'eng-GB',2,0,'',1), + (0,6,42,0,0,'Anonymous users','ibexa_string',100,'eng-GB',2,0,'anonymous users',1), + (0,7,42,0,0,'User group for the anonymous user','ibexa_string',101,'eng-GB',2,0,'user group for the anonymous user',1), + (0,155,1,NULL,NULL,'Ibexa Platform','ibexa_string',102,'eng-GB',2,0,'ibexa platform',9), + (0,155,41,0,0,'','ibexa_string',103,'eng-GB',2,0,'',1), + (0,156,1,NULL,NULL,'
This is the clean installation coming with Ibexa Platform.It''s a bare-bones setup of the Platform, an excellent foundation to build upon if you want to start your project from scratch.
','ibexa_richtext',104,'eng-GB',2,0,'',9), + (0,156,41,0,1045487555,'\n
\n','ibexa_richtext',105,'eng-GB',2,0,'',1), + (0,4,49,0,0,'Images','ibexa_string',142,'eng-GB',2,0,'images',1), + (0,155,49,0,0,'','ibexa_string',143,'eng-GB',2,0,'',1), + (0,119,49,0,1045487555,'\n
\n','ibexa_richtext',144,'eng-GB',2,0,'',1), + (0,156,49,0,1045487555,'\n
\n','ibexa_richtext',145,'eng-GB',2,0,'',1), + (0,4,50,0,0,'Files','ibexa_string',147,'eng-GB',2,0,'files',1), + (0,155,50,0,0,'','ibexa_string',148,'eng-GB',2,0,'',1), + (0,119,50,0,1045487555,'\n
\n','ibexa_richtext',149,'eng-GB',2,0,'',1), + (0,156,50,0,1045487555,'\n
\n','ibexa_richtext',150,'eng-GB',2,0,'',1), + (0,4,51,0,0,'Multimedia','ibexa_string',152,'eng-GB',2,0,'multimedia',1), + (0,155,51,0,0,'','ibexa_string',153,'eng-GB',2,0,'',1), + (0,119,51,0,1045487555,'\n
\n','ibexa_richtext',154,'eng-GB',2,0,'',1), + (0,156,51,0,1045487555,'\n
\n','ibexa_richtext',155,'eng-GB',2,0,'',1), + (0,179,10,0,0,'','ibexa_text',177,'eng-GB',2,0,'',2), + (0,179,14,0,0,'','ibexa_text',178,'eng-GB',2,0,'',3), + (0,180,10,0,0,'','ibexa_image',179,'eng-GB',2,0,'',2), + (0,180,14,0,0,'\n\n','ibexa_image',180,'eng-GB',2,0,'',3); INSERT INTO `ibexa_content_name` (`content_translation`, `content_version`, `contentobject_id`, `language_id`, `name`, `real_translation`) VALUES ('eng-GB',9,1,2,'Ibexa Platform','eng-GB'), - ('eng-GB',1,4,3,'Users','eng-GB'), - ('eng-GB',2,10,3,'Anonymous User','eng-GB'), - ('eng-GB',1,11,3,'Guest accounts','eng-GB'), - ('eng-GB',1,12,3,'Administrator users','eng-GB'), - ('eng-GB',1,13,3,'Editors','eng-GB'), - ('eng-GB',3,14,3,'Administrator User','eng-GB'), - ('eng-GB',1,41,3,'Media','eng-GB'), - ('eng-GB',1,42,3,'Anonymous users','eng-GB'), - ('eng-GB',1,49,3,'Images','eng-GB'), - ('eng-GB',1,50,3,'Files','eng-GB'), - ('eng-GB',1,51,3,'Multimedia','eng-GB'); + ('eng-GB',1,4,2,'Users','eng-GB'), + ('eng-GB',2,10,2,'Anonymous User','eng-GB'), + ('eng-GB',1,11,2,'Guest accounts','eng-GB'), + ('eng-GB',1,12,2,'Administrator users','eng-GB'), + ('eng-GB',1,13,2,'Editors','eng-GB'), + ('eng-GB',3,14,2,'Administrator User','eng-GB'), + ('eng-GB',1,41,2,'Media','eng-GB'), + ('eng-GB',1,42,2,'Anonymous users','eng-GB'), + ('eng-GB',1,49,2,'Images','eng-GB'), + ('eng-GB',1,50,2,'Files','eng-GB'), + ('eng-GB',1,51,2,'Multimedia','eng-GB'); INSERT INTO `ibexa_content_tree` (`contentobject_id`, `contentobject_is_published`, `contentobject_version`, `depth`, `is_hidden`, `is_invisible`, `main_node_id`, `modified_subnode`, `node_id`, `parent_node_id`, `path_identification_string`, `path_string`, `priority`, `remote_id`, `sort_field`, `sort_order`) VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96a',1,1), @@ -183,19 +183,19 @@ VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96 (50,1,1,2,0,0,52,1081860720,52,43,'media/files','/1/43/52/',0,'0b113a208f7890f9ad3c24444ff5988c',9,1), (51,1,1,2,0,0,53,1081860720,53,43,'media/multimedia','/1/43/53/',0,'4f18b82c75f10aad476cae5adf98c11f',9,1); -INSERT INTO `ibexa_content_version` (`contentobject_id`, `created`, `creator_id`, `id`, `initial_language_id`, `language_mask`, `always_available`, `modified`, `status`, `user_id`, `version`, `workflow_event_pos`) -VALUES (4,0,14,4,2,3,1,0,1,0,1,1), - (11,1033920737,14,439,2,3,1,1033920746,1,0,1,0), - (12,1033920760,14,440,2,3,1,1033920775,1,0,1,0), - (13,1033920786,14,441,2,3,1,1033920794,1,0,1,0), - (41,1060695450,14,472,2,3,1,1060695457,1,0,1,0), - (42,1072180278,14,473,2,3,1,1072180330,1,0,1,0), - (10,1072180337,14,474,2,3,1,1072180405,1,0,2,0), - (49,1080220181,14,488,2,3,1,1080220197,1,0,1,0), - (50,1080220211,14,489,2,3,1,1080220220,1,0,1,0), - (51,1080220225,14,490,2,3,1,1080220233,1,0,1,0), - (14,1301061783,14,499,2,3,1,1301062024,1,0,3,0), - (1,1448889045,14,506,2,3,1,1448889046,1,0,9,0); +INSERT INTO `ibexa_content_version` (`contentobject_id`, `created`, `creator_id`, `id`, `initial_language_id`, `always_available`, `modified`, `status`, `user_id`, `version`, `workflow_event_pos`) +VALUES (4,0,14,4,2,1,0,1,0,1,1), + (11,1033920737,14,439,2,1,1033920746,1,0,1,0), + (12,1033920760,14,440,2,1,1033920775,1,0,1,0), + (13,1033920786,14,441,2,1,1033920794,1,0,1,0), + (41,1060695450,14,472,2,1,1060695457,1,0,1,0), + (42,1072180278,14,473,2,1,1072180330,1,0,1,0), + (10,1072180337,14,474,2,1,1072180405,1,0,2,0), + (49,1080220181,14,488,2,1,1080220197,1,0,1,0), + (50,1080220211,14,489,2,1,1080220220,1,0,1,0), + (51,1080220225,14,490,2,1,1080220233,1,0,1,0), + (14,1301061783,14,499,2,1,1301062024,1,0,3,0), + (1,1448889045,14,506,2,1,1448889046,1,0,9,0); INSERT INTO `ibexa_content_version_translation` (`content_version_id`, `language_id`) VALUES (4,2), @@ -280,32 +280,32 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `lang_mask`, `always_available`, `link`, `parent`, `text`, `text_md5`) -VALUES ('nop:','nop',1,17,0,0,1,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), - ('eznode:43','eznode',1,9,0,1,3,1,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), - ('nop:','nop',1,3,0,0,1,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), - ('eznode:5','eznode',1,2,0,1,3,1,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), - ('eznode:2','eznode',1,1,0,1,3,1,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), - ('eznode:14','eznode',1,6,0,1,3,1,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), - ('eznode:44','eznode',1,10,0,1,3,1,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), - ('eznode:12','eznode',1,4,0,1,3,1,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), - ('eznode:13','eznode',1,5,0,1,3,1,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), - ('nop:','nop',1,11,0,0,1,1,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), - ('eznode:12','eznode',1,26,0,0,1,1,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), - ('eznode:14','eznode',1,29,0,0,1,1,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), - ('nop:','nop',1,7,0,0,1,1,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), - ('eznode:13','eznode',1,27,0,0,1,1,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), - ('eznode:44','eznode',1,30,0,0,1,1,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), - ('eznode:15','eznode',1,8,0,1,3,1,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), - ('eznode:15','eznode',1,28,0,0,0,0,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), - ('eznode:53','eznode',1,20,0,1,3,1,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,19,0,1,3,1,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,18,0,1,3,1,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), - ('eznode:45','eznode',1,12,0,1,3,1,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), - ('eznode:45','eznode',1,31,0,0,1,1,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), - ('eznode:53','eznode',1,34,0,0,1,1,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,33,0,0,1,1,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,32,0,0,1,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); +INSERT INTO `ibexa_url_alias_ml` (`action`, `action_type`, `alias_redirects`, `id`, `is_alias`, `is_original`, `always_available`, `link`, `parent`, `text`, `text_md5`) +VALUES ('nop:','nop',1,17,0,0,1,17,0,'media2','50e2736330de124f6edea9b008556fe6'), + ('eznode:43','eznode',1,9,0,1,1,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), + ('nop:','nop',1,3,0,0,1,3,0,'users2','86425c35a33507d479f71ade53a669aa'), + ('eznode:5','eznode',1,2,0,1,1,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), + ('eznode:2','eznode',1,1,0,1,1,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), + ('eznode:14','eznode',1,6,0,1,1,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), + ('eznode:44','eznode',1,10,0,1,1,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), + ('eznode:12','eznode',1,4,0,1,1,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), + ('eznode:13','eznode',1,5,0,1,1,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), + ('nop:','nop',1,11,0,0,1,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), + ('eznode:12','eznode',1,26,0,0,1,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), + ('eznode:14','eznode',1,29,0,0,1,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), + ('nop:','nop',1,7,0,0,1,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), + ('eznode:13','eznode',1,27,0,0,1,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), + ('eznode:44','eznode',1,30,0,0,1,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), + ('eznode:15','eznode',1,8,0,1,1,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), + ('eznode:15','eznode',1,28,0,0,0,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), + ('eznode:53','eznode',1,20,0,1,1,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,19,0,1,1,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,18,0,1,1,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), + ('eznode:45','eznode',1,12,0,1,1,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), + ('eznode:45','eznode',1,31,0,0,1,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), + ('eznode:53','eznode',1,34,0,0,1,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,33,0,0,1,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,32,0,0,1,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); INSERT INTO `ibexa_url_alias_ml_translation` (`parent`, `text_md5`, `language_id`) VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), @@ -322,42 +322,9 @@ VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), (10,'ccb62ebca03a31272430bc414bd5cd5b',2); INSERT INTO `ibexa_url_alias_ml_incr` (`id`) -VALUES (1), - (2), - (3), - (4), - (5), - (6), - (7), - (8), - (9), - (10), - (11), - (12), - (13), - (14), - (15), - (16), - (17), - (18), - (19), - (20), - (21), - (22), - (24), - (25), - (26), - (27), - (28), - (29), - (30), - (31), - (32), - (33), - (34), - (35), - (36), - (37); +VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), + (18), (19), (20), (21), (22), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), + (34), (35), (36), (37); INSERT INTO `ibexa_user` (`contentobject_id`, `email`, `login`, `password_hash`, `password_hash_type`) VALUES (10,'anonymous@link.invalid','anonymous','$2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC',7), diff --git a/data/postgresql/cleandata.sql b/data/postgresql/cleandata.sql index 0d74db889f..856472ed67 100644 --- a/data/postgresql/cleandata.sql +++ b/data/postgresql/cleandata.sql @@ -1,16 +1,16 @@ -INSERT INTO "ibexa_object_state" ("default_language_id", "group_id", "id", "identifier", "language_mask", "priority") -VALUES (2, 2, 1, 'not_locked', 3, 0), - (2, 2, 2, 'locked', 3, 1); +INSERT INTO "ibexa_object_state" ("default_language_id", "group_id", "id", "identifier", "priority") +VALUES (2, 2, 1, 'not_locked', 0), + (2, 2, 2, 'locked', 1); -INSERT INTO "ibexa_object_state_group" ("default_language_id", "id", "identifier", "language_mask") -VALUES (2, 2, 'ibexa_lock', 3); +INSERT INTO "ibexa_object_state_group" ("default_language_id", "id", "identifier") +VALUES (2, 2, 'ibexa_lock'); INSERT INTO "ibexa_object_state_group_language" ("contentobject_state_group_id", "description","language_id", "name", "real_language_id") -VALUES (2, '', 3, 'Lock', 2); +VALUES (2, '', 2, 'Lock', 2); INSERT INTO "ibexa_object_state_language" ("contentobject_state_id", "description", "language_id", "name") -VALUES (1,'',3,'Not locked'), - (2,'',3,'Locked'); +VALUES (1,'',2,'Not locked'), + (2,'',2,'Locked'); INSERT INTO "ibexa_object_state_link" ("contentobject_id", "contentobject_state_id") VALUES ( 1, 1), @@ -29,13 +29,13 @@ VALUES ( 1, 1), INSERT INTO "ibexa_content_language" ("disabled", "id", "locale", "name") VALUES (0, 2, 'eng-GB', 'English (United Kingdom)'); -INSERT INTO "ibexa_content_type" ("always_available", "contentobject_name", "created", "creator_id", "id", "identifier", "initial_language_id", "is_container", "language_mask", "modified", "modifier_id", "remote_id", "serialized_description_list", "serialized_name_list", "sort_field", "sort_order", "url_alias_name", "status") -VALUES (1,'',1024392098,14,1,'folder',2,1,2,1448831672,14,'a3d405b81be900468eb153d774f4f0d2','a:0:{}','a:1:{s:6:"eng-GB";s:6:"Folder";}',1,1,NULL,0), - (0,'',1024392098,14,2,'article',2,1,3,1082454989,14,'c15b600eb9198b1924063b5a68758232',NULL,'a:2:{s:6:"eng-GB";s:7:"Article";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), - (1,'',1024392098,14,3,'user_group',2,1,3,1048494743,14,'25b4268cdcd01921b808a0d854b877ef',NULL,'a:2:{s:6:"eng-GB";s:10:"User group";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), - (1,' ',1024392098,14,4,'user',2,0,3,1082018364,14,'40faa822edc579b02c25f6bb7beec3ad',NULL,'a:2:{s:6:"eng-GB";s:4:"User";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), - (1,'',1031484992,14,5,'image',2,0,3,1048494784,14,'f6df12aa74e36230eb675f364fccd25a',NULL,'a:2:{s:6:"eng-GB";s:5:"Image";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), - (1,'',1052385472,14,12,'file',2,0,3,1052385669,14,'637d58bfddf164627bdfd265733280a0',NULL,'a:2:{s:6:"eng-GB";s:4:"File";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0); +INSERT INTO "ibexa_content_type" ("always_available", "contentobject_name", "created", "creator_id", "id", "identifier", "initial_language_id", "is_container", "modified", "modifier_id", "remote_id", "serialized_description_list", "serialized_name_list", "sort_field", "sort_order", "url_alias_name", "status") +VALUES (1,'',1024392098,14,1,'folder',2,1,1448831672,14,'a3d405b81be900468eb153d774f4f0d2','a:0:{}','a:1:{s:6:"eng-GB";s:6:"Folder";}',1,1,NULL,0), + (0,'',1024392098,14,2,'article',2,1,1082454989,14,'c15b600eb9198b1924063b5a68758232',NULL,'a:2:{s:6:"eng-GB";s:7:"Article";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), + (1,'',1024392098,14,3,'user_group',2,1,1048494743,14,'25b4268cdcd01921b808a0d854b877ef',NULL,'a:2:{s:6:"eng-GB";s:10:"User group";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), + (1,' ',1024392098,14,4,'user',2,0,1082018364,14,'40faa822edc579b02c25f6bb7beec3ad',NULL,'a:2:{s:6:"eng-GB";s:4:"User";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), + (1,'',1031484992,14,5,'image',2,0,1048494784,14,'f6df12aa74e36230eb675f364fccd25a',NULL,'a:2:{s:6:"eng-GB";s:5:"Image";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0), + (1,'',1052385472,14,12,'file',2,0,1052385669,14,'637d58bfddf164627bdfd265733280a0',NULL,'a:2:{s:6:"eng-GB";s:4:"File";s:16:"always-available";s:6:"eng-GB";}',1,1,NULL,0); INSERT INTO "ibexa_content_type_field_definition" ("can_translate", "category", "content_type_id", "data_float1", "data_float2", "data_float3", "data_float4", "data_int1", "data_int2", "data_int3", "data_int4", "data_text1", "data_text2", "data_text3", "data_text4", "data_text5", "data_type_string", "id", "identifier", "is_information_collector", "is_required", "is_searchable", "is_thumbnail", "placement", "serialized_data_text", "serialized_description_list", "serialized_name_list", "status") VALUES (1,'',2,0,0,0,0,255,0,0,0,'New article','','','','','ibexa_string',1,'title',0,1,1,FALSE,1,NULL,NULL,'a:2:{s:6:"eng-GB";s:5:"Title";s:16:"always-available";s:6:"eng-GB";}',0), @@ -73,30 +73,30 @@ VALUES (1,0,1,'Content'), INSERT INTO "ibexa_content_type_name" ("content_type_id", "content_type_status", "language_id", "language_locale", "name") VALUES (1,0,2,'eng-GB','Folder'), - (2,0,3,'eng-GB','Article'), - (3,0,3,'eng-GB','User group'), - (4,0,3,'eng-GB','User'), - (5,0,3,'eng-GB','Image'), - (12,0,3,'eng-GB','File'); + (2,0,2,'eng-GB','Article'), + (3,0,2,'eng-GB','User group'), + (4,0,2,'eng-GB','User'), + (5,0,2,'eng-GB','Image'), + (12,0,2,'eng-GB','File'); INSERT INTO "ibexa_content_type_group" ("created", "creator_id", "id", "modified", "modifier_id", "name") VALUES (1031216928, 14, 1, 1033922106, 14, 'Content'), (1031216941, 14, 2, 1033922113, 14, 'Users'), (1032009743, 14, 3, 1033922120, 14, 'Media'); -INSERT INTO "ibexa_content" ("content_type_id", "current_version", "id", "initial_language_id", "language_mask", "always_available", "modified", "name", "owner_id", "published", "remote_id", "section_id", "status") -VALUES (1,9,1,2,3,TRUE,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), - (3,1,4,2,3,TRUE,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), - (4,2,10,2,3,TRUE,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), - (3,1,11,2,3,TRUE,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), - (3,1,12,2,3,TRUE,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), - (3,1,13,2,3,TRUE,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), - (4,3,14,2,3,TRUE,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), - (1,1,41,2,3,TRUE,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), - (3,1,42,2,3,TRUE,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), - (1,1,49,2,3,TRUE,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), - (1,1,50,2,3,TRUE,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), - (1,1,51,2,3,TRUE,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); +INSERT INTO "ibexa_content" ("content_type_id", "current_version", "id", "initial_language_id", "always_available", "modified", "name", "owner_id", "published", "remote_id", "section_id", "status") +VALUES (1,9,1,2,TRUE,1448889046,'Ibexa Platform',14,1448889046,'9459d3c29e15006e45197295722c7ade',1,1), + (3,1,4,2,TRUE,1033917596,'Users',14,1033917596,'f5c88a2209584891056f987fd965b0ba',2,1), + (4,2,10,2,TRUE,1072180405,'Anonymous User',14,1033920665,'faaeb9be3bd98ed09f606fc16d144eca',2,1), + (3,1,11,2,TRUE,1033920746,'Guest accounts',14,1033920746,'5f7f0bdb3381d6a461d8c29ff53d908f',2,1), + (3,1,12,2,TRUE,1033920775,'Administrator users',14,1033920775,'9b47a45624b023b1a76c73b74d704acf',2,1), + (3,1,13,2,TRUE,1033920794,'Editors',14,1033920794,'3c160cca19fb135f83bd02d911f04db2',2,1), + (4,3,14,2,TRUE,1301062024,'Administrator User',14,1033920830,'1bb4fe25487f05527efa8bfd394cecc7',2,1), + (1,1,41,2,TRUE,1060695457,'Media',14,1060695457,'a6e35cbcb7cd6ae4b691f3eee30cd262',3,1), + (3,1,42,2,TRUE,1072180330,'Anonymous users',14,1072180330,'15b256dbea2ae72418ff5facc999e8f9',2,1), + (1,1,49,2,TRUE,1080220197,'Images',14,1080220197,'e7ff633c6b8e0fd3531e74c6e712bead',3,1), + (1,1,50,2,TRUE,1080220220,'Files',14,1080220220,'732a5acd01b51a6fe6eab448ad4138a9',3,1), + (1,1,51,2,TRUE,1080220233,'Multimedia',14,1080220233,'09082deb98662a104f325aaa8c4933d3',3,1); INSERT INTO "ibexa_content_translation" ("content_id", "language_id") VALUES (1,2), @@ -113,60 +113,60 @@ VALUES (1,2), (51,2); INSERT INTO "ibexa_content_field" ("attribute_original_id", "content_type_field_definition_id", "contentobject_id", "data_float", "data_int", "data_text", "data_type_string", "id", "language_code", "language_id", "sort_key_int", "sort_key_string", "version") -VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',3,0,'ibexa platform',9), - (0,119,1,NULL,NULL,E'
You are now ready to start your project.
','ibexa_richtext',2,'eng-GB',3,0,'',9), - (0,7,4,NULL,NULL,'Main group','ibexa_string',7,'eng-GB',3,0,'',1), - (0,6,4,NULL,NULL,'Users','ibexa_string',8,'eng-GB',3,0,'',1), - (0,8,10,0,0,'Anonymous','ibexa_string',19,'eng-GB',3,0,'anonymous',2), - (0,9,10,0,0,'User','ibexa_string',20,'eng-GB',3,0,'user',2), - (0,12,10,0,0,'','ibexa_user',21,'eng-GB',3,0,'',2), - (0,6,11,0,0,'Guest accounts','ibexa_string',22,'eng-GB',3,0,'',1), - (0,7,11,0,0,'','ibexa_string',23,'eng-GB',3,0,'',1), - (0,6,12,0,0,'Administrator users','ibexa_string',24,'eng-GB',3,0,'',1), - (0,7,12,0,0,'','ibexa_string',25,'eng-GB',3,0,'',1), - (0,6,13,0,0,'Editors','ibexa_string',26,'eng-GB',3,0,'',1), - (0,7,13,0,0,'','ibexa_string',27,'eng-GB',3,0,'',1), - (0,8,14,0,0,'Administrator','ibexa_string',28,'eng-GB',3,0,'administrator',3), - (0,9,14,0,0,'User','ibexa_string',29,'eng-GB',3,0,'user',3), - (30,12,14,0,0,'','ibexa_user',30,'eng-GB',3,0,'',3), - (0,4,41,0,0,'Media','ibexa_string',98,'eng-GB',3,0,'',1), - (0,119,41,0,1045487555,E'\n
\n','ibexa_richtext',99,'eng-GB',3,0,'',1), - (0,6,42,0,0,'Anonymous users','ibexa_string',100,'eng-GB',3,0,'anonymous users',1), - (0,7,42,0,0,'User group for the anonymous user','ibexa_string',101,'eng-GB',3,0,'user group for the anonymous user',1), - (0,155,1,NULL,NULL,'Ibexa Platform','ibexa_string',102,'eng-GB',3,0,'ibexa platform',9), - (0,155,41,0,0,'','ibexa_string',103,'eng-GB',3,0,'',1), - (0,156,1,NULL,NULL,E'
This is the clean installation coming with Ibexa Platform.It''s a bare-bones setup of the Platform, an excellent foundation to build upon if you want to start your project from scratch.
','ibexa_richtext',104,'eng-GB',3,0,'',9), - (0,156,41,0,1045487555,E'\n
\n','ibexa_richtext',105,'eng-GB',3,0,'',1), - (0,4,49,0,0,'Images','ibexa_string',142,'eng-GB',3,0,'images',1), - (0,155,49,0,0,'','ibexa_string',143,'eng-GB',3,0,'',1), - (0,119,49,0,1045487555,E'\n
\n','ibexa_richtext',144,'eng-GB',3,0,'',1), - (0,156,49,0,1045487555,E'\n
\n','ibexa_richtext',145,'eng-GB',3,0,'',1), - (0,4,50,0,0,'Files','ibexa_string',147,'eng-GB',3,0,'files',1), - (0,155,50,0,0,'','ibexa_string',148,'eng-GB',3,0,'',1), - (0,119,50,0,1045487555,E'\n
\n','ibexa_richtext',149,'eng-GB',3,0,'',1), - (0,156,50,0,1045487555,E'\n
\n','ibexa_richtext',150,'eng-GB',3,0,'',1), - (0,4,51,0,0,'Multimedia','ibexa_string',152,'eng-GB',3,0,'multimedia',1), - (0,155,51,0,0,'','ibexa_string',153,'eng-GB',3,0,'',1), - (0,119,51,0,1045487555,E'\n
\n','ibexa_richtext',154,'eng-GB',3,0,'',1), - (0,156,51,0,1045487555,E'\n
\n','ibexa_richtext',155,'eng-GB',3,0,'',1), - (0,179,10,0,0,'','ibexa_text',177,'eng-GB',3,0,'',2), - (0,179,14,0,0,'','ibexa_text',178,'eng-GB',3,0,'',3), - (0,180,10,0,0,'','ibexa_image',179,'eng-GB',3,0,'',2), - (0,180,14,0,0,E'\n\n','ibexa_image',180,'eng-GB',3,0,'',3); +VALUES (0,4,1,NULL,NULL,'Ibexa Platform','ibexa_string',1,'eng-GB',2,0,'ibexa platform',9), + (0,119,1,NULL,NULL,E'
You are now ready to start your project.
','ibexa_richtext',2,'eng-GB',2,0,'',9), + (0,7,4,NULL,NULL,'Main group','ibexa_string',7,'eng-GB',2,0,'',1), + (0,6,4,NULL,NULL,'Users','ibexa_string',8,'eng-GB',2,0,'',1), + (0,8,10,0,0,'Anonymous','ibexa_string',19,'eng-GB',2,0,'anonymous',2), + (0,9,10,0,0,'User','ibexa_string',20,'eng-GB',2,0,'user',2), + (0,12,10,0,0,'','ibexa_user',21,'eng-GB',2,0,'',2), + (0,6,11,0,0,'Guest accounts','ibexa_string',22,'eng-GB',2,0,'',1), + (0,7,11,0,0,'','ibexa_string',23,'eng-GB',2,0,'',1), + (0,6,12,0,0,'Administrator users','ibexa_string',24,'eng-GB',2,0,'',1), + (0,7,12,0,0,'','ibexa_string',25,'eng-GB',2,0,'',1), + (0,6,13,0,0,'Editors','ibexa_string',26,'eng-GB',2,0,'',1), + (0,7,13,0,0,'','ibexa_string',27,'eng-GB',2,0,'',1), + (0,8,14,0,0,'Administrator','ibexa_string',28,'eng-GB',2,0,'administrator',3), + (0,9,14,0,0,'User','ibexa_string',29,'eng-GB',2,0,'user',3), + (30,12,14,0,0,'','ibexa_user',30,'eng-GB',2,0,'',3), + (0,4,41,0,0,'Media','ibexa_string',98,'eng-GB',2,0,'',1), + (0,119,41,0,1045487555,E'\n
\n','ibexa_richtext',99,'eng-GB',2,0,'',1), + (0,6,42,0,0,'Anonymous users','ibexa_string',100,'eng-GB',2,0,'anonymous users',1), + (0,7,42,0,0,'User group for the anonymous user','ibexa_string',101,'eng-GB',2,0,'user group for the anonymous user',1), + (0,155,1,NULL,NULL,'Ibexa Platform','ibexa_string',102,'eng-GB',2,0,'ibexa platform',9), + (0,155,41,0,0,'','ibexa_string',103,'eng-GB',2,0,'',1), + (0,156,1,NULL,NULL,E'
This is the clean installation coming with Ibexa Platform.It''s a bare-bones setup of the Platform, an excellent foundation to build upon if you want to start your project from scratch.
','ibexa_richtext',104,'eng-GB',2,0,'',9), + (0,156,41,0,1045487555,E'\n
\n','ibexa_richtext',105,'eng-GB',2,0,'',1), + (0,4,49,0,0,'Images','ibexa_string',142,'eng-GB',2,0,'images',1), + (0,155,49,0,0,'','ibexa_string',143,'eng-GB',2,0,'',1), + (0,119,49,0,1045487555,E'\n
\n','ibexa_richtext',144,'eng-GB',2,0,'',1), + (0,156,49,0,1045487555,E'\n
\n','ibexa_richtext',145,'eng-GB',2,0,'',1), + (0,4,50,0,0,'Files','ibexa_string',147,'eng-GB',2,0,'files',1), + (0,155,50,0,0,'','ibexa_string',148,'eng-GB',2,0,'',1), + (0,119,50,0,1045487555,E'\n
\n','ibexa_richtext',149,'eng-GB',2,0,'',1), + (0,156,50,0,1045487555,E'\n
\n','ibexa_richtext',150,'eng-GB',2,0,'',1), + (0,4,51,0,0,'Multimedia','ibexa_string',152,'eng-GB',2,0,'multimedia',1), + (0,155,51,0,0,'','ibexa_string',153,'eng-GB',2,0,'',1), + (0,119,51,0,1045487555,E'\n
\n','ibexa_richtext',154,'eng-GB',2,0,'',1), + (0,156,51,0,1045487555,E'\n
\n','ibexa_richtext',155,'eng-GB',2,0,'',1), + (0,179,10,0,0,'','ibexa_text',177,'eng-GB',2,0,'',2), + (0,179,14,0,0,'','ibexa_text',178,'eng-GB',2,0,'',3), + (0,180,10,0,0,'','ibexa_image',179,'eng-GB',2,0,'',2), + (0,180,14,0,0,E'\n\n','ibexa_image',180,'eng-GB',2,0,'',3); INSERT INTO "ibexa_content_name" ("content_translation", "content_version", "contentobject_id", "language_id", "name", "real_translation") VALUES ('eng-GB',9,1,2,'Ibexa Platform','eng-GB'), - ('eng-GB',1,4,3,'Users','eng-GB'), - ('eng-GB',2,10,3,'Anonymous User','eng-GB'), - ('eng-GB',1,11,3,'Guest accounts','eng-GB'), - ('eng-GB',1,12,3,'Administrator users','eng-GB'), - ('eng-GB',1,13,3,'Editors','eng-GB'), - ('eng-GB',3,14,3,'Administrator User','eng-GB'), - ('eng-GB',1,41,3,'Media','eng-GB'), - ('eng-GB',1,42,3,'Anonymous users','eng-GB'), - ('eng-GB',1,49,3,'Images','eng-GB'), - ('eng-GB',1,50,3,'Files','eng-GB'), - ('eng-GB',1,51,3,'Multimedia','eng-GB'); + ('eng-GB',1,4,2,'Users','eng-GB'), + ('eng-GB',2,10,2,'Anonymous User','eng-GB'), + ('eng-GB',1,11,2,'Guest accounts','eng-GB'), + ('eng-GB',1,12,2,'Administrator users','eng-GB'), + ('eng-GB',1,13,2,'Editors','eng-GB'), + ('eng-GB',3,14,2,'Administrator User','eng-GB'), + ('eng-GB',1,41,2,'Media','eng-GB'), + ('eng-GB',1,42,2,'Anonymous users','eng-GB'), + ('eng-GB',1,49,2,'Images','eng-GB'), + ('eng-GB',1,50,2,'Files','eng-GB'), + ('eng-GB',1,51,2,'Multimedia','eng-GB'); INSERT INTO "ibexa_content_tree" ("contentobject_id", "contentobject_is_published", "contentobject_version", "depth", "is_hidden", "is_invisible", "main_node_id", "modified_subnode", "node_id", "parent_node_id", "path_identification_string", "path_string", "priority", "remote_id", "sort_field", "sort_order") VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96a',1,1), @@ -183,19 +183,19 @@ VALUES (0,1,1,0,0,0,1,1448999778,1,1,'','/1/',0,'629709ba256fe317c3ddcee35453a96 (50,1,1,2,0,0,52,1081860720,52,43,'media/files','/1/43/52/',0,'0b113a208f7890f9ad3c24444ff5988c',9,1), (51,1,1,2,0,0,53,1081860720,53,43,'media/multimedia','/1/43/53/',0,'4f18b82c75f10aad476cae5adf98c11f',9,1); -INSERT INTO "ibexa_content_version" ("contentobject_id", "created", "creator_id", "id", "initial_language_id", "language_mask", "always_available", "modified", "status", "user_id", "version", "workflow_event_pos") -VALUES (4,0,14,4,2,3,TRUE,0,1,0,1,1), - (11,1033920737,14,439,2,3,TRUE,1033920746,1,0,1,0), - (12,1033920760,14,440,2,3,TRUE,1033920775,1,0,1,0), - (13,1033920786,14,441,2,3,TRUE,1033920794,1,0,1,0), - (41,1060695450,14,472,2,3,TRUE,1060695457,1,0,1,0), - (42,1072180278,14,473,2,3,TRUE,1072180330,1,0,1,0), - (10,1072180337,14,474,2,3,TRUE,1072180405,1,0,2,0), - (49,1080220181,14,488,2,3,TRUE,1080220197,1,0,1,0), - (50,1080220211,14,489,2,3,TRUE,1080220220,1,0,1,0), - (51,1080220225,14,490,2,3,TRUE,1080220233,1,0,1,0), - (14,1301061783,14,499,2,3,TRUE,1301062024,1,0,3,0), - (1,1448889045,14,506,2,3,TRUE,1448889046,1,0,9,0); +INSERT INTO "ibexa_content_version" ("contentobject_id", "created", "creator_id", "id", "initial_language_id", "always_available", "modified", "status", "user_id", "version", "workflow_event_pos") +VALUES (4,0,14,4,2,TRUE,0,1,0,1,1), + (11,1033920737,14,439,2,TRUE,1033920746,1,0,1,0), + (12,1033920760,14,440,2,TRUE,1033920775,1,0,1,0), + (13,1033920786,14,441,2,TRUE,1033920794,1,0,1,0), + (41,1060695450,14,472,2,TRUE,1060695457,1,0,1,0), + (42,1072180278,14,473,2,TRUE,1072180330,1,0,1,0), + (10,1072180337,14,474,2,TRUE,1072180405,1,0,2,0), + (49,1080220181,14,488,2,TRUE,1080220197,1,0,1,0), + (50,1080220211,14,489,2,TRUE,1080220220,1,0,1,0), + (51,1080220225,14,490,2,TRUE,1080220233,1,0,1,0), + (14,1301061783,14,499,2,TRUE,1301062024,1,0,3,0), + (1,1448889045,14,506,2,TRUE,1448889046,1,0,9,0); INSERT INTO "ibexa_content_version_translation" ("content_version_id", "language_id") VALUES (4,2), @@ -280,32 +280,32 @@ VALUES ('content/view/full/2',0,12,1,1,0,'d41d8cd98f00b204e9800998ecf8427e',''), ('content/view/full/52',0,29,1,1,0,'ad5a8c6f6aac3b1b9df267fe22e7aef6','media/files'), ('content/view/full/53',0,30,1,1,0,'562a0ac498571c6c3529173184a2657c','media/multimedia'); -INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "lang_mask", "always_available", "link", "parent", "text", "text_md5") -VALUES ('nop:','nop',1,17,0,0,1,TRUE,17,0,'media2','50e2736330de124f6edea9b008556fe6'), - ('eznode:43','eznode',1,9,0,1,3,TRUE,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), - ('nop:','nop',1,3,0,0,1,TRUE,3,0,'users2','86425c35a33507d479f71ade53a669aa'), - ('eznode:5','eznode',1,2,0,1,3,TRUE,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), - ('eznode:2','eznode',1,1,0,1,3,TRUE,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), - ('eznode:14','eznode',1,6,0,1,3,TRUE,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), - ('eznode:44','eznode',1,10,0,1,3,TRUE,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), - ('eznode:12','eznode',1,4,0,1,3,TRUE,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), - ('eznode:13','eznode',1,5,0,1,3,TRUE,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), - ('nop:','nop',1,11,0,0,1,TRUE,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), - ('eznode:12','eznode',1,26,0,0,1,TRUE,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), - ('eznode:14','eznode',1,29,0,0,1,TRUE,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), - ('nop:','nop',1,7,0,0,1,TRUE,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), - ('eznode:13','eznode',1,27,0,0,1,TRUE,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), - ('eznode:44','eznode',1,30,0,0,1,TRUE,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), - ('eznode:15','eznode',1,8,0,1,3,TRUE,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), - ('eznode:15','eznode',1,28,0,0,0,FALSE,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), - ('eznode:53','eznode',1,20,0,1,3,TRUE,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,19,0,1,3,TRUE,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,18,0,1,3,TRUE,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), - ('eznode:45','eznode',1,12,0,1,3,TRUE,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), - ('eznode:45','eznode',1,31,0,0,1,TRUE,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), - ('eznode:53','eznode',1,34,0,0,1,TRUE,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), - ('eznode:52','eznode',1,33,0,0,1,TRUE,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), - ('eznode:51','eznode',1,32,0,0,1,TRUE,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); +INSERT INTO "ibexa_url_alias_ml" ("action", "action_type", "alias_redirects", "id", "is_alias", "is_original", "always_available", "link", "parent", "text", "text_md5") +VALUES ('nop:','nop',1,17,0,0,TRUE,17,0,'media2','50e2736330de124f6edea9b008556fe6'), + ('eznode:43','eznode',1,9,0,1,TRUE,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), + ('nop:','nop',1,3,0,0,TRUE,3,0,'users2','86425c35a33507d479f71ade53a669aa'), + ('eznode:5','eznode',1,2,0,1,TRUE,2,0,'Users','9bc65c2abec141778ffaa729489f3e87'), + ('eznode:2','eznode',1,1,0,1,TRUE,1,0,'','d41d8cd98f00b204e9800998ecf8427e'), + ('eznode:14','eznode',1,6,0,1,TRUE,6,2,'Editors','a147e136bfa717592f2bd70bd4b53b17'), + ('eznode:44','eznode',1,10,0,1,TRUE,10,2,'Anonymous-Users','c2803c3fa1b0b5423237b4e018cae755'), + ('eznode:12','eznode',1,4,0,1,TRUE,4,2,'Guest-accounts','e57843d836e3af8ab611fde9e2139b3a'), + ('eznode:13','eznode',1,5,0,1,TRUE,5,2,'Administrator-users','f89fad7f8a3abc8c09e1deb46a420007'), + ('nop:','nop',1,11,0,0,TRUE,11,3,'anonymous_users2','505e93077a6dde9034ad97a14ab022b1'), + ('eznode:12','eznode',1,26,0,0,TRUE,4,3,'guest_accounts','70bb992820e73638731aa8de79b3329e'), + ('eznode:14','eznode',1,29,0,0,TRUE,6,3,'editors','a147e136bfa717592f2bd70bd4b53b17'), + ('nop:','nop',1,7,0,0,TRUE,7,3,'administrator_users2','a7da338c20bf65f9f789c87296379c2a'), + ('eznode:13','eznode',1,27,0,0,TRUE,5,3,'administrator_users','aeb8609aa933b0899aa012c71139c58c'), + ('eznode:44','eznode',1,30,0,0,TRUE,10,3,'anonymous_users','e9e5ad0c05ee1a43715572e5cc545926'), + ('eznode:15','eznode',1,8,0,1,TRUE,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), + ('eznode:15','eznode',1,28,0,0,FALSE,8,7,'administrator_user','a3cca2de936df1e2f805710399989971'), + ('eznode:53','eznode',1,20,0,1,TRUE,20,9,'Multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,19,0,1,TRUE,19,9,'Files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,18,0,1,TRUE,18,9,'Images','59b514174bffe4ae402b3d63aad79fe0'), + ('eznode:45','eznode',1,12,0,1,TRUE,12,10,'Anonymous-User','ccb62ebca03a31272430bc414bd5cd5b'), + ('eznode:45','eznode',1,31,0,0,TRUE,12,11,'anonymous_user','c593ec85293ecb0e02d50d4c5c6c20eb'), + ('eznode:53','eznode',1,34,0,0,TRUE,20,17,'multimedia','2e5bc8831f7ae6a29530e7f1bbf2de9c'), + ('eznode:52','eznode',1,33,0,0,TRUE,19,17,'files','45b963397aa40d4a0063e0d85e4fe7a1'), + ('eznode:51','eznode',1,32,0,0,TRUE,18,17,'images','59b514174bffe4ae402b3d63aad79fe0'); INSERT INTO "ibexa_url_alias_ml_translation" ("parent", "text_md5", "language_id") VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), @@ -322,42 +322,9 @@ VALUES (0,'62933a2951ef01f4eafd9bdf4d3cd2f0',2), (10,'ccb62ebca03a31272430bc414bd5cd5b',2); INSERT INTO "ibexa_url_alias_ml_incr" ("id") -VALUES (1), - (2), - (3), - (4), - (5), - (6), - (7), - (8), - (9), - (10), - (11), - (12), - (13), - (14), - (15), - (16), - (17), - (18), - (19), - (20), - (21), - (22), - (24), - (25), - (26), - (27), - (28), - (29), - (30), - (31), - (32), - (33), - (34), - (35), - (36), - (37); +VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), + (18), (19), (20), (21), (22), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), + (34), (35), (36), (37); INSERT INTO "ibexa_user" ("contentobject_id", "email", "login", "password_hash", "password_hash_type") VALUES (10,'anonymous@link.invalid','anonymous','$2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC',7), diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 937e499a1b..125d746cb5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11040,42 +11040,6 @@ parameters: count: 1 path: src/lib/Persistence/Legacy/Content/Language/Mapper.php - - - message: '#^Call to function is_int\(\) with 2\|int\<4, max\> will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\:\:extractLanguageCodesFromMask\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\:\:extractLanguageIdsFromMask\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\:\:isLanguageAlwaysAvailable\(\) has parameter \$languages with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - - - message: '#^Parameter \#1 \$array of function array_keys expects array, iterable\ given\.$#' - identifier: argument.type - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - - - message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\:\:\$languageHandler \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\Handler\) does not accept Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway\:\:getBasicNodeData\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -32532,66 +32496,6 @@ parameters: count: 1 path: tests/lib/Persistence/Legacy/Content/Language/LanguageHandlerTest.php - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:getLanguageHandler\(\) should return Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\Handler but returns Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\.$#' - identifier: return.type - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:getLanguageIndicatorData\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:isAlwaysAvailableProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:languageIdsFromMaskProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:removeAlwaysAvailableFlagProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:testExtractLanguageIdsFromMask\(\) has parameter \$expectedResult with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:testRemoveAlwaysAvailableFlag\(\) has parameter \$expectedResult with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGeneratorTest\:\:testRemoveAlwaysAvailableFlag\(\) has parameter \$langMask with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Offset string might not exist on array\{\}\|array\{eng\-US\?\: Ibexa\\Contracts\\Core\\Persistence\\Content\\Language, eng\-GB\?\: Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\}\.$#' - identifier: offsetAccess.notFound - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - - - message: '#^Property Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\LanguageAwareTestCase\:\:\$languageHandler \(Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\LanguageAwareTestCase\:\:getFullTextSearchConfiguration\(\) has no return type specified\.$#' identifier: missingType.return @@ -32610,12 +32514,6 @@ parameters: count: 1 path: tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php - - - message: '#^Property Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\LanguageAwareTestCase\:\:\$languageMaskGenerator \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\MaskGenerator\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php - - message: '#^Method Ibexa\\Tests\\Core\\Persistence\\Legacy\\Content\\LanguageHandlerMock\:\:delete\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/bundle/Core/Resources/config/doctrine_migrations.php b/src/bundle/Core/Resources/config/doctrine_migrations.php index 04691f6550..b058a0db8b 100644 --- a/src/bundle/Core/Resources/config/doctrine_migrations.php +++ b/src/bundle/Core/Resources/config/doctrine_migrations.php @@ -16,6 +16,7 @@ use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertMariaDbJsonColumnsTo6_0Migration; use Ibexa\Bundle\RepositoryInstaller\Migration\ConvertPostgreSqlSerialColumnsToIdentityMigration; +use Ibexa\Bundle\RepositoryInstaller\Migration\DropLanguageBitmaskColumnsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\FixLegacyIdentifiersMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\ImportDataMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\InstallSchemaMigration; @@ -23,6 +24,7 @@ use Ibexa\Bundle\RepositoryInstaller\Migration\RemoveStateAssignLocationLimitationsMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\RenamePostgreSqlPrimaryKeysMigration; use Ibexa\Bundle\RepositoryInstaller\Migration\RenameSchemaTo5_0Migration; +use Ibexa\Bundle\RepositoryInstaller\Migration\StripAlwaysAvailableBitFromLanguageIdsMigration; use Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationTag; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -101,7 +103,15 @@ ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); + $services->set(DropLanguageBitmaskColumnsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + $services->set(BackfillLanguageTranslationsMigration::class) ->arg('$connection', service('ibexa.persistence.connection')) ->tag(IbexaMigrationTag::TAG); + + $services->set(StripAlwaysAvailableBitFromLanguageIdsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); }; diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index 2701bdd342..dd7041f642 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -11,7 +11,6 @@ tables: ibexa_object_state: indexes: ibexa_object_state_priority: { fields: [priority] } - ibexa_object_state_lmask: { fields: [language_mask] } uniqueConstraints: ibexa_object_state_identifier: { fields: [group_id, identifier] } id: @@ -20,11 +19,8 @@ tables: default_language_id: { type: bigint, nullable: false, options: { default: '0' } } group_id: { type: integer, nullable: false, options: { default: '0' } } identifier: { type: string, nullable: false, length: 45, options: { default: '' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } priority: { type: integer, nullable: false, options: { default: '0' } } ibexa_object_state_group: - indexes: - ibexa_object_state_group_lmask: { fields: [language_mask] } uniqueConstraints: ibexa_object_state_group_identifier: { fields: [identifier] } id: @@ -32,7 +28,6 @@ tables: fields: default_language_id: { type: bigint, nullable: false, options: { default: '0' } } identifier: { type: string, nullable: false, length: 45, options: { default: '' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } ibexa_object_state_group_language: id: contentobject_state_group_id: { type: integer, nullable: false, options: { default: '0' } } @@ -129,7 +124,6 @@ tables: identifier: { type: string, nullable: false, length: 50, options: { default: '' } } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } is_container: { type: integer, nullable: false, options: { default: '0' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } modified: { type: integer, nullable: false, options: { default: '0' } } modifier_id: { type: integer, nullable: false, options: { default: '0' } } remote_id: { type: string, nullable: false, length: 100, options: { default: '' } } @@ -214,7 +208,6 @@ tables: ibexa_content: indexes: ibexa_content_type_id: { fields: [content_type_id] } - ibexa_content_lmask: { fields: [language_mask] } ibexa_content_pub: { fields: [published] } ibexa_content_section: { fields: [section_id] } ibexa_content_currentversion: { fields: [current_version] } @@ -228,7 +221,6 @@ tables: content_type_id: { type: integer, nullable: false, options: { default: '0' } } current_version: { type: integer, nullable: true } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } always_available: { type: boolean, nullable: false, options: { default: false } } modified: { type: integer, nullable: false, options: { default: '0' } } name: { type: string, nullable: true, length: 255 } @@ -327,7 +319,6 @@ tables: created: { type: integer, nullable: false, options: { default: '0' } } creator_id: { type: integer, nullable: false, options: { default: '0' } } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } always_available: { type: boolean, nullable: false, options: { default: false } } modified: { type: integer, nullable: false, options: { default: '0' } } status: { type: integer, nullable: false, options: { default: '0' } } @@ -531,7 +522,6 @@ tables: published: { type: integer, nullable: false, options: { default: '0' } } section_id: { type: integer, nullable: false, options: { default: '0' } } word_id: { type: integer, nullable: false, options: { default: '0' } } - language_mask: { type: bigint, nullable: false, options: { default: '0' } } language_id: { type: bigint, nullable: false, options: { default: '0' } } is_main_and_always_available: { type: boolean, nullable: false, options: { default: false } } ibexa_search_word: @@ -599,7 +589,7 @@ tables: ibexa_url_alias_ml: indexes: ibexa_url_alias_ml_actt_org_al: { fields: [action_type, is_original, is_alias] } - ibexa_url_alias_ml_text_lang: { fields: [text, lang_mask, parent], options: { lengths: ['32', null, null] } } + ibexa_url_alias_ml_text_lang: { fields: [text, parent], options: { lengths: ['32', null] } } ibexa_url_alias_ml_par_act_id_lnk: { fields: [action, id, link, parent], options: { lengths: ['32', null, null, null] } } ibexa_url_alias_ml_par_lnk_txt: { fields: [parent, text, link], options: { lengths: [null, '32', null] } } ibexa_url_alias_ml_act_org: { fields: [action, is_original], options: { lengths: ['32', null] } } @@ -616,7 +606,6 @@ tables: id: { type: integer, nullable: false, options: { default: '0' } } is_alias: { type: integer, nullable: false, options: { default: '0' } } is_original: { type: integer, nullable: false, options: { default: '0' } } - lang_mask: { type: bigint, nullable: false, options: { default: '0' } } link: { type: integer, nullable: false, options: { default: '0' } } text: { type: text, nullable: false, length: 0 } always_available: { type: boolean, nullable: false, options: { default: false } } diff --git a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php new file mode 100644 index 0000000000..b062ae37df --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -0,0 +1,232 @@ +hasTable()/hasColumn() would always report false there. + */ +final class DropLanguageBitmaskColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string CONTENT_TABLE = 'ibexa_content'; + + /** + * Not yet renamed to "ibexa_language" at this point in the migration sequence - that rename + * happens later, in {@see RenameLanguageTableMigration}. + */ + private const string LANGUAGE_TABLE = 'ibexa_content_language'; + + /** + * Table => [mask column, index to drop (if any), whether the index needs replacing with a + * lang-less equivalent rather than just dropped (only "ibexa_url_alias_ml")]. + * + * @var array + */ + private const array DROPS = [ + 'ibexa_object_state' => ['language_mask', 'ibexa_object_state_lmask', false], + 'ibexa_object_state_group' => ['language_mask', 'ibexa_object_state_group_lmask', false], + 'ibexa_content_type' => ['language_mask', null, false], + self::CONTENT_TABLE => ['language_mask', 'ibexa_content_lmask', false], + 'ibexa_content_version' => ['language_mask', null, false], + 'ibexa_search_object_word_link' => ['language_mask', null, false], + 'ibexa_url_alias_ml' => ['lang_mask', 'ibexa_url_alias_ml_text_lang', true], + ]; + + /** + * Which of {@see DROPS} also need a `abortIfTranslationsNotBackfilled()` check before their + * column is dropped, and what to check it against. + */ + private const array BACKFILL_CHECKS = [ + self::CONTENT_TABLE => ['ibexa_content_translation', 'content_id'], + 'ibexa_content_version' => ['ibexa_content_version_translation', 'content_version_id'], + 'ibexa_url_alias_ml' => ['ibexa_url_alias_ml_translation', null], + ]; + + public function getDescription(): string + { + return 'Drops the language bitmask ("language_mask"/"lang_mask") columns, now that nothing reads them'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 05:00:00'); + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::CONTENT_TABLE])) { + return; + } + + $tablesStillCarryingMask = []; + + foreach (self::DROPS as $table => [$maskColumn]) { + if ( + $schemaManager->tablesExist([$table]) + && $schemaManager->introspectTable($table)->hasColumn($maskColumn) + ) { + $tablesStillCarryingMask[$table] = true; + } + } + + if ($tablesStillCarryingMask === []) { + // Already dropped everywhere (or a fresh install whose schema.yaml never had it). + return; + } + + $this->abortIfTranslationsNotBackfilled(array_keys($tablesStillCarryingMask)); + + foreach (self::DROPS as $table => [$maskColumn, $indexName, $replaceIndex]) { + if (!isset($tablesStillCarryingMask[$table])) { + continue; + } + + $introspectedTable = $schemaManager->introspectTable($table); + + if ($indexName !== null) { + $indexExists = $introspectedTable->hasIndex($indexName); + $indexStillHasMaskColumn = $indexExists + && in_array($maskColumn, $introspectedTable->getIndex($indexName)->getColumns(), true); + + if ($replaceIndex) { + if ($indexStillHasMaskColumn) { + // Still the old, mask-including definition - drop it before recreating + // without the mask column below. + $this->addSql($this->buildDropIndexSql($table, $indexName)); + } + + if ($indexStillHasMaskColumn || !$indexExists) { + // Either just dropped above, or missing entirely because a prior partial + // run dropped it but was interrupted before recreating it - either way it + // still needs (re)creating in its final, mask-less form. If neither is true, + // the index already exists in that final form and needs no change. + $this->addSql($this->buildCreateUrlAliasTextParentIndexSql()); + } + } elseif ($indexExists) { + $this->addSql($this->buildDropIndexSql($table, $indexName)); + } + } + + $this->addSql("ALTER TABLE {$table} DROP COLUMN {$maskColumn}"); + } + } + + private function buildDropIndexSql( + string $table, + string $indexName + ): string { + // MySQL ties an index's identity to its table ("DROP INDEX x ON t" / "ALTER TABLE t DROP + // INDEX x"); PostgreSQL/SQLite index names are unique connection/schema-wide, dropped + // without referencing the table. + return $this->isMySQL() || $this->isMariaDB() + ? "ALTER TABLE {$table} DROP INDEX {$indexName}" + : "DROP INDEX {$indexName}"; + } + + private function buildCreateUrlAliasTextParentIndexSql(): string + { + // Replaces the dropped "(text(32), parent)"/"(text, parent)" + lang index with a lang-less + // equivalent - "lang_mask" is gone, but the (text, parent) lookup itself is still needed. + return $this->isMySQL() || $this->isMariaDB() + ? 'ALTER TABLE ibexa_url_alias_ml ADD INDEX ibexa_url_alias_ml_text_lang (text(32), parent)' + : 'CREATE INDEX ibexa_url_alias_ml_text_lang ON ibexa_url_alias_ml (text, parent)'; + } + + /** + * Refuses to drop the mask columns if any row still carrying a real (non-always-available) + * language bit has no corresponding row in the relational replacement it should have been + * backfilled into - i.e. `ibexa:languages:backfill-translations` was never run, or didn't + * finish, for this table. Once the mask columns are gone the mask data is unrecoverable, so + * this check is deliberately a hard abort rather than a warning. + * + * Joins against every language bit actually set in the mask (via {@see LANGUAGE_TABLE}, the + * table of valid bit values) rather than just checking "does any translation row exist for this + * content id at all" - a row with two bits set but only one backfilled (e.g. mask 2|4 with only + * language 2's translation row written) must still be caught here, or dropping the mask below + * would silently and irrecoverably lose language 4's membership for that row. + * + * Only checks tables in $tablesStillCarryingMask (rather than unconditionally checking all of + * {@see BACKFILL_CHECKS}): once a table's mask column is actually dropped, the column this + * check's SQL references no longer exists, so re-running it unconditionally on a later retry + * would fail with an unrelated "unknown column" error instead of the intended abort message. + * + * @param string[] $tablesStillCarryingMask + */ + private function abortIfTranslationsNotBackfilled(array $tablesStillCarryingMask): void + { + foreach (self::BACKFILL_CHECKS as $maskTable => [$translationTable, $idColumn]) { + if (!in_array($maskTable, $tablesStillCarryingMask, true)) { + continue; + } + + $maskColumn = $maskTable === 'ibexa_url_alias_ml' ? 'lang_mask' : 'language_mask'; + + if ($idColumn !== null) { + $joinCondition = "t.{$idColumn} = m.id AND t.language_id = l.id"; + } else { + // ibexa_url_alias_ml's primary key is (parent, text_md5), not a single "id" column. + $joinCondition = 't.parent = m.parent AND t.text_md5 = m.text_md5 AND t.language_id = l.id'; + } + + $missingCount = (int)$this->connection->fetchOne( + "SELECT COUNT(*) FROM {$maskTable} m + JOIN " . self::LANGUAGE_TABLE . " l ON (m.{$maskColumn} & l.id) = l.id + WHERE NOT EXISTS (SELECT 1 FROM {$translationTable} t WHERE {$joinCondition})" + ); + + $this->abortIf( + $missingCount > 0, + "Refusing to drop \"{$maskColumn}\" from \"{$maskTable}\": {$missingCount} row(s) carry a " . + "real language bit with no matching row in \"{$translationTable}\" - run " . + '"ibexa:languages:backfill-translations" (and confirm ' . + '"ibexa:languages:verify-translations" reports clean) before this migration.' + ); + } + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php new file mode 100644 index 0000000000..c1d6d68db4 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php @@ -0,0 +1,154 @@ + column to chunk by, or null for tables small enough for a single statement. + */ + private const array TABLES = [ + 'ibexa_content_field' => 'id', + 'ibexa_content_name' => 'contentobject_id', + 'ibexa_content_type_name' => null, + 'ibexa_object_state_language' => null, + 'ibexa_object_state_group_language' => null, + ]; + + public function getDescription(): string + { + return 'Strips the legacy "always available" bit from language_id columns'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 07:00:00'); + } + + public function isTransactional(): bool + { + return false; + } + + public function up(Schema $schema): void + { + $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + if ($schemaManager->tablesExist([self::LANGUAGE_TABLE]) && $this->hasSequentialLanguageIds()) { + return; + } + + if ($schemaManager->tablesExist(['ibexa_object_state', 'ibexa_object_state_language'])) { + $this->addStaleObjectStateTranslationRemoval(); + } + + foreach (self::TABLES as $table => $chunkColumn) { + if (!$schemaManager->tablesExist([$table])) { + continue; + } + + $updateSql = "UPDATE {$table} SET language_id = language_id - 1 WHERE language_id % 2 = 1"; + if ($chunkColumn === null) { + $this->addSql($updateSql); + continue; + } + + $this->addChunkedSql($table, $chunkColumn, $updateSql); + } + } + + private function hasSequentialLanguageIds(): bool + { + foreach ($this->connection->fetchFirstColumn('SELECT id FROM ' . self::LANGUAGE_TABLE) as $languageId) { + $languageId = (int)$languageId; + if (($languageId & ($languageId - 1)) !== 0) { + return true; + } + } + + return false; + } + + private function addStaleObjectStateTranslationRemoval(): void + { + if ($this->isMySQL() || $this->isMariaDB()) { + $this->addSqlFile(__DIR__ . '/sql/remove-stale-object-state-translations-mysql.sql'); + } elseif ($this->isPostgreSQL()) { + $this->addSqlFile(__DIR__ . '/sql/remove-stale-object-state-translations-postgresql.sql'); + } else { + $this->addSqlFile(__DIR__ . '/sql/remove-stale-object-state-translations-sqlite.sql'); + } + } + + private function addChunkedSql( + string $table, + string $chunkColumn, + string $updateSql + ): void { + $range = $this->connection->fetchAssociative( + "SELECT MIN({$chunkColumn}) AS min_id, MAX({$chunkColumn}) AS max_id FROM {$table}" + ); + if ($range === false || $range['min_id'] === null) { + return; + } + + $maxId = (int)$range['max_id']; + for ($from = (int)$range['min_id']; $from <= $maxId; $from += self::BATCH_SIZE) { + $this->addSql( + "{$updateSql} AND {$chunkColumn} BETWEEN :from AND :to", + ['from' => $from, 'to' => min($from + self::BATCH_SIZE - 1, $maxId)], + ['from' => ParameterType::INTEGER, 'to' => ParameterType::INTEGER] + ); + } + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql new file mode 100644 index 0000000000..4bace1e7b6 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql @@ -0,0 +1,7 @@ +DELETE stale +FROM ibexa_object_state_language AS stale + INNER JOIN ibexa_object_state AS state ON state.id = stale.contentobject_state_id + INNER JOIN ibexa_object_state_language AS twin + ON twin.contentobject_state_id = stale.contentobject_state_id + AND twin.language_id = stale.language_id + 1 - 2 * (stale.language_id % 2) +WHERE (stale.language_id % 2 = 1) <> (stale.language_id - stale.language_id % 2 = state.default_language_id); diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql new file mode 100644 index 0000000000..35fe0f94c0 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql @@ -0,0 +1,6 @@ +DELETE FROM ibexa_object_state_language AS stale +USING ibexa_object_state AS state, ibexa_object_state_language AS twin +WHERE state.id = stale.contentobject_state_id + AND twin.contentobject_state_id = stale.contentobject_state_id + AND twin.language_id = stale.language_id + 1 - 2 * (stale.language_id % 2) + AND (stale.language_id % 2 = 1) <> (stale.language_id - stale.language_id % 2 = state.default_language_id); diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql new file mode 100644 index 0000000000..0a16dd8397 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql @@ -0,0 +1,14 @@ +DELETE FROM ibexa_object_state_language +WHERE EXISTS ( + SELECT 1 + FROM ibexa_object_state_language AS twin + WHERE twin.contentobject_state_id = ibexa_object_state_language.contentobject_state_id + AND twin.language_id = ibexa_object_state_language.language_id + 1 - 2 * (ibexa_object_state_language.language_id % 2) + ) + AND (language_id % 2 = 1) <> ( + language_id - language_id % 2 = ( + SELECT state.default_language_id + FROM ibexa_object_state AS state + WHERE state.id = ibexa_object_state_language.contentobject_state_id + ) + ); diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 032650e6e6..342ddd0640 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -23,6 +23,17 @@ */ final class FixtureImporter { + /** + * Tables whose "language_id" the legacy bitmask scheme ORed the "always available" bit into. + */ + private const TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT = [ + 'ibexa_content_field', + 'ibexa_content_name', + 'ibexa_content_type_name', + 'ibexa_object_state_language', + 'ibexa_object_state_group_language', + ]; + /** * Join tables referencing "ibexa_content_language" (ON DELETE RESTRICT), keyed to the table owning their rows. */ @@ -66,6 +77,7 @@ public function import(Fixture $fixture): void // updating in lockstep with schema changes. $existingColumns = $this->getExistingColumns($table); foreach ($rows as $row) { + $row = $this->stripLegacyAlwaysAvailableBit($table, $row); $this->connection->insert($table, array_intersect_key($row, array_flip($existingColumns))); } } @@ -132,6 +144,26 @@ private function reattachLanguageTranslations(array $detachedTranslations): void } } + /** + * Fixture data was captured under the legacy bitmask scheme, where every language id is a power + * of two - mirrors what StripAlwaysAvailableBitFromLanguageIdsMigration does for production + * upgrades, applied to the fixture rows only. + * + * @param array $row + * + * @return array + */ + private function stripLegacyAlwaysAvailableBit( + string $table, + array $row + ): array { + if (isset($row['language_id']) && in_array($table, self::TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT, true)) { + $row['language_id'] = (int)$row['language_id'] & ~1; + } + + return $row; + } + /** * @return string[] */ diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index 1adadd6e3f..4c36ec52b4 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -36,7 +36,6 @@ use Ibexa\Core\FieldType\FieldTypeAliasResolverInterface; use Ibexa\Core\Persistence\Legacy\Content\Gateway; use Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Content\StorageFieldValue; use Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway as SharedGateway; @@ -53,18 +52,11 @@ */ final class DoctrineDatabase extends Gateway { - /** - * Pre-computed integer constant which, when combined with proper bit-wise operator, - * removes always available flag from the mask. - */ - private const int REMOVE_ALWAYS_AVAILABLE_LANG_MASK_OPERAND = -2; - public function __construct( protected Connection $connection, private readonly SharedGateway $sharedGateway, protected QueryBuilder $queryBuilder, protected LanguageHandler $languageHandler, - protected LanguageMaskGenerator $languageMaskGenerator, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver ) {} @@ -110,14 +102,6 @@ public function insertContentObject( ContentInfo::STATUS_DRAFT, ParameterType::INTEGER ), - 'language_mask' => $query->createPositionalParameter( - $this->languageMaskGenerator->generateLanguageMaskForFields( - $struct->fields, - $initialLanguageCode, - $struct->alwaysAvailable - ), - ParameterType::INTEGER - ), 'always_available' => $query->createPositionalParameter( $struct->alwaysAvailable, ParameterType::BOOLEAN @@ -175,14 +159,6 @@ public function insertVersion( $versionInfo->contentInfo->id, ParameterType::INTEGER ), - 'language_mask' => $query->createPositionalParameter( - $this->languageMaskGenerator->generateLanguageMaskForFields( - $fields, - $versionInfo->initialLanguageCode, - $versionInfo->contentInfo->alwaysAvailable - ), - ParameterType::INTEGER - ), 'always_available' => $query->createPositionalParameter( $versionInfo->contentInfo->alwaysAvailable, ParameterType::BOOLEAN @@ -356,14 +332,6 @@ public function updateContent( if ($prePublishVersionInfo !== null) { $alwaysAvailable = $struct->alwaysAvailable ?? $prePublishVersionInfo->contentInfo->alwaysAvailable; - $mask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - $prePublishVersionInfo->languageCodes, - $alwaysAvailable - ); - $query->set( - 'language_mask', - $query->createNamedParameter($mask, ParameterType::INTEGER, ':languageMask') - ); $query->set( 'always_available', $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') @@ -409,13 +377,6 @@ public function updateVersion( ->set('creator_id', ':creator_id') ->set('modified', ':modified') ->set('initial_language_id', ':initial_language_id') - ->set( - 'language_mask', - $this->getDatabasePlatform()->getBitOrComparisonExpression( - 'language_mask', - ':language_mask' - ) - ) ->setParameter('creator_id', $struct->creatorId, ParameterType::INTEGER) ->setParameter('modified', $struct->modificationDate, ParameterType::INTEGER) ->setParameter( @@ -423,15 +384,6 @@ public function updateVersion( $struct->initialLanguageId, ParameterType::INTEGER ) - ->setParameter( - 'language_mask', - $this->languageMaskGenerator->generateLanguageMaskForFields( - $struct->fields, - $this->languageHandler->load($struct->initialLanguageId)->languageCode, - false - ), - ParameterType::INTEGER - ) ->where('contentobject_id = :content_id') ->andWhere('version = :version_no') ->setParameter('content_id', $contentId, ParameterType::INTEGER) @@ -462,35 +414,11 @@ public function updateAlwaysAvailableFlag( int $contentId, ?bool $alwaysAvailable = null ): void { - // We will need to know some info on the current language mask to update the flag - // everywhere needed - $contentInfoRow = $this->loadContentInfo($contentId); - $versionNo = (int)$contentInfoRow['current_version']; - $languageMask = (int)$contentInfoRow['language_mask']; - $initialLanguageId = (int)$contentInfoRow['initial_language_id']; if (!isset($alwaysAvailable)) { - $alwaysAvailable = 1 === ($languageMask & 1); + $contentInfoRow = $this->loadContentInfo($contentId); + $alwaysAvailable = (bool)$contentInfoRow['always_available']; } - $this->updateContentItemAlwaysAvailableFlag($contentId, $alwaysAvailable); - $this->updateContentNameAlwaysAvailableFlag( - $contentId, - $versionNo, - $alwaysAvailable - ); - $this->updateContentFieldsAlwaysAvailableFlag( - $contentId, - $versionNo, - $alwaysAvailable, - $languageMask, - $initialLanguageId - ); - } - - private function updateContentItemAlwaysAvailableFlag( - int $contentId, - bool $alwaysAvailable - ): void { $query = $this->connection->createQueryBuilder(); $expr = $query->expr(); $query @@ -498,128 +426,14 @@ private function updateContentItemAlwaysAvailableFlag( ->set( 'always_available', $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') - ); - $this - ->setLanguageMaskForUpdateQuery($alwaysAvailable, $query, 'language_mask') - ->where( - $expr->eq( - 'id', - $query->createNamedParameter($contentId, ParameterType::INTEGER, ':contentId') - ) - ); - $query->executeStatement(); - } - - private function updateContentNameAlwaysAvailableFlag( - int $contentId, - int $versionNo, - bool $alwaysAvailable - ): void { - $query = $this->connection->createQueryBuilder(); - $expr = $query->expr(); - $query - ->update(self::CONTENT_NAME_TABLE); - $this - ->setLanguageMaskForUpdateQuery($alwaysAvailable, $query, 'language_id') - ->where( - $expr->eq( - 'contentobject_id', - $query->createNamedParameter($contentId, ParameterType::INTEGER, ':contentId') - ) ) - ->andWhere( - $expr->eq( - 'content_version', - $query->createNamedParameter($versionNo, ParameterType::INTEGER, ':versionNo') - ) - ); - $query->executeStatement(); - } - - private function updateContentFieldsAlwaysAvailableFlag( - int $contentId, - int $versionNo, - bool $alwaysAvailable, - int $languageMask, - int $initialLanguageId - ): void { - $query = $this->connection->createQueryBuilder(); - $expr = $query->expr(); - $query - ->update(self::CONTENT_FIELD_TABLE) ->where( $expr->eq( - 'contentobject_id', + 'id', $query->createNamedParameter($contentId, ParameterType::INTEGER, ':contentId') ) - ) - ->andWhere( - $expr->eq( - 'version', - $query->createNamedParameter($versionNo, ParameterType::INTEGER, ':versionNo') - ) ); - - // If there is only a single language, update all fields and return - if (!$this->languageMaskGenerator->isLanguageMaskComposite($languageMask)) { - $this->setLanguageMaskForUpdateQuery($alwaysAvailable, $query, 'language_id'); - - $query->executeStatement(); - - return; - } - - // Otherwise: - // 1. Remove always available flag on all fields - $query - ->set( - 'language_id', - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'language_id', - ':languageMaskOperand' - ) - ) - ->setParameter('languageMaskOperand', self::REMOVE_ALWAYS_AVAILABLE_LANG_MASK_OPERAND) - ; $query->executeStatement(); - - // 2. If Content is always available set the flag only on fields in main language - if ($alwaysAvailable) { - $mainLanguageQuery = $this->connection->createQueryBuilder(); - $mainLanguageExpr = $mainLanguageQuery->expr(); - $mainLanguageQuery - ->update(self::CONTENT_FIELD_TABLE) - ->where( - $mainLanguageExpr->eq( - 'contentobject_id', - $mainLanguageQuery->createNamedParameter($contentId, ParameterType::INTEGER, ':contentId') - ) - ) - ->andWhere( - $mainLanguageExpr->eq( - 'version', - $mainLanguageQuery->createNamedParameter($versionNo, ParameterType::INTEGER, ':versionNo') - ) - ) - ->set( - 'language_id', - $this->getDatabasePlatform()->getBitOrComparisonExpression( - 'language_id', - ':languageMaskOperand' - ) - ) - ->setParameter('languageMaskOperand', 1) - ->andWhere( - $mainLanguageExpr->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - 'language_id', - $mainLanguageQuery->createNamedParameter($initialLanguageId, ParameterType::INTEGER, ':initialLanguageId') - ), - $mainLanguageQuery->createNamedParameter(0, ParameterType::INTEGER, ':zero') - ) - ); - $mainLanguageQuery->executeStatement(); - } } public function setStatus( @@ -782,27 +596,11 @@ private function setInsertFieldValues( ) ->setParameter( 'language_id', - $this->languageMaskGenerator->generateLanguageIndicator( - $field->languageCode, - $this->isLanguageAlwaysAvailable($content, $field->languageCode) - ), + $this->languageHandler->loadByLanguageCode($field->languageCode)->id, ParameterType::INTEGER ); } - /** - * Check if $languageCode is always available in $content. - */ - private function isLanguageAlwaysAvailable( - Content $content, - string $languageCode - ): bool { - return - $content->versionInfo->contentInfo->alwaysAvailable && - $content->versionInfo->contentInfo->mainLanguageCode === $languageCode - ; - } - public function updateField( Field $field, StorageFieldValue $value @@ -1595,7 +1393,7 @@ public function setName( 'content_version' => ':version_no', 'content_translation' => ':language_code', 'name' => ':name', - 'language_id' => $this->getSetNameLanguageMaskSubQuery(), + 'language_id' => ':language_id', 'real_translation' => ':language_code', ] ); @@ -1603,7 +1401,7 @@ public function setName( $query ->update(self::CONTENT_NAME_TABLE) ->set('name', ':name') - ->set('language_id', $this->getSetNameLanguageMaskSubQuery()) + ->set('language_id', ':language_id') ->set('real_translation', ':language_code') ->where('contentobject_id = :content_id') ->andWhere('content_version = :version_no') @@ -1613,19 +1411,6 @@ public function setName( $query->executeStatement(); } - /** - * Return a language sub select query for setName. - * - * The query generates the proper language mask at the runtime of the INSERT/UPDATE query - * generated by setName. - * - * @see setName - */ - private function getSetNameLanguageMaskSubQuery(): string - { - return $this->sharedGateway->getSetNameLanguageMaskSubQuery(); - } - public function deleteContent(int $contentId): void { $query = $this->connection->createQueryBuilder(); @@ -2244,7 +2029,7 @@ private function deleteTranslationFromContentNames( } /** - * Remove language from ibexa_content_translation and the language_mask of ibexa_content. + * Remove language from ibexa_content_translation. * * @param int $contentId * @param int $languageId @@ -2271,8 +2056,6 @@ private function deleteTranslationFromContentObject( $query = $this->connection->createQueryBuilder(); $query->update(Gateway::CONTENT_ITEM_TABLE) - // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS - ->set('language_mask', 'language_mask & ~ ' . $languageId) ->set('modified', ':now') ->where('id = :contentId') ->setParameter('now', time()) @@ -2288,8 +2071,7 @@ private function deleteTranslationFromContentObject( } /** - * Remove language from ibexa_content_version_translation and the language_mask of ibexa_content_version, - * and update initialLanguageId + * Remove language from ibexa_content_version_translation and update initialLanguageId * if it matches the removed one. * * @param int|null $versionNo optional, if specified, apply to this Version only. @@ -2337,8 +2119,6 @@ private function deleteTranslationFromContentVersions( $query = $this->connection->createQueryBuilder(); $query->update($versionTable) - // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS - ->set('language_mask', 'language_mask & ~ ' . $languageId) ->set('modified', ':now') // update initial_language_id only if it matches removed translation languageId ->set( @@ -2362,38 +2142,6 @@ private function deleteTranslationFromContentVersions( ); } - /** - * Compute language mask and append it to a QueryBuilder (both column and parameter). - * - * **Can be used on UPDATE queries only!** - */ - private function setLanguageMaskForUpdateQuery( - bool $alwaysAvailable, - DoctrineQueryBuilder $query, - string $languageMaskColumnName - ): DoctrineQueryBuilder { - if ($alwaysAvailable) { - $languageMaskExpr = $this->getDatabasePlatform()->getBitOrComparisonExpression( - $languageMaskColumnName, - ':languageMaskOperand' - ); - } else { - $languageMaskExpr = $this->getDatabasePlatform()->getBitAndComparisonExpression( - $languageMaskColumnName, - ':languageMaskOperand' - ); - } - - $query - ->set($languageMaskColumnName, $languageMaskExpr) - ->setParameter( - 'languageMaskOperand', - $alwaysAvailable ? 1 : self::REMOVE_ALWAYS_AVAILABLE_LANG_MASK_OPERAND - ); - - return $query; - } - /** * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway.php b/src/lib/Persistence/Legacy/Content/Language/Gateway.php index eba63900a7..bc5a211f0a 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway.php @@ -12,7 +12,6 @@ use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway as ObjectStateGateway; use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway; -use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway; /** * Content Model language gateway. @@ -24,27 +23,26 @@ abstract class Gateway public const CONTENT_LANGUAGE_TABLE = 'ibexa_content_language'; /** - * A map of language-related table name to its language column. + * A map of language-related table name to the single column identifying a real language id + * that row references (an explicit id column, never a bitmask). * - * The first column is considered to be a language bitmask. - * The second, optional, column is an explicit language id. + * "ibexa_content"/"ibexa_content_version" (their "initial_language_id"), the URL alias + * translations table, and the Legacy Search Engine's word index are checked explicitly in + * {@see DoctrineDatabase::canDeleteLanguage()} instead of via this map. * * It depends on the schema defined in * ./src/bundle/Core/Resources/config/storage/legacy/schema.yaml */ public const MULTILINGUAL_TABLES_COLUMNS = [ - ObjectStateGateway::OBJECT_STATE_TABLE => ['language_mask', 'default_language_id'], + ObjectStateGateway::OBJECT_STATE_TABLE => ['default_language_id'], ObjectStateGateway::OBJECT_STATE_GROUP_LANGUAGE_TABLE => ['language_id'], - ObjectStateGateway::OBJECT_STATE_GROUP_TABLE => ['language_mask', 'default_language_id'], + ObjectStateGateway::OBJECT_STATE_GROUP_TABLE => ['default_language_id'], ObjectStateGateway::OBJECT_STATE_LANGUAGE_TABLE => ['language_id'], ContentTypeGateway::MULTILINGUAL_FIELD_DEFINITION_TABLE => ['language_id'], ContentTypeGateway::CONTENT_TYPE_NAME_TABLE => ['language_id'], - ContentTypeGateway::CONTENT_TYPE_TABLE => ['language_mask', 'initial_language_id'], + ContentTypeGateway::CONTENT_TYPE_TABLE => ['initial_language_id'], ContentGateway::CONTENT_FIELD_TABLE => ['language_id'], ContentGateway::CONTENT_NAME_TABLE => ['language_id'], - ContentGateway::CONTENT_VERSION_TABLE => ['language_mask', 'initial_language_id'], - ContentGateway::CONTENT_ITEM_TABLE => ['language_mask', 'initial_language_id'], - UrlAliasGateway::TABLE => ['lang_mask'], ]; /** diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php index c23b3b884f..cf4768baf2 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php @@ -10,15 +10,13 @@ use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Ibexa\Contracts\Core\Persistence\Content\Language; use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; -use Ibexa\Core\Base\Exceptions\DatabaseException; +use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway; -use RuntimeException; +use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway; /** * Doctrine database based Language Gateway. @@ -42,14 +40,12 @@ public function insertLanguage(Language $language): int $lastId = (int)$statement->fetchOne(); - // Legacy only supports 8 * PHP_INT_SIZE - 2 languages: - // One bit cannot be used because PHP uses signed integers and a second one is reserved for the - // "always available flag". - if ($lastId == (2 ** (8 * PHP_INT_SIZE - 2))) { - throw new RuntimeException('Maximum number of languages reached.'); - } - // Next power of 2 for bit masks - $nextId = ($lastId !== 0 ? $lastId << 1 : 2); + // id 1 is permanently reserved (it was the legacy bitmask's "always available" sentinel, + // never a real language) - installs upgrading from that scheme may have existing ids that + // are powers of two, but nothing depends on that anymore, so new ids are just the next + // integer instead of the next power of two. This is what actually removes the old ~62 + // language ceiling. + $nextId = $lastId !== 0 ? $lastId + 1 : 2; $query = $this->connection->createQueryBuilder(); $query @@ -160,13 +156,37 @@ public function deleteLanguage(int $id): void public function canDeleteLanguage(int $id): bool { + if ($this->existsWithColumnValue($id, ContentGateway::CONTENT_TRANSLATION_TABLE, 'language_id')) { + return false; + } + + if ($this->existsWithColumnValue($id, ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, 'language_id')) { + return false; + } + + // "ibexa_content"/"ibexa_content_version" also count as referencing the language when it's + // their "initial_language_id" (main language), even without a matching translation row - + // e.g. right after ContentService::updateContentMetadata() changes the main language code + // without publishing a new version for it. + if ($this->existsWithColumnValue($id, ContentGateway::CONTENT_ITEM_TABLE, 'initial_language_id')) { + return false; + } + + if ($this->existsWithColumnValue($id, ContentGateway::CONTENT_VERSION_TABLE, 'initial_language_id')) { + return false; + } + + if ($this->existsWithColumnValue($id, UrlAliasGateway::TRANSLATION_TABLE, 'language_id')) { + return false; + } + + if ($this->existsWithColumnValue($id, 'ibexa_search_object_word_link', 'language_id')) { + return false; + } + // note: at some point this should be delegated to specific gateways foreach (self::MULTILINGUAL_TABLES_COLUMNS as $tableName => $columns) { - $languageMaskColumn = $columns[0]; - $languageIdColumn = $columns[1] ?? null; - if ( - $this->countTableData($id, $tableName, $languageMaskColumn, $languageIdColumn) > 0 - ) { + if ($this->existsWithColumnValue($id, $tableName, $columns[0])) { return false; } } @@ -175,49 +195,25 @@ public function canDeleteLanguage(int $id): bool } /** - * Count table data rows related to the given language. - * - * @param string|null $languageIdColumn optional column name containing explicit language id + * Checks whether $tableName has a row with $columnName equal to $languageId. */ - private function countTableData( + private function existsWithColumnValue( int $languageId, string $tableName, - string $languageMaskColumn, - ?string $languageIdColumn = null - ): int { + string $columnName + ): bool { $query = $this->connection->createQueryBuilder(); $query - // avoiding using "*" as count argument, but don't specify column name because it varies - ->select('COUNT(1)') + ->select('1') ->from($tableName) ->where( - $query->expr()->gt( - $this->getDatabasePlatform()->getBitAndComparisonExpression( - $languageMaskColumn, - $query->createPositionalParameter($languageId, ParameterType::INTEGER) - ), - '0' + $query->expr()->eq( + $columnName, + $query->createPositionalParameter($languageId, ParameterType::INTEGER) ) - ); - if (null !== $languageIdColumn) { - $query - ->orWhere( - $query->expr()->eq( - $languageIdColumn, - $query->createPositionalParameter($languageId, ParameterType::INTEGER) - ) - ); - } - - return (int)$query->executeQuery()->fetchOne(); - } + ) + ->setMaxResults(1); - private function getDatabasePlatform(): AbstractPlatform - { - try { - return $this->connection->getDatabasePlatform(); - } catch (Exception $e) { - throw DatabaseException::wrap($e); - } + return $query->executeQuery()->fetchOne() !== false; } } diff --git a/src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php b/src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php deleted file mode 100644 index 3d9fd6c82b..0000000000 --- a/src/lib/Persistence/Legacy/Content/Language/MaskGenerator.php +++ /dev/null @@ -1,236 +0,0 @@ -languageHandler = $languageHandler; - } - - /** - * Generates a language mask from pre-loaded Language Ids. - * - * @param int[] $languageIds - * @param bool $alwaysAvailable - * - * @return int - */ - public function generateLanguageMaskFromLanguageIds( - array $languageIds, - $alwaysAvailable - ): int { - // make sure alwaysAvailable part of bit mask always results in 1 or 0 - $languageMask = $alwaysAvailable ? 1 : 0; - - foreach ($languageIds as $languageId) { - $languageMask |= $languageId; - } - - return $languageMask; - } - - /** - * Generates a language indicator from $languageCode and $alwaysAvailable. - * - * @param string $languageCode - * @param bool $alwaysAvailable - * - * @return int - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ - public function generateLanguageIndicator( - $languageCode, - $alwaysAvailable - ): int { - return $this->languageHandler->loadByLanguageCode($languageCode)->id | ($alwaysAvailable ? 1 : 0); - } - - /** - * Checks if $language is always available in $languages;. - * - * @param string $language - * @param array $languages - * - * @return bool - */ - public function isLanguageAlwaysAvailable( - $language, - array $languages - ): bool { - return isset($languages['always-available']) - && ($languages['always-available'] == $language) - ; - } - - /** - * Checks if $languageMask contains the alwaysAvailable bit field. - * - * @param int $languageMask - * - * @return bool - */ - public function isAlwaysAvailable($languageMask): bool - { - return (bool)($languageMask & 1); - } - - /** - * Removes the alwaysAvailable flag from $languageId and returns cleaned up $languageId. - * - * @param int $languageId - * - * @return int - */ - public function removeAlwaysAvailableFlag($languageId): int - { - return $languageId & ~1; - } - - /** - * Extracts every language Ids contained in $languageMask. - * - * @param int $languageMask - * - * @return array Array of language Id - */ - public function extractLanguageIdsFromMask($languageMask): array - { - $exp = 2; - $result = []; - - // Decomposition of $languageMask into its binary components. - // check if $exp has not overflown and became float (happens for the last possible language in the mask) - while (is_int($exp) && $exp <= $languageMask) { - if ($languageMask & $exp) { - $result[] = $exp; - } - - $exp *= 2; - } - - return $result; - } - - /** - * Extracts Language codes contained in given $languageMask. - * - * @param int $languageMask - * - * @return array - */ - public function extractLanguageCodesFromMask($languageMask): array - { - $languageCodes = []; - $languageList = $this->languageHandler->loadList( - $this->extractLanguageIdsFromMask($languageMask) - ); - foreach ($languageList as $language) { - $languageCodes[] = $language->languageCode; - } - - return $languageCodes; - } - - /** - * Checks if given $languageMask consists of multiple languages. - * - * @param int $languageMask - * - * @return bool - */ - public function isLanguageMaskComposite($languageMask): bool - { - // Ignore first bit - $languageMask = $this->removeAlwaysAvailableFlag($languageMask); - - // Special case - if ($languageMask === 0) { - return false; - } - - // Return false if power of 2 - return (bool)($languageMask & ($languageMask - 1)); - } - - /** - * Generates a language mask from plain array of language codes and always available flag. - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If language(s) in $languageCodes was not be found - * - * @param string[] $languageCodes - * @param bool $isAlwaysAvailable - * - * @return int - */ - public function generateLanguageMaskFromLanguageCodes( - array $languageCodes, - bool $isAlwaysAvailable = false - ): int { - $mask = $isAlwaysAvailable ? 1 : 0; - - $languageList = $this->languageHandler->loadListByLanguageCodes($languageCodes); - foreach ($languageList as $language) { - $mask |= $language->id; - } - - if ($missing = array_diff($languageCodes, array_keys($languageList))) { - throw new NotFoundException('Language', implode(', ', $missing)); - } - - return $mask; - } - - /** - * Collect all translations of the given Persistence Fields and generate language mask. - * - * @param Field[] $fields - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ - public function generateLanguageMaskForFields( - array $fields, - string $initialLanguageCode, - bool $isAlwaysAvailable - ): int { - $languages = [$initialLanguageCode => true]; - foreach ($fields as $field) { - if (isset($languages[$field->languageCode])) { - continue; - } - - $languages[$field->languageCode] = true; - } - - return $this->generateLanguageMaskFromLanguageCodes( - array_keys($languages), - $isAlwaysAvailable - ); - } -} diff --git a/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php index c7915e6b4e..a3b147afe6 100644 --- a/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php @@ -156,23 +156,13 @@ public function insertObjectState( ParameterType::INTEGER ), 'default_language_id' => $query->createPositionalParameter( - $this->generateLanguageIndicator( - $objectState->defaultLanguage, - false - ), + $this->languageHandler->loadByLanguageCode($objectState->defaultLanguage)->id, ParameterType::INTEGER ), 'identifier' => $query->createPositionalParameter( $objectState->identifier, ParameterType::STRING ), - 'language_mask' => $query->createPositionalParameter( - $this->generateLanguageMask( - $objectState->languageCodes, - true - ), - ParameterType::INTEGER - ), 'priority' => $query->createPositionalParameter( $objectState->priority, ParameterType::INTEGER @@ -202,16 +192,13 @@ public function insertObjectState( } /** - * @param string[] $languageCodes - * * @throws NotFoundException */ private function updateObjectStateCommonFields( string $tableName, int $id, string $identifier, - string $defaultLanguageCode, - array $languageCodes + string $defaultLanguageCode ): void { $query = $this->connection->createQueryBuilder(); $query @@ -219,10 +206,7 @@ private function updateObjectStateCommonFields( ->set( 'default_language_id', $query->createPositionalParameter( - $this->generateLanguageIndicator( - $defaultLanguageCode, - false - ), + $this->languageHandler->loadByLanguageCode($defaultLanguageCode)->id, ParameterType::INTEGER ) ) @@ -233,16 +217,6 @@ private function updateObjectStateCommonFields( ParameterType::STRING ) ) - ->set( - 'language_mask', - $query->createPositionalParameter( - $this->generateLanguageMask( - $languageCodes, - true - ), - ParameterType::INTEGER - ) - ) ->where( $query->expr()->eq( 'id', @@ -260,8 +234,7 @@ public function updateObjectState(ObjectState $objectState): void self::OBJECT_STATE_TABLE, $objectState->id, $objectState->identifier, - $objectState->defaultLanguage, - $objectState->languageCodes + $objectState->defaultLanguage ); // And then refresh object state translations @@ -369,23 +342,13 @@ public function insertObjectStateGroup(Group $objectStateGroup): void ->values( [ 'default_language_id' => $query->createPositionalParameter( - $this->generateLanguageIndicator( - $objectStateGroup->defaultLanguage, - false - ), + $this->languageHandler->loadByLanguageCode($objectStateGroup->defaultLanguage)->id, ParameterType::INTEGER ), 'identifier' => $query->createPositionalParameter( $objectStateGroup->identifier, ParameterType::STRING ), - 'language_mask' => $query->createPositionalParameter( - $this->generateLanguageMask( - $objectStateGroup->languageCodes, - true - ), - ParameterType::INTEGER - ), ] ) ; @@ -404,8 +367,7 @@ public function updateObjectStateGroup(Group $objectStateGroup): void self::OBJECT_STATE_GROUP_TABLE, $objectStateGroup->id, $objectStateGroup->identifier, - $objectStateGroup->defaultLanguage, - $objectStateGroup->languageCodes + $objectStateGroup->defaultLanguage ); // And then refresh group translations @@ -526,7 +488,6 @@ private function createObjectStateFindQuery(): QueryBuilder 'state.group_id AS ibexa_object_state_group_id', 'state.id AS ibexa_object_state_id', 'state.identifier AS ibexa_object_state_identifier', - 'state.language_mask AS ibexa_object_state_language_mask', 'state.priority AS ibexa_object_state_priority', // Object state language 'lang.description AS ibexa_object_state_language_description', @@ -556,7 +517,6 @@ private function createObjectStateGroupFindQuery(): QueryBuilder 'state_group.default_language_id AS ibexa_object_state_group_default_language_id', 'state_group.id AS ibexa_object_state_group_id', 'state_group.identifier AS ibexa_object_state_group_identifier', - 'state_group.language_mask AS ibexa_object_state_group_language_mask', // Object state group language 'state_group_lang.description AS ibexa_object_state_group_language_description', 'state_group_lang.language_id AS ibexa_object_state_group_language_language_id', @@ -600,10 +560,7 @@ private function insertObjectStateTranslations(ObjectState $objectState): void ParameterType::STRING ), 'language_id' => $query->createPositionalParameter( - $this->generateLanguageIndicator( - $languageCode, - $languageCode === $objectState->defaultLanguage - ), + $this->languageHandler->loadByLanguageCode($languageCode)->id, ParameterType::INTEGER ), ] @@ -654,16 +611,13 @@ private function insertObjectStateGroupTranslations(Group $objectStateGroup): vo ) ; foreach ($objectStateGroup->languageCodes as $languageCode) { - $languageId = $this->generateLanguageIndicator( - $languageCode, - $languageCode === $objectStateGroup->defaultLanguage - ); + $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id; $query ->setParameter('contentobject_state_group_id', $objectStateGroup->id, ParameterType::INTEGER) ->setParameter('description', $objectStateGroup->description[$languageCode], ParameterType::STRING) ->setParameter('name', $objectStateGroup->name[$languageCode], ParameterType::STRING) ->setParameter('language_id', $languageId, ParameterType::INTEGER) - ->setParameter('real_language_id', $languageId & ~1, ParameterType::INTEGER); + ->setParameter('real_language_id', $languageId, ParameterType::INTEGER); $query->executeStatement(); } @@ -759,31 +713,4 @@ private function insertContentStateAssignment( $query->executeStatement(); } - - /** - * The language id, with the legacy "always available" bit for as long as the language bitmask is around. - */ - private function generateLanguageIndicator( - string $languageCode, - bool $alwaysAvailable - ): int { - return $this->languageHandler->loadByLanguageCode($languageCode)->id | ($alwaysAvailable ? 1 : 0); - } - - /** - * Keeps the legacy "language_mask" up to date for as long as the language bitmask is around. - * - * @param string[] $languageCodes - */ - private function generateLanguageMask( - array $languageCodes, - bool $alwaysAvailable - ): int { - $languageMask = $alwaysAvailable ? 1 : 0; - foreach ($languageCodes as $languageCode) { - $languageMask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; - } - - return $languageMask; - } } diff --git a/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php b/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php index a2f957c3df..8180f81191 100644 --- a/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php @@ -48,9 +48,9 @@ public function createObjectStateFromData(array $data) $languageIds = [(int)$data[0]['ibexa_object_state_default_language_id']]; foreach ($data as $stateTranslation) { - $languageIds[] = (int)$stateTranslation['ibexa_object_state_language_language_id'] & ~1; + $languageIds[] = (int)$stateTranslation['ibexa_object_state_language_language_id']; } - $languages = iterator_to_array($this->languageHandler->loadList($languageIds)); + $languages = iterator_to_array($this->languageHandler->loadList(array_unique($languageIds))); $objectState->id = (int)$data[0]['ibexa_object_state_id']; $objectState->groupId = (int)$data[0]['ibexa_object_state_group_id']; @@ -63,7 +63,7 @@ public function createObjectStateFromData(array $data) $objectState->description = []; foreach ($data as $stateTranslation) { - $languageCode = $languages[$stateTranslation['ibexa_object_state_language_language_id'] & ~1]->languageCode; + $languageCode = $languages[(int)$stateTranslation['ibexa_object_state_language_language_id']]->languageCode; $objectState->languageCodes[] = $languageCode; $objectState->name[$languageCode] = $stateTranslation['ibexa_object_state_language_name']; $objectState->description[$languageCode] = $stateTranslation['ibexa_object_state_language_description']; diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php index dadbebaebf..52d842ff36 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php @@ -60,7 +60,6 @@ final class DoctrineDatabase extends Gateway 'identifier', 'initial_language_id', 'is_container', - 'language_mask', 'remote_id', 'serialized_description_list', 'serialized_name_list', @@ -295,9 +294,7 @@ private function insertTypeNameData( ParameterType::INTEGER ), 'language_id' => $query->createPositionalParameter( - // the legacy "always available" bit stays until the language bitmask goes - $this->languageHandler->loadByLanguageCode($language)->id - | (($languages['always-available'] ?? null) === $language ? 1 : 0), + $this->languageHandler->loadByLanguageCode($language)->id, ParameterType::INTEGER ), 'language_locale' => $query->createPositionalParameter( @@ -418,13 +415,6 @@ private function mapCommonContentTypeColumnsToQueryValuesAndTypes(Type $type): a 'url_alias_name' => [$type->urlAliasSchema, ParameterType::STRING], 'contentobject_name' => [$type->nameSchema, ParameterType::STRING], 'is_container' => [(int)$type->isContainer, ParameterType::INTEGER], - 'language_mask' => [ - $this->generateLanguageMask( - $type->languageCodes, - array_key_exists('always-available', $type->name) - ), - ParameterType::INTEGER, - ], 'initial_language_id' => [$type->initialLanguageId, ParameterType::INTEGER], 'sort_field' => [$type->sortField, ParameterType::INTEGER], 'sort_order' => [$type->sortOrder, ParameterType::INTEGER], @@ -432,23 +422,6 @@ private function mapCommonContentTypeColumnsToQueryValuesAndTypes(Type $type): a ]; } - /** - * Keeps the legacy "language_mask" up to date for as long as the language bitmask is around. - * - * @param string[] $languageCodes - */ - private function generateLanguageMask( - array $languageCodes, - bool $alwaysAvailable - ): int { - $languageMask = $alwaysAvailable ? 1 : 0; - foreach ($languageCodes as $languageCode) { - $languageMask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; - } - - return $languageMask; - } - public function insertGroupAssignment( int $groupId, int $typeId, diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index e2df8999b8..92481a700b 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -52,7 +52,6 @@ final class DoctrineDatabase extends Gateway 'is_original' => ParameterType::INTEGER, 'action' => ParameterType::STRING, 'action_type' => ParameterType::STRING, - 'lang_mask' => ParameterType::INTEGER, 'text' => ParameterType::STRING, 'parent' => ParameterType::INTEGER, 'text_md5' => ParameterType::STRING, @@ -422,13 +421,6 @@ private function removeTranslation( string $textMD5, int $languageId ): void { - $this->connection->executeStatement( - 'UPDATE ' . $this->connection->quoteSingleIdentifier($this->table) . ' - SET lang_mask = lang_mask & ~ ' . $languageId . ' - WHERE parent = :parent AND text_md5 = :textMd5', - ['parent' => $parentId, 'textMd5' => $textMD5], - ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] - ); $this->connection->executeStatement( 'DELETE FROM ' . self::TRANSLATION_TABLE . ' WHERE parent = :parent AND text_md5 = :textMd5 AND language_id = :languageId', ['parent' => $parentId, 'textMd5' => $textMD5, 'languageId' => $languageId], @@ -519,7 +511,6 @@ public function updateRow( ): void { $languageIds = $values['language_ids'] ?? null; unset($values['language_ids']); - $values = $this->withLanguageMask($values, $languageIds, $parentId, $textMD5); $query = $this->connection->createQueryBuilder(); $query->update($this->connection->quoteSingleIdentifier($this->table)); @@ -607,7 +598,6 @@ private function doInsertRow(array $values): int $languageIds = $values['language_ids'] ?? null; unset($values['language_ids']); - $values = $this->withLanguageMask($values, $languageIds); $query = $this->connection->createQueryBuilder(); $query->insert($this->connection->quoteSingleIdentifier($this->table)); @@ -630,45 +620,6 @@ private function doInsertRow(array $values): int return (int)$values['id']; } - /** - * Keeps the legacy "lang_mask" in step with the row's translations and "always_available", - * for as long as the language bitmask is still around. - * - * @param array $values - * @param int[]|null $languageIds - * - * @return array - */ - private function withLanguageMask( - array $values, - ?array $languageIds, - ?int $parentId = null, - ?string $textMD5 = null - ): array { - if (null === $languageIds && !array_key_exists('always_available', $values)) { - return $values; - } - - $existing = null !== $parentId && null !== $textMD5; - $languageIds ??= $existing ? $this->loadTranslationLanguageIds($parentId, $textMD5) : []; - $alwaysAvailable = array_key_exists('always_available', $values) - ? (bool)$values['always_available'] - : $existing && (bool)$this->connection->fetchOne( - 'SELECT always_available FROM ' . $this->connection->quoteSingleIdentifier($this->table) - . ' WHERE parent = :parent AND text_md5 = :textMd5', - ['parent' => $parentId, 'textMd5' => $textMD5], - ['parent' => ParameterType::INTEGER, 'textMd5' => ParameterType::STRING] - ); - - $languageMask = $alwaysAvailable ? 1 : 0; - foreach ($languageIds as $languageId) { - $languageMask |= (int)$languageId; - } - $values['lang_mask'] = $languageMask; - - return $values; - } - /** * Replaces $parentId/$textMD5's rows in "ibexa_url_alias_ml_translation" with $languageIds. * @@ -1095,15 +1046,6 @@ public function bulkRemoveTranslation( int $languageId, array $actions ): void { - $query = $this->connection->createQueryBuilder(); - $query - ->update($this->connection->quoteSingleIdentifier($this->table)) - // parameter for bitwise operation has to be placed verbatim (w/o binding) for this to work cross-DBMS - ->set('lang_mask', 'lang_mask & ~ ' . $languageId) - ->where('action IN (:actions)') - ->setParameter('actions', $actions, ArrayParameterType::STRING); - $query->executeStatement(); - $this->connection->executeStatement( 'DELETE FROM ' . self::TRANSLATION_TABLE . ' WHERE language_id = :languageId diff --git a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/AbstractGateway.php b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/AbstractGateway.php index d1dcf2b5b4..beaf81ae24 100644 --- a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/AbstractGateway.php +++ b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/AbstractGateway.php @@ -31,28 +31,6 @@ public function getColumnNextIntegerValue( return null; } - /** - * Return a language sub select query for setName. - * - * The query generates the proper language mask at the runtime of the INSERT/UPDATE query - * generated by setName. - * - * @see setName - */ - public function getSetNameLanguageMaskSubQuery(): string - { - return << 0 ) - THEN (:language_id | 1) - ELSE :language_id - END - FROM ibexa_content - WHERE id = :content_id) - SQL; - } - public function getLastInsertedId(string $sequenceName): int { return (int)$this->connection->lastInsertId(); diff --git a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/PostgresqlGateway.php b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/PostgresqlGateway.php index 847ffc2e32..0ea7bfca79 100644 --- a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/PostgresqlGateway.php +++ b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/PostgresqlGateway.php @@ -8,27 +8,4 @@ namespace Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform; -final class PostgresqlGateway extends AbstractGateway -{ - /** - * Return a language sub select query for setName. - * - * The query generates the proper language mask at the runtime of the INSERT/UPDATE query - * generated by setName. - * - * @see setName - */ - public function getSetNameLanguageMaskSubQuery(): string - { - return << 0 ) - THEN (cast(:language_id as BIGINT) | 1) - ELSE :language_id - END - FROM ibexa_content - WHERE id = :content_id) - SQL; - } -} +final class PostgresqlGateway extends AbstractGateway {} diff --git a/src/lib/Persistence/Legacy/SharedGateway/Gateway.php b/src/lib/Persistence/Legacy/SharedGateway/Gateway.php index c417bd2761..0b327f29dc 100644 --- a/src/lib/Persistence/Legacy/SharedGateway/Gateway.php +++ b/src/lib/Persistence/Legacy/SharedGateway/Gateway.php @@ -41,9 +41,4 @@ public function getColumnNextIntegerValue( * It returns integer as all the IDs in the Ibexa Legacy Storage are (big)integers */ public function getLastInsertedId(string $sequenceName): int; - - /** - * Return a language sub select query for setName. - */ - public function getSetNameLanguageMaskSubQuery(): string; } diff --git a/src/lib/Resources/settings/storage_engines/legacy/content.yml b/src/lib/Resources/settings/storage_engines/legacy/content.yml index 4c9885041e..8c39e0eed7 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content.yml @@ -28,7 +28,6 @@ services: - '@Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway' - '@Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder' - '@ibexa.spi.persistence.legacy.language.handler' - - '@Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' Ibexa\Core\Persistence\Legacy\Content\Gateway\ExceptionConversion: diff --git a/src/lib/Resources/settings/storage_engines/legacy/language.yml b/src/lib/Resources/settings/storage_engines/legacy/language.yml index 711cafdbc4..a97b49b8de 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/language.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/language.yml @@ -32,7 +32,3 @@ services: ibexa.spi.persistence.legacy.language.handler: alias: Ibexa\Core\Persistence\Legacy\Content\Language\CachingHandler - - Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator: - class: Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator - arguments: ['@ibexa.spi.persistence.legacy.language.handler'] diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php index bc288d3a1c..034480730b 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -22,12 +22,6 @@ */ final readonly class LanguagePriorityConditionBuilder { - /** - * Pre-computed integer constant which, when combined with a bit-wise AND, removes the - * always-available bit from a language id. - */ - private const int REMOVE_ALWAYS_AVAILABLE_BIT_OPERAND = -2; - public function __construct( private Connection $connection, private LanguageHandler $languageHandler @@ -44,13 +38,6 @@ public function buildCondition( string $mainLanguageIdColumn = 'c.initial_language_id', string $alwaysAvailableColumn = 'c.always_available' ): string { - // Field language ids still carry the legacy "always available" bit until it's stripped - // together with the language bitmask - compare them without it. - $languageIdColumn = $this->connection->getDatabasePlatform()->getBitAndComparisonExpression( - $languageIdColumn, - (string)self::REMOVE_ALWAYS_AVAILABLE_BIT_OPERAND - ); - return $query->expr()->eq( $languageIdColumn, $this->buildMatchedLanguageExpression( diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php index 6915a71869..b5c2cfb362 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php @@ -181,10 +181,6 @@ public function addObjectWordLink( $integerValue, ParameterType::INTEGER ), - 'language_mask' => $query->createPositionalParameter( - $languageId | ($isMainAndAlwaysAvailable ? 1 : 0), - ParameterType::INTEGER - ), 'language_id' => $query->createPositionalParameter( $languageId, ParameterType::INTEGER diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php index 5ac964d28a..960f66fade 100644 --- a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -30,6 +30,14 @@ protected function setUp(): void $connection = $this->getDatabaseConnection(); + // These commands exist specifically for installs upgrading from before the language + // bitmask columns were dropped - simulate that pre-drop schema state here, since the + // current schema.yaml (and therefore this test's own bootstrapped schema) no longer has + // them. + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_content_version ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); + // content id 1: eng-US only, not always available -> mask 2 // content id 2: eng-US + eng-GB, always available -> mask 7 $connection->insert('ibexa_content', [ @@ -273,9 +281,6 @@ public function testVerifyReportsNothingToDoOnAnAlreadyMigratedSchema(): void */ private function simulateFullyMigratedSchema(Connection $connection): void { - // SQLite can't drop a column an index still covers - $connection->executeStatement('DROP INDEX ibexa_content_lmask'); - $connection->executeStatement('DROP INDEX ibexa_url_alias_ml_text_lang'); $connection->executeStatement('ALTER TABLE ibexa_content DROP COLUMN language_mask'); $connection->executeStatement('ALTER TABLE ibexa_content_version DROP COLUMN language_mask'); $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml DROP COLUMN lang_mask'); diff --git a/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php index 1b2f9ed14b..286fea7b45 100644 --- a/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php @@ -24,6 +24,9 @@ protected function setUp(): void { parent::setUp(); + $this->getDatabaseConnection()->executeStatement( + 'ALTER TABLE ibexa_search_object_word_link ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL' + ); foreach ([1 => 3, 5001 => 4] as $id => $languageMask) { $this->getDatabaseConnection()->insert( 'ibexa_search_object_word_link', diff --git a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php index a3c61b5750..a21a1c6b0f 100644 --- a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php @@ -22,6 +22,7 @@ final class AddUrlAliasAlwaysAvailableColumnMigrationTest extends TestCase public function testBackfillsTheFlagInChunksById(): void { $connection = $this->getDatabaseConnection(); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); foreach ([1 => ['foo', 'acbd18db4cc2f85cedef654fccc4a4d8', 3], 5001 => ['bar', '37b51d194a7513e45b56f6524f2d51f2', 2]] as $id => [$text, $textMd5, $langMask]) { $connection->insert('ibexa_url_alias_ml', [ 'parent' => 0, diff --git a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php index 18f83ec3b6..abe404ca24 100644 --- a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php @@ -29,6 +29,9 @@ protected function setUp(): void ); $connection = $this->getDatabaseConnection(); + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_content_version ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); foreach ([1 => 2, 2 => 7] as $id => $languageMask) { $connection->insert('ibexa_content', [ 'id' => $id, diff --git a/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php b/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php index ec1c6539d0..8e78d18ade 100644 --- a/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php +++ b/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php @@ -40,6 +40,13 @@ protected function setUp(): void $this->prepareMaxLanguages(); } + /** + * Number of languages to create beyond the fixture's 62 (the old bitmask ceiling, + * 8 * PHP_INT_SIZE - 2 on 64-bit PHP) - proves content creation works with translations in + * languages allocated past where the old power-of-two id scheme would have thrown. + */ + private const EXTRA_LANGUAGES_BEYOND_OLD_LIMIT = 5; + /** * @throws Exception */ @@ -55,6 +62,11 @@ public function testCreateContent(): void ], self::$languagesRawList )); + + for ($i = 1; $i <= self::EXTRA_LANGUAGES_BEYOND_OLD_LIMIT; ++$i) { + $names["xtr-{$i}"] = "Beyond old limit {$i} name"; + } + $this->createFolder($names); } @@ -72,5 +84,12 @@ private function prepareMaxLanguages(): void $languageCreateStruct->name = $languageData['name']; $languageService->createLanguage($languageCreateStruct); } + + for ($i = 1; $i <= self::EXTRA_LANGUAGES_BEYOND_OLD_LIMIT; ++$i) { + $languageCreateStruct = $languageService->newLanguageCreateStruct(); + $languageCreateStruct->languageCode = "xtr-{$i}"; + $languageCreateStruct->name = "Beyond old limit {$i}"; + $languageService->createLanguage($languageCreateStruct); + } } } diff --git a/tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php b/tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php index bb642115fa..dd87e62c7b 100644 --- a/tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php +++ b/tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php @@ -9,11 +9,11 @@ use Ibexa\Core\Repository\LanguageService; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DependsExternal; use PHPUnit\Framework\Attributes\Group; /** - * Test case for maximum number of languages supported in the LanguageService. + * Test case proving the language bitmask's old ~62-language ceiling (8 * PHP_INT_SIZE - 2, from + * language ids being powers of two) is gone now that language ids are plain sequential integers. * * @see \Ibexa\Contracts\Core\Repository\LanguageService */ @@ -28,33 +28,11 @@ class LanguageServiceMaximumSupportedLanguagesTest extends BaseTestCase /** @var array */ private $createdLanguages = []; - /** - * Creates as much languages as possible. - */ protected function setUp(): void { parent::setUp(); $this->languageService = $this->getRepository()->getContentLanguageService(); - - $languageCreate = $this->languageService->newLanguageCreateStruct(); - $languageCreate->enabled = true; - - // Create as much languages as possible - for ($i = count($this->languageService->loadLanguages()) + 1; $i <= 8 * PHP_INT_SIZE - 2; ++$i) { - $languageCreate->name = "Language $i"; - $languageCreate->languageCode = sprintf('lan-%02d', $i); - - try { - $this->createdLanguages[] = $this->languageService->createLanguage($languageCreate); - } catch (\Exception $e) { - if (PHP_INT_SIZE === 8 && $i === 32) { - throw new \Exception('PHP/HHVM is 64bit, but seems INT column in db only supports 32bit', 0, $e); - } - - throw new \Exception("Unknown issue on iteration $i, PHP_INT_SIZE: " . PHP_INT_SIZE, 0, $e); - } - } } protected function tearDown(): void @@ -67,20 +45,27 @@ protected function tearDown(): void } /** - * Test for the number of maximum language that can be created. + * Creates more languages than the old bitmask ceiling (8 * PHP_INT_SIZE - 2, i.e. 62 on 64-bit + * PHP) ever allowed, proving the limit no longer exists. */ - #[DependsExternal(LanguageServiceTest::class, 'testNewLanguageCreateStruct')] - public function testCreateMaximumLanguageLimit(): void + public function testCreateMoreLanguagesThanOldBitmaskLimit(): void { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Maximum number of languages reached.'); + $existingLanguageCount = count($this->languageService->loadLanguages()); + $countToCreate = (8 * PHP_INT_SIZE - 2) - $existingLanguageCount + 10; $languageCreate = $this->languageService->newLanguageCreateStruct(); $languageCreate->enabled = true; - $languageCreate->name = 'Bad Language'; - $languageCreate->languageCode = 'lan-ER'; + for ($i = 1; $i <= $countToCreate; ++$i) { + $languageCreate->name = "Language $i"; + $languageCreate->languageCode = sprintf('lan-%03d', $i); + + $this->createdLanguages[] = $this->languageService->createLanguage($languageCreate); + } - $this->languageService->createLanguage($languageCreate); + self::assertCount( + $existingLanguageCount + $countToCreate, + $this->languageService->loadLanguages() + ); } } diff --git a/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml b/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml index 8638e058ce..dc536e544b 100644 --- a/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml +++ b/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml @@ -214,26 +214,26 @@ ibexa_content_type_name: - { content_type_id: 13, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: Comment } - { content_type_id: 14, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: 'Common ini settings' } - { content_type_id: 15, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: 'Template look' } - - { content_type_id: 16, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Article } - - { content_type_id: 17, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Blog } - - { content_type_id: 18, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Blog post' } - - { content_type_id: 19, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Product } - - { content_type_id: 20, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Feedback form' } - - { content_type_id: 21, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Landing Page' } - - { content_type_id: 22, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Wiki Page' } - - { content_type_id: 23, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Poll } - - { content_type_id: 24, content_type_status: 0, language_id: 9, language_locale: eng-US, name: File } - - { content_type_id: 25, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Image } - - { content_type_id: 26, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Link } - - { content_type_id: 27, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Gallery } - - { content_type_id: 28, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Forum } - - { content_type_id: 29, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Forum topic' } - - { content_type_id: 30, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Forum reply' } - - { content_type_id: 31, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Event } - - { content_type_id: 32, content_type_status: 0, language_id: 9, language_locale: eng-US, name: 'Event calendar' } - - { content_type_id: 33, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Banner } - - { content_type_id: 34, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Forums } - - { content_type_id: 35, content_type_status: 0, language_id: 9, language_locale: eng-US, name: Video } + - { content_type_id: 16, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Article } + - { content_type_id: 17, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Blog } + - { content_type_id: 18, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Blog post' } + - { content_type_id: 19, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Product } + - { content_type_id: 20, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Feedback form' } + - { content_type_id: 21, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Landing Page' } + - { content_type_id: 22, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Wiki Page' } + - { content_type_id: 23, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Poll } + - { content_type_id: 24, content_type_status: 0, language_id: 8, language_locale: eng-US, name: File } + - { content_type_id: 25, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Image } + - { content_type_id: 26, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Link } + - { content_type_id: 27, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Gallery } + - { content_type_id: 28, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Forum } + - { content_type_id: 29, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Forum topic' } + - { content_type_id: 30, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Forum reply' } + - { content_type_id: 31, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Event } + - { content_type_id: 32, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Event calendar' } + - { content_type_id: 33, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Banner } + - { content_type_id: 34, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Forums } + - { content_type_id: 35, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Video } ibexa_content_type_group: - { created: 1031216928, creator_id: 14, id: 1, modified: 1033922106, modifier_id: 14, name: Content, is_system: 0 } - { created: 1031216941, creator_id: 14, id: 2, modified: 1033922113, modifier_id: 14, name: Users, is_system: 0 } @@ -324,7 +324,7 @@ ibexa_content_field: - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 56, data_float: 0, data_int: null, data_text: Design, data_type_string: ibexa_string, id: 181, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: design, version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 56, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_string, id: 182, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 56, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 185, language_code: eng-GB, language_id: 3, sort_key_int: 1, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 219, contentobject_id: 57, data_float: 0, data_int: null, data_text: Home, data_type_string: ibexa_string, id: 186, language_code: eng-US, language_id: 9, sort_key_int: 0, sort_key_string: home, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 219, contentobject_id: 57, data_float: 0, data_int: null, data_text: Home, data_type_string: ibexa_string, id: 186, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: home, version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 212, contentobject_id: 58, data_float: 0, data_int: null, data_text: 'Contact Us', data_type_string: ibexa_string, id: 188, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: 'contact us', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 214, contentobject_id: 58, data_float: 0, data_int: null, data_text: 'Firstname Lastname', data_type_string: ibexa_string, id: 190, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: 'firstname lastname', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 215, contentobject_id: 58, data_float: 0, data_int: null, data_text: Subject, data_type_string: ibexa_string, id: 191, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: subject, version: 1 } @@ -370,7 +370,7 @@ ibexa_content_name: - { content_translation: eng-GB, content_version: 1, contentobject_id: 52, language_id: 2, name: 'Common INI settings', real_translation: eng-GB } - { content_translation: eng-GB, content_version: 2, contentobject_id: 54, language_id: 2, name: 'Ibexa Demo Design (without demo content)', real_translation: eng-GB } - { content_translation: eng-GB, content_version: 1, contentobject_id: 56, language_id: 3, name: Design, real_translation: eng-GB } - - { content_translation: eng-US, content_version: 1, contentobject_id: 57, language_id: 9, name: Home, real_translation: eng-US } + - { content_translation: eng-US, content_version: 1, contentobject_id: 57, language_id: 8, name: Home, real_translation: eng-US } - { content_translation: eng-US, content_version: 1, contentobject_id: 58, language_id: 8, name: 'Contact Us', real_translation: eng-US } - { content_translation: eng-GB, content_version: 1, contentobject_id: 59, language_id: 3, name: Partners, real_translation: eng-GB } ibexa_content_trash: { } diff --git a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php index c4917b80c8..c616f98fec 100644 --- a/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php @@ -86,7 +86,6 @@ public function testInsertContentObject(): void 'current_version' => '1', 'initial_language_id' => '2', 'remote_id' => 'some_remote_id', - 'language_mask' => '3', 'always_available' => '1', 'modified' => '0', 'published' => '0', @@ -103,7 +102,6 @@ public function testInsertContentObject(): void 'current_version', 'initial_language_id', 'remote_id', - 'language_mask', 'always_available', 'modified', 'published', @@ -212,7 +210,6 @@ public function testInsertVersion(): void 'status' => '0', 'workflow_event_pos' => '0', 'version' => '1', - 'language_mask' => '5', 'always_available' => '1', 'initial_language_id' => '4', // Not needed, according to field mapping document @@ -229,7 +226,6 @@ public function testInsertVersion(): void 'status', 'workflow_event_pos', 'version', - 'language_mask', 'always_available', 'initial_language_id' )->from(Gateway::CONTENT_VERSION_TABLE) @@ -489,7 +485,7 @@ public function testInsertNewAlwaysAvailableField(): void 'data_text' => 'Test text', 'data_type_string' => 'ibexa_string', 'language_code' => self::ENG_GB, - 'language_id' => '5', + 'language_id' => '4', 'sort_key_int' => '23', 'sort_key_string' => 'Test', 'version' => '1', @@ -1463,7 +1459,6 @@ public function testDeleteTranslationFromContentKeepsVersionsWithOnlyThatTransla 'content_type_id' => 1, 'current_version' => 2, 'initial_language_id' => 2, - 'language_mask' => 10, 'name' => 'Foo', 'owner_id' => 14, 'remote_id' => 'foo', @@ -1477,7 +1472,6 @@ public function testDeleteTranslationFromContentKeepsVersionsWithOnlyThatTransla 'contentobject_id' => 1, 'version' => $versionId, 'initial_language_id' => $languageIds[0], - 'language_mask' => array_sum($languageIds), ]); foreach ($languageIds as $languageId) { $connection->insert( @@ -1497,13 +1491,6 @@ public function testDeleteTranslationFromContentKeepsVersionsWithOnlyThatTransla ->orderBy('content_version_id') ->addOrderBy('language_id') ); - self::assertQueryResult( - [['id' => 1, 'language_mask' => 8], ['id' => 2, 'language_mask' => 2]], - $connection->createQueryBuilder() - ->select('id', 'language_mask') - ->from(Gateway::CONTENT_VERSION_TABLE) - ->orderBy('id') - ); } public function testUpdateAlwaysAvailableFlagRemove(): void @@ -1523,58 +1510,6 @@ public function testUpdateAlwaysAvailableFlagRemove(): void ->from(Gateway::CONTENT_ITEM_TABLE) ->where('id = 103') ); - - $query = $connection->createQueryBuilder(); - self::assertQueryResult( - [['id' => 2]], - $query - ->select('language_mask') - ->from(Gateway::CONTENT_ITEM_TABLE) - ->where( - $query->expr()->eq( - 'id', - $query->createPositionalParameter(103, ParameterType::INTEGER) - ) - ) - ); - - $query = $connection->createQueryBuilder(); - self::assertQueryResult( - [['language_id' => 2]], - $query - ->select( - 'language_id' - )->from( - Gateway::CONTENT_NAME_TABLE - )->where( - $query->expr()->and( - $query->expr()->eq( - 'contentobject_id', - $query->createPositionalParameter(103, ParameterType::INTEGER) - ), - $query->expr()->eq( - 'content_version', - $query->createPositionalParameter(1, ParameterType::INTEGER) - ) - ) - ) - ); - - $query = $connection->createQueryBuilder(); - self::assertQueryResult( - [ - ['language_id' => 2], - ], - $query - ->select('DISTINCT language_id') - ->from(Gateway::CONTENT_FIELD_TABLE) - ->where( - $query->expr()->and( - $query->expr()->eq('contentobject_id', $query->createNamedParameter(103, ParameterType::INTEGER)), - $query->expr()->eq('version', $query->createNamedParameter(1, ParameterType::INTEGER)) - ) - ) - ); } /** @@ -1598,60 +1533,6 @@ public function testUpdateAlwaysAvailableFlagAdd(): void ->from(Gateway::CONTENT_ITEM_TABLE) ->where('id = 102') ); - - $expectedLanguageId = 3; - self::assertQueryResult( - [['id' => $expectedLanguageId]], - $connection->createQueryBuilder() - ->select('language_mask') - ->from(Gateway::CONTENT_ITEM_TABLE) - ->where('id = 102') - ); - - $versionNo = 1; - $query = $this->getDatabaseConnection()->createQueryBuilder(); - self::assertQueryResult( - [ - ['language_id' => $expectedLanguageId], - ], - $query - ->select('language_id') - ->from(Gateway::CONTENT_NAME_TABLE) - ->where( - $query->expr()->and( - $query->expr()->eq( - 'contentobject_id', - $query->createPositionalParameter($contentId, ParameterType::INTEGER) - ), - $query->expr()->eq( - 'content_version', - $query->createPositionalParameter($versionNo, ParameterType::INTEGER) - ) - ) - ) - ); - - $query = $this->getDatabaseConnection()->createQueryBuilder(); - self::assertQueryResult( - [ - ['language_id' => $expectedLanguageId], - ], - $query - ->select('DISTINCT language_id') - ->from(Gateway::CONTENT_FIELD_TABLE) - ->where( - $query->expr()->and( - $query->expr()->eq( - 'contentobject_id', - $query->createPositionalParameter($contentId, ParameterType::INTEGER) - ), - $query->expr()->eq( - 'version', - $query->createPositionalParameter($versionNo, ParameterType::INTEGER) - ) - ) - ) - ); } /** @@ -1674,9 +1555,9 @@ public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void $gateway->updateContent(4, $contentMetadataUpdateStruct); self::assertQueryResult( - [['id' => 7]], + [['always_available' => 1]], $this->getDatabaseConnection()->createQueryBuilder()->select( - 'language_mask' + 'always_available' )->from( Gateway::CONTENT_ITEM_TABLE )->where( @@ -1684,12 +1565,14 @@ public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void ) ); + // ibexa_content_field.language_id is no longer touched by an always-available cascade - + // it retains its original (fixture) values, unchanged, for both versions. $this->assertContentVersionAttributesLanguages( 4, 2, [ ['id' => '7', 'language_id' => 2], - ['id' => '8', 'language_id' => 5], + ['id' => '8', 'language_id' => 4], ] ); @@ -1698,7 +1581,7 @@ public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void 1, [ ['id' => '7', 'language_id' => 2], - ['id' => '8', 'language_id' => 5], + ['id' => '8', 'language_id' => 4], ] ); } @@ -1723,9 +1606,9 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void $gateway->updateContent(4, $contentMetadataUpdateStruct); self::assertQueryResult( - [['id' => 6]], + [['always_available' => 0]], $this->getDatabaseConnection()->createQueryBuilder()->select( - 'language_mask' + 'always_available' )->from( Gateway::CONTENT_ITEM_TABLE )->where( @@ -1733,6 +1616,8 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void ) ); + // ibexa_content_field.language_id is no longer touched by an always-available cascade - + // it retains its original (fixture) values, unchanged, for both versions. $this->assertContentVersionAttributesLanguages( 4, 2, @@ -1747,7 +1632,7 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void 1, [ ['id' => '7', 'language_id' => 2], - ['id' => '8', 'language_id' => 5], + ['id' => '8', 'language_id' => 4], ] ); } @@ -2005,7 +1890,6 @@ protected function getDatabaseGateway(): DoctrineDatabase $this->getSharedGateway(), new DoctrineDatabase\QueryBuilder($connection), $this->getLanguageHandler(), - $this->getLanguageMaskGenerator(), $this->getFieldTypeAliasResolver() ); } diff --git a/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php index 62c4d676b4..a95ceb6eb4 100644 --- a/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php @@ -44,7 +44,7 @@ public function testInsertLanguage(): void self::assertQueryResult( [ [ - 'id' => '8', + 'id' => '5', 'locale' => 'de-DE', 'name' => 'Deutsch (Deutschland)', 'disabled' => '0', @@ -53,7 +53,7 @@ public function testInsertLanguage(): void $this->getDatabaseConnection()->createQueryBuilder() ->select('id', 'locale', 'name', 'disabled') ->from(Gateway::CONTENT_LANGUAGE_TABLE) - ->where('id=8') + ->where('id=5') ); } @@ -172,6 +172,30 @@ public function testDeleteLanguage(): void ); } + public function testCanDeleteUnusedLanguageAdjacentToAnotherInUseLanguage(): void + { + $gateway = $this->getDatabaseGateway(); + $connection = $this->getDatabaseConnection(); + + // Both real, independently-allocated languages (post-migration sequential ids commonly end + // up adjacent like this) - 65 is in use, 64 is not, and must stay deletable regardless. + $connection->insert( + Gateway::CONTENT_LANGUAGE_TABLE, + ['id' => 64, 'locale' => 'fr-FR', 'name' => 'Francais (France)', 'disabled' => 0] + ); + $connection->insert( + Gateway::CONTENT_LANGUAGE_TABLE, + ['id' => 65, 'locale' => 'it-IT', 'name' => 'Italiano (Italia)', 'disabled' => 0] + ); + $connection->insert( + 'ibexa_object_state_language', + ['contentobject_state_id' => 1, 'language_id' => 65, 'description' => '', 'name' => 'x'] + ); + + self::assertTrue($gateway->canDeleteLanguage(64)); + self::assertFalse($gateway->canDeleteLanguage(65)); + } + /** * Return a ready to test DoctrineDatabase gateway. */ diff --git a/tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php b/tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php deleted file mode 100644 index 6c3c0da0d6..0000000000 --- a/tests/lib/Persistence/Legacy/Content/Language/MaskGeneratorTest.php +++ /dev/null @@ -1,303 +0,0 @@ - $languages - */ - #[DataProvider('getLanguageMaskData')] - public function testGenerateLanguageMaskFromLanguagesCodes( - array $languages, - bool $isAlwaysAvailable, - int $expectedMask - ): void { - $generator = $this->getMaskGenerator(); - - self::assertSame( - $expectedMask, - $generator->generateLanguageMaskFromLanguageCodes(array_keys($languages), $isAlwaysAvailable) - ); - } - - /** - * Returns test data {@link testGenerateLanguageMaskFromLanguagesCodes()}. - * - * @return array, bool, int}> - */ - public static function getLanguageMaskData(): array - { - return [ - 'error' => [ - [], - false, - 0, - ], - 'single_lang' => [ - ['eng-GB' => true], - false, - 4, - ], - 'multi_lang' => [ - ['eng-US' => true, 'eng-GB' => true], - false, - 6, - ], - 'always_available' => [ - ['eng-US' => true], - true, - 3, - ], - 'full' => [ - ['eng-US' => true, 'eng-GB' => true], - true, - 7, - ], - ]; - } - - /** - * @param string $languageCode - * @param bool $alwaysAvailable - * @param int $expectedIndicator - */ - #[DataProvider('getLanguageIndicatorData')] - public function testGenerateLanguageIndicator( - $languageCode, - $alwaysAvailable, - $expectedIndicator - ): void { - $generator = $this->getMaskGenerator(); - - self::assertSame( - $expectedIndicator, - $generator->generateLanguageIndicator($languageCode, $alwaysAvailable) - ); - } - - /** - * Returns test data for {@link testGenerateLanguageIndicator()}. - * - * @return array - */ - public static function getLanguageIndicatorData(): array - { - return [ - 'not_available' => [ - 'eng-GB', - false, - 4, - ], - 'always_available' => [ - 'eng-US', - true, - 3, - ], - ]; - } - - public function testIsLanguageAlwaysAvailable(): void - { - $generator = $this->getMaskGenerator(); - - self::assertTrue( - $generator->isLanguageAlwaysAvailable( - 'eng-GB', - [ - 'always-available' => 'eng-GB', - 'eng-GB' => 'lala', - ] - ) - ); - } - - public function testIsLanguageAlwaysAvailableOtherLanguage(): void - { - $generator = $this->getMaskGenerator(); - - self::assertFalse( - $generator->isLanguageAlwaysAvailable( - 'eng-GB', - [ - 'always-available' => 'eng-US', - 'eng-GB' => 'lala', - ] - ) - ); - } - - public function testIsLanguageAlwaysAvailableNoDefault(): void - { - $generator = $this->getMaskGenerator(); - - self::assertFalse( - $generator->isLanguageAlwaysAvailable( - 'eng-GB', - [ - 'eng-GB' => 'lala', - ] - ) - ); - } - - /** - * @param int $langMask - * @param bool $expectedResult - */ - #[DataProvider('isAlwaysAvailableProvider')] - public function testIsAlwaysAvailable( - $langMask, - $expectedResult - ): void { - $generator = $this->getMaskGenerator(); - self::assertSame($expectedResult, $generator->isAlwaysAvailable($langMask)); - } - - /** - * Returns test data for {@link testIsAlwaysAvailable()}. - * - * @return array - */ - public static function isAlwaysAvailableProvider(): array - { - return [ - [2, false], - [3, true], - [62, false], - [14, false], - [15, true], - ]; - } - - #[DataProvider('removeAlwaysAvailableFlagProvider')] - public function testRemoveAlwaysAvailableFlag( - $langMask, - $expectedResult - ): void { - $generator = $this->getMaskGenerator(); - self::assertSame($expectedResult, $generator->removeAlwaysAvailableFlag($langMask)); - } - - /** - * Returns test data for {@link testRemoveAlwaysAvailableFlag}. - * - * @return array - */ - public static function removeAlwaysAvailableFlagProvider(): array - { - return [ - [3, 2], - [7, 6], - [14, 14], - [62, 62], - ]; - } - - /** - * @param int $langMask - * @param array $expectedResult - */ - #[DataProvider('languageIdsFromMaskProvider')] - public function testExtractLanguageIdsFromMask( - $langMask, - array $expectedResult - ): void { - $generator = $this->getMaskGenerator(); - self::assertSame($expectedResult, $generator->extractLanguageIdsFromMask($langMask)); - } - - /** - * Returns test data for {@link testExtractLanguageIdsFromMask}. - * - * @return array - */ - public static function languageIdsFromMaskProvider(): array - { - return [ - [ - 2, - [2], - ], - [ - 15, - [2, 4, 8], - ], - [ - 62, - [2, 4, 8, 16, 32], - ], - ]; - } - - /** - * Returns the mask generator to test. - * - * @return MaskGenerator - */ - protected function getMaskGenerator() - { - return new MaskGenerator($this->getLanguageHandler()); - } - - /** - * Returns a language handler mock. - * - * @return Handler - */ - protected function getLanguageHandler() - { - if (!isset($this->languageHandler)) { - $this->languageHandler = $this->createMock(LanguageHandler::class); - $this->languageHandler->expects($this->any()) - ->method(self::anything())// loadByLanguageCode && loadListByLanguageCodes - ->will( - $this->returnCallback( - static function ($languageCodes): Language | array { - if (is_string($languageCodes)) { - $language = $languageCodes; - $languageCodes = [$language]; - } - - $languages = []; - if (in_array('eng-US', $languageCodes, true)) { - $languages['eng-US'] = new Language( - [ - 'id' => 2, - 'languageCode' => 'eng-US', - 'name' => 'US english', - ] - ); - } - - if (in_array('eng-GB', $languageCodes, true)) { - $languages['eng-GB'] = new Language( - [ - 'id' => 4, - 'languageCode' => 'eng-GB', - 'name' => 'British english', - ] - ); - } - - return isset($language) ? $languages[$language] : $languages; - } - ) - ); - } - - return $this->languageHandler; - } -} diff --git a/tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php b/tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php index e39b79376a..2d5865f921 100644 --- a/tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php +++ b/tests/lib/Persistence/Legacy/Content/LanguageAwareTestCase.php @@ -9,7 +9,6 @@ use Ibexa\Contracts\Core\Persistence\Content\Language\Handler; use Ibexa\Core\Persistence; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor; use Ibexa\Core\Search\Common\FieldNameGenerator; use Ibexa\Core\Search\Common\FieldRegistry; @@ -31,13 +30,6 @@ abstract class LanguageAwareTestCase extends TestCase */ protected $languageHandler; - /** - * Language mask generator. - * - * @var LanguageMaskGenerator - */ - protected $languageMaskGenerator; - protected CriterionVisitor $criterionVisitor; /** @@ -54,22 +46,6 @@ protected function getLanguageHandler() return $this->languageHandler; } - /** - * Returns a language mask generator. - * - * @return LanguageMaskGenerator - */ - protected function getLanguageMaskGenerator() - { - if (!isset($this->languageMaskGenerator)) { - $this->languageMaskGenerator = new LanguageMaskGenerator( - $this->getLanguageHandler() - ); - } - - return $this->languageMaskGenerator; - } - protected function getCriterionVisitor(): CriterionVisitor { if (!isset($this->criterionVisitor)) { diff --git a/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php index 7707ea5f6d..0a06fe28cf 100644 --- a/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php @@ -9,7 +9,6 @@ use Ibexa\Contracts\Core\Persistence\Content\ObjectState; use Ibexa\Contracts\Core\Persistence\Content\ObjectState\Group; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway; use Ibexa\Core\Persistence\Legacy\Content\ObjectState\Gateway\DoctrineDatabase; use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase; @@ -25,13 +24,6 @@ class DoctrineDatabaseTest extends LanguageAwareTestCase */ protected $databaseGateway; - /** - * Language mask generator. - * - * @var MaskGenerator - */ - protected $languageMaskGenerator; - /** * Inserts DB fixture. */ @@ -61,10 +53,9 @@ public function testLoadObjectStateData(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'not_locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ], @@ -85,10 +76,9 @@ public function testLoadObjectStateDataByIdentifier(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'not_locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ], @@ -110,10 +100,9 @@ public function testLoadObjectStateListData(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'not_locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ], @@ -123,10 +112,9 @@ public function testLoadObjectStateListData(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 2, 'ibexa_object_state_identifier' => 'locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 1, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Locked', ], ], @@ -147,9 +135,8 @@ public function testLoadObjectStateGroupData(): void 'ibexa_object_state_group_default_language_id' => 2, 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_group_identifier' => 'ibexa_lock', - 'ibexa_object_state_group_language_mask' => 3, 'ibexa_object_state_group_language_description' => '', - 'ibexa_object_state_group_language_language_id' => 3, + 'ibexa_object_state_group_language_language_id' => 2, 'ibexa_object_state_group_language_real_language_id' => 2, 'ibexa_object_state_group_language_name' => 'Lock', ], @@ -170,9 +157,8 @@ public function testLoadObjectStateGroupDataByIdentifier(): void 'ibexa_object_state_group_default_language_id' => 2, 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_group_identifier' => 'ibexa_lock', - 'ibexa_object_state_group_language_mask' => 3, 'ibexa_object_state_group_language_description' => '', - 'ibexa_object_state_group_language_language_id' => 3, + 'ibexa_object_state_group_language_language_id' => 2, 'ibexa_object_state_group_language_real_language_id' => 2, 'ibexa_object_state_group_language_name' => 'Lock', ], @@ -194,9 +180,8 @@ public function testLoadObjectStateGroupListData(): void 'ibexa_object_state_group_default_language_id' => 2, 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_group_identifier' => 'ibexa_lock', - 'ibexa_object_state_group_language_mask' => 3, 'ibexa_object_state_group_language_description' => '', - 'ibexa_object_state_group_language_language_id' => 3, + 'ibexa_object_state_group_language_language_id' => 2, 'ibexa_object_state_group_language_real_language_id' => 2, 'ibexa_object_state_group_language_name' => 'Lock', ], @@ -220,11 +205,10 @@ public function testInsertObjectState(): void // The new state should be added with state ID = 3 'ibexa_object_state_id' => 3, 'ibexa_object_state_identifier' => 'test_state', - 'ibexa_object_state_language_mask' => 5, // The new state should have priority = 2 'ibexa_object_state_priority' => 2, 'ibexa_object_state_language_description' => 'Test state description', - 'ibexa_object_state_language_language_id' => 5, + 'ibexa_object_state_language_language_id' => 4, 'ibexa_object_state_language_name' => 'Test state', ], ], @@ -249,11 +233,10 @@ public function testInsertObjectStateInEmptyGroup(): void // The new state should be added with state ID = 3 'ibexa_object_state_id' => 3, 'ibexa_object_state_identifier' => 'test_state', - 'ibexa_object_state_language_mask' => 5, // The new state should have priority = 0 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => 'Test state description', - 'ibexa_object_state_language_language_id' => 5, + 'ibexa_object_state_language_language_id' => 4, 'ibexa_object_state_language_name' => 'Test state', ], ], @@ -284,10 +267,9 @@ public function testUpdateObjectState(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'test_state', - 'ibexa_object_state_language_mask' => 5, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => 'Test state description', - 'ibexa_object_state_language_language_id' => 5, + 'ibexa_object_state_language_language_id' => 4, 'ibexa_object_state_language_name' => 'Test state', ], ], @@ -339,9 +321,8 @@ public function testInsertObjectStateGroup(): void // The new state group should be added with state group ID = 3 'ibexa_object_state_group_id' => 3, 'ibexa_object_state_group_identifier' => 'test_group', - 'ibexa_object_state_group_language_mask' => 5, 'ibexa_object_state_group_language_description' => 'Test group description', - 'ibexa_object_state_group_language_language_id' => 5, + 'ibexa_object_state_group_language_language_id' => 4, 'ibexa_object_state_group_language_real_language_id' => 4, 'ibexa_object_state_group_language_name' => 'Test group', ], @@ -366,9 +347,8 @@ public function testUpdateObjectStateGroup(): void 'ibexa_object_state_group_default_language_id' => 4, 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_group_identifier' => 'test_group', - 'ibexa_object_state_group_language_mask' => 5, 'ibexa_object_state_group_language_description' => 'Test group description', - 'ibexa_object_state_group_language_language_id' => 5, + 'ibexa_object_state_group_language_language_id' => 4, 'ibexa_object_state_group_language_real_language_id' => 4, 'ibexa_object_state_group_language_name' => 'Test group', ], @@ -422,10 +402,9 @@ public function testLoadObjectStateDataForContent(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'not_locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ], @@ -458,10 +437,9 @@ public function testUpdateObjectStatePriority(): void 'ibexa_object_state_group_id' => 2, 'ibexa_object_state_id' => 1, 'ibexa_object_state_identifier' => 'not_locked', - 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 10, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ], diff --git a/tests/lib/Persistence/Legacy/Content/ObjectState/MapperTest.php b/tests/lib/Persistence/Legacy/Content/ObjectState/MapperTest.php index 30cdfb79ca..d7a8717bc0 100644 --- a/tests/lib/Persistence/Legacy/Content/ObjectState/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/ObjectState/MapperTest.php @@ -135,7 +135,7 @@ protected function getObjectStateRowsFixture() 'ibexa_object_state_language_mask' => 3, 'ibexa_object_state_priority' => 0, 'ibexa_object_state_language_description' => '', - 'ibexa_object_state_language_language_id' => 3, + 'ibexa_object_state_language_language_id' => 2, 'ibexa_object_state_language_name' => 'Not locked', ], ]; @@ -155,7 +155,7 @@ protected function getObjectStateGroupRowsFixture() 'ibexa_object_state_group_identifier' => 'ibexa_lock', 'ibexa_object_state_group_language_mask' => 3, 'ibexa_object_state_group_language_description' => '', - 'ibexa_object_state_group_language_language_id' => 3, + 'ibexa_object_state_group_language_language_id' => 2, 'ibexa_object_state_group_language_real_language_id' => 2, 'ibexa_object_state_group_language_name' => 'Lock', ], diff --git a/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php index 8e90b847e0..bf860ce958 100644 --- a/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php @@ -425,7 +425,6 @@ public static function getTypeCreationExpectations(): array ['identifier', 'folder'], ['initial_language_id', '2'], ['is_container', '1'], - ['language_mask', 7], ['modified', '1082454875'], ['modifier_id', '14'], ['remote_id', 'a3d405b81be900468eb153d774f4f0d2'], @@ -466,7 +465,7 @@ public static function getTypeCreationContentClassNameExpectations(): array { return [ ['content_type_status', [0, 0]], - ['language_id', [3, 4]], + ['language_id', [2, 4]], ['language_locale', ['eng-US', 'eng-GB']], ['name', ['Folder', 'Folder (GB)']], ]; @@ -859,7 +858,7 @@ public function testUpdateTypeName(): void [ 'content_type_id' => 1, 'content_type_status' => 0, - 'language_id' => 3, + 'language_id' => 2, 'language_locale' => 'eng-US', 'name' => 'New Folder', ], diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index 89f94a9f82..b3ff4896c7 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php @@ -100,8 +100,6 @@ public function testLoadUrlaliasData(): void 'language_ids' => [2], 'ibexa_url_alias_ml0_always_available' => '0', 'always_available' => '1', - 'ibexa_url_alias_ml0_lang_mask' => '2', - 'lang_mask' => '3', ], $row ); @@ -144,8 +142,6 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'language_ids' => [2, 4], 'ibexa_url_alias_ml0_always_available' => '1', 'always_available' => '0', - 'ibexa_url_alias_ml0_lang_mask' => '3', - 'lang_mask' => '6', ], $row ); @@ -383,7 +379,6 @@ public function testCleanupAfterPublishRemovesLanguage( $reloadedRow = $gateway->loadRow($parentId, $textMD5); $languageIdsAfter = $gateway->loadTranslationLanguageIds($parentId, $textMD5); - $loadedRow['lang_mask'] = $loadedRow['lang_mask'] & ~$languageId; $loadedRow['language_ids'] = array_values(array_diff($loadedRow['language_ids'], [$languageId])); self::assertEquals($loadedRow, $reloadedRow); @@ -425,7 +420,6 @@ public function testReparent(): void 'id' => '3', 'is_alias' => '0', 'is_original' => '1', - 'lang_mask' => '3', 'link' => '3', 'parent' => '42', 'text' => 'dva', diff --git a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php index ce28c65e61..99c321dac6 100644 --- a/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php @@ -22,7 +22,6 @@ use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase as LanguageGateway; use Ibexa\Core\Persistence\Legacy\Content\Language\Handler as LanguageHandler; use Ibexa\Core\Persistence\Legacy\Content\Language\Mapper as LanguageMapper; -use Ibexa\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase as DoctrineDatabaseLocation; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway; @@ -5342,7 +5341,6 @@ protected function getHandler(): Handler $this->getSharedGateway(), new ContentGateway\QueryBuilder($connection), $languageHandler, - new LanguageMaskGenerator($languageHandler), new FieldTypeAliasResolver(new FieldTypeAliasRegistry()) ); diff --git a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php index fe5d8b5962..c02730e70f 100644 --- a/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php +++ b/tests/lib/Persistence/Legacy/Content/_fixtures/extract_content_from_rows_multiple_versions.php @@ -31,7 +31,7 @@ 'content_field_content_type_field_definition_id' => 6, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => 3, + 'content_field_language_id' => 2, 'content_field_data_float' => 0.0, 'content_field_data_int' => 0, 'content_field_data_text' => 'Guest accounts', @@ -65,7 +65,7 @@ 'content_field_content_type_field_definition_id' => 7, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => 3, + 'content_field_language_id' => 2, 'content_field_data_float' => 0.0, 'content_field_data_int' => 0, 'content_field_data_text' => '', @@ -99,7 +99,7 @@ 'content_field_content_type_field_definition_id' => 6, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => 3, + 'content_field_language_id' => 2, 'content_field_data_float' => 0.0, 'content_field_data_int' => 0, 'content_field_data_text' => 'Members', @@ -133,7 +133,7 @@ 'content_field_content_type_field_definition_id' => 7, 'content_field_data_type_string' => 'ibexa_string', 'content_field_language_code' => 'eng-US', - 'content_field_language_id' => 3, + 'content_field_language_id' => 2, 'content_field_data_float' => 0.0, 'content_field_data_int' => 0, 'content_field_data_text' => '', From d30feae7d52725d06962544d9ef88ee6e7493c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 12 Nov 2026 16:46:53 +0100 Subject: [PATCH 40/54] IBX-11939: Refused to drop the language masks while always_available disagrees with them --- .../DropLanguageBitmaskColumnsMigration.php | 32 ++++++++ ...ropLanguageBitmaskColumnsMigrationTest.php | 80 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php diff --git a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php index b062ae37df..48af053aad 100644 --- a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -79,6 +79,13 @@ final class DropLanguageBitmaskColumnsMigration extends AbstractSqlMigration imp 'ibexa_url_alias_ml' => ['ibexa_url_alias_ml_translation', null], ]; + /** @var array */ + private const array ALWAYS_AVAILABLE_CHECKS = [ + self::CONTENT_TABLE => ['language_mask', 'always_available'], + 'ibexa_content_version' => ['language_mask', 'always_available'], + 'ibexa_url_alias_ml' => ['lang_mask', 'always_available'], + ]; + public function getDescription(): string { return 'Drops the language bitmask ("language_mask"/"lang_mask") columns, now that nothing reads them'; @@ -121,6 +128,7 @@ public function up(Schema $schema): void } $this->abortIfTranslationsNotBackfilled(array_keys($tablesStillCarryingMask)); + $this->abortIfAlwaysAvailableNotBackfilled(array_keys($tablesStillCarryingMask)); foreach (self::DROPS as $table => [$maskColumn, $indexName, $replaceIndex]) { if (!isset($tablesStillCarryingMask[$table])) { @@ -229,4 +237,28 @@ private function abortIfTranslationsNotBackfilled(array $tablesStillCarryingMask ); } } + + /** + * Refuses to drop the mask columns while an always-available column disagrees with bit 0 of the mask. + * + * @param string[] $tablesStillCarryingMask + */ + private function abortIfAlwaysAvailableNotBackfilled(array $tablesStillCarryingMask): void + { + foreach (self::ALWAYS_AVAILABLE_CHECKS as $table => [$maskColumn, $alwaysAvailableColumn]) { + if (!in_array($table, $tablesStillCarryingMask, true)) { + continue; + } + + $mismatchCount = (int)$this->connection->fetchOne( + "SELECT COUNT(*) FROM {$table} WHERE {$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)" + ); + + $this->abortIf( + $mismatchCount > 0, + "Refusing to drop \"{$maskColumn}\" from \"{$table}\": {$mismatchCount} row(s) have \"{$alwaysAvailableColumn}\" " . + 'disagreeing with bit 0 of the mask - run "ibexa:languages:verify-translations --fix" before this migration.' + ); + } + } } diff --git a/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php new file mode 100644 index 0000000000..82f39ddbed --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php @@ -0,0 +1,80 @@ +insertDatabaseFixture( + __DIR__ . '/../../../lib/Persistence/Legacy/Content/_fixtures/languages.php' + ); + + $connection = $this->getDatabaseConnection(); + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_content_version ADD COLUMN language_mask INTEGER DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_url_alias_ml ADD COLUMN lang_mask INTEGER DEFAULT 0 NOT NULL'); + + $connection->insert('ibexa_content', [ + 'id' => 1, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => 2, + 'language_mask' => 3, + 'name' => 'Foo', + 'owner_id' => 14, + 'remote_id' => 'foo', + ]); + $connection->insert('ibexa_content_translation', ['content_id' => 1, 'language_id' => 2]); + } + + public function testAbortsWhileAlwaysAvailableDisagreesWithTheMask(): void + { + $this->expectException(AbortMigration::class); + $this->expectExceptionMessage('"always_available" disagreeing with bit 0 of the mask'); + + $this->createMigration()->up(new Schema()); + } + + public function testDropsTheMasksOnceAlwaysAvailableMatches(): void + { + $this->getDatabaseConnection()->update( + 'ibexa_content', + ['always_available' => true], + ['id' => 1], + ['always_available' => ParameterType::BOOLEAN] + ); + + $migration = $this->createMigration(); + $migration->up(new Schema()); + + self::assertContains( + 'ALTER TABLE ibexa_content DROP COLUMN language_mask', + array_map(static fn (Query $query): string => $query->getStatement(), $migration->getSql()) + ); + } + + private function createMigration(): DropLanguageBitmaskColumnsMigration + { + return new DropLanguageBitmaskColumnsMigration($this->getDatabaseConnection(), new NullLogger(), new MigrationRunContext()); + } +} From 4042f7e5663e3f1a7cf2106487b0ccaabfcaec99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 13:59:13 +0100 Subject: [PATCH 41/54] IBX-13142: Moved the language mask drop to the end of the migration sequence --- .../Migration/DropLanguageBitmaskColumnsMigration.php | 6 +----- .../StripAlwaysAvailableBitFromLanguageIdsMigration.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php index 48af053aad..39e346a6dd 100644 --- a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -47,10 +47,6 @@ final class DropLanguageBitmaskColumnsMigration extends AbstractSqlMigration imp { private const string CONTENT_TABLE = 'ibexa_content'; - /** - * Not yet renamed to "ibexa_language" at this point in the migration sequence - that rename - * happens later, in {@see RenameLanguageTableMigration}. - */ private const string LANGUAGE_TABLE = 'ibexa_content_language'; /** @@ -98,7 +94,7 @@ public static function getTargetVersion(): string public static function getCreationDate(): DateTimeImmutable { - return new DateTimeImmutable('2026-10-19 05:00:00'); + return new DateTimeImmutable('2026-10-19 08:00:00'); } public function up(Schema $schema): void diff --git a/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php index c1d6d68db4..f3cf808e70 100644 --- a/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php @@ -17,7 +17,7 @@ /** * Strips the legacy "always available" bit (bit 0) from the "language_id" columns that the bitmask - * scheme folded it into, as the final step of the language bitmask migration. + * scheme folded it into. * * Under the bitmask scheme every language id was a power of two, so an odd "language_id" can only be * an id with the always-available bit ORed in. That bit carries nothing worth keeping here - it From 1dbe8312f684ff786ffe59ecf74afb330c63d9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:06:26 +0100 Subject: [PATCH 42/54] IBX-13142: Stripped the always-available bit by each row's own language instead of the shape of the ids --- ...ysAvailableBitFromLanguageIdsMigration.php | 90 ++++++----- ...-stale-object-state-translations-mysql.sql | 6 +- ...e-object-state-translations-postgresql.sql | 4 + ...stale-object-state-translations-sqlite.sql | 4 + ...ailableBitFromLanguageIdsMigrationTest.php | 141 ++++++++++++++++++ 5 files changed, 205 insertions(+), 40 deletions(-) create mode 100644 tests/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigrationTest.php diff --git a/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php index f3cf808e70..a69496de86 100644 --- a/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php @@ -19,18 +19,11 @@ * Strips the legacy "always available" bit (bit 0) from the "language_id" columns that the bitmask * scheme folded it into. * - * Under the bitmask scheme every language id was a power of two, so an odd "language_id" can only be - * an id with the always-available bit ORed in. That bit carries nothing worth keeping here - it - * duplicates "ibexa_content.always_available", "ibexa_content_type.always_available" and object - * state (group) "default_language_id" - but left in place it collides with the sequential ids new - * languages now get: the first language added after the upgrade is allocated MAX(id) + 1, exactly - * the tainted value of the highest existing language. - * - * That reasoning only holds while every language id is still a power of two: once a language has been - * created with a sequential id, an odd "language_id" may be that language's genuine id. Such an id - * proves the bit was stripped before that language was created - by an earlier run, or by an upgrade - * script that converted the database outside this migration sequence - so the migration then does - * nothing, instead of moving that language's rows onto its neighbour's id. + * Each row is checked against the language it names: the locale columns of fields, names and + * content type names, "real_language_id" of object state groups, and the state's default language + * for object states, which always have a translation in it. A row whose id already belongs to its + * own language is left alone, so the rows of a language created with a sequential id before this + * runs keep it, and a rerun changes nothing. * * Legacy eZ Publish can leave an object state with two rows for one language, one with the bit and * one without: changing a state's default language there inserted rows with the flipped bit instead @@ -39,24 +32,23 @@ * legacy's own group fix used: the state's default language keeps the row with the bit, every other * language the row without it. * - * Chunked and non-transactional for the same reasons as BackfillLanguageTranslationsMigration; - * re-running a chunk is a no-op, since stripped values are even. + * Chunked and non-transactional for the same reasons as BackfillLanguageTranslationsMigration. */ final class StripAlwaysAvailableBitFromLanguageIdsMigration extends AbstractSqlMigration implements IbexaMigrationInterface { private const int BATCH_SIZE = 5000; - private const string LANGUAGE_TABLE = 'ibexa_language'; + private const string LANGUAGE_TABLE = 'ibexa_content_language'; /** - * Table => column to chunk by, or null for tables small enough for a single statement. + * Table => [locale column, column to chunk by, or null for tables small enough for a single statement]. + * + * @var array */ - private const array TABLES = [ - 'ibexa_content_field' => 'id', - 'ibexa_content_name' => 'contentobject_id', - 'ibexa_content_type_name' => null, - 'ibexa_object_state_language' => null, - 'ibexa_object_state_group_language' => null, + private const array LOCALE_COLUMNS = [ + 'ibexa_content_field' => ['language_code', 'id'], + 'ibexa_content_name' => ['content_translation', 'contentobject_id'], + 'ibexa_content_type_name' => ['language_locale', null], ]; public function getDescription(): string @@ -84,20 +76,27 @@ public function up(Schema $schema): void $this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); $schemaManager = $this->connection->createSchemaManager(); - if ($schemaManager->tablesExist([self::LANGUAGE_TABLE]) && $this->hasSequentialLanguageIds()) { + if (!$schemaManager->tablesExist([self::LANGUAGE_TABLE])) { return; } if ($schemaManager->tablesExist(['ibexa_object_state', 'ibexa_object_state_language'])) { - $this->addStaleObjectStateTranslationRemoval(); + $this->addObjectStateTranslationStrip(); + } + + if ($schemaManager->tablesExist(['ibexa_object_state_group_language'])) { + $this->addSql( + 'UPDATE ibexa_object_state_group_language SET language_id = real_language_id WHERE language_id <> real_language_id' + ); } - foreach (self::TABLES as $table => $chunkColumn) { + foreach (self::LOCALE_COLUMNS as $table => [$localeColumn, $chunkColumn]) { if (!$schemaManager->tablesExist([$table])) { continue; } - $updateSql = "UPDATE {$table} SET language_id = language_id - 1 WHERE language_id % 2 = 1"; + $updateSql = "UPDATE {$table} SET language_id = language_id - 1 WHERE language_id % 2 = 1" + . ' AND NOT EXISTS (SELECT 1 FROM ' . self::LANGUAGE_TABLE . " l WHERE l.id = {$table}.language_id AND l.locale = {$table}.{$localeColumn})"; if ($chunkColumn === null) { $this->addSql($updateSql); continue; @@ -107,19 +106,7 @@ public function up(Schema $schema): void } } - private function hasSequentialLanguageIds(): bool - { - foreach ($this->connection->fetchFirstColumn('SELECT id FROM ' . self::LANGUAGE_TABLE) as $languageId) { - $languageId = (int)$languageId; - if (($languageId & ($languageId - 1)) !== 0) { - return true; - } - } - - return false; - } - - private function addStaleObjectStateTranslationRemoval(): void + private function addObjectStateTranslationStrip(): void { if ($this->isMySQL() || $this->isMariaDB()) { $this->addSqlFile(__DIR__ . '/sql/remove-stale-object-state-translations-mysql.sql'); @@ -128,6 +115,31 @@ private function addStaleObjectStateTranslationRemoval(): void } else { $this->addSqlFile(__DIR__ . '/sql/remove-stale-object-state-translations-sqlite.sql'); } + + $this->addSql( + 'UPDATE ibexa_object_state_language SET language_id = language_id - 1 WHERE language_id % 2 = 1' + . ' AND NOT EXISTS (SELECT 1 FROM ' . self::LANGUAGE_TABLE . ' l WHERE l.id = ibexa_object_state_language.language_id)' + ); + + $defaultTranslations = $this->connection->fetchAllAssociative( + 'SELECT t.contentobject_state_id, t.language_id + FROM ibexa_object_state_language t + JOIN ibexa_object_state s ON s.id = t.contentobject_state_id + JOIN ' . self::LANGUAGE_TABLE . ' l ON l.id = t.language_id + WHERE t.language_id % 2 = 1 + AND t.language_id - 1 = s.default_language_id + AND NOT EXISTS ( + SELECT 1 FROM ibexa_object_state_language d + WHERE d.contentobject_state_id = t.contentobject_state_id AND d.language_id = s.default_language_id + )' + ); + foreach ($defaultTranslations as $row) { + $this->addSql( + 'UPDATE ibexa_object_state_language SET language_id = :to WHERE contentobject_state_id = :state AND language_id = :from', + ['to' => (int)$row['language_id'] - 1, 'state' => (int)$row['contentobject_state_id'], 'from' => (int)$row['language_id']], + ['to' => ParameterType::INTEGER, 'state' => ParameterType::INTEGER, 'from' => ParameterType::INTEGER] + ); + } } private function addChunkedSql( diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql index 4bace1e7b6..449fed9c69 100644 --- a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql @@ -4,4 +4,8 @@ FROM ibexa_object_state_language AS stale INNER JOIN ibexa_object_state_language AS twin ON twin.contentobject_state_id = stale.contentobject_state_id AND twin.language_id = stale.language_id + 1 - 2 * (stale.language_id % 2) -WHERE (stale.language_id % 2 = 1) <> (stale.language_id - stale.language_id % 2 = state.default_language_id); +WHERE NOT EXISTS ( + SELECT 1 FROM ibexa_content_language AS odd_language + WHERE odd_language.id = stale.language_id + 1 - stale.language_id % 2 + ) + AND (stale.language_id % 2 = 1) <> (stale.language_id - stale.language_id % 2 = state.default_language_id); diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql index 35fe0f94c0..9d4db54689 100644 --- a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql @@ -3,4 +3,8 @@ USING ibexa_object_state AS state, ibexa_object_state_language AS twin WHERE state.id = stale.contentobject_state_id AND twin.contentobject_state_id = stale.contentobject_state_id AND twin.language_id = stale.language_id + 1 - 2 * (stale.language_id % 2) + AND NOT EXISTS ( + SELECT 1 FROM ibexa_content_language AS odd_language + WHERE odd_language.id = stale.language_id + 1 - stale.language_id % 2 + ) AND (stale.language_id % 2 = 1) <> (stale.language_id - stale.language_id % 2 = state.default_language_id); diff --git a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql index 0a16dd8397..97f734154c 100644 --- a/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql @@ -5,6 +5,10 @@ WHERE EXISTS ( WHERE twin.contentobject_state_id = ibexa_object_state_language.contentobject_state_id AND twin.language_id = ibexa_object_state_language.language_id + 1 - 2 * (ibexa_object_state_language.language_id % 2) ) + AND NOT EXISTS ( + SELECT 1 FROM ibexa_content_language AS odd_language + WHERE odd_language.id = ibexa_object_state_language.language_id + 1 - ibexa_object_state_language.language_id % 2 + ) AND (language_id % 2 = 1) <> ( language_id - language_id % 2 = ( SELECT state.default_language_id diff --git a/tests/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigrationTest.php new file mode 100644 index 0000000000..e94ca69e14 --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigrationTest.php @@ -0,0 +1,141 @@ +insertDatabaseFixture( + __DIR__ . '/../../../lib/Persistence/Legacy/Content/_fixtures/languages.php' + ); + + $connection = $this->getDatabaseConnection(); + $connection->insert('ibexa_content_language', ['id' => 5, 'locale' => 'fre-FR', 'name' => 'French', 'disabled' => 0]); + + foreach ([[1, 'eng-GB', 5], [2, 'fre-FR', 5], [3, 'eng-US', 3], [4, 'eng-US', 2]] as [$id, $languageCode, $languageId]) { + $connection->insert('ibexa_content_field', [ + 'id' => $id, + 'version' => 1, + 'contentobject_id' => 1, + 'language_code' => $languageCode, + 'language_id' => $languageId, + ]); + } + + foreach ([['eng-GB', 5], ['fre-FR', 5]] as [$languageCode, $languageId]) { + $connection->insert('ibexa_content_name', [ + 'contentobject_id' => 1, + 'content_version' => 1, + 'content_translation' => $languageCode, + 'language_id' => $languageId, + ]); + } + + foreach ([[1, 'eng-GB', 5], [2, 'fre-FR', 5], [3, 'eng-US', 3]] as [$typeId, $languageLocale, $languageId]) { + $connection->insert('ibexa_content_type_name', [ + 'content_type_id' => $typeId, + 'content_type_status' => 0, + 'language_locale' => $languageLocale, + 'language_id' => $languageId, + ]); + } + + foreach ([[4, 5], [5, 5]] as [$realLanguageId, $languageId]) { + $connection->insert('ibexa_object_state_group_language', [ + 'contentobject_state_group_id' => 1, + 'real_language_id' => $realLanguageId, + 'language_id' => $languageId, + 'description' => '', + ]); + } + + foreach ([1 => 4, 2 => 2, 3 => 2] as $stateId => $defaultLanguageId) { + $connection->insert('ibexa_object_state', [ + 'id' => $stateId, + 'group_id' => 1, + 'default_language_id' => $defaultLanguageId, + 'identifier' => 'state_' . $stateId, + ]); + } + + foreach ([[1, 5, 'default'], [2, 3, 'default'], [2, 4, 'eng-GB'], [2, 5, 'fre-FR'], [3, 2, 'without bit'], [3, 3, 'with bit']] as [$stateId, $languageId, $name]) { + $connection->insert('ibexa_object_state_language', [ + 'contentobject_state_id' => $stateId, + 'language_id' => $languageId, + 'name' => $name, + 'description' => '', + ]); + } + } + + public function testStripsTheBitAndKeepsTheRowsOfASequentialLanguage(): void + { + $this->runMigration(); + + $this->assertStripped(); + } + + public function testRerunChangesNothing(): void + { + $this->runMigration(); + $this->runMigration(); + + $this->assertStripped(); + } + + private function runMigration(): void + { + $connection = $this->getDatabaseConnection(); + $migration = new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext()); + $migration->up(new Schema()); + + foreach ($migration->getSql() as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + } + + private function assertStripped(): void + { + $connection = $this->getDatabaseConnection(); + + self::assertEquals( + [[1, 4], [2, 5], [3, 2], [4, 2]], + $connection->fetchAllNumeric('SELECT id, language_id FROM ibexa_content_field ORDER BY id') + ); + self::assertEquals( + [['eng-GB', 4], ['fre-FR', 5]], + $connection->fetchAllNumeric('SELECT content_translation, language_id FROM ibexa_content_name ORDER BY content_translation') + ); + self::assertEquals( + [[1, 4], [2, 5], [3, 2]], + $connection->fetchAllNumeric('SELECT content_type_id, language_id FROM ibexa_content_type_name ORDER BY content_type_id') + ); + self::assertEquals( + [[4, 4], [5, 5]], + $connection->fetchAllNumeric('SELECT real_language_id, language_id FROM ibexa_object_state_group_language ORDER BY real_language_id') + ); + self::assertEquals( + [[1, 4, 'default'], [2, 2, 'default'], [2, 4, 'eng-GB'], [2, 5, 'fre-FR'], [3, 2, 'with bit']], + $connection->fetchAllNumeric( + 'SELECT contentobject_state_id, language_id, name FROM ibexa_object_state_language ORDER BY contentobject_state_id, language_id' + ) + ); + } +} From f7568de0141bc1ad17e723eb8a369a8b095acb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:11:40 +0100 Subject: [PATCH 43/54] IBX-13142: Dropped the URL alias text and language index without a replacement --- .../config/storage/legacy/schema.yaml | 1 - .../DropLanguageBitmaskColumnsMigration.php | 56 ++++--------------- ...ropLanguageBitmaskColumnsMigrationTest.php | 14 +++++ 3 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index dd7041f642..d87f8d3913 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -589,7 +589,6 @@ tables: ibexa_url_alias_ml: indexes: ibexa_url_alias_ml_actt_org_al: { fields: [action_type, is_original, is_alias] } - ibexa_url_alias_ml_text_lang: { fields: [text, parent], options: { lengths: ['32', null] } } ibexa_url_alias_ml_par_act_id_lnk: { fields: [action, id, link, parent], options: { lengths: ['32', null, null, null] } } ibexa_url_alias_ml_par_lnk_txt: { fields: [parent, text, link], options: { lengths: [null, '32', null] } } ibexa_url_alias_ml_act_org: { fields: [action, is_original], options: { lengths: ['32', null] } } diff --git a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php index 39e346a6dd..00688928e9 100644 --- a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -50,19 +50,18 @@ final class DropLanguageBitmaskColumnsMigration extends AbstractSqlMigration imp private const string LANGUAGE_TABLE = 'ibexa_content_language'; /** - * Table => [mask column, index to drop (if any), whether the index needs replacing with a - * lang-less equivalent rather than just dropped (only "ibexa_url_alias_ml")]. + * Table => [mask column, index on it to drop first (if any)]. * - * @var array + * @var array */ private const array DROPS = [ - 'ibexa_object_state' => ['language_mask', 'ibexa_object_state_lmask', false], - 'ibexa_object_state_group' => ['language_mask', 'ibexa_object_state_group_lmask', false], - 'ibexa_content_type' => ['language_mask', null, false], - self::CONTENT_TABLE => ['language_mask', 'ibexa_content_lmask', false], - 'ibexa_content_version' => ['language_mask', null, false], - 'ibexa_search_object_word_link' => ['language_mask', null, false], - 'ibexa_url_alias_ml' => ['lang_mask', 'ibexa_url_alias_ml_text_lang', true], + 'ibexa_object_state' => ['language_mask', 'ibexa_object_state_lmask'], + 'ibexa_object_state_group' => ['language_mask', 'ibexa_object_state_group_lmask'], + 'ibexa_content_type' => ['language_mask', null], + self::CONTENT_TABLE => ['language_mask', 'ibexa_content_lmask'], + 'ibexa_content_version' => ['language_mask', null], + 'ibexa_search_object_word_link' => ['language_mask', null], + 'ibexa_url_alias_ml' => ['lang_mask', 'ibexa_url_alias_ml_text_lang'], ]; /** @@ -126,35 +125,13 @@ public function up(Schema $schema): void $this->abortIfTranslationsNotBackfilled(array_keys($tablesStillCarryingMask)); $this->abortIfAlwaysAvailableNotBackfilled(array_keys($tablesStillCarryingMask)); - foreach (self::DROPS as $table => [$maskColumn, $indexName, $replaceIndex]) { + foreach (self::DROPS as $table => [$maskColumn, $indexName]) { if (!isset($tablesStillCarryingMask[$table])) { continue; } - $introspectedTable = $schemaManager->introspectTable($table); - - if ($indexName !== null) { - $indexExists = $introspectedTable->hasIndex($indexName); - $indexStillHasMaskColumn = $indexExists - && in_array($maskColumn, $introspectedTable->getIndex($indexName)->getColumns(), true); - - if ($replaceIndex) { - if ($indexStillHasMaskColumn) { - // Still the old, mask-including definition - drop it before recreating - // without the mask column below. - $this->addSql($this->buildDropIndexSql($table, $indexName)); - } - - if ($indexStillHasMaskColumn || !$indexExists) { - // Either just dropped above, or missing entirely because a prior partial - // run dropped it but was interrupted before recreating it - either way it - // still needs (re)creating in its final, mask-less form. If neither is true, - // the index already exists in that final form and needs no change. - $this->addSql($this->buildCreateUrlAliasTextParentIndexSql()); - } - } elseif ($indexExists) { - $this->addSql($this->buildDropIndexSql($table, $indexName)); - } + if ($indexName !== null && $schemaManager->introspectTable($table)->hasIndex($indexName)) { + $this->addSql($this->buildDropIndexSql($table, $indexName)); } $this->addSql("ALTER TABLE {$table} DROP COLUMN {$maskColumn}"); @@ -173,15 +150,6 @@ private function buildDropIndexSql( : "DROP INDEX {$indexName}"; } - private function buildCreateUrlAliasTextParentIndexSql(): string - { - // Replaces the dropped "(text(32), parent)"/"(text, parent)" + lang index with a lang-less - // equivalent - "lang_mask" is gone, but the (text, parent) lookup itself is still needed. - return $this->isMySQL() || $this->isMariaDB() - ? 'ALTER TABLE ibexa_url_alias_ml ADD INDEX ibexa_url_alias_ml_text_lang (text(32), parent)' - : 'CREATE INDEX ibexa_url_alias_ml_text_lang ON ibexa_url_alias_ml (text, parent)'; - } - /** * Refuses to drop the mask columns if any row still carrying a real (non-always-available) * language bit has no corresponding row in the relational replacement it should have been diff --git a/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php index 82f39ddbed..7235f4687c 100644 --- a/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php @@ -73,6 +73,20 @@ public function testDropsTheMasksOnceAlwaysAvailableMatches(): void ); } + public function testDropsTheUrlAliasTextIndexWithoutReplacingIt(): void + { + $connection = $this->getDatabaseConnection(); + $connection->executeStatement('CREATE INDEX ibexa_url_alias_ml_text_lang ON ibexa_url_alias_ml (text, lang_mask, parent)'); + $connection->update('ibexa_content', ['always_available' => true], ['id' => 1], ['always_available' => ParameterType::BOOLEAN]); + + $migration = $this->createMigration(); + $migration->up(new Schema()); + $statements = array_map(static fn (Query $query): string => $query->getStatement(), $migration->getSql()); + + self::assertContains('DROP INDEX ibexa_url_alias_ml_text_lang', $statements); + self::assertSame([], preg_grep('/CREATE INDEX|ADD INDEX/', $statements)); + } + private function createMigration(): DropLanguageBitmaskColumnsMigration { return new DropLanguageBitmaskColumnsMigration($this->getDatabaseConnection(), new NullLogger(), new MigrationRunContext()); From 7875fbace55f3754b7d9b4796c36dbbbf9341b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:13:42 +0100 Subject: [PATCH 44/54] IBX-13142: Deleted a language's legacy search index rows with it instead of refusing the delete --- .../Persistence/Legacy/Content/Language/Gateway.php | 6 +++--- .../Content/Language/Gateway/DoctrineDatabase.php | 10 ++++++---- .../Language/Gateway/DoctrineDatabaseTest.php | 13 +++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway.php b/src/lib/Persistence/Legacy/Content/Language/Gateway.php index bc5a211f0a..851b6d4f04 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway.php @@ -26,9 +26,9 @@ abstract class Gateway * A map of language-related table name to the single column identifying a real language id * that row references (an explicit id column, never a bitmask). * - * "ibexa_content"/"ibexa_content_version" (their "initial_language_id"), the URL alias - * translations table, and the Legacy Search Engine's word index are checked explicitly in - * {@see DoctrineDatabase::canDeleteLanguage()} instead of via this map. + * "ibexa_content"/"ibexa_content_version" (their "initial_language_id") and the URL alias + * translations table are checked explicitly in {@see DoctrineDatabase::canDeleteLanguage()} + * instead of via this map. * * It depends on the schema defined in * ./src/bundle/Core/Resources/config/storage/legacy/schema.yaml diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php index cf4768baf2..4b03f53f17 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php @@ -141,6 +141,12 @@ public function loadAllLanguagesData(): array public function deleteLanguage(int $id): void { + $this->connection->delete( + 'ibexa_search_object_word_link', + ['language_id' => $id], + ['language_id' => ParameterType::INTEGER] + ); + $query = $this->connection->createQueryBuilder(); $query ->delete(self::CONTENT_LANGUAGE_TABLE) @@ -180,10 +186,6 @@ public function canDeleteLanguage(int $id): bool return false; } - if ($this->existsWithColumnValue($id, 'ibexa_search_object_word_link', 'language_id')) { - return false; - } - // note: at some point this should be delegated to specific gateways foreach (self::MULTILINGUAL_TABLES_COLUMNS as $tableName => $columns) { if ($this->existsWithColumnValue($id, $tableName, $columns[0])) { diff --git a/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php index a95ceb6eb4..a5d5fbae98 100644 --- a/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php +++ b/tests/lib/Persistence/Legacy/Content/Language/Gateway/DoctrineDatabaseTest.php @@ -172,6 +172,19 @@ public function testDeleteLanguage(): void ); } + public function testStaleSearchIndexRowsDoNotBlockDeletingALanguage(): void + { + $gateway = $this->getDatabaseGateway(); + $connection = $this->getDatabaseConnection(); + $connection->insert('ibexa_search_object_word_link', ['id' => 1, 'identifier' => '', 'language_id' => 2]); + + self::assertTrue($gateway->canDeleteLanguage(2)); + + $gateway->deleteLanguage(2); + + self::assertSame(0, (int)$connection->fetchOne('SELECT COUNT(*) FROM ibexa_search_object_word_link')); + } + public function testCanDeleteUnusedLanguageAdjacentToAnotherInUseLanguage(): void { $gateway = $this->getDatabaseGateway(); From 8c057bbee7cdf3565230321235f6ddf5633b3212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:24:33 +0100 Subject: [PATCH 45/54] IBX-13142: Stripped the legacy bit from fixtures only for ids that aren't a language, and from core's test data itself --- .../Persistence/Fixture/FixtureImporter.php | 23 ++- .../_fixtures/Legacy/data/test_data.yaml | 144 +++++++++--------- .../Fixture/FixtureImporterTest.php | 44 ++++++ 3 files changed, 132 insertions(+), 79 deletions(-) create mode 100644 tests/lib/Test/Persistence/Fixture/FixtureImporterTest.php diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index 342ddd0640..fd7dc28874 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -71,13 +71,17 @@ public function import(Fixture $fixture): void static fn (array $tableData, string $table): bool => !empty($tableData) && in_array($table, $tablesList, true), ARRAY_FILTER_USE_BOTH ); + $languageIds = array_merge( + $this->loadValidLanguageIds(), + array_map('intval', array_column($data['ibexa_content_language'] ?? [], 'id')) + ); foreach ($nonEmptyTablesData as $table => $rows) { // Fixtures predate columns being dropped over time (e.g. the language bitmask // columns) - silently drop unknown keys rather than letting every fixture file need // updating in lockstep with schema changes. $existingColumns = $this->getExistingColumns($table); foreach ($rows as $row) { - $row = $this->stripLegacyAlwaysAvailableBit($table, $row); + $row = $this->stripLegacyAlwaysAvailableBit($table, $row, $languageIds); $this->connection->insert($table, array_intersect_key($row, array_flip($existingColumns))); } } @@ -145,20 +149,25 @@ private function reattachLanguageTranslations(array $detachedTranslations): void } /** - * Fixture data was captured under the legacy bitmask scheme, where every language id is a power - * of two - mirrors what StripAlwaysAvailableBitFromLanguageIdsMigration does for production - * upgrades, applied to the fixture rows only. + * Clears the legacy "always available" bit from a row's odd "language_id" unless it's a language. * * @param array $row + * @param int[] $languageIds * * @return array */ private function stripLegacyAlwaysAvailableBit( string $table, - array $row + array $row, + array $languageIds ): array { - if (isset($row['language_id']) && in_array($table, self::TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT, true)) { - $row['language_id'] = (int)$row['language_id'] & ~1; + if (!isset($row['language_id']) || !in_array($table, self::TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT, true)) { + return $row; + } + + $languageId = (int)$row['language_id']; + if ($languageId % 2 === 1 && !in_array($languageId, $languageIds, true)) { + $row['language_id'] = $languageId - 1; } return $row; diff --git a/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml b/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml index dc536e544b..c9c521aef4 100644 --- a/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml +++ b/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml @@ -5,10 +5,10 @@ ibexa_object_state: ibexa_object_state_group: - { default_language_id: 2, id: 2, identifier: ibexa_lock, language_mask: 3 } ibexa_object_state_group_language: - - { contentobject_state_group_id: 2, description: '', language_id: 3, name: Lock, real_language_id: 2 } + - { contentobject_state_group_id: 2, description: '', language_id: 2, name: Lock, real_language_id: 2 } ibexa_object_state_language: - - { contentobject_state_id: 1, description: '', language_id: 3, name: 'Not locked' } - - { contentobject_state_id: 2, description: '', language_id: 3, name: Locked } + - { contentobject_state_id: 1, description: '', language_id: 2, name: 'Not locked' } + - { contentobject_state_id: 2, description: '', language_id: 2, name: Locked } ibexa_object_state_link: - { contentobject_id: 4, contentobject_state_id: 1 } - { contentobject_id: 10, contentobject_state_id: 1 } @@ -208,12 +208,12 @@ ibexa_content_type_group_assignment: - { content_type_id: 35, content_type_status: 0, group_id: 3, group_name: Media } - { content_type_id: 36, content_type_status: 0, group_id: 1, group_name: Content } ibexa_content_type_name: - - { content_type_id: 1, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: Folder } - - { content_type_id: 3, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: 'User group' } - - { content_type_id: 4, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: User } - - { content_type_id: 13, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: Comment } - - { content_type_id: 14, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: 'Common ini settings' } - - { content_type_id: 15, content_type_status: 0, language_id: 3, language_locale: eng-GB, name: 'Template look' } + - { content_type_id: 1, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: Folder } + - { content_type_id: 3, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: 'User group' } + - { content_type_id: 4, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: User } + - { content_type_id: 13, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: Comment } + - { content_type_id: 14, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: 'Common ini settings' } + - { content_type_id: 15, content_type_status: 0, language_id: 2, language_locale: eng-GB, name: 'Template look' } - { content_type_id: 16, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Article } - { content_type_id: 17, content_type_status: 0, language_id: 8, language_locale: eng-US, name: Blog } - { content_type_id: 18, content_type_status: 0, language_id: 8, language_locale: eng-US, name: 'Blog post' } @@ -260,42 +260,42 @@ ibexa_content: - { content_type_id: 20, current_version: 1, id: 58, initial_language_id: 8, language_mask: 8, modified: 1332927282, name: 'Contact Us', owner_id: 14, published: 1332927205, remote_id: f8cc7a4cf8a964a1a0ea6666f5da7d0d, section_id: 1, status: 1 } - { content_type_id: 3, current_version: 1, id: 59, initial_language_id: 2, language_mask: 3, modified: 1343140541, name: Partners, owner_id: 14, published: 1343140541, remote_id: 14e4411b264a6194a33847843919451a, section_id: 2, status: 1 } ibexa_content_field: - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 4, data_float: null, data_int: null, data_text: 'Main group', data_type_string: ibexa_string, id: 7, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 4, data_float: null, data_int: null, data_text: Users, data_type_string: ibexa_string, id: 8, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 10, data_float: 0, data_int: 0, data_text: Anonymous, data_type_string: ibexa_string, id: 19, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: anonymous, version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 10, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 20, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: user, version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 12, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 21, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 11, data_float: 0, data_int: 0, data_text: 'Guest accounts', data_type_string: ibexa_string, id: 22, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 11, data_float: 0, data_int: 0, data_text: Members, data_type_string: ibexa_string, id: 22, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: members, version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 11, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 23, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 11, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 23, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 12, data_float: 0, data_int: 0, data_text: 'Administrator users', data_type_string: ibexa_string, id: 24, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 12, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 25, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 13, data_float: 0, data_int: 0, data_text: Editors, data_type_string: ibexa_string, id: 26, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 13, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 27, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 14, data_float: 0, data_int: 0, data_text: Administrator, data_type_string: ibexa_string, id: 28, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: administrator, version: 3 } - - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 14, data_float: 0, data_int: 0, data_text: Administrator, data_type_string: ibexa_string, id: 28, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: administrator, version: 4 } - - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 14, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 29, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: user, version: 3 } - - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 14, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 29, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: user, version: 4 } - - { attribute_original_id: 30, content_type_field_definition_id: 12, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 30, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 3 } - - { attribute_original_id: 30, content_type_field_definition_id: 12, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 30, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 4 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 41, data_float: 0, data_int: 0, data_text: Media, data_type_string: ibexa_string, id: 98, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: media, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 42, data_float: 0, data_int: 0, data_text: 'Anonymous users', data_type_string: ibexa_string, id: 100, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: 'anonymous users', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 42, data_float: 0, data_int: 0, data_text: 'User group for the anonymous user', data_type_string: ibexa_string, id: 101, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: 'user group for the anonymous user', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 41, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 103, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 41, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_boolean, id: 109, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 45, data_float: 0, data_int: 0, data_text: Setup, data_type_string: ibexa_string, id: 123, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: setup, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 45, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 124, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 45, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_boolean, id: 128, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 49, data_float: 0, data_int: 0, data_text: Images, data_type_string: ibexa_string, id: 142, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: images, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 49, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 143, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 49, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 146, language_code: eng-GB, language_id: 3, sort_key_int: 1, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 50, data_float: 0, data_int: 0, data_text: Files, data_type_string: ibexa_string, id: 147, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: files, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 50, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 148, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 50, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 151, language_code: eng-GB, language_id: 3, sort_key_int: 1, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 51, data_float: 0, data_int: 0, data_text: Multimedia, data_type_string: ibexa_string, id: 152, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: multimedia, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 51, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 153, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 51, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 156, language_code: eng-GB, language_id: 3, sort_key_int: 1, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 4, data_float: null, data_int: null, data_text: 'Main group', data_type_string: ibexa_string, id: 7, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 4, data_float: null, data_int: null, data_text: Users, data_type_string: ibexa_string, id: 8, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 10, data_float: 0, data_int: 0, data_text: Anonymous, data_type_string: ibexa_string, id: 19, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: anonymous, version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 10, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 20, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: user, version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 12, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 21, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 11, data_float: 0, data_int: 0, data_text: 'Guest accounts', data_type_string: ibexa_string, id: 22, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 11, data_float: 0, data_int: 0, data_text: Members, data_type_string: ibexa_string, id: 22, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: members, version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 11, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 23, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 11, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 23, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 12, data_float: 0, data_int: 0, data_text: 'Administrator users', data_type_string: ibexa_string, id: 24, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 12, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 25, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 13, data_float: 0, data_int: 0, data_text: Editors, data_type_string: ibexa_string, id: 26, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 13, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 27, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 14, data_float: 0, data_int: 0, data_text: Administrator, data_type_string: ibexa_string, id: 28, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: administrator, version: 3 } + - { attribute_original_id: 0, content_type_field_definition_id: 8, contentobject_id: 14, data_float: 0, data_int: 0, data_text: Administrator, data_type_string: ibexa_string, id: 28, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: administrator, version: 4 } + - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 14, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 29, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: user, version: 3 } + - { attribute_original_id: 0, content_type_field_definition_id: 9, contentobject_id: 14, data_float: 0, data_int: 0, data_text: User, data_type_string: ibexa_string, id: 29, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: user, version: 4 } + - { attribute_original_id: 30, content_type_field_definition_id: 12, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 30, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 3 } + - { attribute_original_id: 30, content_type_field_definition_id: 12, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_user, id: 30, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 4 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 41, data_float: 0, data_int: 0, data_text: Media, data_type_string: ibexa_string, id: 98, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: media, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 42, data_float: 0, data_int: 0, data_text: 'Anonymous users', data_type_string: ibexa_string, id: 100, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: 'anonymous users', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 42, data_float: 0, data_int: 0, data_text: 'User group for the anonymous user', data_type_string: ibexa_string, id: 101, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: 'user group for the anonymous user', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 41, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 103, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 41, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_boolean, id: 109, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 45, data_float: 0, data_int: 0, data_text: Setup, data_type_string: ibexa_string, id: 123, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: setup, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 45, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 124, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 45, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_boolean, id: 128, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 49, data_float: 0, data_int: 0, data_text: Images, data_type_string: ibexa_string, id: 142, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: images, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 49, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 143, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 49, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 146, language_code: eng-GB, language_id: 2, sort_key_int: 1, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 50, data_float: 0, data_int: 0, data_text: Files, data_type_string: ibexa_string, id: 147, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: files, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 50, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 148, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 50, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 151, language_code: eng-GB, language_id: 2, sort_key_int: 1, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 51, data_float: 0, data_int: 0, data_text: Multimedia, data_type_string: ibexa_string, id: 152, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: multimedia, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 51, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_string, id: 153, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 51, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 156, language_code: eng-GB, language_id: 2, sort_key_int: 1, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 159, contentobject_id: 52, data_float: 0, data_int: 0, data_text: 'Common INI settings', data_type_string: ibexa_string, id: 157, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: 'common ini settings', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 160, contentobject_id: 52, data_float: 0, data_int: 0, data_text: /content/view/full/2/, data_type_string: ezinisetting, id: 158, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 161, contentobject_id: 52, data_float: 0, data_int: 0, data_text: /content/view/full/2, data_type_string: ezinisetting, id: 159, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } @@ -315,15 +315,15 @@ ibexa_content_field: - { attribute_original_id: 0, content_type_field_definition_id: 175, contentobject_id: 54, data_float: 0, data_int: 0, data_text: 0, data_type_string: ezpackage, id: 173, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: 0, version: 2 } - { attribute_original_id: 0, content_type_field_definition_id: 177, contentobject_id: 54, data_float: 0, data_int: 0, data_text: spam@ibexa.co, data_type_string: ezinisetting, id: 175, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } - { attribute_original_id: 0, content_type_field_definition_id: 178, contentobject_id: 54, data_float: 0, data_int: 0, data_text: ws2/dump_47_demo/index.php, data_type_string: ezinisetting, id: 176, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 177, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 178, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 3 } - - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 178, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 4 } - - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_image, id: 179, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 14, data_float: 0, data_int: 0, data_text: "\n\n", data_type_string: ibexa_image, id: 180, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 3 } - - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 14, data_float: 0, data_int: 0, data_text: "\n\n", data_type_string: ibexa_image, id: 180, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 4 } - - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 56, data_float: 0, data_int: null, data_text: Design, data_type_string: ibexa_string, id: 181, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: design, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 56, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_string, id: 182, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 56, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 185, language_code: eng-GB, language_id: 3, sort_key_int: 1, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 177, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 178, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 3 } + - { attribute_original_id: 0, content_type_field_definition_id: 179, contentobject_id: 14, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_text, id: 178, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 4 } + - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 10, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_image, id: 179, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } + - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 14, data_float: 0, data_int: 0, data_text: "\n\n", data_type_string: ibexa_image, id: 180, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 3 } + - { attribute_original_id: 0, content_type_field_definition_id: 180, contentobject_id: 14, data_float: 0, data_int: 0, data_text: "\n\n", data_type_string: ibexa_image, id: 180, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 4 } + - { attribute_original_id: 0, content_type_field_definition_id: 4, contentobject_id: 56, data_float: 0, data_int: null, data_text: Design, data_type_string: ibexa_string, id: 181, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: design, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 155, contentobject_id: 56, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_string, id: 182, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 158, contentobject_id: 56, data_float: 0, data_int: 1, data_text: '', data_type_string: ibexa_boolean, id: 185, language_code: eng-GB, language_id: 2, sort_key_int: 1, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 219, contentobject_id: 57, data_float: 0, data_int: null, data_text: Home, data_type_string: ibexa_string, id: 186, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: home, version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 212, contentobject_id: 58, data_float: 0, data_int: null, data_text: 'Contact Us', data_type_string: ibexa_string, id: 188, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: 'contact us', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 214, contentobject_id: 58, data_float: 0, data_int: null, data_text: 'Firstname Lastname', data_type_string: ibexa_string, id: 190, language_code: eng-US, language_id: 8, sort_key_int: 0, sort_key_string: 'firstname lastname', version: 1 } @@ -343,8 +343,8 @@ ibexa_content_field: - { attribute_original_id: 0, content_type_field_definition_id: 288, contentobject_id: 54, data_float: 0, data_int: null, data_text: 'Copyright © 2012 eZ Systems AS (except where otherwise noted). All rights reserved.', data_type_string: ibexa_text, id: 204, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } - { attribute_original_id: 0, content_type_field_definition_id: 289, contentobject_id: 54, data_float: 0, data_int: 0, data_text: '', data_type_string: ibexa_boolean, id: 205, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } - { attribute_original_id: 0, content_type_field_definition_id: 290, contentobject_id: 54, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_text, id: 206, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 2 } - - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 59, data_float: 0, data_int: null, data_text: Partners, data_type_string: ibexa_string, id: 207, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: partners, version: 1 } - - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 59, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_string, id: 208, language_code: eng-GB, language_id: 3, sort_key_int: 0, sort_key_string: '', version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 6, contentobject_id: 59, data_float: 0, data_int: null, data_text: Partners, data_type_string: ibexa_string, id: 207, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: partners, version: 1 } + - { attribute_original_id: 0, content_type_field_definition_id: 7, contentobject_id: 59, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_string, id: 208, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 292, contentobject_id: 41, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_keyword, id: 215, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 292, contentobject_id: 45, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_keyword, id: 216, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } - { attribute_original_id: 0, content_type_field_definition_id: 292, contentobject_id: 49, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_keyword, id: 217, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } @@ -353,26 +353,26 @@ ibexa_content_field: - { attribute_original_id: 0, content_type_field_definition_id: 292, contentobject_id: 56, data_float: 0, data_int: null, data_text: '', data_type_string: ibexa_keyword, id: 220, language_code: eng-GB, language_id: 2, sort_key_int: 0, sort_key_string: '', version: 1 } ibexa_content_relation: { } ibexa_content_name: - - { content_translation: eng-GB, content_version: 1, contentobject_id: 4, language_id: 3, name: Users, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 2, contentobject_id: 10, language_id: 3, name: 'Anonymous User', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 11, language_id: 3, name: 'Guest accounts', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 2, contentobject_id: 11, language_id: 3, name: Members, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 12, language_id: 3, name: 'Administrator users', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 13, language_id: 3, name: Editors, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 3, contentobject_id: 14, language_id: 3, name: 'Administrator User', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 4, contentobject_id: 14, language_id: 3, name: 'Administrator User', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 41, language_id: 3, name: Media, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 42, language_id: 3, name: 'Anonymous users', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 45, language_id: 3, name: Setup, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 49, language_id: 3, name: Images, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 50, language_id: 3, name: Files, real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 51, language_id: 3, name: Multimedia, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 4, language_id: 2, name: Users, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 2, contentobject_id: 10, language_id: 2, name: 'Anonymous User', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 11, language_id: 2, name: 'Guest accounts', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 2, contentobject_id: 11, language_id: 2, name: Members, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 12, language_id: 2, name: 'Administrator users', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 13, language_id: 2, name: Editors, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 3, contentobject_id: 14, language_id: 2, name: 'Administrator User', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 4, contentobject_id: 14, language_id: 2, name: 'Administrator User', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 41, language_id: 2, name: Media, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 42, language_id: 2, name: 'Anonymous users', real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 45, language_id: 2, name: Setup, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 49, language_id: 2, name: Images, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 50, language_id: 2, name: Files, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 51, language_id: 2, name: Multimedia, real_translation: eng-GB } - { content_translation: eng-GB, content_version: 1, contentobject_id: 52, language_id: 2, name: 'Common INI settings', real_translation: eng-GB } - { content_translation: eng-GB, content_version: 2, contentobject_id: 54, language_id: 2, name: 'Ibexa Demo Design (without demo content)', real_translation: eng-GB } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 56, language_id: 3, name: Design, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 56, language_id: 2, name: Design, real_translation: eng-GB } - { content_translation: eng-US, content_version: 1, contentobject_id: 57, language_id: 8, name: Home, real_translation: eng-US } - { content_translation: eng-US, content_version: 1, contentobject_id: 58, language_id: 8, name: 'Contact Us', real_translation: eng-US } - - { content_translation: eng-GB, content_version: 1, contentobject_id: 59, language_id: 3, name: Partners, real_translation: eng-GB } + - { content_translation: eng-GB, content_version: 1, contentobject_id: 59, language_id: 2, name: Partners, real_translation: eng-GB } ibexa_content_trash: { } ibexa_content_tree: - { contentobject_id: 0, contentobject_is_published: 1, contentobject_version: 1, depth: 0, is_hidden: 0, is_invisible: 0, main_node_id: 1, modified_subnode: 1343140542, node_id: 1, parent_node_id: 1, path_identification_string: '', path_string: /1/, priority: 0, remote_id: 629709ba256fe317c3ddcee35453a96a, sort_field: 1, sort_order: 1 } diff --git a/tests/lib/Test/Persistence/Fixture/FixtureImporterTest.php b/tests/lib/Test/Persistence/Fixture/FixtureImporterTest.php new file mode 100644 index 0000000000..1e9c3aecef --- /dev/null +++ b/tests/lib/Test/Persistence/Fixture/FixtureImporterTest.php @@ -0,0 +1,44 @@ +getDatabaseConnection(); + + (new FixtureImporter($connection))->import(new class() implements Fixture { + public function load(): array + { + return [ + 'ibexa_content_language' => [ + ['id' => 2, 'locale' => 'eng-US', 'name' => 'English (American)', 'disabled' => 0], + ['id' => 5, 'locale' => 'fre-FR', 'name' => 'French', 'disabled' => 0], + ], + 'ibexa_content_field' => [ + ['id' => 1, 'version' => 1, 'contentobject_id' => 1, 'language_code' => 'eng-US', 'language_id' => 3], + ['id' => 2, 'version' => 1, 'contentobject_id' => 1, 'language_code' => 'fre-FR', 'language_id' => 5], + ], + ]; + } + }); + + self::assertEquals( + [[1, 2], [2, 5]], + $connection->fetchAllNumeric('SELECT id, language_id FROM ibexa_content_field ORDER BY id') + ); + } +} From 6c6a88608bb88b95fbae6545d56d899a4171a9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:31:19 +0100 Subject: [PATCH 46/54] IBX-13142: Checked the translations and an alias of the content created in languages beyond the old limit --- .../MaxLanguagesContentServiceTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php b/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php index 8e78d18ade..651c030850 100644 --- a/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php +++ b/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php @@ -11,6 +11,7 @@ use Ibexa\Contracts\Core\Repository\Exceptions\Exception; use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; +use Ibexa\Contracts\Core\Repository\URLAliasService; use Ibexa\Core\Repository\ContentService; use Ibexa\Tests\Integration\Core\RepositoryTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -45,7 +46,7 @@ protected function setUp(): void * 8 * PHP_INT_SIZE - 2 on 64-bit PHP) - proves content creation works with translations in * languages allocated past where the old power-of-two id scheme would have thrown. */ - private const EXTRA_LANGUAGES_BEYOND_OLD_LIMIT = 5; + private const int EXTRA_LANGUAGES_BEYOND_OLD_LIMIT = 5; /** * @throws Exception @@ -67,7 +68,17 @@ public function testCreateContent(): void $names["xtr-{$i}"] = "Beyond old limit {$i} name"; } - $this->createFolder($names); + $folder = $this->createFolder($names); + + $content = $this->getIbexaTestCore()->getContentService()->loadContent($folder->id); + self::assertEqualsCanonicalizing(array_keys($names), $content->getVersionInfo()->languageCodes); + for ($i = 1; $i <= self::EXTRA_LANGUAGES_BEYOND_OLD_LIMIT; ++$i) { + self::assertSame("Beyond old limit {$i} name", $content->getName("xtr-{$i}")); + } + + $urlAlias = $this->getIbexaTestCore()->getServiceByClassName(URLAliasService::class)->lookup('/Beyond-old-limit-3-name'); + self::assertSame($content->getContentInfo()->getMainLocationId(), $urlAlias->destination); + self::assertSame(['xtr-3'], $urlAlias->languageCodes); } /** From 480686145d133df573a6952212348f684345e7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 14:34:56 +0100 Subject: [PATCH 47/54] IBX-13142: Declared strict types in the content gateway, object state mapper and search index repository --- phpstan-baseline.neon | 6 ------ .../Persistence/Fixture/FixtureImporter.php | 2 +- .../Content/Gateway/DoctrineDatabase.php | 1 + .../Legacy/Content/ObjectState/Mapper.php | 21 ++++--------------- .../WordIndexer/Repository/SearchIndex.php | 1 + 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 125d746cb5..d38fb9eca1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11700,12 +11700,6 @@ parameters: count: 1 path: src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php - - - message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\ObjectState\\Mapper\:\:\$languageHandler \(Ibexa\\Core\\Persistence\\Legacy\\Content\\Language\\Handler\) does not accept Ibexa\\Contracts\\Core\\Persistence\\Content\\Language\\Handler\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php - - message: '#^Method Ibexa\\Core\\Persistence\\Legacy\\Content\\Section\\Gateway\:\:loadAllSectionData\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php index fd7dc28874..970da45187 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -26,7 +26,7 @@ final class FixtureImporter /** * Tables whose "language_id" the legacy bitmask scheme ORed the "always available" bit into. */ - private const TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT = [ + private const array TABLES_WITH_LEGACY_ALWAYS_AVAILABLE_BIT = [ 'ibexa_content_field', 'ibexa_content_name', 'ibexa_content_type_name', diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index 4c36ec52b4..f7dc4c3dff 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -4,6 +4,7 @@ * @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\Core\Persistence\Legacy\Content\Gateway; diff --git a/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php b/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php index 8180f81191..9db75ca96b 100644 --- a/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php @@ -4,6 +4,7 @@ * @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\Core\Persistence\Legacy\Content\ObjectState; @@ -11,29 +12,15 @@ use Ibexa\Contracts\Core\Persistence\Content\ObjectState; use Ibexa\Contracts\Core\Persistence\Content\ObjectState\Group; use Ibexa\Contracts\Core\Persistence\Content\ObjectState\InputStruct; -use Ibexa\Core\Persistence\Legacy\Content\Language\Handler; /** * Mapper for ObjectState and object state Group objects. */ class Mapper { - /** - * Language handler. - * - * @var Handler - */ - protected $languageHandler; - - /** - * Creates a new mapper. - * - * @param LanguageHandler $languageHandler - */ - public function __construct(LanguageHandler $languageHandler) - { - $this->languageHandler = $languageHandler; - } + public function __construct( + protected LanguageHandler $languageHandler + ) {} /** * Creates ObjectState object from provided $data. diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php index b5c2cfb362..978be62d0f 100644 --- a/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php +++ b/src/lib/Search/Legacy/Content/WordIndexer/Repository/SearchIndex.php @@ -4,6 +4,7 @@ * @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\Core\Search\Legacy\Content\WordIndexer\Repository; From 45d7109b2e61c13b6bdc5b69baf30433aba3d7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 15:04:56 +0100 Subject: [PATCH 48/54] IBX-13142: Replaced the deprecated introspectTable() calls with introspectTableByUnquotedName() --- .../Migration/DropLanguageBitmaskColumnsMigration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php index 00688928e9..3828cb7b40 100644 --- a/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -111,7 +111,7 @@ public function up(Schema $schema): void foreach (self::DROPS as $table => [$maskColumn]) { if ( $schemaManager->tablesExist([$table]) - && $schemaManager->introspectTable($table)->hasColumn($maskColumn) + && $schemaManager->introspectTableByUnquotedName($table)->hasColumn($maskColumn) ) { $tablesStillCarryingMask[$table] = true; } @@ -130,7 +130,7 @@ public function up(Schema $schema): void continue; } - if ($indexName !== null && $schemaManager->introspectTable($table)->hasIndex($indexName)) { + if ($indexName !== null && $schemaManager->introspectTableByUnquotedName($table)->hasIndex($indexName)) { $this->addSql($this->buildDropIndexSql($table, $indexName)); } From 9d53ffea397db165b2d11aba7411705fd775873c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 17:28:25 +0100 Subject: [PATCH 49/54] IBX-13142: Added a test running the whole language bitmask upgrade on a seeded pre-6.0 database --- .../LanguageBitmaskUpgradeSequenceTest.php | 754 ++++++++++++++++++ ...pre_language_bitmask_migration_schema.yaml | 662 +++++++++++++++ 2 files changed, 1416 insertions(+) create mode 100644 tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php create mode 100644 tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml diff --git a/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php b/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php new file mode 100644 index 0000000000..ebbd3cae8f --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php @@ -0,0 +1,754 @@ +getDatabaseConnection(), new SchemaAssetsFilterBypass(), DefaultTableOptions::AS_ARRAY); + $schemaImporter->importSchema( + __DIR__ . '/_fixtures/pre_language_bitmask_migration_schema.yaml' + ); + } + + public function testFullSequenceMigratesExistingDataCorrectly(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + + $schemaManager = $connection->createSchemaManager(); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_content')->hasColumn('language_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_content_version')->hasColumn('language_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_url_alias_ml')->hasColumn('lang_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_search_object_word_link')->hasColumn('language_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_object_state')->hasColumn('language_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_object_state_group')->hasColumn('language_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_content_type')->hasColumn('language_mask')); + + // Content 1: eng-US + eng-GB, not always available (mask 10 = 2|8) + self::assertEquals(0, $connection->fetchOne('SELECT always_available FROM ibexa_content WHERE id = 1')); + self::assertEqualsCanonicalizing( + [self::ENG_US, self::ENG_GB], + $this->fetchLanguageIds($connection, 'ibexa_content_translation', 'content_id', 1) + ); + self::assertEqualsCanonicalizing( + [self::ENG_US, self::ENG_GB], + $this->fetchLanguageIds($connection, 'ibexa_content_version_translation', 'content_version_id', 1) + ); + + // Content 2: ger-DE only, always available (mask 5 = 4|1) + self::assertEquals(1, $connection->fetchOne('SELECT always_available FROM ibexa_content WHERE id = 2')); + self::assertEqualsCanonicalizing( + [self::GER_DE], + $this->fetchLanguageIds($connection, 'ibexa_content_translation', 'content_id', 2) + ); + self::assertEqualsCanonicalizing( + [self::GER_DE], + $this->fetchLanguageIds($connection, 'ibexa_content_version_translation', 'content_version_id', 2) + ); + + // URL alias: eng-US + eng-GB, always available (mask 11 = 2|8|1) + self::assertEquals( + 1, + $connection->fetchOne( + "SELECT always_available FROM ibexa_url_alias_ml WHERE parent = 0 AND text_md5 = 'hash1'" + ) + ); + self::assertEqualsCanonicalizing( + [self::ENG_US, self::ENG_GB], + array_map( + 'intval', + $connection->fetchFirstColumn( + "SELECT language_id FROM ibexa_url_alias_ml_translation WHERE parent = 0 AND text_md5 = 'hash1'" + ) + ) + ); + + // Search word link: eng-GB, always available (mask 9 = 8|1) + $wordLinkRow = $connection->fetchAssociative( + 'SELECT language_id, is_main_and_always_available FROM ibexa_search_object_word_link WHERE id = 1' + ); + self::assertIsArray($wordLinkRow); + self::assertEquals(self::ENG_GB, $wordLinkRow['language_id']); + self::assertEquals(1, $wordLinkRow['is_main_and_always_available']); + + // Always-available bit stripped from every "language_id" column it was folded into, + // genuine (even) ids left untouched. + self::assertSame( + [1 => self::ENG_US, 2 => self::ENG_GB, 3 => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT id AS k, language_id FROM ibexa_content_field') + ); + self::assertSame( + ['eng-GB' => self::ENG_GB, 'eng-US' => self::ENG_US, 'ger-DE' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT content_translation AS k, language_id FROM ibexa_content_name') + ); + self::assertSame( + ['eng-GB' => self::ENG_GB, 'eng-US' => self::ENG_US], + $this->fetchLanguageIdMap($connection, 'SELECT language_locale AS k, language_id FROM ibexa_content_type_name') + ); + self::assertSame( + ['default' => self::ENG_GB, 'other' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT name AS k, language_id FROM ibexa_object_state_language') + ); + self::assertSame( + ['default' => self::ENG_GB, 'other' => self::GER_DE], + $this->fetchLanguageIdMap( + $connection, + 'SELECT name AS k, language_id FROM ibexa_object_state_group_language WHERE language_id = real_language_id' + ) + ); + + // The first language created after the upgrade gets MAX(id) + 1 - exactly the tainted value + // of the highest legacy language - and must not inherit any of that language's rows. + $newLanguageId = (new LanguageGateway($connection))->insertLanguage( + new Language(['languageCode' => 'fre-FR', 'name' => 'French', 'isEnabled' => true]) + ); + self::assertSame(self::ENG_GB | 1, $newLanguageId); + foreach ( + [ + 'ibexa_content_field', + 'ibexa_content_name', + 'ibexa_content_type_name', + 'ibexa_object_state_language', + 'ibexa_object_state_group_language', + ] as $table + ) { + self::assertEquals( + 0, + $connection->fetchOne("SELECT COUNT(*) FROM {$table} WHERE language_id = ?", [$newLanguageId]), + "\"{$table}\" still has rows pointing at the newly created language" + ); + } + } + + public function testStripMigrationLeavesSequentialLanguageIdsUntouched(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + + // Simulate a database converted without this migration being recorded (e.g. by an upgrade + // script), followed by a new language before the next "doctrine:migrations:migrate": its id + // is odd (MAX(id) + 1), yet genuine, so running the migration again must leave its rows alone. + $newLanguageId = (new LanguageGateway($connection))->insertLanguage( + new Language(['languageCode' => 'fre-FR', 'name' => 'French', 'isEnabled' => true]) + ); + self::assertSame(self::ENG_GB | 1, $newLanguageId); + + $connection->insert('ibexa_content_field', [ + 'id' => 4, + 'contentobject_id' => 1, + 'version' => 1, + 'language_code' => 'fre-FR', + 'language_id' => $newLanguageId, + ]); + $connection->insert('ibexa_content_name', [ + 'contentobject_id' => 1, + 'content_version' => 1, + 'content_translation' => 'fre-FR', + 'real_translation' => 'fre-FR', + 'language_id' => $newLanguageId, + 'name' => 'fre-FR', + ]); + $connection->insert('ibexa_content_type_name', [ + 'content_type_id' => 1, + 'content_type_status' => 0, + 'language_locale' => 'fre-FR', + 'language_id' => $newLanguageId, + 'name' => 'fre-FR', + ]); + $connection->insert('ibexa_object_state_language', [ + 'contentobject_state_id' => 1, + 'language_id' => $newLanguageId, + 'name' => 'french', + 'description' => '', + ]); + $connection->insert('ibexa_object_state_group_language', [ + 'contentobject_state_group_id' => 1, + 'language_id' => $newLanguageId, + 'real_language_id' => $newLanguageId, + 'name' => 'french', + 'description' => '', + ]); + + $this->runMigration(new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext())); + + foreach ( + [ + 'ibexa_content_field', + 'ibexa_content_name', + 'ibexa_content_type_name', + 'ibexa_object_state_language', + 'ibexa_object_state_group_language', + ] as $table + ) { + self::assertEquals( + 1, + $connection->fetchOne("SELECT COUNT(*) FROM {$table} WHERE language_id = ?", [$newLanguageId]), + "\"{$table}\" lost its row pointing at the newly created language" + ); + } + } + + public function testStripMigrationRemovesStaleObjectStateTranslations(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + // Legacy eZ Publish, changing this state's default language from ger-DE to eng-GB, inserted + // the rows with the flipped bit next to the old ones instead of updating them. + $connection->insert('ibexa_object_state', [ + 'id' => 1, + 'group_id' => 1, + 'identifier' => 'state', + 'default_language_id' => self::ENG_GB, + 'language_mask' => self::ENG_GB | self::GER_DE | 1, + ]); + foreach ([['stale default', self::ENG_GB], ['stale other', self::GER_DE | 1]] as [$name, $languageId]) { + $connection->insert('ibexa_object_state_language', [ + 'contentobject_state_id' => 1, + 'language_id' => $languageId, + 'name' => $name, + 'description' => '', + ]); + } + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + + self::assertSame( + ['default' => self::ENG_GB, 'other' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT name AS k, language_id FROM ibexa_object_state_language') + ); + } + + public function testStripMigrationKeepsTheRowsOfALanguageCreatedBeforeIt(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + $connection->insert('ibexa_object_state', [ + 'id' => 1, + 'group_id' => 1, + 'identifier' => 'state', + 'default_language_id' => self::ENG_GB, + 'language_mask' => self::ENG_GB | self::GER_DE | 1, + ]); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + + $newLanguageId = (new LanguageGateway($connection))->insertLanguage( + new Language(['languageCode' => 'fre-FR', 'name' => 'French', 'isEnabled' => true]) + ); + self::assertSame(self::ENG_GB | 1, $newLanguageId); + + $connection->insert('ibexa_content_field', [ + 'id' => 4, + 'contentobject_id' => 1, + 'version' => 1, + 'language_code' => 'fre-FR', + 'language_id' => $newLanguageId, + ]); + $connection->insert('ibexa_content_type_name', [ + 'content_type_id' => 2, + 'content_type_status' => 0, + 'language_locale' => 'fre-FR', + 'language_id' => $newLanguageId, + 'name' => 'fre-FR', + ]); + $connection->insert('ibexa_object_state_language', [ + 'contentobject_state_id' => 2, + 'language_id' => $newLanguageId, + 'name' => 'french', + 'description' => '', + ]); + $connection->insert('ibexa_object_state_group_language', [ + 'contentobject_state_group_id' => 1, + 'language_id' => $newLanguageId, + 'real_language_id' => $newLanguageId, + 'name' => 'french', + 'description' => '', + ]); + + $this->runMigration(new StripAlwaysAvailableBitFromLanguageIdsMigration($connection, new NullLogger(), new MigrationRunContext())); + + self::assertSame( + ['eng-GB' => self::ENG_GB, 'eng-US' => self::ENG_US, 'fre-FR' => $newLanguageId, 'ger-DE' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT language_code AS k, language_id FROM ibexa_content_field') + ); + self::assertSame( + ['eng-GB' => self::ENG_GB, 'eng-US' => self::ENG_US, 'fre-FR' => $newLanguageId], + $this->fetchLanguageIdMap($connection, 'SELECT language_locale AS k, language_id FROM ibexa_content_type_name') + ); + self::assertSame( + ['default' => self::ENG_GB, 'french' => $newLanguageId, 'other' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT name AS k, language_id FROM ibexa_object_state_language') + ); + self::assertSame( + ['default' => self::ENG_GB, 'french' => $newLanguageId, 'other' => self::GER_DE], + $this->fetchLanguageIdMap($connection, 'SELECT name AS k, language_id FROM ibexa_object_state_group_language') + ); + } + + public function testDropMigrationAbortsIfBackfillWasSkipped(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + // Deliberately skip BackfillLanguageTranslationsMigration, simulating an interrupted or + // manually-mismanaged upgrade. + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + + $this->expectException(AbortMigration::class); + $this->expectExceptionMessageMatches('/backfill-translations/'); + + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + } + + public function testDropMigrationAbortsIfBackfillWasOnlyPartial(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + + // Content 1 carries mask 10 = eng-US(2)|eng-GB(8), fully backfilled by the migration above. + // Simulate an interrupted backfill that only wrote one of its two languages: a row with + // multiple set bits but only one matching translation row must still block the drop, not + // just a row with zero translation rows at all. + $connection->executeStatement( + 'DELETE FROM ibexa_content_translation WHERE content_id = 1 AND language_id = :languageId', + ['languageId' => self::ENG_GB], + ['languageId' => ParameterType::INTEGER] + ); + + $this->expectException(AbortMigration::class); + $this->expectExceptionMessageMatches('/backfill-translations/'); + + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + } + + public function testAddContentAlwaysAvailableColumnsMigrationRecoversFromPartialFailure(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + // Simulate a MySQL run that added the first column then died before the second one (and + // before either backfill): a retry must not mistake "ibexa_content already has the column" + // for "this migration already fully ran". + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN always_available BOOLEAN DEFAULT 0 NOT NULL'); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + + $schemaManager = $connection->createSchemaManager(); + self::assertTrue($schemaManager->introspectTableByUnquotedName('ibexa_content_version')->hasColumn('always_available')); + + // Content 1: mask 10 (not always available), Content 2: mask 5 (always available). + self::assertEquals(0, $connection->fetchOne('SELECT always_available FROM ibexa_content WHERE id = 1')); + self::assertEquals(1, $connection->fetchOne('SELECT always_available FROM ibexa_content WHERE id = 2')); + self::assertEquals(0, $connection->fetchOne('SELECT always_available FROM ibexa_content_version WHERE id = 1')); + self::assertEquals(1, $connection->fetchOne('SELECT always_available FROM ibexa_content_version WHERE id = 2')); + } + + public function testAddLanguageTranslationTablesMigrationRecoversFromPartialFailure(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + // All 3 tables already exist by this point (created by the current schema.yaml import in + // the base TestCase::setUp()). Simulate a run that only got as far as creating the first + // one before dying (on SQLite, each table+its FKs is created atomically in one statement, + // so "table exists but a constraint is missing" can't happen there the way it can on + // MySQL/PostgreSQL - the meaningful partial state to simulate here is a missing table): a + // retry must not mistake "ibexa_content_translation already exists" for "everything already + // ran" and skip creating the other two. + $connection->executeStatement('DROP TABLE ibexa_content_version_translation'); + $connection->executeStatement('DROP TABLE ibexa_url_alias_ml_translation'); + + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + + $schemaManager = $connection->createSchemaManager(); + self::assertTrue($schemaManager->tablesExist(['ibexa_content_version_translation'])); + self::assertTrue($schemaManager->tablesExist(['ibexa_url_alias_ml_translation'])); + self::assertTrue( + $schemaManager->introspectTableByUnquotedName('ibexa_content_version_translation') + ->hasForeignKey('ibexa_content_version_translation_language_fk') + ); + self::assertTrue( + $schemaManager->introspectTableByUnquotedName('ibexa_url_alias_ml_translation') + ->hasForeignKey('ibexa_url_alias_ml_translation_language_fk') + ); + // The untouched table must survive re-running the migration undisturbed. + self::assertTrue( + $schemaManager->introspectTableByUnquotedName('ibexa_content_translation') + ->hasForeignKey('ibexa_content_translation_language_fk') + ); + } + + public function testAddSearchObjectWordLinkLanguageIdColumnsMigrationRecoversFromPartialFailure(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + // Simulate a MySQL run that added "language_id" then died before adding + // "is_main_and_always_available" and before either backfill: a retry must not mistake + // "language_id already exists" for "this migration already fully ran". + $connection->executeStatement( + 'ALTER TABLE ibexa_search_object_word_link ADD COLUMN language_id BIGINT DEFAULT 0 NOT NULL' + ); + + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + + $schemaManager = $connection->createSchemaManager(); + self::assertTrue( + $schemaManager->introspectTableByUnquotedName('ibexa_search_object_word_link') + ->hasColumn('is_main_and_always_available') + ); + + // Search word link row: mask 9 = eng-GB(8)|1, always available. + $wordLinkRow = $connection->fetchAssociative( + 'SELECT language_id, is_main_and_always_available FROM ibexa_search_object_word_link WHERE id = 1' + ); + self::assertIsArray($wordLinkRow); + self::assertEquals(self::ENG_GB, $wordLinkRow['language_id']); + self::assertEquals(1, $wordLinkRow['is_main_and_always_available']); + } + + public function testAddUrlAliasAlwaysAvailableColumnMigrationRecoversFromPartialFailure(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + // Simulate a MySQL run that added the column then died before the backfill UPDATE: the + // column's mere presence is not proof the backfill ever ran, so a retry must still backfill. + $connection->executeStatement( + 'ALTER TABLE ibexa_url_alias_ml ADD COLUMN always_available BOOLEAN DEFAULT 0 NOT NULL' + ); + + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + + // URL alias: mask 11 = eng-US(2)|eng-GB(8)|1, always available. + self::assertEquals( + 1, + $connection->fetchOne( + "SELECT always_available FROM ibexa_url_alias_ml WHERE parent = 0 AND text_md5 = 'hash1'" + ) + ); + } + + public function testAddUrlAliasAlwaysAvailableColumnMigrationSkipsBackfillWithoutLanguageMask(): void + { + $connection = $this->getDatabaseConnection(); + + // As the SchemaBuilderEvent installs it: the column is already there, "lang_mask" isn't. + $connection->executeStatement('DROP TABLE ibexa_url_alias_ml'); + $connection->executeStatement( + 'CREATE TABLE ibexa_url_alias_ml (parent INTEGER NOT NULL, text_md5 VARCHAR(32) NOT NULL, always_available BOOLEAN DEFAULT 0 NOT NULL)' + ); + + $migration = new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext()); + $migration->up(new Schema()); + + self::assertSame([], $migration->getSql()); + } + + public function testDropMigrationRecoversFromPartialFailure(): void + { + $connection = $this->getDatabaseConnection(); + $this->seedPreMigrationData($connection); + + $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new BackfillLanguageTranslationsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddSearchObjectWordLinkLanguageIdColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); + + // Simulate a MySQL run that dropped the first table's column (and index) then died before + // reaching any of the other six: a retry must not mistake "ibexa_object_state's mask column + // is already gone" for "this migration already fully ran" - every other table's column/index + // must still get dropped/replaced, not left dangling forever. + $connection->executeStatement('DROP INDEX ibexa_object_state_lmask'); + $connection->executeStatement('ALTER TABLE ibexa_object_state DROP COLUMN language_mask'); + + $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); + + $schemaManager = $connection->createSchemaManager(); + foreach ( + [ + 'ibexa_object_state_group', + 'ibexa_content_type', + 'ibexa_content', + 'ibexa_content_version', + 'ibexa_search_object_word_link', + ] as $table + ) { + self::assertFalse( + $schemaManager->introspectTableByUnquotedName($table)->hasColumn('language_mask'), + "\"{$table}\" should no longer have a \"language_mask\" column" + ); + } + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_url_alias_ml')->hasColumn('lang_mask')); + self::assertFalse($schemaManager->introspectTableByUnquotedName('ibexa_url_alias_ml')->hasIndex('ibexa_url_alias_ml_text_lang')); + } + + private function seedPreMigrationData(Connection $connection): void + { + foreach ( + [ + [self::ENG_US, 'eng-US', 'English (American)'], + [self::GER_DE, 'ger-DE', 'German'], + [self::ENG_GB, 'eng-GB', 'English (United Kingdom)'], + ] as [$id, $locale, $name] + ) { + $connection->insert( + 'ibexa_content_language', + ['id' => $id, 'locale' => $locale, 'name' => $name, 'disabled' => 0] + ); + } + + // Content 1: eng-US(2) + eng-GB(8), not always available -> mask 10 + $connection->insert('ibexa_content', [ + 'id' => 1, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => self::ENG_US, + 'language_mask' => self::ENG_US | self::ENG_GB, + 'name' => 'Foo', + 'owner_id' => 14, + 'remote_id' => 'foo', + ]); + $connection->insert('ibexa_content_version', [ + 'id' => 1, + 'contentobject_id' => 1, + 'version' => 1, + 'initial_language_id' => self::ENG_US, + 'language_mask' => self::ENG_US | self::ENG_GB, + ]); + + // Content 2: ger-DE(4), always available -> mask 5 + $connection->insert('ibexa_content', [ + 'id' => 2, + 'content_type_id' => 1, + 'current_version' => 1, + 'initial_language_id' => self::GER_DE, + 'language_mask' => self::GER_DE | 1, + 'name' => 'Bar', + 'owner_id' => 14, + 'remote_id' => 'bar', + ]); + $connection->insert('ibexa_content_version', [ + 'id' => 2, + 'contentobject_id' => 2, + 'version' => 1, + 'initial_language_id' => self::GER_DE, + 'language_mask' => self::GER_DE | 1, + ]); + + // URL alias: eng-US + eng-GB, always available -> mask 11 + $connection->insert( + 'ibexa_url_alias_ml', + [ + 'parent' => 0, + 'text_md5' => 'hash1', + 'id' => 1, + 'text' => 'foo', + 'action' => 'eznode:1', + 'action_type' => 'eznode', + 'lang_mask' => self::ENG_US | self::ENG_GB | 1, + ], + ['lang_mask' => ParameterType::INTEGER] + ); + + // Search word link: eng-GB, always available -> mask 9 + $connection->insert('ibexa_search_object_word_link', [ + 'id' => 1, + 'contentobject_id' => 1, + 'word_id' => 1, + 'identifier' => 'foo', + 'language_mask' => self::ENG_GB | 1, + ]); + + // Legacy folded the always-available bit into these "language_id" columns too: for the + // main-language fields/names of always-available content (Content 2), for always-available + // content type names, and for the default-language row of object states and groups. + foreach ( + [ + [1, 1, 'eng-US', self::ENG_US], + [2, 1, 'eng-GB', self::ENG_GB], + [3, 2, 'ger-DE', self::GER_DE | 1], + ] as [$fieldId, $contentId, $languageCode, $languageId] + ) { + $connection->insert('ibexa_content_field', [ + 'id' => $fieldId, + 'contentobject_id' => $contentId, + 'version' => 1, + 'language_code' => $languageCode, + 'language_id' => $languageId, + ]); + $connection->insert('ibexa_content_name', [ + 'contentobject_id' => $contentId, + 'content_version' => 1, + 'content_translation' => $languageCode, + 'real_translation' => $languageCode, + 'language_id' => $languageId, + 'name' => $languageCode, + ]); + } + + foreach ([['eng-GB', self::ENG_GB | 1], ['eng-US', self::ENG_US]] as [$locale, $languageId]) { + $connection->insert('ibexa_content_type_name', [ + 'content_type_id' => 1, + 'content_type_status' => 0, + 'language_locale' => $locale, + 'language_id' => $languageId, + 'name' => $locale, + ]); + } + + foreach ([['default', self::ENG_GB], ['other', self::GER_DE]] as [$name, $realLanguageId]) { + $storedLanguageId = $name === 'default' ? $realLanguageId | 1 : $realLanguageId; + $connection->insert('ibexa_object_state_language', [ + 'contentobject_state_id' => 1, + 'language_id' => $storedLanguageId, + 'name' => $name, + 'description' => '', + ]); + $connection->insert('ibexa_object_state_group_language', [ + 'contentobject_state_group_id' => 1, + 'language_id' => $storedLanguageId, + 'real_language_id' => $realLanguageId, + 'name' => $name, + 'description' => '', + ]); + } + } + + /** + * @return array + */ + private function fetchLanguageIdMap( + Connection $connection, + string $sql + ): array { + $map = array_map('intval', $connection->fetchAllKeyValue($sql)); + ksort($map); + + return $map; + } + + /** + * @return int[] + */ + private function fetchLanguageIds( + Connection $connection, + string $table, + string $idColumn, + int $id + ): array { + return array_map( + 'intval', + $connection->fetchFirstColumn( + "SELECT language_id FROM {$table} WHERE {$idColumn} = :id", + ['id' => $id], + ['id' => ParameterType::INTEGER] + ) + ); + } + + /** + * Runs a migration exactly as {@see TaggedMigrationsRunner} + * does: call up() to populate its queued SQL, then execute each queued statement in order. + */ + private function runMigration(AbstractSqlMigration $migration): void + { + $migration->up(new Schema()); + + $connection = $this->getDatabaseConnection(); + foreach ($migration->getSql() as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + } +} diff --git a/tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml b/tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml new file mode 100644 index 0000000000..e3939a7eca --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml @@ -0,0 +1,662 @@ +tables: + ibexa_binary_file: + id: + contentobject_attribute_id: { type: integer, nullable: false, options: { default: '0' } } + version: { type: integer, nullable: false, options: { default: '0' } } + fields: + download_count: { type: integer, nullable: false, options: { default: '0' } } + filename: { type: string, nullable: false, length: 255, options: { default: '' } } + mime_type: { type: string, nullable: false, length: 255, options: { default: '' } } + original_filename: { type: string, nullable: false, length: 255, options: { default: '' } } + ibexa_object_state: + indexes: + ibexa_object_state_priority: { fields: [priority] } + ibexa_object_state_lmask: { fields: [language_mask] } + uniqueConstraints: + ibexa_object_state_identifier: { fields: [group_id, identifier] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + default_language_id: { type: bigint, nullable: false, options: { default: '0' } } + group_id: { type: integer, nullable: false, options: { default: '0' } } + identifier: { type: string, nullable: false, length: 45, options: { default: '' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + priority: { type: integer, nullable: false, options: { default: '0' } } + ibexa_object_state_group: + indexes: + ibexa_object_state_group_lmask: { fields: [language_mask] } + uniqueConstraints: + ibexa_object_state_group_identifier: { fields: [identifier] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + default_language_id: { type: bigint, nullable: false, options: { default: '0' } } + identifier: { type: string, nullable: false, length: 45, options: { default: '' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + ibexa_object_state_group_language: + id: + contentobject_state_group_id: { type: integer, nullable: false, options: { default: '0' } } + real_language_id: { type: bigint, nullable: false, options: { default: '0' } } + fields: + description: { type: text, nullable: false, length: 0 } + language_id: { type: bigint, nullable: false, options: { default: '0' } } + name: { type: string, nullable: false, length: 45, options: { default: '' } } + ibexa_object_state_language: + id: + contentobject_state_id: { type: integer, nullable: false, options: { default: '0' } } + language_id: { type: bigint, nullable: false, options: { default: '0' } } + fields: + description: { type: text, nullable: false, length: 0 } + name: { type: string, nullable: false, length: 45, options: { default: '' } } + ibexa_object_state_link: + id: + contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + contentobject_state_id: { type: integer, nullable: false, options: { default: '0' } } + ibexa_user: + uniqueConstraints: + ibexa_user_login: { fields: [login] } + id: + contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + fields: + email: { type: string, nullable: false, length: 150, options: { default: '' } } + login: { type: string, nullable: false, length: 150, options: { default: '' } } + password_hash: { type: string, nullable: true, length: 255 } + password_hash_type: { type: integer, nullable: false, options: { default: '1' } } + password_updated_at: { type: integer, nullable: true } + ibexa_content_tree: + indexes: + ibexa_content_tree_p_node_id: { fields: [parent_node_id] } + ibexa_content_tree_path_ident: { fields: [path_identification_string], options: { lengths: ['50'] } } + ibexa_content_tree_contentobject_id_path_string: { fields: [path_string, contentobject_id], options: { lengths: ['191', null] } } + ibexa_content_tree_co_id: { fields: [contentobject_id] } + ibexa_content_tree_depth: { fields: [depth] } + ibexa_content_tree_path: { fields: [path_string], options: { lengths: ['191'] } } + ibexa_content_modified_subnode: { fields: [modified_subnode] } + ibexa_content_tree_remote_id: { fields: [remote_id] } + id: + node_id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + contentobject_id: { type: integer, nullable: true } + contentobject_is_published: { type: integer, nullable: true } + contentobject_version: { type: integer, nullable: true } + depth: { type: integer, nullable: false, options: { default: '0' } } + is_hidden: { type: integer, nullable: false, options: { default: '0' } } + is_invisible: { type: integer, nullable: false, options: { default: '0' } } + main_node_id: { type: integer, nullable: true } + modified_subnode: { type: integer, nullable: true, options: { default: '0' } } + parent_node_id: { type: integer, nullable: false, options: { default: '0' } } + path_identification_string: { type: text, nullable: true, length: 0 } + path_string: { type: string, nullable: false, length: 255, options: { default: '' } } + priority: { type: integer, nullable: false, options: { default: '0' } } + remote_id: { type: string, nullable: false, length: 100, options: { default: '' } } + sort_field: { type: integer, nullable: true, options: { default: '1' } } + sort_order: { type: integer, nullable: true, options: { default: '1' } } + ibexa_content_bookmark: + indexes: + ibexa_content_bookmark_location: { fields: [node_id] } + ibexa_content_bookmark_user: { fields: [user_id] } + ibexa_content_bookmark_user_location: { fields: [user_id, node_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + node_id: { type: integer, nullable: false, options: { default: '0' } } + user_id: { type: integer, nullable: false, options: { default: '0' } } + name: { type: string, nullable: false, length: 255, options: { default: '' } } + foreignKeys: + ibexa_content_bookmark_location_fk: { fields: [node_id], foreignTable: ibexa_content_tree, foreignFields: [node_id], options: { onDelete: CASCADE, onUpdate: 'NO ACTION' } } + ibexa_content_bookmark_user_fk: { fields: [user_id], foreignTable: ibexa_user, foreignFields: [contentobject_id], options: { onDelete: CASCADE, onUpdate: 'NO ACTION' } } + ibexa_content_type: + indexes: + ibexa_content_type_status: { fields: [status] } + ibexa_content_type_identifier: { fields: [identifier, status] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + status: { type: integer, nullable: false, options: { default: '0' } } + fields: + always_available: { type: integer, nullable: false, options: { default: '0' } } + contentobject_name: { type: string, nullable: true, length: 255 } + created: { type: integer, nullable: false, options: { default: '0' } } + creator_id: { type: integer, nullable: false, options: { default: '0' } } + identifier: { type: string, nullable: false, length: 50, options: { default: '' } } + initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } + is_container: { type: integer, nullable: false, options: { default: '0' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + modified: { type: integer, nullable: false, options: { default: '0' } } + modifier_id: { type: integer, nullable: false, options: { default: '0' } } + remote_id: { type: string, nullable: false, length: 100, options: { default: '' } } + serialized_description_list: { type: text, nullable: true, length: 0 } + serialized_name_list: { type: text, nullable: true, length: 0 } + sort_field: { type: integer, nullable: false, options: { default: '1' } } + sort_order: { type: integer, nullable: false, options: { default: '1' } } + url_alias_name: { type: string, nullable: true, length: 255 } + ibexa_content_type_field_definition: + indexes: + ibexa_content_type_field_definition_ctid: { fields: [content_type_id] } + ibexa_content_type_field_definition_dts: { fields: [data_type_string] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + status: { type: integer, nullable: false, options: { default: '0' } } + fields: + can_translate: { type: integer, nullable: true, options: { default: '1' } } + category: { type: string, nullable: false, length: 25, options: { default: '' } } + content_type_id: { type: integer, nullable: false, options: { default: '0' } } + data_float1: { type: float, nullable: true, length: 0 } + data_float2: { type: float, nullable: true, length: 0 } + data_float3: { type: float, nullable: true, length: 0 } + data_float4: { type: float, nullable: true, length: 0 } + data_int1: { type: integer, nullable: true } + data_int2: { type: integer, nullable: true } + data_int3: { type: integer, nullable: true } + data_int4: { type: integer, nullable: true } + data_text1: { type: string, nullable: true, length: 255 } + data_text2: { type: string, nullable: true, length: 50 } + data_text3: { type: string, nullable: true, length: 50 } + data_text4: { type: string, nullable: true, length: 255 } + data_text5: { type: text, nullable: true, length: 0 } + data_type_string: { type: string, nullable: false, length: 50, options: { default: '' } } + identifier: { type: string, nullable: false, length: 50, options: { default: '' } } + is_information_collector: { type: integer, nullable: false, options: { default: '0' } } + is_required: { type: integer, nullable: false, options: { default: '0' } } + is_searchable: { type: integer, nullable: false, options: { default: '0' } } + is_thumbnail: { type: boolean, nullable: false, options: { default: '0' } } + placement: { type: integer, nullable: false, options: { default: '0' } } + serialized_data_text: { type: text, nullable: true, length: 0 } + serialized_description_list: { type: text, nullable: true, length: 0 } + serialized_name_list: { type: text, nullable: false, length: 0 } + ibexa_content_type_field_definition_ml: + indexes: + ibexa_content_type_field_definition_ml_lang_fk: { fields: [language_id] } + id: + content_type_field_definition_id: { type: integer, nullable: false } + status: { type: integer, nullable: false } + language_id: { type: bigint, nullable: false } + fields: + name: { type: string, nullable: false, length: 255 } + description: { type: text, nullable: true, length: 65535 } + data_text: { type: text, nullable: true, length: 65535 } + data_json: { type: text, nullable: true, length: 65535 } + foreignKeys: + ibexa_content_type_field_definition_ml_lang_fk: { fields: [language_id], foreignTable: ibexa_content_language, foreignFields: [id], options: { onDelete: CASCADE, onUpdate: CASCADE } } + ibexa_content_type_group_assignment: + id: + content_type_id: { type: integer, nullable: false, options: { default: '0' } } + content_type_status: { type: integer, nullable: false, options: { default: '0' } } + group_id: { type: integer, nullable: false, options: { default: '0' } } + fields: + group_name: { type: string, nullable: true, length: 255 } + ibexa_content_type_name: + id: + content_type_id: { type: integer, nullable: false, options: { default: '0' } } + content_type_status: { type: integer, nullable: false, options: { default: '0' } } + language_id: { type: bigint, nullable: false, options: { default: '0' } } + fields: + language_locale: { type: string, nullable: false, length: 20, options: { default: '' } } + name: { type: string, nullable: false, length: 255, options: { default: '' } } + ibexa_content_type_group: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + created: { type: integer, nullable: false, options: { default: '0' } } + creator_id: { type: integer, nullable: false, options: { default: '0' } } + modified: { type: integer, nullable: false, options: { default: '0' } } + modifier_id: { type: integer, nullable: false, options: { default: '0' } } + name: { type: string, nullable: true, length: 255 } + is_system: { type: boolean, nullable: false, options: { default: '0' } } + ibexa_content: + indexes: + ibexa_content_type_id: { fields: [content_type_id] } + ibexa_content_lmask: { fields: [language_mask] } + ibexa_content_pub: { fields: [published] } + ibexa_content_section: { fields: [section_id] } + ibexa_content_currentversion: { fields: [current_version] } + ibexa_content_owner: { fields: [owner_id] } + ibexa_content_status: { fields: [status] } + uniqueConstraints: + ibexa_content_remote_id: { fields: [remote_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + content_type_id: { type: integer, nullable: false, options: { default: '0' } } + current_version: { type: integer, nullable: true } + initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + modified: { type: integer, nullable: false, options: { default: '0' } } + name: { type: string, nullable: true, length: 255 } + owner_id: { type: integer, nullable: false, options: { default: '0' } } + published: { type: integer, nullable: false, options: { default: '0' } } + remote_id: { type: string, nullable: true, length: 100 } + section_id: { type: integer, nullable: false, options: { default: '0' } } + status: { type: integer, nullable: true, options: { default: '0' } } + is_hidden: { type: boolean, nullable: false, options: { default: '0' } } + ibexa_content_field: + indexes: + ibexa_content_field_co_id_ver_lang_code: { fields: [contentobject_id, version, language_code] } + ibexa_content_field_field_definition_id: { fields: [content_type_field_definition_id] } + sort_key_string: { fields: [sort_key_string], options: { lengths: ['191'] } } + ibexa_content_field_language_code: { fields: [language_code] } + sort_key_int: { fields: [sort_key_int] } + ibexa_content_field_co_id_ver: { fields: [contentobject_id, version] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + version: { type: integer, nullable: false, options: { default: '0' } } + fields: + attribute_original_id: { type: integer, nullable: true, options: { default: '0' } } + content_type_field_definition_id: { type: integer, nullable: false, options: { default: '0' } } + contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + data_float: { type: float, nullable: true, length: 0 } + data_int: { type: integer, nullable: true } + data_text: { type: text, nullable: true, length: 0 } + data_type_string: { type: string, nullable: true, length: 50, options: { default: '' } } + language_code: { type: string, nullable: false, length: 20, options: { default: '' } } + language_id: { type: bigint, nullable: false, options: { default: '0' } } + sort_key_int: { type: integer, nullable: false, options: { default: '0' } } + sort_key_string: { type: string, nullable: false, length: 255, options: { default: '' } } + ibexa_content_relation: + indexes: + ibexa_content_relation_to_co_id: { fields: [to_contentobject_id] } + ibexa_content_relation_from: { fields: [from_contentobject_id, from_contentobject_version, content_type_field_definition_id] } + ibexa_content_relation_ccfd_id: { fields: [ content_type_field_definition_id ] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + content_type_field_definition_id: { type: integer, nullable: false, options: { default: '0' } } + from_contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + from_contentobject_version: { type: integer, nullable: false, options: { default: '0' } } + relation_type: { type: integer, nullable: false, options: { default: '1' } } + to_contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + ibexa_content_name: + indexes: + ibexa_content_name_lang_id: { fields: [language_id] } + ibexa_content_name_cov_id: { fields: [content_version] } + ibexa_content_name_name: { fields: [name], options: { lengths: ['191'] } } + id: + contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + content_version: { type: integer, nullable: false, options: { default: '0' } } + content_translation: { type: string, nullable: false, length: 20, options: { default: '' } } + fields: + language_id: { type: bigint, nullable: false, options: { default: '0' } } + name: { type: string, nullable: true, length: 255 } + real_translation: { type: string, nullable: true, length: 20 } + ibexa_content_trash: + indexes: + ibexa_content_trash_depth: { fields: [depth] } + ibexa_content_trash_p_node_id: { fields: [parent_node_id] } + ibexa_content_trash_path_ident: { fields: [path_identification_string], options: { lengths: ['50'] } } + ibexa_content_trash_co_id: { fields: [contentobject_id] } + ibexa_content_trash_modified_subnode: { fields: [modified_subnode] } + ibexa_content_trash_path: { fields: [path_string], options: { lengths: ['191'] } } + id: + node_id: { type: integer, nullable: false, options: { default: '0' } } + fields: + contentobject_id: { type: integer, nullable: true } + contentobject_version: { type: integer, nullable: true } + depth: { type: integer, nullable: false, options: { default: '0' } } + is_hidden: { type: integer, nullable: false, options: { default: '0' } } + is_invisible: { type: integer, nullable: false, options: { default: '0' } } + main_node_id: { type: integer, nullable: true } + modified_subnode: { type: integer, nullable: true, options: { default: '0' } } + parent_node_id: { type: integer, nullable: false, options: { default: '0' } } + path_identification_string: { type: text, nullable: true, length: 0 } + path_string: { type: string, nullable: false, length: 255, options: { default: '' } } + priority: { type: integer, nullable: false, options: { default: '0' } } + remote_id: { type: string, nullable: false, length: 100, options: { default: '' } } + sort_field: { type: integer, nullable: true, options: { default: '1' } } + sort_order: { type: integer, nullable: true, options: { default: '1' } } + trashed: { type: integer, nullable: false, options: { default: '0' } } + ibexa_content_version: + indexes: + ibexa_content_version_status: { fields: [status] } + ibexa_content_version_idx_ver: { fields: [contentobject_id, version] } + ibexa_content_version_idx_status: { fields: [contentobject_id, status] } + ibexa_content_version_creator_id: { fields: [creator_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + contentobject_id: { type: integer, nullable: true } + created: { type: integer, nullable: false, options: { default: '0' } } + creator_id: { type: integer, nullable: false, options: { default: '0' } } + initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + modified: { type: integer, nullable: false, options: { default: '0' } } + status: { type: integer, nullable: false, options: { default: '0' } } + user_id: { type: integer, nullable: false, options: { default: '0' } } + version: { type: integer, nullable: false, options: { default: '0' } } + workflow_event_pos: { type: integer, nullable: true, options: { default: '0' } } + ibexa_dfs_file: + indexes: + ibexa_dfs_file_name_trunk: { fields: [name_trunk], options: { lengths: ['191'] } } + ibexa_dfs_file_expired_name: { fields: [expired, name], options: { lengths: [null, '191'] } } + ibexa_dfs_file_name: { fields: [name], options: { lengths: ['191'] } } + ibexa_dfs_file_mtime: { fields: [mtime] } + id: + name_hash: { type: string, nullable: false, length: 34, options: { default: '' } } + fields: + name: { type: text, nullable: false, length: 65535 } + name_trunk: { type: text, nullable: false, length: 65535 } + datatype: { type: string, nullable: false, length: 255, options: { default: application/octet-stream } } + scope: { type: string, nullable: false, length: 25, options: { default: '' } } + size: { type: bigint, nullable: false, options: { default: '0', unsigned: true } } + mtime: { type: integer, nullable: false, options: { default: '0' } } + expired: { type: boolean, nullable: false, options: { default: '0' } } + status: { type: boolean, nullable: false, options: { default: '0' } } + ibexa_map_location: + indexes: + ibexa_map_location_latitude_longitude_key: { fields: [latitude, longitude] } + id: + contentobject_attribute_id: { type: integer, nullable: false, options: { default: '0' } } + contentobject_version: { type: integer, nullable: false, options: { default: '0' } } + fields: + latitude: { type: float, nullable: false, length: 0, options: { default: '0' } } + longitude: { type: float, nullable: false, length: 0, options: { default: '0' } } + address: { type: string, nullable: true, length: 150 } + ibexa_image_file: + indexes: + ibexa_image_file_file: { fields: [filepath], options: { lengths: ['191'] } } + ibexa_image_file_coid: { fields: [contentobject_attribute_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + contentobject_attribute_id: { type: integer, nullable: false, options: { default: '0' } } + filepath: { type: text, nullable: false, length: 0 } + ibexa_keyword: + indexes: + ibexa_keyword_keyword: { fields: [keyword], options: { lengths: ['191'] } } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + class_id: { type: integer, nullable: false, options: { default: '0' } } + keyword: { type: string, nullable: true, length: 255 } + ibexa_keyword_field_link: + indexes: + ibexa_keyword_field_link_oaid: { fields: [objectattribute_id] } + ibexa_keyword_field_link_kid_oaid: { fields: [keyword_id, objectattribute_id] } + ibexa_keyword_field_link_oaid_ver: { fields: [objectattribute_id, version] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + keyword_id: { type: integer, nullable: false, options: { default: '0' } } + objectattribute_id: { type: integer, nullable: false, options: { default: '0' } } + version: { type: integer, nullable: false, options: { default: '0' } } + ibexa_media: + id: + contentobject_attribute_id: { type: integer, nullable: false, options: { default: '0' } } + version: { type: integer, nullable: false, options: { default: '0' } } + fields: + controls: { type: string, nullable: true, length: 50 } + filename: { type: string, nullable: false, length: 255, options: { default: '' } } + has_controller: { type: integer, nullable: true, options: { default: '0' } } + height: { type: integer, nullable: true } + is_autoplay: { type: integer, nullable: true, options: { default: '0' } } + is_loop: { type: integer, nullable: true, options: { default: '0' } } + mime_type: { type: string, nullable: false, length: 50, options: { default: '' } } + original_filename: { type: string, nullable: false, length: 255, options: { default: '' } } + pluginspage: { type: string, nullable: true, length: 255 } + quality: { type: string, nullable: true, length: 50 } + width: { type: integer, nullable: true } + ibexa_node_assignment: + indexes: + ibexa_node_assignment_is_main: { fields: [is_main] } + ibexa_node_assignment_coid_cov: { fields: [contentobject_id, contentobject_version] } + ibexa_node_assignment_parent_node: { fields: [parent_node] } + ibexa_node_assignment_co_version: { fields: [contentobject_version] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + contentobject_id: { type: integer, nullable: true } + contentobject_version: { type: integer, nullable: true } + from_node_id: { type: integer, nullable: true, options: { default: '0' } } + is_main: { type: integer, nullable: false, options: { default: '0' } } + op_code: { type: integer, nullable: false, options: { default: '0' } } + parent_node: { type: integer, nullable: true } + parent_remote_id: { type: string, nullable: false, length: 100, options: { default: '' } } + remote_id: { type: string, nullable: false, length: 100, options: { default: '0' } } + sort_field: { type: integer, nullable: true, options: { default: '1' } } + sort_order: { type: integer, nullable: true, options: { default: '1' } } + priority: { type: integer, nullable: false, options: { default: '0' } } + is_hidden: { type: integer, nullable: false, options: { default: '0' } } + ibexa_notification: + indexes: + ibexa_notification_owner_is_pending: { fields: [owner_id, is_pending] } + ibexa_notification_owner: { fields: [owner_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + owner_id: { type: integer, nullable: false, options: { default: '0' } } + is_pending: { type: boolean, nullable: false, options: { default: '1' } } + type: { type: string, nullable: false, length: 128, options: { default: '' } } + created: { type: integer, nullable: false, options: { default: '0' } } + data: { type: text, nullable: true } + ibexa_package: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + install_date: { type: integer, nullable: false, options: { default: '0' } } + name: { type: string, nullable: false, length: 100, options: { default: '' } } + version: { type: string, nullable: false, length: 30, options: { default: '0' } } + ibexa_policy: + indexes: + ibexa_policy_role_id: { fields: [role_id] } + ibexa_policy_original_id: { fields: [original_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + function_name: { type: string, nullable: true, length: 255 } + module_name: { type: string, nullable: true, length: 255 } + original_id: { type: integer, nullable: false, options: { default: '0' } } + role_id: { type: integer, nullable: true } + ibexa_policy_limitation: + indexes: + ibexa_policy_id: { fields: [policy_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + identifier: { type: string, nullable: false, length: 255, options: { default: '' } } + policy_id: { type: integer, nullable: true } + ibexa_policy_limitation_value: + indexes: + ibexa_policy_limit_value_limit_id: { fields: [limitation_id] } + ibexa_policy_limitation_value_val: { fields: [value], options: { lengths: ['191'] } } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + limitation_id: { type: integer, nullable: true } + value: { type: string, nullable: true, length: 255 } + ibexa_user_preference: + indexes: + ibexa_user_preference_user_id_idx: { fields: [user_id, name] } + ibexa_user_preference_name: { fields: [name] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + name: { type: string, nullable: true, length: 100 } + user_id: { type: integer, nullable: false, options: { default: '0' } } + value: { type: text, nullable: true, length: 0 } + ibexa_role: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + is_new: { type: integer, nullable: false, options: { default: '0' } } + name: { type: string, nullable: false, length: 255, options: { default: '' } } + value: { type: string, nullable: true, length: 1, options: { fixed: true } } + version: { type: integer, nullable: true, options: { default: '0' } } + ibexa_search_object_word_link: + indexes: + ibexa_search_object_word_link_object: { fields: [contentobject_id] } + ibexa_search_object_word_link_identifier: { fields: [identifier], options: { lengths: ['191'] } } + ibexa_search_object_word_link_integer_value: { fields: [integer_value] } + ibexa_search_object_word_link_word: { fields: [word_id] } + ibexa_search_object_word_link_frequency: { fields: [frequency] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + content_type_field_definition_id: { type: integer, nullable: false, options: { default: '0' } } + content_type_id: { type: integer, nullable: false, options: { default: '0' } } + contentobject_id: { type: integer, nullable: false, options: { default: '0' } } + frequency: { type: float, nullable: false, length: 0, options: { default: '0' } } + identifier: { type: string, nullable: false, length: 255, options: { default: '' } } + integer_value: { type: integer, nullable: false, options: { default: '0' } } + next_word_id: { type: integer, nullable: false, options: { default: '0' } } + placement: { type: integer, nullable: false, options: { default: '0' } } + prev_word_id: { type: integer, nullable: false, options: { default: '0' } } + published: { type: integer, nullable: false, options: { default: '0' } } + section_id: { type: integer, nullable: false, options: { default: '0' } } + word_id: { type: integer, nullable: false, options: { default: '0' } } + language_mask: { type: bigint, nullable: false, options: { default: '0' } } + ibexa_search_word: + indexes: + ibexa_search_word_word_i: { fields: [word] } + ibexa_search_word_obj_count: { fields: [object_count] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + object_count: { type: integer, nullable: false, options: { default: '0' } } + word: { type: string, nullable: true, length: 150 } + ibexa_section: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + identifier: { type: string, nullable: true, length: 255 } + locale: { type: string, nullable: true, length: 255 } + name: { type: string, nullable: true, length: 255 } + navigation_part_identifier: { type: string, nullable: true, length: 100, options: { default: ezcontentnavigationpart } } + ibexa_site_data: + id: + name: { type: string, nullable: false, length: 60, options: { default: '' } } + fields: + value: { type: text, nullable: false, length: 0 } + ibexa_url: + indexes: + ibexa_url_url: { fields: [url], options: { lengths: ['191'] } } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + created: { type: integer, nullable: false, options: { default: '0' } } + is_valid: { type: integer, nullable: false, options: { default: '1' } } + last_checked: { type: integer, nullable: false, options: { default: '0' } } + modified: { type: integer, nullable: false, options: { default: '0' } } + original_url_md5: { type: string, nullable: false, length: 32, options: { default: '' } } + url: { type: text, nullable: true, length: 0 } + ibexa_url_content_link: + indexes: + ibexa_url_ol_coa_id: { fields: [contentobject_attribute_id] } + ibexa_url_ol_url_id: { fields: [url_id] } + ibexa_url_ol_coa_version: { fields: [contentobject_attribute_version] } + ibexa_url_ol_coa_id_cav: { fields: [contentobject_attribute_id, contentobject_attribute_version] } + fields: + contentobject_attribute_id: { type: integer, nullable: false, options: { default: '0' } } + contentobject_attribute_version: { type: integer, nullable: false, options: { default: '0' } } + url_id: { type: integer, nullable: false, options: { default: '0' } } + ibexa_url_alias: + indexes: + ibexa_url_alias_source_md5: { fields: [source_md5] } + ibexa_url_alias_wcard_fwd: { fields: [is_wildcard, forward_to_id] } + ibexa_url_alias_forward_to_id: { fields: [forward_to_id] } + ibexa_url_alias_imp_wcard_fwd: { fields: [is_imported, is_wildcard, forward_to_id] } + ibexa_url_alias_source_url: { fields: [source_url], options: { lengths: ['191'] } } + ibexa_url_alias_desturl: { fields: [destination_url], options: { lengths: ['191'] } } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + destination_url: { type: text, nullable: false, length: 0 } + forward_to_id: { type: integer, nullable: false, options: { default: '0' } } + is_imported: { type: integer, nullable: false, options: { default: '0' } } + is_internal: { type: integer, nullable: false, options: { default: '1' } } + is_wildcard: { type: integer, nullable: false, options: { default: '0' } } + source_md5: { type: string, nullable: true, length: 32 } + source_url: { type: text, nullable: false, length: 0 } + ibexa_url_alias_ml: + indexes: + ibexa_url_alias_ml_actt_org_al: { fields: [action_type, is_original, is_alias] } + ibexa_url_alias_ml_text_lang: { fields: [text, lang_mask, parent], options: { lengths: ['32', null, null] } } + ibexa_url_alias_ml_par_act_id_lnk: { fields: [action, id, link, parent], options: { lengths: ['32', null, null, null] } } + ibexa_url_alias_ml_par_lnk_txt: { fields: [parent, text, link], options: { lengths: [null, '32', null] } } + ibexa_url_alias_ml_act_org: { fields: [action, is_original], options: { lengths: ['32', null] } } + ibexa_url_alias_ml_text: { fields: [text, id, link], options: { lengths: ['32', null, null] } } + ibexa_url_alias_ml_link: { fields: [link] } + ibexa_url_alias_ml_id: { fields: [id] } + id: + parent: { type: integer, nullable: false, options: { default: '0' } } + text_md5: { type: string, nullable: false, length: 32, options: { default: '' } } + fields: + action: { type: text, nullable: false, length: 0 } + action_type: { type: string, nullable: false, length: 32, options: { default: '' } } + alias_redirects: { type: integer, nullable: false, options: { default: '1' } } + id: { type: integer, nullable: false, options: { default: '0' } } + is_alias: { type: integer, nullable: false, options: { default: '0' } } + is_original: { type: integer, nullable: false, options: { default: '0' } } + lang_mask: { type: bigint, nullable: false, options: { default: '0' } } + link: { type: integer, nullable: false, options: { default: '0' } } + text: { type: text, nullable: false, length: 0 } + ibexa_url_alias_ml_incr: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + ibexa_url_wildcard: + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + destination_url: { type: text, nullable: false, length: 0 } + source_url: { type: text, nullable: false, length: 0 } + type: { type: integer, nullable: false, options: { default: '0' } } + ibexa_user_accountkey: + indexes: + hash_key: { fields: [hash_key] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + hash_key: { type: string, nullable: false, length: 32, options: { default: '' } } + time: { type: integer, nullable: false, options: { default: '0' } } + user_id: { type: integer, nullable: false, options: { default: '0' } } + ibexa_user_role: + indexes: + ibexa_user_role_role_id: { fields: [role_id] } + ibexa_user_role_contentobject_id: { fields: [contentobject_id] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + contentobject_id: { type: integer, nullable: true } + limit_identifier: { type: string, nullable: true, length: 255, options: { default: '' } } + limit_value: { type: string, nullable: true, length: 255, options: { default: '' } } + role_id: { type: integer, nullable: true } + ibexa_user_setting: + id: + user_id: { type: integer, nullable: false, options: { default: '0' } } + fields: + is_enabled: { type: integer, nullable: false, options: { default: '0' } } + max_login: { type: integer, nullable: true } + ibexa_setting: + indexes: + ibexa_setting_id: { fields: [id] } + uniqueConstraints: + ibexa_setting_group_identifier: { fields: [group, identifier] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + group: { type: string, nullable: false, length: 128 } + identifier: { type: string, nullable: false, length: 128 } + value: { type: json, nullable: false, length: 0 } + ibexa_token_type: + uniqueConstraints: + ibexa_token_type_unique: { fields: [identifier] } + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + identifier: { type: string, nullable: false, length: 64 } + ibexa_token: + uniqueConstraints: + ibexa_token_unique: { fields: [token, identifier, type_id] } + foreignKeys: + ibexa_token_type_id_fk: + fields: [type_id] + foreignTable: ibexa_token_type + foreignFields: [id] + options: + onDelete: CASCADE + id: + id: { type: integer, nullable: false, options: { autoincrement: true } } + fields: + type_id: { type: integer, nullable: false } + token: { type: string, nullable: false, length: 255 } + identifier: { type: string, nullable: true, length: 128 } + created: { type: integer, nullable: false, options: { default: '0' } } + expires: { type: integer, nullable: false, options: { default: '0' } } + revoked: { type: boolean, nullable: false, options: { default: '0' } } From fa90b80ce40c698c86c75148b88c232af4418bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 17:28:25 +0100 Subject: [PATCH 50/54] IBX-13142: Typed the language gateway constants --- src/lib/Persistence/Legacy/Content/Language/Gateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Language/Gateway.php b/src/lib/Persistence/Legacy/Content/Language/Gateway.php index 851b6d4f04..eaa5568c8e 100644 --- a/src/lib/Persistence/Legacy/Content/Language/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Language/Gateway.php @@ -20,7 +20,7 @@ */ abstract class Gateway { - public const CONTENT_LANGUAGE_TABLE = 'ibexa_content_language'; + public const string CONTENT_LANGUAGE_TABLE = 'ibexa_content_language'; /** * A map of language-related table name to the single column identifying a real language id @@ -33,7 +33,7 @@ abstract class Gateway * It depends on the schema defined in * ./src/bundle/Core/Resources/config/storage/legacy/schema.yaml */ - public const MULTILINGUAL_TABLES_COLUMNS = [ + public const array MULTILINGUAL_TABLES_COLUMNS = [ ObjectStateGateway::OBJECT_STATE_TABLE => ['default_language_id'], ObjectStateGateway::OBJECT_STATE_GROUP_LANGUAGE_TABLE => ['language_id'], ObjectStateGateway::OBJECT_STATE_GROUP_TABLE => ['default_language_id'], From 153157ff8fef9190685223ef58055d42a8e24938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 17 Nov 2026 11:43:50 +0100 Subject: [PATCH 51/54] IBX-13142: Dropped the schema assets filter bypass from the language bitmask upgrade test IBX-13070 removed SchemaAssetsFilterBypass, and LegacySchemaImporter no longer takes one. --- .../Migration/LanguageBitmaskUpgradeSequenceTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php b/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php index ebbd3cae8f..efbb99e194 100644 --- a/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php @@ -25,7 +25,6 @@ use Ibexa\Contracts\DoctrineMigrations\Migrations\MigrationRunContext; use Ibexa\Contracts\DoctrineSchema\Database\DefaultTableOptions; use Ibexa\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase as LanguageGateway; -use Ibexa\DoctrineSchema\Filter\SchemaAssetsFilterBypass; use Ibexa\Tests\Core\Persistence\Legacy\TestCase; use Ibexa\Tests\Core\Repository\LegacySchemaImporter; use PHPUnit\Framework\Attributes\CoversClass; @@ -56,7 +55,7 @@ protected function setUp(): void { parent::setUp(); - $schemaImporter = new LegacySchemaImporter($this->getDatabaseConnection(), new SchemaAssetsFilterBypass(), DefaultTableOptions::AS_ARRAY); + $schemaImporter = new LegacySchemaImporter($this->getDatabaseConnection(), DefaultTableOptions::AS_ARRAY); $schemaImporter->importSchema( __DIR__ . '/_fixtures/pre_language_bitmask_migration_schema.yaml' ); From dd5f1d39df014b493d1834c5eee419575489e251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 17 Nov 2026 12:40:25 +0100 Subject: [PATCH 52/54] IBX-13142: Matched the name and field languages exactly in the Filter The names and fields of a version only matched its languages with the always-available bit added too, which the language ids don't carry anymore. --- .../Filter/Gateway/Content/Doctrine/DoctrineGateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index ecd3470570..d7b1d7c000 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -219,7 +219,7 @@ private function bulkFetchVersionNames(FilteringQueryBuilder $query): array 'EXISTS ( SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id - AND content_name.language_id IN (cvt.language_id, cvt.language_id + 1) + AND content_name.language_id = cvt.language_id )' ) ) @@ -259,7 +259,7 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array 'EXISTS ( SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt WHERE cvt.content_version_id = version.id - AND content_field.language_id IN (cvt.language_id, cvt.language_id + 1) + AND content_field.language_id = cvt.language_id )' ) ) From 8bb44d52a79bc34ae82b177dd373869d5fa4d55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 17 Nov 2026 12:40:33 +0100 Subject: [PATCH 53/54] IBX-13142: Dropped the language mask mentions from the comments --- src/lib/Persistence/Legacy/Content/Gateway.php | 4 ++-- .../Legacy/Content/Gateway/DoctrineDatabase.php | 7 ++----- .../Persistence/Legacy/Content/Type/Gateway.php | 4 +--- .../Legacy/Content/UrlAlias/Gateway.php | 4 +--- .../Content/UrlAlias/Gateway/DoctrineDatabase.php | 14 ++------------ .../Persistence/Legacy/Content/UrlAlias/Mapper.php | 1 - 6 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Gateway.php b/src/lib/Persistence/Legacy/Content/Gateway.php index 046c72ee94..983dfcbc78 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Gateway.php @@ -208,7 +208,7 @@ abstract public function loadContentInfoByLocationId(int $locationId): array; /** * Load info for content identified by $contentId. * Will basically return a hash containing all field values for ibexa_content table plus following keys: - * - always_available => Boolean indicating if content's language mask contains alwaysAvailable bit field + * - always_available => Boolean indicating if the content is always available * - main_language_code => Language code for main (initial) language. E.g. "eng-GB". * * @throws NotFoundException @@ -229,7 +229,7 @@ abstract public function loadContentInfoList(array $contentIds): array; * Load version info for content identified by $contentId and $versionNo. * Will basically return a hash containing all field values from ibexa_content_version table plus following keys: * - names => Hash of content object names. Key is the language code, value is the name. - * - languages => Hash of language ids. Key is the language code (e.g. "eng-GB"), value is the language numeric id without the always available bit. + * - languages => Hash of language ids. Key is the language code (e.g. "eng-GB"), value is the language numeric id. * - initial_language_code => Language code for initial language in this version. * * @param int|null $versionNo Load current version if null. diff --git a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index f7dc4c3dff..113f86f11c 100644 --- a/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -234,8 +234,7 @@ private function insertVersionTranslations( } /** - * Adds $languageCodes to Version $versionId's translations, leaving any already present - * untouched - mirrors updateVersion()'s additive bit-OR merge onto "language_mask". + * Adds $languageCodes to Version $versionId's translations, leaving any already present untouched. * * @param string[] $languageCodes */ @@ -260,9 +259,7 @@ private function addVersionTranslationsIfMissing( } /** - * Replaces Content $contentId's translations with exactly $languageCodes - mirrors - * updateContent()'s publish-time replace of "language_mask" with the newly published - * version's language set (not a union with whatever the content previously had). + * Replaces Content $contentId's translations with exactly $languageCodes. * * @param string[] $languageCodes */ diff --git a/src/lib/Persistence/Legacy/Content/Type/Gateway.php b/src/lib/Persistence/Legacy/Content/Type/Gateway.php index 276569afaa..48c6ac1e0e 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway.php @@ -165,9 +165,7 @@ abstract public function loadTypeDataByRemoteId( ): array; /** - * Loads the language codes each of the given (Type id, status) pairs is translated into, from - * ibexa_content_type_name - the relational replacement for decoding - * ibexa_content_type.language_mask. + * Loads the language codes each of the given (Type id, status) pairs is translated into. * * @param array $typeIdStatusPairs * diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php index 9d145c7971..cdf16805ab 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php @@ -157,9 +157,7 @@ abstract public function reparent( abstract public function loadPathData(int $id): array; /** - * Loads the real (non-always-available) language ids a specific alias row is translated - * into, from "ibexa_url_alias_ml_translation" - the relational replacement for decoding - * "lang_mask". + * Loads the language ids a specific alias row is translated into. * * @return int[] */ diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index 92481a700b..9c021a56ff 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -1387,9 +1387,7 @@ public function getAllChildrenAliases(int $parentId): array } /** - * Filter from the given result set original (current) only URL aliases and index them by their - * real (non-always-available) language id set - the relational replacement for indexing by - * "lang_mask" (each distinct language set can have one URL Alias). + * Filter from the given result set original (current) only URL aliases and index them by their language id set. * * @param array $urlAliasesData */ @@ -1529,15 +1527,7 @@ private function getDatabasePlatform(): AbstractPlatform } /** - * Builds an "at least one of $languageIds is a real translation of this row" condition against - * "ibexa_url_alias_ml_translation", correlated via $parentColumn/$textMd5Column (must be - * qualified with $query's own table alias) - the relational replacement for bitwise-AND-ing a - * row's "lang_mask". - * - * $parentColumn/$textMd5Column must be alias-qualified (e.g. "u.parent"), never bare column - * names - "ibexa_url_alias_ml_translation" has its own same-named columns, so an unqualified - * reference inside the subquery would resolve to its own column (the innermost scope), silently - * turning the correlation into a tautology instead of a real join back to the outer row. + * Builds an "at least one of $languageIds is a translation of this row" condition, correlated via alias-qualified $parentColumn and $textMd5Column. * * @param int[] $languageIds */ diff --git a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php index d16f81307f..a0db9b9804 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -177,7 +177,6 @@ protected function normalizePathDataRow( $pathElementData['translations'][$languageCode] = $row['text']; } } elseif ($pathElementData['always-available']) { - // NOP entry, lang_mask == 1 $pathElementData['translations']['always-available'] = $row['text']; } } From 8682b71f54bf85b421450f283052f8ee0ad54fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Fri, 13 Nov 2026 17:29:21 +0100 Subject: [PATCH 54/54] IBX-13142: Ran the language bitmask upgrade test on MySQL and PostgreSQL too Moved it to its own PHPUnit config, run by "composer integration" after the two integration suites, and made its setup portable. --- composer.json | 3 +- phpunit-migrations.xml | 30 +++++++++++++++++++ phpunit.xml | 1 + .../LanguageBitmaskUpgradeSequenceTest.php | 26 ++++++++-------- ...pre_language_bitmask_migration_schema.yaml | 0 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 phpunit-migrations.xml rename tests/bundle/RepositoryInstaller/Migration/{ => Upgrade}/LanguageBitmaskUpgradeSequenceTest.php (97%) rename tests/bundle/RepositoryInstaller/Migration/{ => Upgrade}/_fixtures/pre_language_bitmask_migration_schema.yaml (100%) diff --git a/composer.json b/composer.json index 52bd30bc03..3d56482aec 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/phpunit-migrations.xml b/phpunit-migrations.xml new file mode 100644 index 0000000000..ebf57caeea --- /dev/null +++ b/phpunit-migrations.xml @@ -0,0 +1,30 @@ + + + + + + + + tests/bundle/RepositoryInstaller/Migration/Upgrade + + + + + src + + + + + + diff --git a/phpunit.xml b/phpunit.xml index 304f8e2410..6f4a725e3b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -26,6 +26,7 @@ tests/bundle/RepositoryInstaller + tests/bundle/RepositoryInstaller/Migration/Upgrade tests/bundle/IO diff --git a/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php b/tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php similarity index 97% rename from tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php rename to tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php index efbb99e194..103187b41d 100644 --- a/tests/bundle/RepositoryInstaller/Migration/LanguageBitmaskUpgradeSequenceTest.php +++ b/tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace Ibexa\Tests\Bundle\RepositoryInstaller\Migration; +namespace Ibexa\Tests\Bundle\RepositoryInstaller\Migration\Upgrade; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; @@ -55,6 +55,13 @@ protected function setUp(): void { parent::setUp(); + // parent::setUp() imported the current schema.yaml: take it back to what a pre-6.0 + // database has, without the translation tables. + $connection = $this->getDatabaseConnection(); + foreach (['ibexa_content_translation', 'ibexa_content_version_translation', 'ibexa_url_alias_ml_translation'] as $table) { + $connection->executeStatement("DROP TABLE {$table}"); + } + $schemaImporter = new LegacySchemaImporter($this->getDatabaseConnection(), DefaultTableOptions::AS_ARRAY); $schemaImporter->importSchema( __DIR__ . '/_fixtures/pre_language_bitmask_migration_schema.yaml' @@ -416,7 +423,7 @@ public function testAddContentAlwaysAvailableColumnsMigrationRecoversFromPartial // Simulate a MySQL run that added the first column then died before the second one (and // before either backfill): a retry must not mistake "ibexa_content already has the column" // for "this migration already fully ran". - $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN always_available BOOLEAN DEFAULT 0 NOT NULL'); + $connection->executeStatement('ALTER TABLE ibexa_content ADD COLUMN always_available BOOLEAN DEFAULT FALSE NOT NULL'); $this->runMigration(new AddContentAlwaysAvailableColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); @@ -437,13 +444,8 @@ public function testAddLanguageTranslationTablesMigrationRecoversFromPartialFail $connection = $this->getDatabaseConnection(); $this->seedPreMigrationData($connection); - // All 3 tables already exist by this point (created by the current schema.yaml import in - // the base TestCase::setUp()). Simulate a run that only got as far as creating the first - // one before dying (on SQLite, each table+its FKs is created atomically in one statement, - // so "table exists but a constraint is missing" can't happen there the way it can on - // MySQL/PostgreSQL - the meaningful partial state to simulate here is a missing table): a - // retry must not mistake "ibexa_content_translation already exists" for "everything already - // ran" and skip creating the other two. + // A run that only got as far as creating the first table: a retry must create the other two. + $this->runMigration(new AddLanguageTranslationTablesMigration($connection, new NullLogger(), new MigrationRunContext())); $connection->executeStatement('DROP TABLE ibexa_content_version_translation'); $connection->executeStatement('DROP TABLE ibexa_url_alias_ml_translation'); @@ -504,7 +506,7 @@ public function testAddUrlAliasAlwaysAvailableColumnMigrationRecoversFromPartial // Simulate a MySQL run that added the column then died before the backfill UPDATE: the // column's mere presence is not proof the backfill ever ran, so a retry must still backfill. $connection->executeStatement( - 'ALTER TABLE ibexa_url_alias_ml ADD COLUMN always_available BOOLEAN DEFAULT 0 NOT NULL' + 'ALTER TABLE ibexa_url_alias_ml ADD COLUMN always_available BOOLEAN DEFAULT FALSE NOT NULL' ); $this->runMigration(new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext())); @@ -525,7 +527,7 @@ public function testAddUrlAliasAlwaysAvailableColumnMigrationSkipsBackfillWithou // As the SchemaBuilderEvent installs it: the column is already there, "lang_mask" isn't. $connection->executeStatement('DROP TABLE ibexa_url_alias_ml'); $connection->executeStatement( - 'CREATE TABLE ibexa_url_alias_ml (parent INTEGER NOT NULL, text_md5 VARCHAR(32) NOT NULL, always_available BOOLEAN DEFAULT 0 NOT NULL)' + 'CREATE TABLE ibexa_url_alias_ml (parent INTEGER NOT NULL, text_md5 VARCHAR(32) NOT NULL, always_available BOOLEAN DEFAULT FALSE NOT NULL)' ); $migration = new AddUrlAliasAlwaysAvailableColumnMigration($connection, new NullLogger(), new MigrationRunContext()); @@ -549,7 +551,7 @@ public function testDropMigrationRecoversFromPartialFailure(): void // reaching any of the other six: a retry must not mistake "ibexa_object_state's mask column // is already gone" for "this migration already fully ran" - every other table's column/index // must still get dropped/replaced, not left dangling forever. - $connection->executeStatement('DROP INDEX ibexa_object_state_lmask'); + $connection->createSchemaManager()->dropIndex('ibexa_object_state_lmask', 'ibexa_object_state'); $connection->executeStatement('ALTER TABLE ibexa_object_state DROP COLUMN language_mask'); $this->runMigration(new DropLanguageBitmaskColumnsMigration($connection, new NullLogger(), new MigrationRunContext())); diff --git a/tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml b/tests/bundle/RepositoryInstaller/Migration/Upgrade/_fixtures/pre_language_bitmask_migration_schema.yaml similarity index 100% rename from tests/bundle/RepositoryInstaller/Migration/_fixtures/pre_language_bitmask_migration_schema.yaml rename to tests/bundle/RepositoryInstaller/Migration/Upgrade/_fixtures/pre_language_bitmask_migration_schema.yaml