diff --git a/core/includes/update.inc b/core/includes/update.inc index 9a4a449..acdf83e 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -412,78 +412,59 @@ function update_prepare_d8_language() { ); db_add_field('locales_target', 'customized', $spec); } - if (db_table_exists('locales_source')) { - if (db_field_exists('locales_source', 'location')) { - $table = array( - 'description' => 'Location information for source strings.', - 'fields' => array( - 'lid' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Unique identifier of this location.', - ), - 'sid' => array( - 'type' => 'int', - 'not null' => TRUE, - 'description' => 'Unique identifier of this string.', - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The location type (file, config, path, etc).', - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Type dependent location information (file name, path, etc).', - ), - 'version' => array( - 'type' => 'varchar', - 'length' => 20, - 'not null' => TRUE, - 'default' => 'none', - 'description' => 'Version of Drupal, where the location was found (for locales optimization).', - ), + // Add locales_location table to track string locations. + // When updating in a non-English language, this table is used for + // refreshing JavaScript translations. + if (db_table_exists('locales_source') && !db_table_exists('locales_location')) { + $table = array( + 'description' => 'Location information for source strings.', + 'fields' => array( + 'lid' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => 'Unique identifier of this location.', ), - 'primary key' => array('lid'), - 'foreign keys' => array( - 'locales_source' => array( - 'table' => 'locales_source', - 'columns' => array('sid' => 'lid'), - ), + 'sid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'description' => 'Unique identifier of this string.', ), - 'indexes' => array( - 'string_id' => array('sid'), - 'string_type' => array('sid', 'type'), + 'type' => array( + 'type' => 'varchar', + 'length' => 50, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The location type (file, config, path, etc).', ), - ); + 'name' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Type dependent location information (file name, path, etc).', + ), + 'version' => array( + 'type' => 'varchar', + 'length' => 20, + 'not null' => TRUE, + 'default' => 'none', + 'description' => 'Version of Drupal where the location was found.', + ), + ), + 'primary key' => array('lid'), + 'foreign keys' => array( + 'locales_source' => array( + 'table' => 'locales_source', + 'columns' => array('sid' => 'lid'), + ), + ), + 'indexes' => array( + 'string_id' => array('sid'), + 'string_type' => array('sid', 'type'), + ), + ); - db_create_table('locales_location', $table); - - // Copy locations for JavaScript strings from old table to new one. - // Other locations from Drupal 7 are not actually used for anything. - $result = db_query("SELECT lid, location FROM {locales_source} WHERE location LIKE '%.js%'"); - while ($string = $result->fetchObject()) { - // The field may contain multiple locations glued together by '; '. - $locations = preg_split('~\s*;\s*~', $string->location); - foreach ($locations as $location) { - if (substr($location, -3) == '.js') { - db_insert('locales_location')->fields(array( - 'sid' => $string->lid, - 'type' => 'javascript', - 'name' => $location, - 'version' => VERSION - ))->execute(); - } - } - } - // Drop old locales_source.location field. - db_drop_field('locales_source', 'location'); - } + db_create_table('locales_location', $table); } } } diff --git a/core/modules/locale/lib/Drupal/locale/StringBase.php b/core/modules/locale/lib/Drupal/locale/StringBase.php index aa14078..e2d9bcc 100644 --- a/core/modules/locale/lib/Drupal/locale/StringBase.php +++ b/core/modules/locale/lib/Drupal/locale/StringBase.php @@ -154,14 +154,14 @@ public function getValues(array $fields) { /** * Implements Drupal\locale\StringInterface::getLocation(). */ - public function getLocations($load = TRUE) { - if ($load && !isset($this->locations)) { + public function getLocations($check_only = FALSE) { + if (!isset($this->locations) && !$check_only) { $this->locations = array(); foreach ($this->getStorage()->getLocations(array('sid' => $this->getId())) as $location) { $this->locations[$location->type][$location->name] = $location->lid; } } - return $this->locations; + return isset($this->locations) ? $this->locations : array(); } /** @@ -176,8 +176,8 @@ public function addLocation($type, $name) { * Implements Drupal\locale\StringInterface::hasLocation(). */ public function hasLocation($type, $name) { - $location = $this->getLocations(TRUE); - return isset($location[$type]) ? !empty($location[$type][$name]) : FALSE; + $locations = $this->getLocations(); + return isset($locations[$type]) ? !empty($locations[$type][$name]) : FALSE; } /** diff --git a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php index 127b06c..33138e7 100644 --- a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php +++ b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php @@ -139,10 +139,10 @@ public function save($string) { * The string object. */ protected function updateLocation($string) { - if ($location = $string->getLocations(FALSE)) { + if ($locations = $string->getLocations(TRUE)) { $created = FALSE; - foreach ($location as $type => $type_location) { - foreach ($type_location as $name => $lid) { + foreach ($locations as $type => $location) { + foreach ($location as $name => $lid) { if (!$lid) { $this->dbDelete('locales_location', array('sid' => $string->getId(), 'type' => $type, 'name' => $name)) ->execute(); diff --git a/core/modules/locale/lib/Drupal/locale/StringInterface.php b/core/modules/locale/lib/Drupal/locale/StringInterface.php index b79b2a4..05e3c01 100644 --- a/core/modules/locale/lib/Drupal/locale/StringInterface.php +++ b/core/modules/locale/lib/Drupal/locale/StringInterface.php @@ -167,14 +167,14 @@ public function getValues(array $fields); * A string can have any number of locations since the same string may be * found on different places of Drupal code and configuration. * - * @param bool $load - * (optional) Whether to load the string locations if not loaded yet. - * Defaults to TRUE. + * @param bool $check_only + * (optional) Set to TRUE to get only new locations added during the + * current page request and not loading all existing locations. * * @return array * Location ids indexed by type and name. */ - public function getLocations($load = TRUE); + public function getLocations($check_only = FALSE); /** * Adds a location for this string. diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 5fa8a05..1e8a3e8 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -70,7 +70,7 @@ function locale_schema() { 'length' => 20, 'not null' => TRUE, 'default' => 'none', - 'description' => 'Version of Drupal, where the string was last used (for locales optimization).', + 'description' => 'Version of Drupal where the string was last used (for locales optimization).', ), ), 'primary key' => array('lid'), @@ -152,7 +152,7 @@ function locale_schema() { 'length' => 20, 'not null' => TRUE, 'default' => 'none', - 'description' => 'Version of Drupal, where the location was found (for locales optimization).', + 'description' => 'Version of Drupal where the location was found.', ), ), 'primary key' => array('lid'), @@ -783,6 +783,13 @@ function locale_update_8013() { } /** + * Drop old 'location' field. + */ +function locale_update_8014() { + db_drop_field('locales_source', 'location'); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ 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 89d5196..65c30de 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -135,10 +135,6 @@ 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'))); - - // Check string locations have been upgraded successfully. - $strings = locale_storage()->getStrings(array('type' => 'javascript', 'name' => 'misc/drupal.js')); - $this->assertEqual(count($strings), 8, 'String locations have been successfully upgraded.'); } /**