Problem/Motivation
After doing a "Refresh strings" for the Taxonomy text group my database table {locales_source} is corrupted with incorrect records. Example:
record: {location: 'taxonomy:term:167:name', textgroup: 'taxonomy', source: 'some term', context: 'term:167:name'}
while in the taxonomy_term_data table the record with tid='167' is defined as 'other term'.
Source of the error
Debugging this error I found that the array_merge_recursive in function i18n_string_object_type_string_list does not retain the keys as they are seen as being numeric.
function i18n_string_object_type_string_list($type) {
$strings = array();
if ($objects = module_invoke_all('i18n_string_objects', $type)) {
foreach ($objects as $object) {
if ($object_strings = i18n_object($type, $object)->get_properties()) {
$strings = array_merge_recursive($strings, $object_strings);
}
}
}
return $strings;
}
After 2 loops $strings contains:
$strings Array [1]
taxonomy Array [1]
term Array [3]
129 Array [2]
name Array [4]
string (string:19) Vakantiehuis / Gîte
title (string:4) Name
format null
name Array [4]
0 (string:8) taxonomy
1 (string:4) term
2 (string:3) 129
3 (string:4) name
description Array [4]
130 Array [2]
name Array [4]
string (string:8) Bungalow
title (string:4) Name
format null
name Array [4]
0 (string:8) taxonomy
1 (string:4) term
2 (string:3) 136
3 (string:4) name
description Array [4]
You can see how the 2nd object is indexed with 130, where it should be 136.
Note that this will not only fail for taxonomy term names,but also for term descriptions, and probably other text groups as well, as most will have numeric keys.
Proposed resolution
I don't see any easy solution. drupal_array_merge_deep() won't help here, see the comments of drupal_array_merge_deep_array... If the keys were not really used, we could try to make them real strings by prefixing an 'id:' to all keys. But function i18n_string_refresh_string_list does use them, so that would need to be changed there as well (removing the 'id:').
Another option is to write your own version of the recursive merge...
Comment | File | Size | Author |
---|---|---|---|
#2 | 1218120.patch | 5.94 KB | fietserwin |
Comments
Comment #1
fietserwinComment #2
fietserwinI attached a patch based on creating a local version of array_merge_recursive() that is based on the drupal version of it but that keeps integer keys. I think that I changed all involved calls to array_merge_recursive to call the local version. (again, some white space removal made it into the patch, please ignore that on reviewing)
Comment #3
Jose Reyero CreditAttribution: Jose Reyero commentedThe patch seems to work. Just renamed the function to fit into i18n_string module.
Thanks.