You are here

function seochecklist_update_5201 in SEO Checklist 5.2

Convert the date_changed and option_checked fields into one UNIX completed field.

File

./seochecklist.install, line 199
Install, update and uninstall functions for the seochecklist module.

Code

function seochecklist_update_5201() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {seo_checklist} ADD completed int unsigned NOT NULL default '0'");
      break;
    case 'pgsql':
      db_add_column($ret, 'seo_checklist', 'completed', 'int', array(
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ));
      break;
  }
  $query = db_query("SELECT id, date_changed FROM {seo_checklist} WHERE option_checked <> 0");
  while ($record = db_fetch_object($query)) {
    $record->changed = strtotime($record->date_changed);
    if (!$record->changed) {
      $record->changed = time();
    }
    $ret[] = update_sql("UPDATE {seo_checklist} SET completed = {$record->changed} WHERE id = {$record->id}");
  }
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP date_changed");
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP option_checked");
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP checked_module");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP COLUMN date_changed");
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP COLUMN option_checked");
      $ret[] = update_sql("ALTER TABLE {seo_checklist} DROP COLUMN checked_module");
      break;
  }
  return $ret;
}