function metatag_update_7014 in Metatag 7
Fix {metatag} records that may have been corrupted by #1871020.
File
- ./
metatag.install, line 1519 - Install, update, and uninstall functions for the metatag module.
Code
function metatag_update_7014() {
$records = db_query("SELECT *\n FROM {metatag} m\n WHERE\n m.data LIKE :nolang\n OR m.data LIKE :lang\n OR m.data LIKE :und", array(
':nolang' => 'a:1:{s:0:"";a:%:{s:%;a:%:{%;}}}',
':lang' => 'a:1:{s:2:"__";a:%:{s:%;a:%:{%;}}}',
':und' => 'a:1:{s:3:"___";a:%:{s:%;a:%:{%;}}}',
));
// Nothing to fix.
if ($records
->rowCount() == 0) {
drupal_set_message(t('No corrupt records to fix, this is good news :-)'));
}
else {
foreach ($records as $record) {
// Extract the data and get the first element of the array, this should be
// valid data.
$record->data = reset(unserialize($record->data));
// Update the record.
drupal_write_record('metatag', $record, array(
'entity_type',
'entity_id',
'language',
));
}
drupal_set_message(t('Fixed @count corrupt meta tag record(s).', array(
'@count' => $records
->rowCount(),
)));
}
}