You are here

function botcha_update_6001 in BOTCHA Spam Prevention 6

Implementation of hook_update_N() Create new 'botcha_points' table and fill it in with defaults

File

./botcha.install, line 144

Code

function botcha_update_6001() {
  $items = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $items[] = update_sql("CREATE TABLE {botcha_points} (\n        form_id varchar(128) NOT NULL,\n        botcha_type varchar(64) default NULL,\n        PRIMARY KEY (form_id)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $succes = TRUE;
      break;
    case 'pgsql':
      $items[] = update_sql("CREATE TABLE {botcha_points} (\n        form_id varchar(128) NOT NULL,\n        botcha_type varchar(64) default NULL,\n        PRIMARY KEY (form_id)\n        );");
      $succes = TRUE;
      break;
    default:
      drupal_set_message(t('Unsupported database.'), 'error');
      $succes = FALSE;
      break;
  }
  if ($succes) {

    // insert some defaults
    $form_ids = _botcha_default_form_ids();
    foreach ($form_ids as $form_id) {
      $items[] = update_sql("INSERT INTO {botcha_points} (form_id, botcha_type) VALUES ('{$form_id}', 'default')");
    }

    // Clear the cache to get updates to menu router and themes.
    cache_clear_all();
  }
  return $items;
}