function metatags_quick_update_7005 in Meta tags quick 7.2
Ensure the field language of path based fields is set to LANGUAGE_NONE.
File
- ./
metatags_quick.install, line 132 - Defines schema for metatags_quick fields
Code
function metatags_quick_update_7005(&$sandbox) {
// Use a sandbox to be able to process huge amounts of data.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_id'] = 0;
// Count items.
$sandbox['max'] = db_query("SELECT COUNT(DISTINCT id) FROM {metatags_quick_path_based}")
->fetchField();
}
// Process twenty entities at a time.
$limit = 20;
// Fetch the entities to process in this run.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'metatags_path_based')
->propertyOrderBy('id')
->propertyCondition('id', $sandbox['current_id'], '>')
->range(0, $limit);
$result = $query
->execute();
if (isset($result['metatags_path_based'])) {
$item_ids = array_keys($result['metatags_path_based']);
$items = entity_load('metatags_path_based', $item_ids);
foreach ($items as $item) {
// Iterate over all fields and ensure there's used only LANGUAGE_NONE as
// language.
$field_infos = field_info_instances('metatags_path_based', 'metatags_path_based');
foreach ($field_infos as $field_name => $field_info) {
foreach ($item->{$field_name} as $language => $values) {
// If the language is different from LANGUAGE_NONE move the values to
// LANGUAGE_NONE and remove the "invalid" language.
if ($language != LANGUAGE_NONE) {
$item->{$field_name}[LANGUAGE_NONE] = $values;
unset($item->{$field_name}[$language]);
}
}
}
entity_save('metatags_path_based', $item);
$sandbox['progress']++;
$sandbox['current_mlid'] = $item->id;
}
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}