You are here

function nodewords_update_6161 in Nodewords: D6 Meta Tags 6

Implements hook_update_N().

File

./nodewords.install, line 1250
Installation file for nodewords.module.

Code

function nodewords_update_6161(&$sandbox) {
  $ret = array();
  drupal_load('module', 'nodewords');
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_result(db_query("SELECT COUNT(*) FROM {nodewords_custom}"));
    $sandbox['current_pid'] = 0;
  }
  if ($sandbox['max']) {
    $metatags = db_query_range("SELECT * FROM {nodewords_custom} WHERE pid > %d", $sandbox['current_pid'], 0, 10);
    while ($metatag = db_fetch_object($metatags)) {
      $ret[] = update_sql("UPDATE {nodewords} SET id = '" . $metatag->pid . "' WHERE id = '" . db_escape_string(drupal_truncate_bytes($metatag->path, 255)) . "'");
      $sandbox['current_pid'] = $metatag->pid;
      $sandbox['progress']++;
    }
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] == 1) {
    $ret[] = array(
      'success' => TRUE,
      'query' => 'Corrected the values saved in the database',
    );
  }
  return $ret;
}