View source
<?php
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;
}
db_query("UPDATE {system} SET weight = 100 WHERE name = 'notifications_content' AND type = 'module'");
}
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}");
}
function notifications_update_1() {
$ret = array();
$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");
$ret[] = update_sql("UPDATE {notifications} SET cron = 1");
$ret[] = update_sql("UPDATE {notifications_queue} SET cron = 1");
return $ret;
}
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;
}
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);");
$ret[] = update_sql("UPDATE {notifications} SET module = 'notifications'");
$ret[] = update_sql("UPDATE {notifications_queue} SET module = 'notifications'");
return $ret;
}
function notifications_update_4() {
$ret[] = update_sql("UPDATE {system} SET weight = 100 WHERE name = 'notifications_content' AND type = 'module'");
return $ret;
}
function notifications_update_5() {
$ret = array();
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);
}
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;
}
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;
}