You are here

function feedapi_update_6106 in FeedAPI 6

Convert checked to next_refresh_time and consolidate skip and next_refresh_time, add an index on next_refresh_time, make next_refresh_time unsigned.

File

./feedapi.install, line 225
Install file for FeedAPI module.

Code

function feedapi_update_6106() {
  $spec = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
  );
  db_change_field($ret, 'feedapi', 'checked', 'next_refresh_time', $spec);

  // Convert the value in next_refresh_time from the last time a feed has been
  // to the next time it should be checked.
  $ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = (next_refresh_time + ' . FEEDAPI_CRON_DEFAULT_REFRESH_TIME . ')');

  // Set next_refresh_time to FEEDAPI_CRON_NEVER_REFRESH where skip = 1.
  $ret[] = update_sql('UPDATE {feedapi} SET next_refresh_time = ' . FEEDAPI_CRON_NEVER_REFRESH . ' WHERE skip = 1');

  // Drop skip row
  db_drop_field($ret, 'feedapi', 'skip');

  // Update all settings.
  $node_types = node_get_types('types');

  // Update all node type settings.
  foreach ($node_types as $node_type) {
    if (feedapi_enabled_type($node_type)) {
      if ($settings = feedapi_get_settings($node_type)) {
        $settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME;
        unset($settings['skip']);
        _feedapi_store_settings(array(
          'node_type' => $node_type,
        ), $settings);
      }
    }
  }

  // Update all node settings.
  $result = db_query('SELECT n.type, f.vid FROM {node} n JOIN {feedapi} f ON f.nid = n.nid');
  while ($node = db_fetch_object($result)) {
    if ($settings = feedapi_get_settings($node->type, $node->vid)) {
      $settings['refresh_time'] = $settings['skip'] ? FEEDAPI_CRON_NEVER_REFRESH : FEEDAPI_CRON_DEFAULT_REFRESH_TIME;
      unset($settings['skip']);
      _feedapi_store_settings(array(
        'node_type' => $node->type,
        'vid' => $node->vid,
      ), $settings);
    }
  }
  return $ret;
}