You are here

function nodewords_update_1 in Nodewords: D6 Meta Tags 5

Update: nodewords.module < version 1.9 to nodewords.module version >= 1.9

File

./nodewords.install, line 86

Code

function nodewords_update_1() {
  $items = array();

  // variable: nodewords_global_keywords => nodewords['global']['keywords']
  $keywords = variable_get('nodewords_global_keywords', '');
  variable_del('nodewords_global_keywords');
  $settings = variable_get('nodewords', array());
  if ($keywords != '') {
    $settings['global']['keywords'] = $keywords;
    variable_set('nodewords', $settings);
  }

  // table: nid, nodewords => nid, abstract, copyright, description, keywords
  $result = db_query('SELECT * FROM {nodewords} LIMIT 1');
  if (db_num_rows($result) == 0) {
    $items[] = update_sql('DROP TABLE {nodewords}');
    $items[] = _nodewords_update_create_table();
  }
  else {
    $row = db_fetch_array($result);
    if (isset($row['nodewords'])) {

      // assume that the table update only needs to be run if it contains a "nodewords" column
      switch ($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
          $items[] = update_sql('ALTER TABLE {nodewords} ADD abstract varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} ADD copyright varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} ADD description varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} CHANGE nodewords keywords varchar(250)');
          break;
        case 'pgsql':
          $items[] = update_sql('ALTER TABLE {nodewords} ADD abstract varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} ADD copyright varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} ADD description varchar(250)');
          $items[] = update_sql('ALTER TABLE {nodewords} RENAME nodewords TO keywords');
          break;
      }
    }
  }

  // permission: 'administer node keywords' => 'administer meta tags'

  /* TODO: does this work? maybe not so important... let users reset the permissions themselves
    $old = 'administer node keywords';
    $new = 'administer meta tags';
    $result = db_query("SELECT p.rid, p.perm, r.name FROM {permission} p INNER JOIN {role} r ON p.rid = r.rid WHERE p.perm LIKE '%$old%'");
    while ($role = db_fetch_object($result)) {
      $rid = $role->rid;
      $name = $role->name;
      $perm = str_replace($old, $new, $role->perm);
      $items[] = update_sql("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm, $rid);
    }
    */
  return $items;
}