You are here

notifications.install in Notifications 5

File

notifications.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function notifications_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {notifications} (\n                `sid` int(10) unsigned NOT NULL auto_increment,\n                `uid` int(11) NOT NULL,\n                `type` varchar(255) default NULL,\n                `event_type` varchar(255) default NULL,\n                `conditions` int(10) unsigned NOT NULL,\n                `send_interval` int(11) default NULL,\n                `send_method` varchar(255) NOT NULL,\n                `cron` TINYINT UNSIGNED NOT NULL DEFAULT 0,\n                `module` VARCHAR(255) DEFAULT NULL,\n                `status` int NOT NULL default 1,\n                PRIMARY KEY  (`sid`)\n              )/*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE  {notifications_fields} (\n                    `sid` int(10) unsigned NOT NULL,\n                    `field` varchar(255) NOT NULL,\n                    `value` varchar(255) NOT NULL,\n                    PRIMARY KEY  (`sid`,`field`)\n                  )/*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE  {notifications_queue} (\n                    `sqid` int(10) unsigned NOT NULL auto_increment,\n                    `eid` int(11) unsigned NOT NULL default '0',\n                    `sid` int(11) unsigned NOT NULL default '0',\n                    `uid` int(11) default NULL,\n                    `language` varchar(255) default NULL,\n                    `type` varchar(255) default NULL,\n                    `send_interval` int(11) default NULL,\n                    `send_method` varchar(255) default NULL,\n                    `sent` int(10) unsigned NOT NULL default '0',\n                    `created` int(10) unsigned NOT NULL default '0',\n                    `cron` TINYINT UNSIGNED NOT NULL DEFAULT 0,\n                    `conditions` INTEGER UNSIGNED NOT NULL DEFAULT 0,\n                    `module` VARCHAR(255) DEFAULT NULL,\n                    PRIMARY KEY  (`sqid`)\n                  )/*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE  {notifications_event} (\n                    `eid` int(11) unsigned NOT NULL auto_increment,\n                    `module` varchar(255) default NULL,\n                    `type` varchar(255) default NULL,\n                    `action` varchar(255) default NULL,\n                    `oid` int(11) unsigned NOT NULL default '0',\n                    `language` varchar(255) default NULL,\n                    `uid` int(11) default NULL,\n                    `params` text,\n                    `created` int(11) unsigned NOT NULL default '0',\n                    PRIMARY KEY  (`eid`)\n                  )/*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE  {notifications_sent} (\n                    `uid` int(11) NOT NULL default '0',\n                    `send_interval` int(10) NOT NULL default '0',\n                    `send_method` varchar(50) NOT NULL,\n                    `sent` int(10) unsigned NOT NULL default '0',\n                    PRIMARY KEY  (`uid`,`send_interval`,`send_method`)\n                  )/*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {notifications} (\n                sid serial,\n                uid int NOT NULL,\n                type varchar(255) DEFAULT NULL,\n                event_type varchar(255) DEFAULT NULL,\n                conditions int NOT NULL,\n                send_interval int DEFAULT NULL,\n                send_method varchar(255) NOT NULL,\n                cron smallint NOT NULL DEFAULT 0,\n                module varchar(255) DEFAULT NULL,\n                status smallint NOT NULL DEFAULT 1,\n                PRIMARY KEY (sid)\n              )");
      db_query("CREATE TABLE  {notifications_fields} (\n                    sid int NOT NULL,\n                    field varchar(255) NOT NULL,\n                    value varchar(255) NOT NULL,\n                    PRIMARY KEY (sid,field)\n                  )");
      db_query("CREATE TABLE  {notifications_queue} (\n                    sqid serial,\n                    eid int NOT NULL DEFAULT '0',\n                    sid int NOT NULL DEFAULT '0',\n                    uid int DEFAULT NULL,\n                    language varchar(255) DEFAULT NULL,\n                    type varchar(255) DEFAULT NULL,\n                    send_interval int DEFAULT NULL,\n                    send_method varchar(255) DEFAULT NULL,\n                    sent int NOT NULL DEFAULT '0',\n                    created int NOT NULL DEFAULT '0',\n                    cron smallint NOT NULL DEFAULT 0,\n                    conditions smallint NOT NULL DEFAULT 0,\n                    module varchar(255) DEFAULT NULL,\n                    PRIMARY KEY (sqid)\n                  )");
      db_query("CREATE TABLE  {notifications_event} (\n                    eid serial,\n                    module varchar(255) DEFAULT NULL,\n                    type varchar(255) DEFAULT NULL,\n                    action varchar(255) DEFAULT NULL,\n                    oid int NOT NULL DEFAULT '0',\n                    language varchar(255) DEFAULT NULL,\n                    uid int DEFAULT NULL,\n                    params text,\n                    created int NOT NULL DEFAULT '0',\n                    PRIMARY KEY (eid)\n                  )");
      db_query("CREATE TABLE  {notifications_sent} (\n                    uid int NOT NULL DEFAULT '0', \n                    send_interval int NOT NULL DEFAULT '0',\n                    send_method varchar(50) NOT NULL,\n                    sent int NOT NULL DEFAULT '0',\n                    PRIMARY KEY (uid,send_interval,send_method)\n                  )");
      break;
  }

  // Module weight. It must run after most modules, to make sure they've done their work before we add the notifications queries
  db_query("UPDATE {system} SET weight = 100 WHERE name = 'notifications_content' AND type = 'module'");
}

/**
 * Implementation of hook_uninstall().
 */
