View source
<?php
function messaging_schema() {
$schema['messaging_store'] = array(
'description' => 'Stores queued messages to be sent or sent messages as logs.',
'fields' => array(
'mqid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Unique message id.',
),
'method' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Messaging send method key.',
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => 'Language code.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {user}.uid for destination if it is a unique destination.',
),
'destination' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Destination identifier, it may be an email address.',
),
'sender' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {user}.uid who sent the message if any.',
),
'sender_address' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Sender address for this sending method.',
),
'subject' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Message subject, single text line.',
),
'body' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => 'Message body, multiple text line.',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'Additional serialized parameters.',
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp, when the message was created/stored.',
),
'sent' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp, when the message was sent.',
),
'cron' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Will be 1 if row marked for processing on cron.',
),
'queue' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Will be 1 if this is a queued message.',
),
'log' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Will be 1 if this is a message log.',
),
),
'primary key' => array(
'mqid',
),
'indexes' => array(
'cron' => array(
'cron',
),
'queue' => array(
'queue',
),
'log' => array(
'log',
),
),
);
$schema['messaging_message_parts'] = array(
'description' => 'Templates for message composition.',
'fields' => array(
'type' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
'description' => 'Message group key.',
),
'method' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
'description' => 'Messaging send method.',
),
'msgkey' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
'description' => 'Message part key, should be unique within a group (header, footer,..).',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Module that owns this template.',
),
'message' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => 'Message template, multiline text with tokens for replacement.',
),
),
'indexes' => array(
'type' => array(
'type',
),
'method' => array(
'method',
),
'msgkey' => array(
'msgkey',
),
),
);
return $schema;
}
function messaging_install() {
drupal_install_schema('messaging');
_messaging_install_create_filter();
}
function _messaging_install_create_filter() {
db_query("INSERT INTO {filter_formats} (name, cache) VALUES('%s', 0)", t('Messaging plain text'));
$format = db_last_insert_id('filter_formats', 'format');
db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'messaging', 1, 0)", $format);
db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'filter', 1, -1)", $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_uninstall() {
drupal_uninstall_schema('messaging');
if ($format = variable_get('messaging_default_filter', 0)) {
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_process_limit');
db_query("DELETE FROM {variable} WHERE name LIKE 'messaging_method_%'");
}
function messaging_update_method_disable($method, $replace) {
if ($method == messaging_method_default()) {
variable_set('messaging_default_method', $replace);
}
messaging_update_method_update($method, $replace);
return $replace;
}
function messaging_update_method_replace($method) {
if ($method_group = messaging_method_info($method, 'group')) {
foreach (messaging_method_info(NULL, 'group') as $index => $group) {
if ($group == $method_group && $method != $index) {
$replace = $index;
break;
}
}
}
if (empty($replace)) {
if ($method == messaging_method_default()) {
$info = messaging_method_info();
unset($info[$method]);
$replace = key($info);
}
else {
$replace = messaging_method_default();
}
}
return $replace;
}
function messaging_update_method_update($old, $new) {
if ($old == variable_get('messaging_default_method', NULL)) {
variable_set('messaging_default_method', $new);
}
module_invoke_all('messaging', 'method update', $old, $new);
}
function messaging_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
$methods = messaging_method_list();
if (!$methods) {
$requirements['messaging'] = array(
'title' => $t('Messaging sending methods'),
'value' => $t('No sending method plug-ins available. Please enable some Sending Method on the !admin-modules page.', array(
'!admin-modules' => l($t('Modules administration'), 'admin/build/modules'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
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);
$ret[] = array();
}
drupal_set_message('Your messaging methods have been updated. Please review the messaging settings.');
}
return $ret;
}
function messaging_update_2() {
$ret = array();
drupal_install_schema('messaging_store');
return $ret;
}
function messaging_update_6001() {
$ret = array();
_messaging_install_create_filter();
return $ret;
}
function messaging_update_6002() {
$ret = array();
module_load_all();
if (module_exists('messaging_phpmailer')) {
$replace['html_mail'] = 'phpmailer';
}
if (module_exists('messaging_mime_mail') && !module_exists('messaging_mail')) {
$replace['mail'] = 'mimemail';
}
if (!empty($replace)) {
foreach ($replace as $old => $new) {
if ($settings = variable_get('messaging_method_' . $old, NULL)) {
variable_set('messaging_method_' . $new, $settings);
variable_del('messaging_method_' . $old);
}
messaging_update_method_update($old, $new);
$ret[] = array(
'success' => TRUE,
'query' => "Replaced sending method {$old} by {$new}",
);
}
drupal_set_message('Please, check all your messaging settings for sending methods.');
}
return $ret;
}
function messaging_update_6003() {
$ret = array();
db_change_field($ret, 'messaging_store', 'params', 'params', array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'serialize' => TRUE,
));
return $ret;
}
function messaging_update_6004() {
$ret = array();
db_add_index($ret, 'messaging_store', 'cron', array(
'cron',
));
db_add_index($ret, 'messaging_store', 'queue', array(
'queue',
));
db_add_index($ret, 'messaging_store', 'log', array(
'log',
));
return $ret;
}
function messaging_update_6005() {
$ret = array();
$ret[] = update_sql('UPDATE {messaging_store} SET log = 1 WHERE log > 1');
$ret[] = update_sql('DELETE FROM {messaging_store} WHERE log = 1 AND queue = 0 AND sent < %d', time() - variable_get('messaging_log', 0));
return $ret;
}
function messaging_update_6006() {
$ret = array();
db_add_field($ret, 'messaging_store', 'data', array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
));
db_add_field($ret, 'messaging_store', 'language', array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, 'messaging_store', 'sender_address', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
return $ret;
}