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/data/mysql/cleandata.sql b/data/mysql/cleandata.sql index 1443e8283a..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,86 +73,100 @@ 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`, `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`, `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), + (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), - (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), @@ -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`, `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), + (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), @@ -252,33 +280,47 @@ 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`) +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,3,9,0,'Media','62933a2951ef01f4eafd9bdf4d3cd2f0'), + ('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,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'), + ('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,3,8,5,'Administrator-User','5a9d7b0ec93173ef4fedee023209cb61'), + ('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,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: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), + (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), (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), diff --git a/data/postgresql/cleandata.sql b/data/postgresql/cleandata.sql index 88fb833efb..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,86 +73,100 @@ 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", "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", "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), + (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), - (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), @@ -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", "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), + (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), @@ -252,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", "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), + (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), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c1f779ff0..d38fb9eca1 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 @@ -11478,12 +11442,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 @@ -11742,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 @@ -12654,24 +12606,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 @@ -12901,13 +12835,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 @@ -12918,12 +12846,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 @@ -17226,12 +17148,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 @@ -17430,24 +17346,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 @@ -17664,12 +17568,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 @@ -17856,12 +17754,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 @@ -17922,30 +17814,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 @@ -18138,12 +18006,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 @@ -18288,12 +18150,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 @@ -32634,66 +32490,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 @@ -32712,12 +32508,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 @@ -33582,12 +33372,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 @@ -34218,12 +34002,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/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/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php new file mode 100644 index 0000000000..c6a7cd90e7 --- /dev/null +++ b/src/bundle/Core/Command/BackfillLanguageTranslationsCommand.php @@ -0,0 +1,274 @@ +%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", + "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, +)] +final class BackfillLanguageTranslationsCommand +{ + private const string LANGUAGE_TABLE = 'ibexa_content_language'; + + private const int DEFAULT_BATCH_SIZE = 5000; + + private const string TABLE_CONTENT = 'content'; + private const string TABLE_CONTENT_VERSION = 'content_version'; + private const string TABLE_URL_ALIAS = 'url_alias'; + private const string TABLE_ALL = 'all'; + + private const array VALID_TABLES = [ + self::TABLE_CONTENT, + self::TABLE_CONTENT_VERSION, + self::TABLE_URL_ALIAS, + ]; + + public function __construct(private readonly Connection $connection) {} + + public function __invoke( + OutputInterface $output, + #[Option(description: 'Which table to backfill: one of "content", "content_version", "url_alias", or "all" for all of them.', shortcut: 't')] + string $table = self::TABLE_ALL, + #[Option(description: 'Number of primary-key values processed per batch.')] + int $batchSize = self::DEFAULT_BATCH_SIZE, + #[Option(description: 'Report how many rows would be inserted per batch without writing anything.')] + bool $dryRun = false, + ): int { + if ($batchSize < 1) { + throw new InvalidArgumentException('batch-size', 'must be a positive integer.'); + } + + $tables = $table === self::TABLE_ALL ? self::VALID_TABLES : [$table]; + foreach ($tables as $singleTable) { + if (!in_array($singleTable, self::VALID_TABLES, true)) { + throw new InvalidArgumentException( + 'table', + sprintf( + '"%s" is not one of "%s" or "%s".', + $singleTable, + implode('", "', self::VALID_TABLES), + self::TABLE_ALL + ) + ); + } + } + + foreach ($tables as $singleTable) { + $this->backfillTable($singleTable, $batchSize, $dryRun, $output); + } + + return Command::SUCCESS; + } + + private function backfillTable( + string $table, + int $batchSize, + bool $dryRun, + OutputInterface $output + ): void { + [$sourceTable, $pkColumn, $maskColumn, $insertSql, $alwaysAvailableColumn] = match ($table) { + self::TABLE_CONTENT => [ + 'ibexa_content', + 'id', + 'language_mask', + 'INSERT %s INTO ibexa_content_translation (content_id, language_id) + SELECT c.id, l.id FROM ibexa_content c + JOIN %s l ON (c.language_mask & l.id) = l.id + WHERE c.id BETWEEN :from AND :to %s', + 'always_available', + ], + self::TABLE_CONTENT_VERSION => [ + 'ibexa_content_version', + 'id', + 'language_mask', + 'INSERT %s INTO ibexa_content_version_translation (content_version_id, language_id) + SELECT v.id, l.id FROM ibexa_content_version v + JOIN %s l ON (v.language_mask & l.id) = l.id + WHERE v.id BETWEEN :from AND :to %s', + 'always_available', + ], + self::TABLE_URL_ALIAS => [ + 'ibexa_url_alias_ml', + 'id', + 'lang_mask', + 'INSERT %s INTO ibexa_url_alias_ml_translation (parent, text_md5, language_id) + SELECT u.parent, u.text_md5, l.id FROM ibexa_url_alias_ml u + JOIN %s l ON (u.lang_mask & l.id) = l.id + WHERE u.id BETWEEN :from AND :to %s', + 'always_available', + ], + default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), + }; + + if (!$this->connection->createSchemaManager()->introspectTableByUnquotedName($sourceTable)->hasColumn($maskColumn)) { + $output->writeln("{$sourceTable} has no \"{$maskColumn}\" column - already migrated, nothing to backfill."); + + return; + } + + $languageTable = self::LANGUAGE_TABLE; + + // MIN()/MAX() rather than COUNT()-based emptiness + a hardcoded lower bound of 1: some of + // these tables (e.g. "ibexa_url_alias_ml" for root-level aliases) legitimately use 0 as a + // valid primary-key value, so neither "MAX() === 0" nor an assumed start of 1 is safe here. + $range = $this->connection->fetchAssociative( + "SELECT MIN({$pkColumn}) AS min_id, MAX({$pkColumn}) AS max_id FROM {$sourceTable}" + ); + if ($range === false || $range['min_id'] === null) { + $output->writeln("{$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()); + $alwaysAvailableMismatch = "{$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)"; + $totalInserted = 0; + $totalFlagged = 0; + + for ($from = $minId; $from <= $maxId; $from += $batchSize) { + $to = min($from + $batchSize - 1, $maxId); + + if ($dryRun) { + $inserted = (int)$this->connection->fetchOne( + $this->buildDryRunCountSql($table, $languageTable), + ['from' => $from, 'to' => $to] + ); + $flagged = (int)$this->connection->fetchOne( + "SELECT COUNT(*) FROM {$sourceTable} WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}", + ['from' => $from, 'to' => $to] + ); + } else { + $inserted = $this->connection->executeStatement($insertSql, ['from' => $from, 'to' => $to]); + $flagged = $this->connection->executeStatement( + "UPDATE {$sourceTable} SET {$alwaysAvailableColumn} = (({$maskColumn} & 1) = 1) + WHERE {$pkColumn} BETWEEN :from AND :to AND {$alwaysAvailableMismatch}", + ['from' => $from, 'to' => $to] + ); + } + + $totalInserted += $inserted; + $totalFlagged += $flagged; + $output->writeln( + sprintf(' %d..%d: %d row(s), %d always-available flag(s)%s', $from, $to, $inserted, $flagged, $dryRun ? ' (dry-run)' : ''), + OutputInterface::VERBOSITY_VERBOSE + ); + } + + $output->writeln(sprintf( + '%s%s: %d row(s) %s, %d always-available flag(s) %s.', + $dryRun ? '[dry-run] ' : '', + $sourceTable, + $totalInserted, + $dryRun ? 'would be inserted' : 'inserted', + $totalFlagged, + $dryRun ? 'would be updated' : 'updated' + )); + } + + /** + * Mirrors the real INSERT's idempotency (via insertIgnoreKeyword()/onConflictClause()) with an + * explicit "NOT EXISTS" against the target translation table: without it, re-running + * `--dry-run` after a prior (partial or complete) backfill would count every mask-derived pair + * again, including ones already present, and report them as "would be inserted" when a real run + * would actually leave them untouched. + */ + private function buildDryRunCountSql( + string $table, + string $languageTable + ): string { + return match ($table) { + self::TABLE_CONTENT => "SELECT COUNT(*) FROM ibexa_content c + JOIN {$languageTable} l ON (c.language_mask & l.id) = l.id + WHERE c.id BETWEEN :from AND :to + AND NOT EXISTS ( + SELECT 1 FROM ibexa_content_translation t + WHERE t.content_id = c.id AND t.language_id = l.id + )", + self::TABLE_CONTENT_VERSION => "SELECT COUNT(*) FROM ibexa_content_version v + JOIN {$languageTable} l ON (v.language_mask & l.id) = l.id + WHERE v.id BETWEEN :from AND :to + AND NOT EXISTS ( + SELECT 1 FROM ibexa_content_version_translation t + WHERE t.content_version_id = v.id AND t.language_id = l.id + )", + self::TABLE_URL_ALIAS => "SELECT COUNT(*) FROM ibexa_url_alias_ml u + JOIN {$languageTable} l ON (u.lang_mask & l.id) = l.id + WHERE u.id BETWEEN :from AND :to + AND NOT EXISTS ( + SELECT 1 FROM ibexa_url_alias_ml_translation t + WHERE t.parent = u.parent AND t.text_md5 = u.text_md5 AND t.language_id = l.id + )", + default => throw new InvalidArgumentException('table', "unknown table \"{$table}\"."), + }; + } + + private function insertIgnoreKeyword(): string + { + return match ($this->resolvePlatformName()) { + DatabasePlatformName::MySQL => 'IGNORE', + DatabasePlatformName::SQLite => 'OR IGNORE', + DatabasePlatformName::PostgreSQL => '', + }; + } + + /** + * Appended after the SELECT to make the insert idempotent on platforms that don't support + * "INSERT IGNORE" (MySQL is handled via insertIgnoreKeyword() instead, since its "ON DUPLICATE + * KEY" clause needs different syntax for an INSERT ... SELECT). + */ + private function onConflictClause(): string + { + return match ($this->resolvePlatformName()) { + DatabasePlatformName::PostgreSQL => 'ON CONFLICT DO NOTHING', + DatabasePlatformName::SQLite => '', // OR IGNORE is part of the INSERT keyword, not a trailing clause + DatabasePlatformName::MySQL => '', + }; + } + + private function resolvePlatformName(): DatabasePlatformName + { + $platform = $this->connection->getDatabasePlatform(); + $name = DatabasePlatformResolver::resolveName($platform); + if ($name === null) { + throw new InvalidArgumentException( + 'platform', + sprintf('Unsupported database platform: %s', $platform::class) + ); + } + + return $name; + } +} diff --git a/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php new file mode 100644 index 0000000000..cf47052387 --- /dev/null +++ b/src/bundle/Core/Command/VerifyLanguageTranslationsCommand.php @@ -0,0 +1,263 @@ +%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 + tables for anything - a clean report here is the precondition for every later migration step. + EOT, +)] +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'; + private const string TABLE_ALL = 'all'; + + private const array VALID_TABLES = [ + self::TABLE_CONTENT, + self::TABLE_CONTENT_VERSION, + self::TABLE_URL_ALIAS, + ]; + + /** + * Table => [source table carrying the legacy mask, mask column, always-available column]. + * + * @var array + */ + 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', 'always_available'], + ]; + + /** + * @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) {} + + 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 { + $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 Command::SUCCESS; + } + + if ($fix) { + $output->writeln('Drift found and fixed.'); + + return Command::SUCCESS; + } + + $output->writeln('Drift found. Re-run with --fix to correct it.'); + + return Command::FAILURE; + } + + private function verifyTable( + string $table, + bool $fix, + OutputInterface $output + ): bool { + [$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."); + + return true; + } + + $languageTable = self::LANGUAGE_TABLE; + $queries = $this->buildQueries($table, $languageTable); + + $alwaysAvailableMismatch = "{$alwaysAvailableColumn} <> (({$maskColumn} & 1) = 1)"; + + $missing = (int)$this->connection->fetchOne($queries['missing']); + $orphaned = (int)$this->connection->fetchOne($queries['orphaned']); + $mismatched = (int)$this->connection->fetchOne("SELECT COUNT(*) FROM {$sourceTable} WHERE {$alwaysAvailableMismatch}"); + + if ($missing === 0 && $orphaned === 0 && $mismatched === 0) { + $output->writeln("{$table}: in sync."); + + return true; + } + + $output->writeln(sprintf( + '%s: %d missing, %d orphaned row(s), %d wrong always-available flag(s).', + $table, + $missing, + $orphaned, + $mismatched + )); + + 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)."); + } + + 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/src/bundle/Core/Resources/config/doctrine_migrations.php b/src/bundle/Core/Resources/config/doctrine_migrations.php index 063b326a44..b058a0db8b 100644 --- a/src/bundle/Core/Resources/config/doctrine_migrations.php +++ b/src/bundle/Core/Resources/config/doctrine_migrations.php @@ -6,11 +6,17 @@ */ 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\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; 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; @@ -18,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; @@ -79,4 +86,32 @@ $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(AddSearchObjectWordLinkLanguageIdColumnsMigration::class) + ->arg('$connection', service('ibexa.persistence.connection')) + ->tag(IbexaMigrationTag::TAG); + + $services->set(AddUrlAliasAlwaysAvailableColumnMigration::class) + ->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/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..d87f8d3913 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,7 @@ 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 } owner_id: { type: integer, nullable: false, options: { default: '0' } } @@ -326,12 +319,30 @@ 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' } } 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'] } } @@ -511,7 +522,8 @@ 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: indexes: ibexa_search_word_word_i: { fields: [word] } @@ -577,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, 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] } } @@ -594,12 +605,22 @@ 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 } } 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..6ca662b925 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddContentAlwaysAvailableColumnsMigration.php @@ -0,0 +1,68 @@ +abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::CONTENT_TABLE, self::CONTENT_VERSION_TABLE])) { + return; + } + + foreach ([self::CONTENT_TABLE, self::CONTENT_VERSION_TABLE] as $table) { + if (!$schemaManager->introspectTableByUnquotedName($table)->hasColumn(self::ALWAYS_AVAILABLE_COLUMN)) { + $this->addSql($this->buildAddColumnSql($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}"; + } +} diff --git a/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php new file mode 100644 index 0000000000..a1560069be --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddLanguageTranslationTablesMigration.php @@ -0,0 +1,121 @@ +> */ + 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->introspectTableByUnquotedName($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/AddSearchObjectWordLinkLanguageIdColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php new file mode 100644 index 0000000000..86512dffde --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigration.php @@ -0,0 +1,116 @@ +abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::TABLE])) { + return; + } + + $table = $schemaManager->introspectTableByUnquotedName(self::TABLE); + + if (!$table->hasColumn(self::LANGUAGE_ID_COLUMN)) { + $this->addSql($this->buildAddLanguageIdColumnSql()); + } + + if (!$table->hasColumn(self::IS_MAIN_AND_ALWAYS_AVAILABLE_COLUMN)) { + $this->addSql($this->buildAddAlwaysAvailableColumnSql()); + } + + 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 + { + // 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/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php new file mode 100644 index 0000000000..f5c4175fdb --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigration.php @@ -0,0 +1,94 @@ +abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE); + + $schemaManager = $this->connection->createSchemaManager(); + + if (!$schemaManager->tablesExist([self::TABLE])) { + return; + } + + $table = $schemaManager->introspectTableByUnquotedName(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; + } + + $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; + } + + $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/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php new file mode 100644 index 0000000000..17321e2f81 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigration.php @@ -0,0 +1,187 @@ +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->backfillAlwaysAvailable('ibexa_content'); + $this->backfillAlwaysAvailable('ibexa_content_version'); + + $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', + '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.id BETWEEN :from AND :to %s' + ); + } + + /** + * @param non-empty-string $sourceTable + */ + 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)" + ); + } + + /** + * @param non-empty-string $sourceTable + */ + private function backfillTable( + string $sourceTable, + string $maskColumn, + string $pkColumn, + string $insertSqlTemplate + ): void { + $this->addChunkedSql( + $sourceTable, + $maskColumn, + $pkColumn, + sprintf($insertSqlTemplate, $this->insertIgnoreKeyword(), $this->onConflictClause()) + ); + } + + /** + * @param non-empty-string $sourceTable + */ + private function addChunkedSql( + string $sourceTable, + string $maskColumn, + string $pkColumn, + string $sql + ): void { + $schemaManager = $this->connection->createSchemaManager(); + if ( + !$schemaManager->tablesExist([$sourceTable]) + || !$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. + 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']; + + for ($from = $minId; $from <= $maxId; $from += self::BATCH_SIZE) { + $to = min($from + self::BATCH_SIZE - 1, $maxId); + $this->addSql( + $sql, + ['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/DropLanguageBitmaskColumnsMigration.php b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php new file mode 100644 index 0000000000..3828cb7b40 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigration.php @@ -0,0 +1,228 @@ +hasTable()/hasColumn() would always report false there. + */ +final class DropLanguageBitmaskColumnsMigration extends AbstractSqlMigration implements IbexaMigrationInterface +{ + private const string CONTENT_TABLE = 'ibexa_content'; + + private const string LANGUAGE_TABLE = 'ibexa_content_language'; + + /** + * Table => [mask column, index on it to drop first (if any)]. + * + * @var array + */ + private const array DROPS = [ + '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'], + ]; + + /** + * 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], + ]; + + /** @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'; + } + + public static function getTargetVersion(): string + { + return '6.0.0'; + } + + public static function getCreationDate(): DateTimeImmutable + { + return new DateTimeImmutable('2026-10-19 08: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->introspectTableByUnquotedName($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)); + $this->abortIfAlwaysAvailableNotBackfilled(array_keys($tablesStillCarryingMask)); + + foreach (self::DROPS as $table => [$maskColumn, $indexName]) { + if (!isset($tablesStillCarryingMask[$table])) { + continue; + } + + if ($indexName !== null && $schemaManager->introspectTableByUnquotedName($table)->hasIndex($indexName)) { + $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}"; + } + + /** + * 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.' + ); + } + } + + /** + * 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/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php new file mode 100644 index 0000000000..a69496de86 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/StripAlwaysAvailableBitFromLanguageIdsMigration.php @@ -0,0 +1,166 @@ + [locale column, column to chunk by, or null for tables small enough for a single statement]. + * + * @var array + */ + 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 + { + 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])) { + return; + } + + if ($schemaManager->tablesExist(['ibexa_object_state', 'ibexa_object_state_language'])) { + $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::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" + . ' 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; + } + + $this->addChunkedSql($table, $chunkColumn, $updateSql); + } + } + + private function addObjectStateTranslationStrip(): 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'); + } + + $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( + 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/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/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..449fed9c69 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-mysql.sql @@ -0,0 +1,11 @@ +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 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 new file mode 100644 index 0000000000..9d4db54689 --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-postgresql.sql @@ -0,0 +1,10 @@ +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 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 new file mode 100644 index 0000000000..97f734154c --- /dev/null +++ b/src/bundle/RepositoryInstaller/Migration/sql/remove-stale-object-state-translations-sqlite.sql @@ -0,0 +1,18 @@ +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 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 + 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 a0780d0ec9..970da45187 100644 --- a/src/contracts/Test/Persistence/Fixture/FixtureImporter.php +++ b/src/contracts/Test/Persistence/Fixture/FixtureImporter.php @@ -11,6 +11,7 @@ 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; @@ -22,15 +23,33 @@ */ final class FixtureImporter { - private Connection $connection; + /** + * Tables whose "language_id" the legacy bitmask scheme ORed the "always available" bit into. + */ + private const array 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. + */ + 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', + ]; /** @var array */ private static array $resetSequenceStatements = []; - public function __construct(Connection $connection) - { - $this->connection = $connection; - } + /** @var array */ + private static array $existingColumnsByTable = []; + + public function __construct(private readonly Connection $connection) {} /** * @throws Exception @@ -40,26 +59,308 @@ public function import(Fixture $fixture): void $data = $fixture->load(); $tablesList = array_keys($data); + $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 + ); + $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) { - $this->connection->insert($table, $row); + $row = $this->stripLegacyAlwaysAvailableBit($table, $row, $languageIds); + $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); + } + } + } + } + + /** + * 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 $languageIds + ): array { + 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; + } + + /** + * @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" 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']; + $this->connection->executeStatement( + '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] + ); + 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, + ] + ); + } + } + } + + private function tableExists(string $table): bool + { + return $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/lib/Persistence/Legacy/Content/Gateway.php b/src/lib/Persistence/Legacy/Content/Gateway.php index 066d3bcabf..983dfcbc78 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'; @@ -206,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 @@ -227,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. @@ -493,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 f44187ed7e..113f86f11c 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; @@ -36,7 +37,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 +53,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,20 +103,22 @@ 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 ), ] ); $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( @@ -165,20 +160,120 @@ 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 ), ] ); $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 ' . self::CONTENT_TRANSLATION_TABLE . ' (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 ' . self::CONTENT_VERSION_TRANSLATION_TABLE . ' (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. + * + * @param string[] $languageCodes + */ + 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 {$translationTable} (content_version_id, language_id) + SELECT :versionId, :languageId + WHERE NOT EXISTS ( + SELECT 1 FROM {$translationTable} + 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. + * + * @param string[] $languageCodes + */ + private function replaceContentTranslations( + int $contentId, + array $languageCodes + ): void { + $this->connection->executeStatement( + 'DELETE FROM ' . self::CONTENT_TRANSLATION_TABLE . ' WHERE content_id = :contentId', + ['contentId' => $contentId], + ['contentId' => ParameterType::INTEGER] + ); + + $this->insertContentTranslations($contentId, $languageCodes); } public function updateContent( @@ -234,13 +329,10 @@ public function updateContent( } if ($prePublishVersionInfo !== null) { - $mask = $this->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - $prePublishVersionInfo->languageCodes, - $struct->alwaysAvailable ?? $prePublishVersionInfo->contentInfo->alwaysAvailable - ); + $alwaysAvailable = $struct->alwaysAvailable ?? $prePublishVersionInfo->contentInfo->alwaysAvailable; $query->set( - 'language_mask', - $query->createNamedParameter($mask, ParameterType::INTEGER, ':languageMask') + 'always_available', + $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') ); $hasSetClause = true; } @@ -260,6 +352,10 @@ public function updateContent( if (isset($struct->alwaysAvailable) || isset($struct->mainLanguageId)) { $this->updateAlwaysAvailableFlag($contentId, $struct->alwaysAvailable); } + + if ($prePublishVersionInfo !== null) { + $this->replaceContentTranslations($contentId, $prePublishVersionInfo->languageCodes); + } } /** @@ -279,13 +375,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( @@ -293,181 +382,56 @@ 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) ->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( 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 - ->update(self::CONTENT_ITEM_TABLE); - $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') - ) + ->update(self::CONTENT_ITEM_TABLE) + ->set( + 'always_available', + $query->createNamedParameter($alwaysAvailable, ParameterType::BOOLEAN, ':alwaysAvailable') ) - ->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( @@ -630,27 +594,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 @@ -756,7 +704,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 +712,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', @@ -1443,7 +1391,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', ] ); @@ -1451,7 +1399,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') @@ -1461,19 +1409,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(); @@ -1886,6 +1821,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 */ @@ -2045,7 +2027,7 @@ private function deleteTranslationFromContentNames( } /** - * Remove language from language_mask of ibexa_content. + * Remove language from ibexa_content_translation. * * @param int $contentId * @param int $languageId @@ -2056,36 +2038,38 @@ private function deleteTranslationFromContentObject( $contentId, $languageId ) { + $hasOtherLanguages = (bool)$this->connection->fetchOne( + '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] + ); + + // 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 ' . self::CONTENT_TRANSLATION_TABLE . ' 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 update initialLanguageId * if it matches the removed one. * * @param int|null $versionNo optional, if specified, apply to this Version only. @@ -2098,79 +2082,62 @@ private function deleteTranslationFromContentVersions( ?int $versionNo = null ) { $contentTable = Gateway::CONTENT_ITEM_TABLE; - $query = $this->connection->createQueryBuilder(); - $query->update(Gateway::CONTENT_VERSION_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') - // 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' - ) + $versionTable = Gateway::CONTENT_VERSION_TABLE; + $versionTranslationTable = Gateway::CONTENT_VERSION_TRANSLATION_TABLE; + + $versionIdsQuery = $this->connection->createQueryBuilder(); + $versionIdsQuery + ->select('id') + ->from($versionTable) ->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' - ) + // 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('now', time()) - ->setParameter('contentId', $contentId) - ->setParameter('languageId', $languageId) + ->setParameter('contentId', $contentId, ParameterType::INTEGER) + ->setParameter('languageId', $languageId, ParameterType::INTEGER) ; if (null !== $versionNo) { - $query + $versionIdsQuery ->andWhere('version = :versionNo') - ->setParameter('versionNo', $versionNo) + ->setParameter('versionNo', $versionNo, ParameterType::INTEGER) ; } - $rowCount = $query->executeStatement(); + $versionIds = array_map('intval', $versionIdsQuery->executeQuery()->fetchFirstColumn()); - // no rows updated means that most likely somehow it was the last remaining translation - if ($rowCount === 0) { + // most likely somehow it was the last remaining translation + if ($versionIds === []) { throw new BadStateException( '$languageCode', 'The provided translation is the only translation in this version' ); } - } - /** - * 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 - ); + $query = $this->connection->createQueryBuilder(); + $query->update($versionTable) + ->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(); - return $query; + $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/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/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 eba63900a7..eaa5568c8e 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. @@ -21,30 +20,29 @@ */ 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 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") 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 */ - public const MULTILINGUAL_TABLES_COLUMNS = [ - ObjectStateGateway::OBJECT_STATE_TABLE => ['language_mask', 'default_language_id'], + 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 => ['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..4b03f53f17 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 @@ -145,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) @@ -160,13 +162,33 @@ 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; + } + // 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 +197,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/Location/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php index ead5424742..e4d3b1ed0b 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(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) + ) + ) + ); + + $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..b24cac8635 100644 --- a/src/lib/Persistence/Legacy/Content/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Mapper.php @@ -215,6 +215,7 @@ public function convertToStorageValue(Field $field) * * @param array> $rows * @param array> $nameRows + * @param array $versionLanguageIds * @param string $prefix * @param array|null $translations * @@ -223,6 +224,7 @@ public function convertToStorageValue(Field $field) public function extractContentFromRows( array $rows, array $nameRows, + array $versionLanguageIds, string $prefix = 'content_', ?array $translations = null ): array { @@ -242,7 +244,8 @@ public function extractContentFromRows( $fieldDefinitions = $this->loadCachedVersionFieldDefinitionsPerLanguage( $rows, $prefix, - $translations + $translations, + $versionLanguageIds ); foreach ($rows as $row) { @@ -258,7 +261,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 +349,7 @@ private function buildContentObjects( * @phpstan-param TRawContentRow[] $rows * * @param string[]|null $translations + * @param array $versionLanguageIds * * @phpstan-return TVersionedLanguageFieldDefinitionsMap * @@ -350,7 +358,8 @@ private function buildContentObjects( private function loadCachedVersionFieldDefinitionsPerLanguage( array $rows, string $prefix, - ?array $translations = null + ?array $translations, + array $versionLanguageIds ): array { $fieldDefinitions = []; $contentTypes = []; @@ -360,13 +369,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 +414,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 +454,14 @@ public function extractContentInfoFromRows( * * @param array $row * @param array $names + * @param int[] $languageIds * * @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 +475,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; @@ -493,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) { @@ -520,8 +529,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 +554,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/Content/ObjectState/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabase.php index 20f237e3b3..a3b147afe6 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,23 +156,13 @@ public function insertObjectState( ParameterType::INTEGER ), 'default_language_id' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageIndicator( - $objectState->defaultLanguage, - false - ), + $this->languageHandler->loadByLanguageCode($objectState->defaultLanguage)->id, ParameterType::INTEGER ), 'identifier' => $query->createPositionalParameter( $objectState->identifier, ParameterType::STRING ), - 'language_mask' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( - $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->maskGenerator->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->maskGenerator->generateLanguageMaskFromLanguageCodes( - $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->maskGenerator->generateLanguageIndicator( - $objectStateGroup->defaultLanguage, - false - ), + $this->languageHandler->loadByLanguageCode($objectStateGroup->defaultLanguage)->id, ParameterType::INTEGER ), 'identifier' => $query->createPositionalParameter( $objectStateGroup->identifier, ParameterType::STRING ), - 'language_mask' => $query->createPositionalParameter( - $this->maskGenerator->generateLanguageMaskFromLanguageCodes( - $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->maskGenerator->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->maskGenerator->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(); } diff --git a/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php b/src/lib/Persistence/Legacy/Content/ObjectState/Mapper.php index a2f957c3df..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. @@ -48,9 +35,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 +50,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/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/Persistence/Legacy/Content/Type/Gateway.php b/src/lib/Persistence/Legacy/Content/Type/Gateway.php index 2891a033db..48c6ac1e0e 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Gateway.php +++ b/src/lib/Persistence/Legacy/Content/Type/Gateway.php @@ -164,6 +164,15 @@ abstract public function loadTypeDataByRemoteId( int $status ): array; + /** + * Loads the language codes each of the given (Type id, status) pairs is translated into. + * + * @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..52d842ff36 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; @@ -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', @@ -103,7 +102,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 +294,7 @@ private function insertTypeNameData( ParameterType::INTEGER ), 'language_id' => $query->createPositionalParameter( - $this->languageMaskGenerator->generateLanguageIndicator( - $language, - $this->languageMaskGenerator->isLanguageAlwaysAvailable( - $language, - $languages - ) - ), + $this->languageHandler->loadByLanguageCode($language)->id, ParameterType::INTEGER ), 'language_locale' => $query->createPositionalParameter( @@ -422,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->languageMaskGenerator->generateLanguageMaskFromLanguageCodes( - $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], @@ -1039,6 +1025,36 @@ 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)) + ) + ->orderBy('language_id'); + + $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 +1081,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 +1419,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/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 faf2a3fe35..347f35ffb5 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Type/Mapper.php @@ -4,9 +4,11 @@ * @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; +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 +17,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; @@ -26,34 +27,12 @@ */ class Mapper { - /** - * Converter registry. - * - * @var ConverterRegistry - */ - protected $converterRegistry; - - /** @var MaskGenerator */ - private $maskGenerator; - - private StorageDispatcherInterface $storageDispatcher; - - /** - * Creates a new content type mapper. - * - * @param ConverterRegistry $converterRegistry - * @param MaskGenerator $maskGenerator - */ public function __construct( - ConverterRegistry $converterRegistry, - MaskGenerator $maskGenerator, - StorageDispatcherInterface $storageDispatcher, + protected ConverterRegistry $converterRegistry, + private LanguageHandler $languageHandler, + private StorageDispatcherInterface $storageDispatcher, private readonly FieldTypeAliasResolverInterface $fieldTypeAliasResolver - ) { - $this->converterRegistry = $converterRegistry; - $this->maskGenerator = $maskGenerator; - $this->storageDispatcher = $storageDispatcher; - } + ) {} /** * Creates a Group from its create struct. @@ -114,12 +93,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 = []; @@ -137,7 +118,8 @@ public function extractTypesFromRows( 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 +167,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 +199,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 +249,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 +302,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 +437,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/Persistence/Legacy/Content/UrlAlias/Gateway.php b/src/lib/Persistence/Legacy/Content/UrlAlias/Gateway.php index ca8f74d772..cdf16805ab 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,16 @@ abstract public function reparent( */ abstract public function loadPathData(int $id): array; + /** + * Loads the language ids a specific alias row is translated into. + * + * @return int[] + */ + abstract public function loadTranslationLanguageIds( + int $parent, + string $textMD5 + ): array; + /** * Load path data identified by given ordered array of hierarchy data. * @@ -214,7 +230,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..9c021a56ff 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; @@ -35,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. @@ -49,10 +52,10 @@ 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, + 'always_available' => ParameterType::BOOLEAN, ]; private string $table; @@ -61,7 +64,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(); @@ -87,7 +90,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( @@ -103,14 +106,14 @@ public function loadLocationEntries( 'link', 'is_alias', 'alias_redirects', - 'lang_mask', + '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,20 +138,12 @@ 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(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function listGlobalEntries( @@ -167,12 +162,12 @@ public function listGlobalEntries( 'link', 'is_alias', 'alias_redirects', - 'lang_mask', + '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,25 +195,12 @@ 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(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function isRootEntry(int $id): bool @@ -259,10 +241,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 +263,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 +287,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 +298,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 +323,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 +356,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 +414,18 @@ 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( + '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 +498,20 @@ 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']); + $query = $this->connection->createQueryBuilder(); $query->update($this->connection->quoteSingleIdentifier($this->table)); foreach ($values as $columnName => $value) { @@ -586,6 +538,10 @@ public function updateRow( ) ); $query->executeStatement(); + + if (null !== $languageIds) { + $this->syncUrlAliasTranslations($parentId, $textMD5, $languageIds); + } } public function insertRow(array $values): int @@ -640,6 +596,9 @@ private function doInsertRow(array $values): int $values['is_original'] = 1; } + $languageIds = $values['language_ids'] ?? null; + unset($values['language_ids']); + $query = $this->connection->createQueryBuilder(); $query->insert($this->connection->quoteSingleIdentifier($this->table)); foreach ($values as $columnName => $value) { @@ -654,9 +613,38 @@ 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']; } + /** + * 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(); @@ -703,7 +691,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 @@ -755,7 +743,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( @@ -798,7 +786,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 @@ -809,7 +797,8 @@ public function loadPathData(int $id): array $query = $this->connection->createQueryBuilder(); $query->select( 'parent', - 'lang_mask', + 'text_md5', + 'always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) @@ -846,7 +835,7 @@ public function loadPathData(int $id): array array_unshift($pathData, $rows); } - return $pathData; + return $this->withLanguageIdsInPathData($pathData); } public function loadPathDataByHierarchy(array $hierarchyData): array @@ -882,7 +871,9 @@ public function loadPathDataByHierarchy(array $hierarchyData): array $query->select( 'action', - 'lang_mask', + 'parent', + 'text_md5', + 'always_available', 'text' )->from( $this->connection->quoteSingleIdentifier($this->table) @@ -907,7 +898,7 @@ public function loadPathDataByHierarchy(array $hierarchyData): array $data[] = $rowsMap[$levelData['action']]; } - return $data; + return $this->withLanguageIdsInPathData($data); } public function removeCustomAlias( @@ -1025,7 +1016,7 @@ public function loadAutogeneratedEntries( $statement = $query->executeQuery(); - return $statement->fetchAllAssociative(); + return $this->withLanguageIds($statement->fetchAllAssociative()); } public function getLocationContentMainLanguageId(int $locationId): int @@ -1055,21 +1046,28 @@ 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 + 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 single language rows (including alwaysAvailable) + // 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 +1089,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 +1104,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 +1142,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 +1277,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 +1387,7 @@ 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 language id set. * * @param array $urlAliasesData */ @@ -1395,8 +1401,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 +1465,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 +1525,106 @@ private function getDatabasePlatform(): AbstractPlatform throw DatabaseException::wrap($e); } } + + /** + * Builds an "at least one of $languageIds is a translation of this row" condition, correlated via alias-qualified $parentColumn and $textMd5Column. + * + * @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()); + } + + /** + * 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/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..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,8 +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\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; @@ -54,89 +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; - - /** - * Language mask generator. - * - * @var MaskGenerator - */ - protected $maskGenerator; - - /** @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 MaskGenerator $maskGenerator - * @param TransactionHandler $transactionHandler - */ public function __construct( - Gateway $gateway, - Mapper $mapper, - LocationGateway $locationGateway, - LanguageHandler $languageHandler, - SlugConverter $slugConverter, - ContentGateway $contentGateway, - MaskGenerator $maskGenerator, - TransactionHandler $transactionHandler - ) { - $this->gateway = $gateway; - $this->mapper = $mapper; - $this->locationGateway = $locationGateway; - $this->languageHandler = $languageHandler; - $this->slugConverter = $slugConverter; - $this->contentGateway = $contentGateway; - $this->maskGenerator = $maskGenerator; - $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, @@ -184,7 +109,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 +140,8 @@ private function internalPublishUrlAliasForLocation( 'link' => $newId, 'parent' => $parentId, 'action' => $action, - 'lang_mask' => $languageMask, + 'language_ids' => $languageIds, + 'always_available' => $alwaysAvailable, 'text' => $newText, 'text_md5' => $newTextMD5, ] @@ -254,8 +180,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, + $row['language_ids'] + )); } } elseif ($newId === null) { // Use reused row ID only if publishing normally, else use given $newId @@ -269,7 +198,8 @@ private function internalPublishUrlAliasForLocation( 'action' => $action, // In case when NOP row was reused 'action_type' => 'eznode', - 'lang_mask' => $languageMask, + 'language_ids' => $languageIds, + '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 +386,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['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['always_available'] = $alwaysAvailable; // If history is reused move link to id $data['link'] = $id = $row['id']; $this->gateway->updateRow( @@ -473,11 +405,12 @@ protected function createUrlAlias( } elseif ( $row['action'] === $action && (int)$row['is_alias'] === 1 && - 0 === ((int)$row['lang_mask'] & $languageId) + !in_array($languageId, $row['language_ids'], 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($row['language_ids'], [$languageId])); + $data['always_available'] = $alwaysAvailable || (bool)$row['always_available']; $this->gateway->updateRow( $parentId, $topElementMD5, @@ -511,7 +444,8 @@ protected function insertNopEntry( ) { return $this->gateway->insertRow( [ - 'lang_mask' => 1, + 'language_ids' => [], + 'always_available' => true, 'action' => Gateway::NOP_ACTION, 'parent' => $parentId, 'text' => $text, @@ -580,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; } } @@ -765,8 +699,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 +728,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 +784,11 @@ private function historizeBeforeSwap( $location2Entries ) { foreach ($location1Entries as $row) { - $this->gateway->historizeBeforeSwap($row['action'], $row['lang_mask']); + $this->gateway->historizeBeforeSwap($row['action'], $row['language_ids']); } foreach ($location2Entries as $row) { - $this->gateway->historizeBeforeSwap($row['action'], $row['lang_mask']); + $this->gateway->historizeBeforeSwap($row['action'], $row['language_ids']); } } @@ -961,7 +905,7 @@ private function getLocationEntryInLanguage( $entries = array_filter( $locationEntries, static function (array $row) use ($languageId): bool { - return (bool) ($row['lang_mask'] & $languageId); + return in_array($languageId, $row['language_ids'], true); } ); @@ -1233,21 +1177,22 @@ 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). + * Restores the swapped Location's custom aliases in the languages they share with its new Content. + * + * @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; + $intersectedLanguageIds = array_values(array_intersect($entry['language_ids'], $contentLanguageIds)); - if ($mask <= 1) { + if (empty($intersectedLanguageIds)) { continue; } @@ -1258,7 +1203,8 @@ private function internalPublishCustomUrlAliasForLocation( 'id' => (int)$entry['id'], 'is_original' => 1, 'is_alias' => 1, - 'lang_mask' => $mask, + 'language_ids' => $intersectedLanguageIds, + '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 2e5aa37a02..a0db9b9804 100644 --- a/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/UrlAlias/Mapper.php @@ -4,32 +4,35 @@ * @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; +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; + public function __construct( + private readonly 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 +49,8 @@ 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($data['language_ids']); + $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']; @@ -83,12 +86,12 @@ public function extractUrlAliasListFromData(array $rows) */ public function extractLanguageCodesFromData(array $rows): array { - $languageMask = 0; + $languageIds = []; foreach ($rows as $row) { - $languageMask |= $row['lang_mask']; + $languageIds[] = $row['language_ids']; } - return $this->languageMaskGenerator->extractLanguageCodesFromMask($languageMask); + return $this->loadLanguageCodes(array_unique(array_merge([], ...$languageIds))); } public function generateIdentityKey( @@ -167,14 +170,13 @@ 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($row['language_ids']); + $pathElementData['always-available'] = (bool)$row['always_available']; if (!empty($languageCodes)) { foreach ($languageCodes as $languageCode) { $pathElementData['translations'][$languageCode] = $row['text']; } } elseif ($pathElementData['always-available']) { - // NOP entry, lang_mask == 1 $pathElementData['translations']['always-available'] = $row['text']; } } diff --git a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php index 0a7f03774d..317e566ecf 100644 --- a/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php +++ b/src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/LanguageCodeQueryBuilder.php @@ -9,10 +9,12 @@ 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; 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; /** @@ -37,10 +39,15 @@ public function buildQueryConstraint( $queryBuilder ->joinOnce( 'version', + ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, + '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 +60,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..d7b1d7c000 100644 --- a/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/src/lib/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -33,7 +33,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 +49,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', @@ -95,6 +95,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 +116,7 @@ public function find( $contentId, $versionNo ); + $row['content_version_translations'] = $translations[(int)$row['content_version_id']] ?? []; yield $row; } @@ -214,7 +216,11 @@ 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' + 'EXISTS ( + SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt + WHERE cvt.content_version_id = version.id + AND content_name.language_id = cvt.language_id + )' ) ) // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints @@ -250,7 +256,11 @@ 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' + 'EXISTS ( + SELECT 1 FROM ' . ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE . ' cvt + WHERE cvt.content_version_id = version.id + AND content_field.language_id = cvt.language_id + )' ) ) // reset not needed parts, keeping FROM, other JOINs, and WHERE constraints @@ -261,6 +271,41 @@ private function bulkFetchFieldValues(FilteringQueryBuilder $query): array return $query->executeQuery()->fetchAllAssociative(); } + /** + * 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 + ->select('version.id AS content_version_id', 'version_languages.language_id') + ->distinct() + ->joinOnce( + 'version', + ContentGateway::CONTENT_VERSION_TRANSLATION_TABLE, + 'version_languages', + 'version_languages.content_version_id = version.id' + ) + ->setMaxResults(null) + ->setFirstResult(0) + ->resetOrderBy(); + + $translations = []; + foreach ($query->executeQuery()->iterateAssociative() as $row) { + $translations[(int)$row['content_version_id']][] = (int)$row['language_id']; + } + + return array_map( + static function (array $languageIds): array { + sort($languageIds); + + return $languageIds; + }, + $translations + ); + } + 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/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/search_engines/legacy.yml b/src/lib/Resources/settings/search_engines/legacy.yml index a028246951..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 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..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 @@ -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,8 @@ 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\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/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/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/content_type.yml b/src/lib/Resources/settings/storage_engines/legacy/content_type.yml index 1fe117e080..0696d80f60 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,7 @@ 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.spi.persistence.legacy.language.handler' - '@Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface' - '@Ibexa\Core\FieldType\FieldTypeAliasResolverInterface' diff --git a/src/lib/Resources/settings/storage_engines/legacy/filter.yaml b/src/lib/Resources/settings/storage_engines/legacy/filter.yaml index 5b23edfb25..00ca79e951 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' 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/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/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/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml b/src/lib/Resources/settings/storage_engines/legacy/url_alias.yml index b8781afa6e..6bf7aeefbc 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,7 @@ 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.spi.persistence.legacy.language.handler' Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Handler: class: Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Handler @@ -29,6 +29,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/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..ebdf25ffdb 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,39 +16,24 @@ 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. */ abstract class FieldBase extends CriterionHandler { - /** - * Content type handler. - * - * @var ContentTypeHandler - */ - protected $contentTypeHandler; - - /** - * Language handler. - * - * @var LanguageHandler - */ - protected $languageHandler; - /** * @throws Exception */ public function __construct( Connection $connection, - ContentTypeHandler $contentTypeHandler, - LanguageHandler $languageHandler, - JoinedTablesTracker $joinedTablesTracker + protected ContentTypeHandler $contentTypeHandler, + protected LanguageHandler $languageHandler, + JoinedTablesTracker $joinedTablesTracker, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); - - $this->contentTypeHandler = $contentTypeHandler; - $this->languageHandler = $languageHandler; } /** @@ -63,85 +47,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..06c47ea26d 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/LanguageCode.php @@ -9,29 +9,28 @@ use Doctrine\DBAL\Connection; 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\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. */ class LanguageCode extends CriterionHandler { - /** @var MaskGenerator */ - private $maskGenerator; - public function __construct( Connection $connection, - MaskGenerator $maskGenerator, - JoinedTablesTracker $joinedTablesTracker + private readonly LanguageHandler $languageHandler, + JoinedTablesTracker $joinedTablesTracker, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection, $joinedTablesTracker); - - $this->maskGenerator = $maskGenerator; } public function accept(CriterionInterface $criterion): bool @@ -49,15 +48,18 @@ 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 - ) - ), - '0' + $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)); + + 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 new file mode 100644 index 0000000000..034480730b --- /dev/null +++ b/src/lib/Search/Legacy/Content/Common/Gateway/LanguagePriorityConditionBuilder.php @@ -0,0 +1,148 @@ +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 $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); + + return sprintf( + 'COALESCE((%s), CASE WHEN %s THEN %s END)', + $subQuery->getSQL(), + $alwaysAvailableColumn, + $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/Common/Gateway/SortClauseHandler/Field.php b/src/lib/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php index 7b283db1ef..9d1da01d68 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; /** @@ -23,29 +24,13 @@ */ class Field extends SortClauseHandler { - /** - * Language handler. - * - * @var LanguageHandler - */ - protected $languageHandler; - - /** - * Content type handler. - * - * @var ContentTypeHandler - */ - protected $contentTypeHandler; - public function __construct( Connection $connection, - LanguageHandler $languageHandler, - ContentTypeHandler $contentTypeHandler + protected LanguageHandler $languageHandler, + protected ContentTypeHandler $contentTypeHandler, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder ) { parent::__construct($connection); - - $this->languageHandler = $languageHandler; - $this->contentTypeHandler = $contentTypeHandler; } /** @@ -161,81 +146,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..4a49d2eee4 100644 --- a/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php @@ -4,23 +4,21 @@ * @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; 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; 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; @@ -30,48 +28,13 @@ */ final class DoctrineDatabase extends Gateway { - /** @var Connection */ - private $connection; - - /** @var AbstractPlatform */ - private $dbPlatform; - - /** - * Criteria converter. - * - * @var CriteriaConverter - */ - private $criteriaConverter; - - /** - * Sort clause converter. - * - * @var SortClauseConverter - */ - private $sortClauseConverter; - - /** - * Language handler. - * - * @var LanguageHandler - */ - private $languageHandler; - - /** - * @throws Exception - */ public function __construct( - Connection $connection, - CriteriaConverter $criteriaConverter, - SortClauseConverter $sortClauseConverter, - LanguageHandler $languageHandler - ) { - $this->connection = $connection; - $this->dbPlatform = $connection->getDatabasePlatform(); - $this->criteriaConverter = $criteriaConverter; - $this->sortClauseConverter = $sortClauseConverter; - $this->languageHandler = $languageHandler; - } + private readonly Connection $connection, + private readonly CriteriaConverter $criteriaConverter, + private readonly SortClauseConverter $sortClauseConverter, + private readonly LanguageHandler $languageHandler, + private readonly LanguagePriorityConditionBuilder $languagePriorityConditionBuilder + ) {} public function find( CriterionInterface $criterion, @@ -99,29 +62,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 * @@ -133,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', @@ -149,20 +89,18 @@ 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'] + ); + + $languageCondition = $this->languagePriorityConditionBuilder->buildTranslationCondition( + $query, + $languageIds, + !empty($languageFilter['useAlwaysAvailable']) ); + + $condition = (string)$expr->and($condition, $languageCondition); } return $condition; @@ -221,6 +159,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) { @@ -239,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 c8a8d99aa7..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, @@ -156,11 +99,7 @@ public function findContent( /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $contentInfo; - $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $data['rows'][$index]['language_mask'], - $data['rows'][$index]['initial_language_id'], - $languageFilter - ); + $searchHit->matchedTranslation = $this->extractMatchedLanguage($data['rows'][$index]['matched_language_id']); $result->searchHits[] = $searchHit; } @@ -168,26 +107,16 @@ public function findContent( return $result; } - protected function extractMatchedLanguage( - $languageMask, - $mainLanguageId, - $languageSettings - ) { - $languageList = !empty($languageSettings['languages']) ? - $this->languageHandler->loadListByLanguageCodes($languageSettings['languages']) : - []; - - foreach ($languageList as $language) { - if ($languageMask & $language->id) { - return $language->languageCode; - } - } - - if ($languageMask & 1 || empty($languageSettings['languages'])) { - return $this->languageHandler->load($mainLanguageId)->languageCode; + /** + * @param int|string|null $languageId + */ + protected function extractMatchedLanguage($languageId): ?string + { + if ($languageId === null) { + return null; } - return null; + return $this->languageHandler->load((int)$languageId)->languageCode; } public function findSingle( @@ -245,11 +174,7 @@ public function findLocations( /** @phpstan-var SearchHit $searchHit */ $searchHit = new SearchHit(); $searchHit->valueObject = $location; - $searchHit->matchedTranslation = $this->extractMatchedLanguage( - $data['rows'][$index]['language_mask'], - $data['rows'][$index]['initial_language_id'], - $languageFilter - ); + $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 3e17642a2d..ca08cc34eb 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -8,17 +8,16 @@ namespace Ibexa\Core\Search\Legacy\Content\Location\Gateway; 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; +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; @@ -38,7 +37,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( @@ -62,8 +62,7 @@ public function find( $selectQuery = $this->connection->createQueryBuilder(); $selectQuery->select( 't.*', - 'c.language_mask', - 'c.initial_language_id' + $this->languagePriorityConditionBuilder->buildMatchedLanguageExpression($selectQuery, $languageFilter) . ' AS matched_language_id' ); if ($sortClauses !== null) { @@ -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,27 @@ 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 array{languages?: string[], useAlwaysAvailable?: bool} $languageFilter * * @throws NotFoundException */ - private function getLanguageMask(array $languageFilter): int - { - if (!isset($languageFilter['languages'])) { - $languageFilter['languages'] = []; - } - - if (!isset($languageFilter['useAlwaysAvailable'])) { - $languageFilter['useAlwaysAvailable'] = true; - } - - $mask = 0; - if ($languageFilter['useAlwaysAvailable']) { - $mask |= 1; - } - - foreach ($languageFilter['languages'] as $languageCode) { - $mask |= $this->languageHandler->loadByLanguageCode($languageCode)->id; - } - - return $mask; - } + private function buildTranslationCondition( + QueryBuilder $queryBuilder, + array $languageFilter + ): string { + $languageIds = array_map( + fn (string $languageCode): int => $this->languageHandler->loadByLanguageCode($languageCode)->id, + $languageFilter['languages'] ?? [] + ); - private function getDatabasePlatform(): AbstractPlatform - { - try { - return $this->connection->getDatabasePlatform(); - } catch (Exception $e) { - throw DatabaseException::wrap($e); - } + return $this->languagePriorityConditionBuilder->buildTranslationCondition( + $queryBuilder, + $languageIds, + $languageFilter['useAlwaysAvailable'] ?? true + ); } } diff --git a/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php b/src/lib/Search/Legacy/Content/WordIndexer/Gateway/DoctrineDatabase.php index 82959d47a4..4f3c4f1e97 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; @@ -28,61 +28,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 MaskGenerator */ - private $languageMaskGenerator; - - /** - * Full text search configuration options. - * - * @var array - */ - protected $fullTextSearchConfiguration; - public function __construct( - Connection $connection, - SPITypeHandler $typeHandler, - TransformationProcessor $transformationProcessor, - SearchIndex $searchIndex, - MaskGenerator $languageMaskGenerator, - array $fullTextSearchConfiguration - ) { - $this->connection = $connection; - $this->typeHandler = $typeHandler; - $this->transformationProcessor = $transformationProcessor; - $this->searchIndex = $searchIndex; - $this->fullTextSearchConfiguration = $fullTextSearchConfiguration; - $this->languageMaskGenerator = $languageMaskGenerator; - } + 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 +58,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 +68,7 @@ public function index(FullTextData $fullTextData) $integerValue = 0; } $text = $this->transformationProcessor->transform( - $fullTextValue->value, + $value, !empty($fullTextValue->transformationRules) ? $fullTextValue->transformationRules : $this->fullTextSearchConfiguration['commands'] @@ -259,10 +213,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 +236,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..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; @@ -131,7 +132,8 @@ public function addObjectWordLink( int $sectionId, string $identifier, int $integerValue, - int $languageMask + int $languageId, + bool $isMainAndAlwaysAvailable ): void { $query = $this->connection->createQueryBuilder(); $query @@ -180,10 +182,14 @@ public function addObjectWordLink( $integerValue, ParameterType::INTEGER ), - 'language_mask' => $query->createPositionalParameter( - $languageMask, + 'language_id' => $query->createPositionalParameter( + $languageId, ParameterType::INTEGER ), + 'is_main_and_always_available' => $query->createPositionalParameter( + $isMainAndAlwaysAvailable, + ParameterType::BOOLEAN + ), ] ); diff --git a/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php new file mode 100644 index 0000000000..960f66fade --- /dev/null +++ b/tests/bundle/Core/Command/BackfillLanguageTranslationsCommandTest.php @@ -0,0 +1,328 @@ +insertDatabaseFixture( + __DIR__ . '/../../../lib/Persistence/Legacy/Content/_fixtures/languages.php' + ); + + $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', [ + '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' + ) + ) + ); + 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 always_available FROM ibexa_url_alias_ml')); + } + + 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') + ); + } + + 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')); + } + + public function testVerifyFindsTheMaskColumnsBehindASchemaAssetsFilter(): void + { + $connection = $this->getDatabaseConnection(); + (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)); + + 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, + * 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 + { + $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); + } + } + + /** + * Drops the mask columns, like a fully migrated schema. + */ + private function simulateFullyMigratedSchema(Connection $connection): void + { + $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_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 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 + */ + 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/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php new file mode 100644 index 0000000000..286fea7b45 --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/AddSearchObjectWordLinkLanguageIdColumnsMigrationTest.php @@ -0,0 +1,81 @@ +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', + ['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' + ) + ); + } +} diff --git a/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php new file mode 100644 index 0000000000..a21a1c6b0f --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/AddUrlAliasAlwaysAvailableColumnMigrationTest.php @@ -0,0 +1,50 @@ +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, + '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, always_available FROM ibexa_url_alias_ml ORDER BY id') + ); + } +} diff --git a/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php new file mode 100644 index 0000000000..abe404ca24 --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/BackfillLanguageTranslationsMigrationTest.php @@ -0,0 +1,149 @@ +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'); + 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(); + } + + 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()); + + $queries = $migration->getSql(); + foreach ($queries as $query) { + $connection->executeStatement($query->getStatement(), $query->getParameters(), $query->getTypes()); + } + + return $queries; + } + + 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') + ); + } +} diff --git a/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php new file mode 100644 index 0000000000..7235f4687c --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/DropLanguageBitmaskColumnsMigrationTest.php @@ -0,0 +1,94 @@ +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()) + ); + } + + 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()); + } +} 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' + ) + ); + } +} diff --git a/tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php b/tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php new file mode 100644 index 0000000000..103187b41d --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/Upgrade/LanguageBitmaskUpgradeSequenceTest.php @@ -0,0 +1,755 @@ +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' + ); + } + + 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 FALSE 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); + + // 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'); + + $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 FALSE 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 FALSE 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->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())); + + $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/Upgrade/_fixtures/pre_language_bitmask_migration_schema.yaml b/tests/bundle/RepositoryInstaller/Migration/Upgrade/_fixtures/pre_language_bitmask_migration_schema.yaml new file mode 100644 index 0000000000..e3939a7eca --- /dev/null +++ b/tests/bundle/RepositoryInstaller/Migration/Upgrade/_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' } } diff --git a/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php b/tests/integration/Core/Persistence/Legacy/UrlAliasGatewayTest.php index d2409bcdc0..07bbb494e8 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], + 'always_available' => true, 'link' => 1, 'parent' => 0, 'text' => self::TEXT, diff --git a/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php b/tests/integration/Core/Repository/ContentService/MaxLanguagesContentServiceTest.php index ec1c6539d0..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; @@ -40,6 +41,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 int EXTRA_LANGUAGES_BEYOND_OLD_LIMIT = 5; + /** * @throws Exception */ @@ -55,7 +63,22 @@ public function testCreateContent(): void ], self::$languagesRawList )); - $this->createFolder($names); + + for ($i = 1; $i <= self::EXTRA_LANGUAGES_BEYOND_OLD_LIMIT; ++$i) { + $names["xtr-{$i}"] = "Beyond old limit {$i} name"; + } + + $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); } /** @@ -72,5 +95,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/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 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/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/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml b/tests/integration/Core/Repository/_fixtures/Legacy/data/test_data.yaml index 8638e058ce..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,32 +208,32 @@ 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: 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: 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' } + - { 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 } @@ -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,16 +315,16 @@ 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: 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: 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 } - { 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 } @@ -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-US, content_version: 1, contentobject_id: 57, language_id: 9, name: Home, real_translation: eng-US } + - { 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/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/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php index 30e05c600b..c616f98fec 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 */ @@ -63,7 +86,7 @@ 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', 'status' => ContentInfo::STATUS_DRAFT, @@ -79,7 +102,7 @@ public function testInsertContentObject(): void 'current_version', 'initial_language_id', 'remote_id', - 'language_mask', + 'always_available', 'modified', 'published', 'status' @@ -187,7 +210,7 @@ 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 // 'user_id', @@ -203,7 +226,7 @@ public function testInsertVersion(): void 'status', 'workflow_event_pos', 'version', - 'language_mask', + 'always_available', 'initial_language_id' )->from(Gateway::CONTENT_VERSION_TABLE) ); @@ -462,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', @@ -1428,6 +1451,48 @@ 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, + '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], + ]); + 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') + ); + } + public function testUpdateAlwaysAvailableFlagRemove(): void { $this->insertDatabaseFixture( @@ -1438,56 +1503,12 @@ public function testUpdateAlwaysAvailableFlagRemove(): void $gateway->updateAlwaysAvailableFlag(103, false); $connection = $this->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); self::assertQueryResult( - [['id' => 2]], - $query - ->select('language_mask') + [['always_available' => 0]], + $connection->createQueryBuilder() + ->select('always_available') ->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)) - ) - ) + ->where('id = 103') ); } @@ -1505,59 +1526,13 @@ public function testUpdateAlwaysAvailableFlagAdd(): void $gateway->updateAlwaysAvailableFlag($contentId, true); $connection = $this->getDatabaseConnection(); - $expectedLanguageId = 3; self::assertQueryResult( - [['id' => $expectedLanguageId]], + [['always_available' => 1]], $connection->createQueryBuilder() - ->select('language_mask') + ->select('always_available') ->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) - ) - ) - ) - ); } /** @@ -1580,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( @@ -1590,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], ] ); @@ -1604,7 +1581,7 @@ public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void 1, [ ['id' => '7', 'language_id' => 2], - ['id' => '8', 'language_id' => 5], + ['id' => '8', 'language_id' => 4], ] ); } @@ -1629,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( @@ -1639,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, @@ -1653,7 +1632,7 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void 1, [ ['id' => '7', 'language_id' => 2], - ['id' => '8', 'language_id' => 5], + ['id' => '8', 'language_id' => 4], ] ); } @@ -1911,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..a5d5fbae98 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,43 @@ 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(); + $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/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..f407c90a1b 100644 --- a/tests/lib/Persistence/Legacy/Content/MapperTest.php +++ b/tests/lib/Persistence/Legacy/Content/MapperTest.php @@ -194,7 +194,7 @@ public function testExtractContentFromRows(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expected = [$this->getContentExtractReference()]; @@ -234,7 +234,7 @@ public function testExtractContentFromRowsWithNewFieldDefinitions(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expectedContent = $this->getContentExtractReference(); $expectedContent->fields[] = new Field([ @@ -284,7 +284,7 @@ static function (Content\Type\FieldDefinition $fieldDefinition): bool { $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [676 => [2]]); $expectedContent = $this->getContentExtractReference(); $expectedContent->fields = array_values( @@ -330,7 +330,7 @@ public function testExtractContentFromRowsMultipleVersions(): void $this->getEventDispatcher(), $this->getFieldTypeAliasResolver(), ); - $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); + $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture, [439 => [2], 674 => [2]]); self::assertCount( 2, diff --git a/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/ObjectState/Gateway/DoctrineDatabaseTest.php index f364407932..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', ], ], @@ -511,7 +489,7 @@ protected function getDatabaseGateway(): DoctrineDatabase if (!isset($this->databaseGateway)) { $this->databaseGateway = new DoctrineDatabase( $this->getDatabaseConnection(), - $this->getLanguageMaskGenerator() + $this->getLanguageHandler() ); } 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/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]; }); diff --git a/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabaseTest.php index 693e8936ac..bf860ce958 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] ); } @@ -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', ], @@ -1154,7 +1153,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..60532ec7b4 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,7 +22,6 @@ 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\Mapper; use Ibexa\Core\Persistence\Legacy\Content\Type\StorageDispatcherInterface; @@ -37,7 +38,7 @@ public function testCreateGroupFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -93,7 +94,7 @@ public function testTypeFromCreateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -114,7 +115,7 @@ public function testTypeFromUpdateStruct(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -204,7 +205,7 @@ public function testCreateStructFromType(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -272,7 +273,7 @@ public function testExtractGroupsFromRows(): void $mapper = new Mapper( $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -307,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, @@ -337,6 +338,7 @@ public function testExtractTypesFromRowsSingle(): void 'sortField' => 1, 'sortOrder' => 1, 'defaultAlwaysAvailable' => true, + 'languageCodes' => ['eng-US'], ], $types[0] ); @@ -401,7 +403,7 @@ public function testToStorageFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ); @@ -438,7 +440,7 @@ public function testToFieldDefinition(): void $mapper = new Mapper( $converterRegistry, - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $storageDispatcher, $this->getFieldTypeAliasResolver(), ); @@ -456,7 +458,7 @@ protected function getNonConvertingMapper() $mapper = $this->getMockBuilder(Mapper::class) ->setConstructorArgs([ $this->getConverterRegistryMock(), - $this->getMaskGeneratorMock(), + $this->getLanguageHandlerStub(), $this->getStorageDispatcherMock(), $this->getFieldTypeAliasResolver(), ]) @@ -511,9 +513,17 @@ protected function getLoadGroupFixture() return require __DIR__ . '/_fixtures/map_load_group.php'; } - protected function getMaskGeneratorMock() + protected function getLanguageHandlerStub(): LanguageHandler { - return $this->createMock(MaskGenerator::class); + $language = new LanguageValueObject(); + $language->id = 2; + $language->languageCode = 'eng-US'; + + $languageHandler = self::createStub(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/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabaseTest.php index 5ee707838b..b3ff4896c7 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,12 @@ public function testLoadUrlaliasData(): void 'is_original' => '1', 'action' => 'eznode:315', 'action_type' => 'eznode', - 'lang_mask' => '3', 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'language_ids' => [2], + 'ibexa_url_alias_ml0_always_available' => '0', + 'always_available' => '1', ], $row ); @@ -102,7 +126,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 +136,12 @@ public function testLoadUrlaliasDataMultipleLanguages(): void 'is_original' => '1', 'action' => 'eznode:315', 'action_type' => 'eznode', - 'lang_mask' => '6', 'text' => 'dva', 'parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'language_ids' => [2, 4], + 'ibexa_url_alias_ml0_always_available' => '1', + 'always_available' => '0', ], $row ); @@ -132,7 +157,7 @@ public static function providerForTestLoadPathData(): array 2, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -140,11 +165,11 @@ public static function providerForTestLoadPathData(): array 3, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'lang_mask' => '5', 'text' => 'two'], - ['parent' => '2', 'lang_mask' => '3', 'text' => 'dva'], + ['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]], ], ], ], @@ -152,16 +177,16 @@ public static function providerForTestLoadPathData(): array 4, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'lang_mask' => '5', 'text' => 'two'], - ['parent' => '2', 'lang_mask' => '3', 'text' => 'dva'], + ['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', 'lang_mask' => '9', 'text' => 'drei'], - ['parent' => '3', 'lang_mask' => '5', 'text' => 'three'], - ['parent' => '3', 'lang_mask' => '3', 'text' => 'tri'], + ['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]], ], ], ], @@ -197,7 +222,7 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 2, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], ], ], @@ -205,10 +230,10 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 3, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'lang_mask' => '6', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], ], ], @@ -216,14 +241,14 @@ public static function providerForTestLoadPathDataMultipleLanguages(): array 4, [ [ - ['parent' => '0', 'lang_mask' => '3', 'text' => 'jedan'], + ['parent' => '0', 'text_md5' => '6896260129051a949051c3847c34466f', 'always_available' => true, 'text' => 'jedan', 'language_ids' => [2]], ], [ - ['parent' => '2', 'lang_mask' => '6', 'text' => 'dva'], + ['parent' => '2', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', 'always_available' => false, 'text' => 'dva', 'language_ids' => [2, 4]], ], [ - ['parent' => '3', 'lang_mask' => '4', 'text' => 'three'], - ['parent' => '3', 'lang_mask' => '2', 'text' => 'tri'], + ['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]], ], ], ], @@ -348,13 +373,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); - $loadedRow['lang_mask'] = $loadedRow['lang_mask'] & ~$languageId; + $languageIdsAfter = $gateway->loadTranslationLanguageIds($parentId, $textMD5); + $loadedRow['language_ids'] = array_values(array_diff($loadedRow['language_ids'], [$languageId])); - self::assertEquals($reloadedRow, $loadedRow); + self::assertEquals($loadedRow, $reloadedRow); + self::assertEquals( + array_values(array_diff($languageIdsBefore, [$languageId])), + array_values($languageIdsAfter) + ); } /** @@ -362,6 +393,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'); @@ -377,11 +420,12 @@ public function testReparent(): void 'id' => '3', 'is_alias' => '0', 'is_original' => '1', - 'lang_mask' => '3', 'link' => '3', 'parent' => '42', 'text' => 'dva', 'text_md5' => 'c67ed9a09ab136fae610b6a087d82e21', + 'always_available' => '1', + 'language_ids' => [2], ], $gateway->loadRow(42, 'c67ed9a09ab136fae610b6a087d82e21') ); @@ -485,14 +529,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 +548,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 00bd4a6888..99c321dac6 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; @@ -21,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; @@ -3148,6 +3148,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, + 'always_available' => 1, + 'link' => 6, + 'parent' => 0, + 'text' => 'custom', + 'text_md5' => '8b9035807842a4e4dbe009f3f1478127', + ], ['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. */ @@ -5266,9 +5295,6 @@ protected function countRows(): int /** @var LanguageHandler */ protected $languageHandler; - /** @var LanguageMaskGenerator */ - protected $languageMaskGenerator; - /** * @param array $methods * @@ -5285,7 +5311,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 +5326,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($languageHandler); $slugConverter = new SlugConverter( $this->getProcessor(), ['transformation' => 'urlalias'] @@ -5317,7 +5341,6 @@ protected function getHandler(): Handler $this->getSharedGateway(), new ContentGateway\QueryBuilder($connection), $languageHandler, - $languageMaskGenerator, new FieldTypeAliasResolver(new FieldTypeAliasRegistry()) ); @@ -5328,7 +5351,6 @@ protected function getHandler(): Handler $languageHandler, $slugConverter, $contentGateway, - $languageMaskGenerator, self::createStub(TransactionHandler::class) ); } @@ -5347,20 +5369,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 */ @@ -5369,7 +5377,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/UrlAlias/UrlAliasMapperTest.php b/tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasMapperTest.php index 3e4857035a..4f9060d086 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\Language\MaskGenerator as LanguageMaskGenerator; use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\Mapper; use Ibexa\Tests\Core\Persistence\Legacy\Content\LanguageAwareTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -26,22 +25,32 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '100', + 'text_md5' => 'path-root_us', 'lang_mask' => 2, + 'always_available' => false, 'text' => 'root_us', ], [ + 'parent' => '100', + 'text_md5' => 'path-root_gb', 'lang_mask' => 4, + 'always_available' => false, 'text' => 'root_gb', ], ], 1 => [ [ + 'parent' => '101', + 'text_md5' => 'path-one', 'lang_mask' => 4, + 'always_available' => false, 'text' => 'one', ], ], ], 'lang_mask' => 5, + 'always_available' => true, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '0', @@ -53,12 +62,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '102', + 'text_md5' => 'path-two', 'lang_mask' => 3, + 'always_available' => true, 'text' => 'two', ], ], ], 'lang_mask' => 3, + 'always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -70,12 +83,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '103', + 'text_md5' => 'path-three', 'lang_mask' => 6, + 'always_available' => false, 'text' => 'three', ], ], ], 'lang_mask' => 6, + 'always_available' => false, 'is_original' => '1', 'is_alias' => '1', 'alias_redirects' => '1', @@ -87,12 +104,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '104', + 'text_md5' => 'path-four', 'lang_mask' => 1, + 'always_available' => true, 'text' => 'four', ], ], ], 'lang_mask' => 1, + 'always_available' => true, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -104,12 +125,16 @@ class UrlAliasMapperTest extends LanguageAwareTestCase 'raw_path_data' => [ 0 => [ [ + 'parent' => '105', + 'text_md5' => 'path-drei', 'lang_mask' => 8, + 'always_available' => false, 'text' => 'drei', ], ], ], 'lang_mask' => 8, + 'always_available' => false, 'is_original' => '0', 'is_alias' => '0', 'alias_redirects' => '1', @@ -287,9 +312,30 @@ public function testExtractLanguageCodesFromData(): void */ protected function getMapper() { - $languageHandler = $this->getLanguageHandler(); - $languageMaskGenerator = new LanguageMaskGenerator($languageHandler); + 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']); + } + } + } - return new Mapper($languageMaskGenerator); + return new Mapper($this->getLanguageHandler()); + } + + /** + * @return int[] + */ + private function extractLanguageIdsFromMask(int $mask): array + { + $languageIds = []; + for ($languageId = 2; $languageId <= $mask; $languageId *= 2) { + if (($mask & $languageId) === $languageId) { + $languageIds[] = $languageId; + } + } + + return $languageIds; } } 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..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 @@ -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' => 2, + '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' => 2, + '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' => 2, + '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' => 2, + '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_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/Search/Legacy/Content/AbstractTestCase.php b/tests/lib/Search/Legacy/Content/AbstractTestCase.php index ada9f8fea8..0d5a0aca2c 100644 --- a/tests/lib/Search/Legacy/Content/AbstractTestCase.php +++ b/tests/lib/Search/Legacy/Content/AbstractTestCase.php @@ -95,12 +95,12 @@ protected function getContentTypeHandler(): SPIContentTypeHandler new ContentTypeGateway( $this->getDatabaseConnection(), $this->getSharedGateway(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getCriterionVisitor() ), new ContentTypeMapper( $this->getConverterRegistry(), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), self::createStub(StorageDispatcherInterface::class), $this->getFieldTypeAliasResolver(), ), diff --git a/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php b/tests/lib/Search/Legacy/Content/HandlerContentSortTest.php index e149daf545..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; @@ -72,11 +73,19 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\SortClauseHandler\Field( $connection, $this->getLanguageHandler(), - $this->getContentTypeHandler() + $this->getContentTypeHandler(), + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), self::createStub(LocationGateway::class), new Content\WordIndexer\Gateway\DoctrineDatabase( @@ -84,7 +93,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), $this->getContentMapperMock(), diff --git a/tests/lib/Search/Legacy/Content/HandlerContentTest.php b/tests/lib/Search/Legacy/Content/HandlerContentTest.php index 03dcd118c2..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; @@ -135,7 +136,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\CriterionHandler\FullText( $connection, $transformationProcessor, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker, $fullTextSearchConfiguration ), @@ -162,7 +163,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $compositeValueHandler ), $transformationProcessor, - $joinedTablesTracker + $joinedTablesTracker, + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new Content\Common\Gateway\CriterionHandler\ObjectStateId( $connection, @@ -170,8 +175,9 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = ), new Content\Common\Gateway\CriterionHandler\LanguageCode( $connection, - $this->getLanguageMaskGenerator(), - $joinedTablesTracker + $this->getLanguageHandler(), + $joinedTablesTracker, + new LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new Content\Gateway\CriterionHandler\Visibility( $connection, @@ -189,7 +195,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), @@ -198,7 +208,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new Content\Common\Gateway\SortClauseHandler\ContentId($connection), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), self::createStub(LocationGateway::class), new Content\WordIndexer\Gateway\DoctrineDatabase( @@ -206,7 +220,7 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), $this->getContentMapperMock(), diff --git a/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php b/tests/lib/Search/Legacy/Content/HandlerLocationSortTest.php index 8bf28dded3..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; @@ -89,18 +90,26 @@ protected function getContentSearchHandler() new CommonSortClauseHandler\Field( $connection, $this->getLanguageHandler(), - $this->getContentTypeHandler() + $this->getContentTypeHandler(), + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), new Content\WordIndexer\Gateway\DoctrineDatabase( $this->getDatabaseConnection(), $this->getContentTypeHandler(), $this->getDefinitionBasedTransformationProcessor(), new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), self::createStub(ContentMapper::class), @@ -133,6 +142,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..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; @@ -118,19 +119,24 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $compositeValueHandler ), $transformationProcessor, - $joinedTablesTracker + $joinedTablesTracker, + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\FullText( $connection, $transformationProcessor, - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $joinedTablesTracker, $fullTextSearchConfiguration ), new CommonCriterionHandler\LanguageCode( $connection, - $this->getLanguageMaskGenerator(), - $joinedTablesTracker + $this->getLanguageHandler(), + $joinedTablesTracker, + new LanguagePriorityConditionBuilder($connection, $this->getLanguageHandler()) ), new CommonCriterionHandler\LogicalAnd($connection, $joinedTablesTracker), new CommonCriterionHandler\LogicalNot($connection, $joinedTablesTracker), @@ -139,7 +145,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\MatchAll($connection, $joinedTablesTracker), new CommonCriterionHandler\ObjectStateId($connection, $joinedTablesTracker), @@ -147,7 +157,11 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = $connection, $this->getContentTypeHandler(), $this->getLanguageHandler(), - $joinedTablesTracker + $joinedTablesTracker, + new LanguagePriorityConditionBuilder( + $connection, + $this->getLanguageHandler() + ) ), new CommonCriterionHandler\RemoteId($connection, $joinedTablesTracker), new CommonCriterionHandler\SectionId($connection, $joinedTablesTracker), @@ -160,14 +174,18 @@ protected function getContentSearchHandler(array $fullTextSearchConfiguration = new CommonSortClauseHandler\ContentId($connection), ] ), - $this->getLanguageHandler() + $this->getLanguageHandler(), + new LanguagePriorityConditionBuilder( + $this->getDatabaseConnection(), + $this->getLanguageHandler() + ) ), new Content\WordIndexer\Gateway\DoctrineDatabase( $this->getDatabaseConnection(), $this->getContentTypeHandler(), $transformationProcessor, new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseConnection()), - $this->getLanguageMaskGenerator(), + $this->getLanguageHandler(), $this->getFullTextSearchConfiguration() ), self::createStub(ContentMapper::class), @@ -200,6 +218,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/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') + ); + } +}