View source
<?php
function notifications_schema() {
$schema['notifications'] = array(
'fields' => array(
'sid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'disp-width' => '10',
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'disp-width' => '11',
),
'type' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'event_type' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'conditions' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'disp-width' => '10',
),
'send_interval' => array(
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
),
'send_method' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'cron' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'disp-width' => '3',
),
'module' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'disp-width' => '11',
),
'destination' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
),
'primary key' => array(
'sid',
),
);
$schema['notifications_fields'] = array(
'fields' => array(
'sid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'disp-width' => '10',
),
'field' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'value' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'intval' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
),
'primary key' => array(
'sid',
'field',
),
);
$schema['notifications_event'] = array(
'fields' => array(
'eid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'disp-width' => '11',
),
'module' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'type' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'action' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'oid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
'language' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'uid' => array(
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
),
'params' => array(
'type' => 'text',
'not null' => FALSE,
),
'created' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
'counter' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
),
'primary key' => array(
'eid',
),
);
$schema['notifications_queue'] = array(
'fields' => array(
'sqid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'disp-width' => '10',
),
'eid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
'sid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
'uid' => array(
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
),
'language' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'type' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'send_interval' => array(
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
),
'send_method' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'sent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'created' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'cron' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'disp-width' => '3',
),
'conditions' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'module' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'destination' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
),
'primary key' => array(
'sqid',
),
);
$schema['notifications_sent'] = array(
'fields' => array(
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
),
'send_interval' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'send_method' => array(
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
),
'sent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
),
'primary key' => array(
'uid',
'send_interval',
'send_method',
),
);
return $schema;
}
function notifications_install() {
drupal_install_schema('notifications');
}
function notifications_uninstall() {
drupal_uninstall_schema('notifications');
foreach (array(
'events',
'send_intervals',
'sender',
'sendself',
'send_immediate',
) as $name) {
variable_del("notifications_{$name}");
}
}
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;
}
function notifications_update_6001() {
$ret = array();
variable_set('notifications_send_immediate', variable_get('notifications_send_inmediate', 0));
variable_del('notifications_send_inmediate');
return $ret;
}
function notifications_update_6002() {
$ret = array();
db_add_field($ret, 'notifications_event', 'counter', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
));
db_add_field($ret, 'notifications', 'destination', array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
));
db_add_field($ret, 'notifications_queue', 'destination', array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
));
$ret[] = update_sql("UPDATE {notifications_event} e SET counter = (SELECT COUNT(*) FROM {notifications_queue} q WHERE q.eid = e.eid)");
return $ret;
}
function notifications_update_6003() {
$ret = array();
db_add_field($ret, 'notifications_fields', 'intval', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '11',
));
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('UPDATE {notifications_fields} SET intval = CAST(value AS UNSIGNED) WHERE value REGEXP \'^-?[0-9]+$\'');
break;
case 'pgsql':
$ret[] = update_sql('UPDATE {notifications_fields} SET intval = CAST(value AS INTEGER) WHERE value SIMILAR TO \'^-?[0-9]+$\'');
break;
}
return $ret;
}