function notifications_uninstall() {
  db_query("DROP TABLE {notifications}");
  db_query("DROP TABLE {notifications_fields}");
  db_query("DROP TABLE {notifications_queue}");
  db_query("DROP TABLE {notifications_event}");
  db_query("DROP TABLE {notifications_sent}");
}

/**
 * Update: Add cron flag for processing
 */
function notifications_update_1() {
  $ret = array();

  // Add field
  $ret[] = update_sql("ALTER TABLE {notifications} ADD COLUMN `cron` TINYINT UNSIGNED NOT NULL DEFAULT 0");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} ADD COLUMN `cron` TINYINT UNSIGNED NOT NULL DEFAULT 0");

  // Populate field, this is new so all stored rows till now should be intended for cron processing
  $ret[] = update_sql("UPDATE {notifications} SET cron = 1");
  $ret[] = update_sql("UPDATE {notifications_queue} SET cron = 1");
  return $ret;
}

/**
 * Update:
 * - Remove unused table and fields
 * - Add conditions field for mysql4 compatibility
 * - Updated variable name
 */
function notifications_update_2() {
  $ret = array();
  $ret[] = update_sql("DROP TABLE {notifications_user}");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} DROP COLUMN `name`;");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} DROP COLUMN `field`;");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} DROP COLUMN `value`;");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} DROP COLUMN `author`;");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} ADD COLUMN `conditions` INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER `cron`");
  variable_set('notifications_default_auto', variable_get('notifications_autoset', 0));
  variable_del('notifications_autoset');
  return $ret;
}

/**
 * - Added status and module fields
 */
function notifications_update_3() {
  $ret[] = update_sql("ALTER TABLE {notifications} ADD COLUMN `module` VARCHAR(255) AFTER `cron`;");
  $ret[] = update_sql("ALTER TABLE {notifications} ADD COLUMN `status` INT  NOT NULL DEFAULT 1 AFTER `module`;");
  $ret[] = update_sql("ALTER TABLE {notifications_queue} ADD COLUMN `module` VARCHAR(255);");

  // Set default module to 'notifications'
  $ret[] = update_sql("UPDATE {notifications} SET module = 'notifications'");
  $ret[] = update_sql("UPDATE {notifications_queue} SET module = 'notifications'");
  return $ret;
}

/**
 * Change module weight
 */
function notifications_update_4() {
  $ret[] = update_sql("UPDATE {system} SET weight = 100 WHERE name = 'notifications_content' AND type = 'module'");
  return $ret;
}

/**
 * Update content type and taxonomy options
 */
function notifications_update_5() {
  $ret = array();

  // Content types
  if ($omitted = variable_get('notifications_omitted_content_types', array())) {
    $allowed = array();
    $types = node_get_types();
    foreach ($types as $type => $info) {
      if (!isset($omitted[$type])) {
        $allowed[$type] = $type;
      }
    }
    variable_set('notifications_content_types', $allowed);
  }

  // Vocabularies
  if ($omitted = variable_get('notifications_omitted_taxa', array())) {
    $vocabularies = taxonomy_get_vocabularies();
    foreach ($omitted as $vid) {
      unset($vocabularies[$vid]);
    }
    variable_set('notifications_tags_vocabularies', array_combine(array_keys($vocabularies), array_keys($vocabularies)));
  }
  return $ret;
}

/**
 * Update ui display options from plaintext to array
 */
function notifications_update_6() {
  $ret = array();
  foreach (node_get_types() as $type => $info) {
    $option = variable_get('notifications_node_ui_' . $type, 0);
    if ($option && !is_array($option)) {
      variable_set('notifications_node_ui_' . $type, array(
        $option,
      ));
    }
  }
  return $ret;
}

Functions

Namesort descending Description
notifications_install Implementation of hook_install().
notifications_uninstall Implementation of hook_uninstall().
notifications_update_1 Update: Add cron flag for processing
notifications_update_2 Update:
notifications_update_3 Added status and module fields
notifications_update_4 Change module weight
notifications_update_5 Update content type and taxonomy options
notifications_update_6 Update ui display options from plaintext to array