function metatag_update_7012 in Metatag 7
Remove duplicate {metatag} records for non-core entities.
File
- ./
metatag.install, line 1222 - Install, update, and uninstall functions for the metatag module.
Code
function metatag_update_7012() {
// Fix the {metatag} table first.
metatag_update_7015();
if (module_exists('entity_translation')) {
drupal_set_message(t("Entity Translation is enabled, duplicate meta tags will not be removed for custom entities, to avoid accidental dataloss."));
return;
}
$records = db_select('metatag', 'm')
->fields('m', array(
'entity_type',
))
->condition('m.entity_type', array(
'node',
'taxonomy_term',
'user',
), 'NOT IN')
->orderBy('m.entity_type', 'ASC')
->orderBy('m.entity_id', 'ASC')
->distinct()
->execute();
$entity_types = array();
foreach ($records as $record) {
$entity_types[] = $record->entity_type;
// Remove duplicates.
_metatag_remove_dupes($record->entity_type);
}
if (empty($entity_types)) {
drupal_set_message(t('There were no other records to fix.'));
}
}