You are here

function legal_install in Legal 5

Same name and namespace in other branches
  1. 8 legal.install \legal_install()
  2. 6.8 legal.install \legal_install()
  3. 6.7 legal.install \legal_install()
  4. 2.0.x legal.install \legal_install()

Implementation of hook_install()

This will automatically install the database tables for the legal module for the MySQL database.

If you are using another database, you will have to install the tables by hand, using the queries below as a reference.

Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing, and will need to be removed.

File

./legal.install, line 13

Code

function legal_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $query1 = db_query("CREATE TABLE IF NOT EXISTS {legal_accepted} (\n                        legal_id int(10) NOT NULL auto_increment,\n                        uid int(10) NOT NULL default '0',\n                        tc_id int(10) NOT NULL default '0',\n                        accepted int(11) NOT NULL default '0',\n                        PRIMARY KEY  (legal_id),\n                        KEY uid (uid)\n                        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $query2 = db_query("CREATE TABLE IF NOT EXISTS {legal_conditions} (\n                        tc_id int(10) NOT NULL auto_increment,\n                        conditions longtext NOT NULL,\n                        date int(11) NOT NULL default '0',\n                        extras text,\n                        changes text,\n                        PRIMARY KEY  (tc_id)\n                        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      if ($query1 && $query2) {
        $created = TRUE;
      }
      break;
    default:
      break;
  }
  if ($created) {
    drupal_set_message(t('Legal module installed successfully.'));
  }
  else {
    drupal_set_message(t('Table installation for the Legal module was unsuccessful. The tables may need to be installed by hand. See legal.install file for a list of the installation queries.'), 'error');
  }
  return;
}