You are here

function nofollowlist_update_7000 in Nofollow List 7

Upgrade settings of input formats to Drupal 7 format.

File

./nofollowlist.install, line 6

Code

function nofollowlist_update_7000() {
  if (!db_table_exists('d6_upgrade_filter')) {
    return t('Setting of input formats from Drupal 6 are not available, no upgrade required.');
  }
  $existing = db_select('filter', 'f')
    ->fields('f', array(
    'format',
  ))
    ->condition('module', 'nofollowlist')
    ->condition('name', 'filter_nofollow')
    ->execute()
    ->fetchAllAssoc('format');
  $settings = serialize(array(
    'nofollowlist_option' => variable_get('nofollowlist_option', 'black'),
    'nofollowlist_hosts' => variable_get('nofollowlist_hosts', 'en.wikipedia.org'),
  ));
  $results = db_select('d6_upgrade_filter', 'd6')
    ->fields('d6')
    ->condition('module', 'nofollowlist')
    ->execute();
  foreach ($results as $filter) {
    if (!empty($existing[$filter->format])) {
      continue;
    }
    db_insert('filter')
      ->fields(array(
      'format' => $filter->format,
      'module' => 'nofollowlist',
      'name' => 'filter_nofollow',
      'weight' => $filter->weight,
      'settings' => $settings,
      'status' => 1,
    ))
      ->execute();
  }
  db_delete('d6_upgrade_filter')
    ->condition('module', 'nofollowlist')
    ->execute();
  variable_del('nofollowlist_option');
  variable_del('nofollowlist_hosts');
}