You are here

function mail_logger_install in Mail Logger 5

Same name and namespace in other branches
  1. 6 mail_logger.install \mail_logger_install()
  2. 7 mail_logger.install \mail_logger_install()

File

./mail_logger.install, line 4

Code

function mail_logger_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {mail_logger} (\n        mlid int(10) unsigned NOT NULL auto_increment,\n        mailkey varchar(255) NOT NULL,\n        `to` varchar(255) NOT NULL,\n        `subject` varchar(255) NOT NULL,\n        body text NOT NULL,\n        `from` varchar(255) NOT NULL,\n        headers text NOT NULL,\n        date_sent int(10) unsigned NOT NULL,\n        PRIMARY KEY  (mlid),\n        KEY `to` (`to`),\n        KEY `from` (`from`),\n        KEY `subject` (`subject`(20)),\n        KEY date_sent (date_sent)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");

      //because modules can modify the mail body, mail_logger must be executed last in order to capture

      //the final mail parameters by setting the weight of mail_logger to something ridicolous
      $max_weight = db_result(db_query("SELECT weight FROM {system} WHERE name LIKE 'mail_logger'"));
      db_query("UPDATE {system} SET weight = %d WHERE name LIKE 'mail_logger' LIMIT 1", $max_weight + 999);
      break;
    case 'pgsql':
      db_query("CREATE TABLE {mail_logger} (\n        mlid int(10) unsigned NOT NULL auto_increment,\n        mailkey varchar(255) NOT NULL,\n        `to` varchar(255) NOT NULL,\n        `subject` varchar(255) NOT NULL,\n        body text NOT NULL,\n        `from` varchar(255) NOT NULL,\n        headers text NOT NULL,\n        date_sent int(10) unsigned NOT NULL,\n        PRIMARY KEY  (mlid),\n        KEY `to` (`to`),\n        KEY `from` (`from`),\n        KEY `subject` (`subject`(20)),\n        KEY date_sent (date_sent)\n      )");

      //because modules can modify the mail body, mail_logger must be executed last in order to capture

      //the final mail parameters by setting the weight of mail_logger to something ridicolous
      $max_weight = db_result(db_query("SELECT weight FROM {system} WHERE name LIKE 'mail_logger'"));
      db_query("UPDATE {system} SET weight = %d WHERE name LIKE 'mail_logger' LIMIT 1", $max_weight + 999);
      break;
  }
}