Issue #3030937 by quietone, Gábor Hojtsy, heddn, mikelutz: Ensure language is not Null in translation source queries

merge-requests/55/head
Gábor Hojtsy 2019-08-30 17:38:18 +02:00
parent d881bd0abb
commit 1be0372d40
20 changed files with 137 additions and 32 deletions

View File

@ -48,7 +48,7 @@ class BlockTranslation extends Block {
])
->condition('i18n_mode', 1);
$query->leftjoin($this->blockTable, 'b', ('b.delta = i18n.objectid'));
$query->leftjoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
// The i18n_string module adds a status column to locale_target. It was
// originally 'status' in a later revision it was named 'i18n_status'.

View File

@ -38,7 +38,7 @@ class BlockTranslationTest extends MigrateSqlSourceTestBase {
'pages' => '',
'title' => '',
'cache' => -1,
'i18n_mode' => 0,
'i18n_mode' => 1,
],
[
'bid' => 2,
@ -84,6 +84,16 @@ class BlockTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => 0,
'format' => '',
],
[
'lid' => 2,
'textgroup' => 'block',
'context' => '1',
'objectid' => 'main',
'type' => 'system',
'property' => 'title',
'objectindex' => 0,
'format' => '',
],
];
$tests[0]['source_data']['locales_target'] = [
@ -147,7 +157,29 @@ class BlockTranslationTest extends MigrateSqlSourceTestBase {
$lt['status'] = $lt['i18n_status'];
unset($lt['i18n_status']);
}
$tests[1]['expected_data'] = [
[
'bid' => 2,
'module' => 'system',
'delta' => 'navigation',
'theme' => 'bartik',
'status' => 1,
'weight' => 0,
'region' => 'sidebar_first',
'custom' => '0',
'visibility' => 0,
'pages' => '',
'title' => 'Navigation',
'cache' => -1,
'i18n_mode' => 1,
'lid' => 1,
'translation' => 'fr - Navigation',
'language' => 'fr',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
];
return $tests;
}

View File

@ -36,8 +36,7 @@ class BlockCustomTranslation extends DrupalSqlBase {
->fields('b', ['bid', 'format', 'body'])
->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language'])
->orderBy('b.bid')
->isNotNull('lt.lid');
->orderBy('b.bid');
// Use 'title' for the info field to match the property name in
// i18nStringTable.
@ -49,7 +48,7 @@ class BlockCustomTranslation extends DrupalSqlBase {
$query->condition('i18n.type', 'block');
// Add in the translation for the property.
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}

View File

@ -38,6 +38,12 @@ class BlockCustomTranslationTest extends MigrateSqlSourceTestBase {
'info' => 'box 2 title',
'format' => '2',
],
[
'bid' => 4,
'body' => 'box 2 body',
'info' => 'box 2 title',
'format' => '2',
],
];
$tests[0]['database']['i18n_string'] = [
@ -65,6 +71,14 @@ class BlockCustomTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => 2,
'format' => 2,
],
[
'lid' => 4,
'objectid' => 4,
'type' => 'block',
'property' => 'body',
'objectindex' => 4,
'format' => 2,
],
];
$tests[0]['database']['locales_target'] = [

View File

@ -20,10 +20,9 @@ class ProfileFieldTranslation extends ProfileField {
public function query() {
$query = parent::query();
$query->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language'])
->isNotNull('language');
->fields('lt', ['lid', 'translation', 'language']);
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}

View File

@ -24,6 +24,11 @@ class ProfileFieldTranslationTest extends MigrateSqlSourceTestBase {
$test = [];
$test[0]['source_data'] = [
'profile_fields' => [
[
'fid' => 2,
'title' => 'Test',
'name' => 'profile_test',
],
[
'fid' => 42,
'title' => 'I love migrations',
@ -31,6 +36,12 @@ class ProfileFieldTranslationTest extends MigrateSqlSourceTestBase {
],
],
'i18n_strings' => [
[
'lid' => 1,
'objectid' => 'profile_test',
'type' => 'field',
'property' => 'explanation',
],
[
'lid' => 10,
'objectid' => 'profile_love_migrations',

View File

@ -22,14 +22,12 @@ class FieldLabelDescriptionTranslation extends DrupalSqlBase {
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n', ['property', 'objectid', 'type'])
->fields('lt', ['lid', 'translation', 'language'])
->condition('i18n.type', 'field')
->isNotNull('language')
->isNotNull('translation');
->condition('i18n.type', 'field');
$condition = $query->orConditionGroup()
->condition('property', 'widget_label')
->condition('property', 'widget_description');
$query->condition($condition);
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}

View File

@ -26,9 +26,8 @@ class FieldOptionTranslation extends Field {
'plural',
])
->condition('i18n.type', 'field')
->condition('property', 'option\_%', 'LIKE')
->isNotNull('translation');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
->condition('property', 'option\_%', 'LIKE');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->leftjoin('content_node_field', 'cnf', 'cnf.field_name = i18n.objectid');
$query->addField('cnf', 'field_name');
$query->addField('cnf', 'global_settings');

View File

@ -38,14 +38,12 @@ class FieldLabelDescriptionTranslation extends DrupalSqlBase {
'data',
'deleted',
])
->condition('i18n.textgroup', 'field')
->isNotNull('language')
->isNotNull('translation');
->condition('i18n.textgroup', 'field');
$condition = $query->orConditionGroup()
->condition('textgroup', 'field')
->condition('objectid', '#allowed_values', '!=');
$query->condition($condition);
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->leftjoin('field_config_instance', 'fci', 'fci.bundle = i18n.objectid AND fci.field_name = i18n.type');
return $query;

View File

@ -18,10 +18,9 @@ class FieldOptionTranslation extends Field {
public function query() {
$query = parent::query();
$query->leftJoin('i18n_string', 'i18n', 'i18n.type = fc.field_name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->condition('i18n.textgroup', 'field')
->condition('objectid', '#allowed_values')
->isNotNull('language');
->condition('objectid', '#allowed_values');
// Add all i18n and locales_target fields.
$query
->fields('i18n')

View File

@ -110,6 +110,14 @@ class FieldOptionTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 22,
'objectid' => 'field_test_integer_selectlist',
'type' => 'field',
'property' => 'option_0',
'objectindex' => 0,
'format' => 0,
],
];
$test[0]['source_data']['locales_target'] = [
[

View File

@ -47,6 +47,13 @@ class FieldInstanceLabelDescriptionTranslationTest extends MigrateSqlSourceTestB
'type' => 'taxonomy_forums',
'property' => 'label',
],
[
'lid' => 1,
'textgroup' => 'field',
'objectid' => 'story',
'type' => 'field_text',
'property' => 'label',
],
],
'locales_target' => [
[

View File

@ -118,6 +118,16 @@ class FieldOptionTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => '0',
'format' => '',
],
[
'lid' => '4',
'textgroup' => 'field',
'context' => 'field_rating:#allowed_values:4',
'objectid' => '#allowed_values',
'type' => 'field_rating',
'property' => '4',
'objectindex' => '0',
'format' => '',
],
];
$test[0]['source_data']['locales_target'] = [
[

View File

@ -41,7 +41,6 @@ class MenuLinkTranslation extends MenuLink {
// Add in the property, which is either title or description. Cast the mlid
// to text so PostgreSQL can make the join.
$query->leftJoin(static::I18N_STRING_TABLE, 'i18n', 'CAST(ml.mlid as CHAR(255)) = i18n.objectid');
$query->isNotNull('i18n.lid');
$query->addField('i18n', 'lid');
$query->addField('i18n', 'property');

View File

@ -32,7 +32,6 @@ class TermLocalizedTranslation extends Term {
// Add in the property, which is either name or description.
// Cast td.tid as char for PostgreSQL compatibility.
$query->leftJoin('i18n_strings', 'i18n', 'CAST(td.tid AS CHAR(255)) = i18n.objectid');
$query->isNotNull('i18n.lid');
$query->addField('i18n', 'lid');
$query->addField('i18n', 'property');

View File

@ -23,17 +23,15 @@ class VocabularyTranslation extends DrupalSqlBase {
->fields('v')
->fields('i18n', ['lid', 'type', 'property', 'objectid'])
->fields('lt', ['lid', 'translation'])
->condition('i18n.type', 'vocabulary')
->isNotNull('lt.language');
->condition('i18n.type', 'vocabulary');
$query->addField('lt', 'language', 'lt.language');
// The i18n_strings table has two columns containing the object ID, objectid
// and objectindex. The objectid column is a text field. Therefore, for the
// join to work in PostgreSQL, use the objectindex field as this is numeric
// like the vid field.
$query->join('i18n_strings', 'i18n', 'v.vid = i18n.objectindex');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$a = $query->execute()->fetchAll();
return $query;
}

View File

@ -101,6 +101,14 @@ class TermLocalizedTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => '3',
'format' => 0,
],
[
'lid' => 9,
'objectid' => 4,
'type' => 'term',
'property' => 'description',
'objectindex' => '4',
'format' => 0,
],
];
$tests[0]['source_data']['locales_target'] = [
[

View File

@ -41,6 +41,14 @@ class VocabularyTranslationTest extends MigrateSqlSourceTestBase {
'objectindex' => 2,
'format' => 0,
],
[
'lid' => 3,
'objectid' => 3,
'type' => 'vocabulary',
'property' => 'name',
'objectindex' => 3,
'format' => 0,
],
];
$tests[0][0]['locales_target'] = [
@ -91,6 +99,20 @@ class VocabularyTranslationTest extends MigrateSqlSourceTestBase {
'weight' => 5,
'language' => '',
],
[
'vid' => 3,
'name' => 'vocabulary 3',
'description' => 'description of vocabulary 3',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 0,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 5,
'language' => '',
],
];
$tests[0]['expected_results'] = [

View File

@ -23,10 +23,9 @@ class ProfileFieldOptionTranslation extends ProfileField {
->fields('i18n', ['property', 'objectid'])
->fields('lt', ['translation', 'language'])
->condition('i18n.type', 'field')
->condition('property', 'options')
->isNotNull('translation');
->condition('property', 'options');
$query->leftjoin('i18n_strings', 'i18n', 'pf.name = i18n.objectid');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}

View File

@ -31,6 +31,12 @@ class ProfileFieldOptionTranslationTest extends ProfileFieldTest {
'type' => 'field',
'property' => 'options',
],
[
'lid' => 1,
'objectid' => 'profile_last_name',
'type' => 'field',
'property' => 'options',
],
];
$test[0]['source_data']['locales_target'] = [
[