View source
<?php
function messaging_schema() {
$schema['messaging_message'] = array(
'description' => 'Stores message destination for users and non users.',
'fields' => array(
'msid' => 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.',
),
'store' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Where the message is stored.',
),
'mqid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Queue id if any.',
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => 'Language code.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Message status.',
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp when the item was created.',
),
'updated' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp when the item was created.',
),
'sent' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp, when the last message was sent to this address.',
),
'error' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Error code if any.',
),
),
'primary key' => array(
'msid',
),
'indexes' => array(
'method' => array(
'method',
),
),
);
$schema['messaging_destination'] = array(
'description' => 'Stores message destination for users and non users.',
'fields' => array(
'mdid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Unique destination id.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {user}.uid for destination if it belongs to a registered user.',
),
'type' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Destination type: mail, xmpp, etc.',
),
'address' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Destination identifier, it may be an email address.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Destination status: 1= active, 0 = inactive.',
),
'sent' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp, when the last message was sent to this address.',
),
),
'primary key' => array(
'mdid',
),
'indexes' => array(
'uid' => array(
'uid',
),
'address' => array(
'address',
),
),
);
return $schema;
}
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, $default = TRUE) {
$replace = NULL;
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) && $default) {
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)) {
if ($new) {
variable_set('messaging_default_method', $new);
}
else {
variable_del('messaging_default_method');
}
}
module_invoke_all('messaging_method', 'replace', $old, $new);
module_invoke_all('messaging_method', 'disable', $old);
}