You are here

function customfilter_update_6118 in Custom filter 7

Same name and namespace in other branches
  1. 7.2 customfilter.install \customfilter_update_6118()

Implements hook_update_N().

1 string reference to 'customfilter_update_6118'
customfilter_update_6119 in ./customfilter.install
Implements hook_update_N().

File

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

Code

function customfilter_update_6118() {
  $ret = array();
  if (!variable_get('customfilter_update_6118', FALSE)) {
    if (!isset($sandbox['progress'])) {
      $sandbox['progress'] = 0;
      $sandbox['max'] = db_query("SELECT COUNT(*) FROM {customfilter_filter}")
        ->fetchField();
    }
    if ($sandbox['max']) {
      $result = db_query_range("SELECT * FROM {customfilter_filter} ORDER BY fid ASC");
      while ($row = db_fetch_object($result)) {

        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query(
           "UPDATE {customfilter_filter} SET type = '%s' WHERE fid = %d", 'filter' . $sandbox['progress'], $row->fid) */
        db_update('customfilter_filter')
          ->fields(array(
          'type' => 'filter' . $sandbox['progress'],
        ))
          ->condition('fid', $row->fid)
          ->execute();
        $sandbox['progress']++;
      }
    }
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] == 1) {
    variable_set('customfilter_update_6118', TRUE);
    if (!empty($sandbox['max'])) {
      drupal_set_message('The filter machine-readable names have been changed because the previous update did not set them correctly.');
    }
  }

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.
  return t('TODO Add a descriptive string here to show in the UI.');
}