View source
<?php
function messaging_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {messaging_message_parts} (\n type varchar(100) NOT NULL,\n method varchar(50) NOT NULL,\n msgkey varchar(100) NOT NULL,\n module varchar(255) NOT NULL,\n message TEXT,\n INDEX (type),\n INDEX (method),\n INDEX (msgkey)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
db_query("CREATE TABLE {messaging_store} (\n mqid int unsigned NOT NULL auto_increment,\n uid int unsigned NOT NULL,\n sender int unsigned NOT NULL default '0',\n method varchar(255) default NULL,\n destination varchar(255) default NULL,\n subject varchar(255) default NULL,\n body longtext NOT NULL,\n params longtext NOT NULL,\n created int NOT NULL default '0',\n sent int NOT NULL default '0',\n cron tinyint NOT NULL default '0',\n queue tinyint NOT NULL default '0',\n log tinyint NOT NULL default '0',\n PRIMARY KEY (mqid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
db_query("CREATE TABLE {messaging_message_parts} (\n type varchar(100) NOT NULL,\n method varchar(50) NOT NULL,\n msgkey varchar(100) NOT NULL,\n module varchar(255) NOT NULL,\n message TEXT\n )");
db_query("CREATE INDEX {messaging_message_parts}_type_idx ON {messaging_message_parts} (type)");
db_query("CREATE INDEX {messaging_message_parts}_method_idx ON {messaging_message_parts} (method)");
db_query("CREATE INDEX {messaging_message_parts}_msgkey_idx ON {messaging_message_parts} (msgkey)");
db_query("CREATE TABLE {messaging_store} (\n mqid serial,\n uid int_unsigned NOT NULL,\n sender int_unsigned NOT NULL default '0',\n method varchar(255) default NULL,\n destination varchar(255) default NULL,\n subject varchar(255) default NULL,\n body text NOT NULL,\n params text NOT NULL,\n created int NOT NULL default '0',\n sent int NOT NULL default '0',\n cron smallint NOT NULL default '0',\n queue smallint NOT NULL default '0',\n log smallint NOT NULL default '0',\n PRIMARY KEY (mqid)\n )");
break;
}
_messaging_install_create_filter();
}
function messaging_uninstall() {
db_query("DROP TABLE {messaging_message_parts}");
db_query("DROP TABLE {messaging_store}");
$format = variable_get('messaging_default_filter', 0);
if ($format) {
db_query('DELETE FROM {filters} WHERE format = %d', $format);
db_query('DELETE FROM {filter_formats} WHERE format = %d', $format);
}
variable_del('messaging_debug');
variable_del('messaging_default_filter');
variable_del('messaging_default_method');
variable_del('messaging_log');
variable_del('messaging_log_expire');
variable_del('messaging_process_limit');
db_query("DELETE FROM {variable} WHERE name LIKE 'messaging_method_%'");
}
function messaging_requirements($phase) {
if ($phase == 'runtime') {
$list = messaging_method_list();
if (empty($list)) {
$t = get_t();
return array(
'messaging' => array(
'title' => $t('Messaging method'),
'value' => $t('At least one delivery module needs to be enabled for the messaging module to function.'),
'severity' => REQUIREMENT_WARNING,
),
);
}
}
}
function _messaging_install_create_filter() {
db_query("INSERT INTO {filter_formats} (name, cache) VALUES('%s', 0)", t('Messaging plain text'));
$format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_formats}"));
db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES(%d, 'messaging', 0, 0)", $format);
variable_set('messaging_default_filter', $format);
drupal_set_message(t("A new Input format has been created: %name", array(
'%name' => t('Messaging plain text'),
)));
}
function messaging_update_1() {
$ret = array();
if ($settings = variable_get('messaging_methods', array())) {
foreach ($settings as $key => $info) {
$info['subject_filter'] = $info['filter'];
variable_set('messaging_method_' . $key, $info);
}
drupal_set_message('Your messaging settings have been updated. Please review them.');
}
return $ret;
}
function messaging_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {messaging_store} (\n mqid int unsigned NOT NULL auto_increment,\n uid int unsigned NOT NULL,\n sender int unsigned NOT NULL default '0',\n method varchar(255) default NULL,\n destination varchar(255) default NULL,\n subject varchar(255) default NULL,\n body longtext NOT NULL,\n params longtext NOT NULL,\n created int NOT NULL default '0',\n sent int NOT NULL default '0',\n cron tinyint NOT NULL default '0',\n queue tinyint NOT NULL default '0',\n log tinyint NOT NULL default '0',\n PRIMARY KEY (mqid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {messaging_store} (\n mqid serial,\n uid int_unsigned NOT NULL,\n sender int_unsigned NOT NULL default '0',\n method varchar(255) default NULL,\n destination varchar(255) default NULL,\n subject varchar(255) default NULL,\n body text NOT NULL,\n params text NOT NULL,\n created int NOT NULL default '0',\n sent int NOT NULL default '0',\n cron smallint NOT NULL default '0',\n queue smallint NOT NULL default '0',\n log smallint NOT NULL default '0',\n PRIMARY KEY (mqid)\n )");
break;
}
return $ret;
}
function messaging_update_3() {
$ret = array();
_messaging_install_create_filter();
return $ret;
}