You are here

function customfilter_update_6120 in Custom filter 6

Implements hook_update_N().

File

./customfilter.install, line 470
Installation file for Custom filter.

Code

function customfilter_update_6120(&$sandbox) {
  $ret = array();
  db_change_field($ret, 'customfilter_filter', 'type', 'id', array(
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  ));
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_result(db_query("SELECT COUNT(*) FROM {customfilter_filter}"));
    $sandbox['current_pid'] = 0;
  }
  if ($sandbox['max']) {
    $result = db_query_range("SELECT * FROM {customfilter_filter} WHERE fid > %d ORDER BY fid ASC", $sandbox['current_pid'], 0, 10);
    while ($row = db_fetch_object($result)) {
      $ret[] = update_sql("UPDATE {customfilter_filter} SET id = '%s' WHERE fid = %d", 'filter' . $sandbox['progress'], $row->fid);
      $sandbox['current_pid'] = $row->fid;
      $sandbox['progress']++;
    }
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] == 1 && !empty($sandbox['max'])) {
    $ret[] = array(
      'success' => TRUE,
      'query' => 'The filter machine-readable names have been changed because the previous update did not set them correctly',
    );
  }
  variable_set('customfilter_update', 6120);
  return $ret;
}