You are here

mail_logger.install in Mail Logger 5

Same filename and directory in other branches
  1. 6 mail_logger.install
  2. 7 mail_logger.install

File

mail_logger.install
View source
<?php

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;
  }
}

/**
 * Implementation of hook_enable()
 *
 */
function mail_logger_enable() {

  //in case there's another module that wants to be executed last we will run these queries to restore highest weight for mail_logger
  $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);
}
function mail_logger_uninstall() {
  db_query("DROP TABLE {mail_logger}");
}