diff --git a/core/modules/search/search.install b/core/modules/search/search.install index 03f0c590510092d0b56c9dbfe8d92ec812795438..40a569c73ebb2c071edb4b702d77033d5fab2f81 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -24,6 +24,7 @@ function search_schema() { 'length' => '12', 'not null' => TRUE, 'description' => 'The {languages}.langcode of the item variant.', + 'default' => '', ), 'type' => array( 'type' => 'varchar', @@ -70,6 +71,7 @@ function search_schema() { 'length' => '12', 'not null' => TRUE, 'description' => 'The {languages}.langcode of the item variant.', + 'default' => '', ), 'type' => array( 'type' => 'varchar', @@ -174,3 +176,41 @@ function search_update_8000() { 'search_default_module' => 'default_module', )); } + +/** + * Adds the langcode field and indexes to {search_dataset} and {search_index}. + */ +function search_update_8001() { + // In order to upgrade the existing entries to have the correct langcode we + // need to recreate search data through running cron. + db_truncate('search_dataset'); + db_truncate('search_index'); + db_truncate('search_node_links'); + + // Add the fields and indexes. + db_drop_primary_key('search_dataset'); + db_add_field('search_dataset', 'langcode', array( + 'type' => 'varchar', + 'length' => '12', + 'not null' => TRUE, + 'description' => 'The {languages}.langcode of the item variant.', + 'default' => '', + )); + db_add_primary_key('search_dataset', array('sid', 'langcode', 'type')); + + db_drop_primary_key('search_index'); + db_drop_index('search_index', 'sid_type'); + db_add_field('search_index', 'langcode', array( + 'type' => 'varchar', + 'length' => '12', + 'not null' => TRUE, + 'description' => 'The {languages}.langcode of the item variant.', + 'default' => '', + ), + array( + 'indexes' => array( + 'sid_type' => array('sid', 'langcode', 'type'), + ), + )); + db_add_primary_key('search_index', array('word', 'sid', 'langcode', 'type')); +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 34c8c9434a24b2a563cd9a27750cab465927be62..6b669a52104cb26d83c8448e38446fb687823cd7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -7,6 +7,8 @@ namespace Drupal\system\Tests\Upgrade; +use Drupal\Core\Database\DatabaseException; + /** * Tests upgrading a filled database with language data. * @@ -136,6 +138,17 @@ public function testLanguageUpgrade() { $translation_string = db_query("SELECT * FROM {locales_target} WHERE lid = 22 AND language = 'ca'")->fetchObject(); $this->assertEqual($translation_string->translation, implode(LOCALE_PLURAL_DELIMITER, array('1 byte', '@count bytes'))); + + // Ensure that re-indexing search for a specific language does not fail. It + // does not matter if the sid exists on not. This tests whether or not + // search_update_8001() has added the langcode fields. + try { + search_reindex(1, 'node', FALSE, 'ca'); + $this->pass("Calling search_reindex succeeds after upgrade."); + } + catch (DatabaseException $e) { + $this->fail("Calling search_reindex fails after upgrade."); + } } /**