You are here

function metatag_update_replace_config_tag in Metatag 7

Replace one meta tag with another in the configs.

Parameters

string $old_tag: The meta tag that is to be replaced.

string $new_tag: The meta tag that replaces the old one.

4 calls to metatag_update_replace_config_tag()
metatag_opengraph_update_7104 in metatag_opengraph/metatag_opengraph.install
Rename the 'og:video' meta tag to 'og:video:url' in the configs.
metatag_twitter_cards_update_7101 in metatag_twitter_cards/metatag_twitter_cards.install
Rename the 'twitter:image:src' meta tag back to 'twitter:image', part 2.
metatag_update_7031 in ./metatag.install
Rename the 'copyright' meta tag to 'rights', part 2.
metatag_update_7110 in ./metatag.install
Rename the 'icon_any' meta tag to 'mask-icon' in the configs.

File

./metatag.install, line 691
Install, update, and uninstall functions for the metatag module.

Code

function metatag_update_replace_config_tag($old_tag, $new_tag) {

  // Find all {metatag_config} records that contained an entry for the old meta
  // tag.
  $records = db_select('metatag_config', 'm')
    ->fields('m', array(
    'cid',
    'config',
  ))
    ->condition('m.config', '%' . db_like('"' . $old_tag . '"') . '%', 'LIKE')
    ->execute();

  // This message will be returned if nothing needed to be updated.
  $none_message = t('No Metatag configuration records needed to have the "@tag" meta tag fixed. That said, there may be other configurations elsewhere that do need updating.', array(
    '@tag' => $old_tag,
  ));

  // Loop over the values and correct them.
  if ($records
    ->rowCount() == 0) {
    $message = $none_message;
  }
  else {
    $keys = array(
      'cid',
    );

    // Loop over the values and correct them.
    $counter = 0;
    foreach ($records as $record) {
      $record->config = unserialize($record->config);
      if (isset($record->config[$old_tag])) {
        $record->config[$new_tag] = $record->config[$old_tag];
        unset($record->config[$old_tag]);
        drupal_write_record('metatag_config', $record, $keys);
        $counter++;
      }
    }
    if ($counter == 0) {
      $message = $none_message;
    }
    else {
      $message = t('Converted the "@old_tag" meta tag for @count configurations to the new "@new_tag" meta tag.', array(
        '@old_tag' => $old_tag,
        '@new_tag' => $new_tag,
        '@count' => $counter,
      ));
    }
  }

  // Clear all Metatag caches.
  cache_clear_all('*', 'cache_metatag', TRUE);
  drupal_static_reset('metatag_config_load_with_defaults');
  drupal_static_reset('metatag_entity_supports_metatags');
  drupal_static_reset('metatag_config_instance_info');
  drupal_static_reset('metatag_get_info');
  ctools_include('export');
  ctools_export_load_object_reset('metatag_config');
  return $message;
}