You are here

function captcha_update_1 in CAPTCHA 6

Same name and namespace in other branches
  1. 5.3 captcha.install \captcha_update_1()
  2. 6.2 captcha.install \captcha_update_1()

Implementation of hook_update_N()

File

./captcha.install, line 56

Code

function captcha_update_1() {
  $items = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $items[] = update_sql("CREATE TABLE {captcha_points} (\n        form_id varchar(128) NOT NULL,\n        module varchar(64) default NULL,\n        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 {captcha_points} (\n        form_id varchar(128) NOT NULL,\n        module varchar(64) default NULL,\n        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 = array(
      'comment_form',
      'contact_mail_user',
      'contact_mail_page',
      'user_register',
      'user_pass',
    );
    foreach ($form_ids as $form_id) {
      $items[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('{$form_id}', NULL, NULL)");
    }
  }
  return $items;
}