From 20ab10429c645d78f0e3d8f0cce1f5165aac6b13 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Wed, 27 Feb 2013 16:26:12 -0500
Subject: [PATCH] =?UTF-8?q?Issue=20#1927546=20by=20alexpott,=20catch,=20G?=
 =?UTF-8?q?=C3=A1bor=20Hojtsy:=20Fixed=20Langcode=20column=20added=20to=20?=
 =?UTF-8?q?search=5Findex()=20and=20search=5Fdataset()=20tables=20but=20th?=
 =?UTF-8?q?ere=20is=20no=20upgrade=20path.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 core/modules/search/search.install            | 40 +++++++++++++++++++
 .../Tests/Upgrade/LanguageUpgradePathTest.php | 13 ++++++
 2 files changed, 53 insertions(+)

diff --git a/core/modules/search/search.install b/core/modules/search/search.install
index 03f0c5905100..40a569c73ebb 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 34c8c9434a24..6b669a52104c 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.");
+    }
   }
 
   /**
-- 
GitLab