Commit 023ad507 authored by webchick's avatar webchick

Issue #746240 by c960657, Gábor Hojtsy: Fixed Race condition in locale() -...

Issue #746240 by c960657, Gábor Hojtsy: Fixed Race condition in locale() - duplicates in {locales_source()}.
parent 46faacc8
......@@ -286,6 +286,36 @@ function locale_update_8001() {
}
}
/**
* Removes duplicates in {locales_source}.
*
* Aggressively removes duplicates that has not already been removed by
* locale_update_7004() in Drupal 7.x.
*/
function locale_update_8002() {
// Look up all duplicates.
$results = db_query("SELECT source, context FROM {locales_source} GROUP BY source, context HAVING COUNT(*) > 1");
// For each set of duplicates, select one row that should survive, preferably
// one that has been translated, and delete the rest.
foreach ($results as $row) {
$lid = db_query("SELECT s.lid FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = :source AND s.context = :context ORDER BY translation IS NULL", array(
':source' => $row->source,
':context' => $row->context,
))->fetchField();
db_delete('locales_source')
->condition('source', $row->source)
->condition('context', $row->context)
->condition('lid', $lid, '<>')
->execute();
}
// Finally remove any rows from {locales_target} that refer to non-existing
// lids.
$subquery = db_select('locales_source', 't')->fields('t', array('lid'));
db_delete('locales_target')->condition('lid', $subquery, 'NOT IN')->execute();
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
......
......@@ -663,12 +663,14 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
}
else {
// We don't have the source string, cache this as untranslated.
db_insert('locales_source')
->fields(array(
db_merge('locales_source')
->insertFields(array(
'location' => request_uri(),
'version' => VERSION,
))
->key(array(
'source' => $string,
'context' => (string) $context,
'version' => VERSION,
))
->execute();
$locale_t[$langcode][$context][$string] = TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment