<?php
function privatemsg_schema() {
$schema = array();
$schema['pm_index'] = array(
'description' => '{pm_index} holds indexing information about messages and recipients for fast retrieval',
'fields' => array(
'mid' => array(
'description' => 'Private Message ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'thread_id' => array(
'description' => 'Messages thread ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'recipient' => array(
'description' => 'ID of the recipient object, typically user',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'is_new' => array(
'description' => 'Whether the user has read this message',
'type' => 'int',
'default' => 1,
'not null' => TRUE,
'unsigned' => TRUE,
),
'deleted' => array(
'description' => 'Whether the user has deleted this message',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0
),
'type' => array(
'description' => 'Type of recipient object',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'user'
),
),
'primary key' => array('mid', 'recipient', 'type'),
'indexes' => array(
'list' => array('recipient', 'type', 'deleted', 'is_new'),
'messages' => array('mid', 'recipient', 'type'),
'participants' => array('thread_id', 'recipient', 'type', 'deleted'),
),
);
$schema['pm_message'] = array(
'description' => '{pm_messages} holds the message information',
'fields' => array(
'mid' => array(
'description' => 'Private Message ID',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
),
'author' => array(
'description' => 'UID of the author',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'subject' => array(
'description' => 'Subject text of the message',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'body' => array(
'description' => 'Body of the message',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
),
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_formats}.format of the message text.',
),
'timestamp' => array(
'description' => 'Time when the message was sent',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'has_tokens' => array(
'description' => 'Indicates if the message has tokens',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
),
'primary key' => array('mid'),
);
$schema['pm_disable'] = array(
'description' => '{pm_disable} holds the list of users that have disabled private messaging',
'fields' => array(
'uid' => array(
'description' => 'ID of the user',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array('uid'),
);
return $schema;
}
function privatemsg_install() {
variable_set("date_format_privatemsg_current_day", 'g:i a');
variable_set("date_format_privatemsg_current_year", 'M j');
variable_set("date_format_privatemsg_years", 'n/j/y');
}
function privatemsg_uninstall() {
variable_del('private_message_view_template');
variable_del('privatemsg_per_page');
variable_del('privatemsg_display_loginmessage');
variable_del('privatemsg_display_fields');
variable_del('privatemsg_display_link_self');
variable_del('privatemsg_view_default_amount');
variable_del('privatemsg_view_max_amount');
variable_del('privatemsg_view_use_max_as_default');
variable_del('privatemsg_display_profile_links');
variable_del('privatemsg_link_node_types');
variable_del('privatemsg_display_on_teaser');
variable_del('privatemsg_no_messages_notification');
variable_del('privatemsg_display_on_comments');
}
function privatemsg_update_dependencies() {
if (module_exists('privatemsg_filter')) {
$dependencies['privatemsg']['7004']['privatemsg_filter'] = '7001';
return $dependencies;
}
}
function privatemsg_update_last_removed() {
return 6007;
}
function privatemsg_update_7000() {
db_add_field('pm_message', 'has_tokens', array(
'description' => 'Indicates if the message has tokens',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
));
}
function privatemsg_update_7001() {
db_change_field('pm_message', 'format', 'format', array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_formats}.format of the message text.',
));
}
function privatemsg_update_7002() {
if (db_table_exists('pm_disable')) {
return;
}
$schema['pm_disable'] = array(
'description' => '{pm_disable} holds the list of users that have disabled private messaging',
'fields' => array(
'uid' => array(
'description' => 'ID of the user',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array('uid'),
);
if (!(db_table_exists('pm_disable'))) {
db_create_table('pm_disable', $schema['pm_disable']);
}
}
function privatemsg_update_7003() {
if (db_field_exists('pm_index', 'recipient')) {
return;
}
db_drop_index('pm_index', 'list');
db_drop_index('pm_index', 'messages');
db_drop_index('pm_index', 'participants');
db_change_field('pm_index', 'uid', 'recipient', array(
'description' => 'ID of the recipient object, typically user',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
));
db_add_field('pm_index', 'type', array(
'description' => 'Type of recipient object',
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => 'user',
), array(
'indexes' => array(
'list' => array('recipient', 'type', 'deleted', 'is_new'),
'messages' => array('mid', 'recipient', 'type'),
'participants' => array('thread_id', 'recipient', 'type', 'deleted'),
),
));
}
function privatemsg_update_7004(&$sandbox) {
if (db_index_exists('pm_index', 'PRIMARY')) {
return;
}
if (!isset($sandbox['current_thread_id'])) {
$sandbox['current_thread_id'] = 0;
$sandbox['max'] = db_query('SELECT MAX(thread_id) FROM {pm_index}')->fetchField();
}
$result = db_query_range('SELECT DISTINCT thread_id FROM {pm_index} WHERE thread_id > :thread_id ORDER BY thread_id ASC', 0, 20, array(':thread_id' => $sandbox['current_thread_id']));
$threads = $result->fetchCol();
if (!empty($threads)) {
$sql = 'SELECT COUNT(*) AS count, pmi.recipient, pmi.type, pmi.mid, pmi.thread_id, MAX(pmi.is_new) As is_new, MIN(pmi.deleted) AS deleted FROM {pm_index} pmi WHERE thread_id IN (:threads) GROUP BY pmi.recipient, pmi.type, pmi.mid, pmi.thread_id HAVING COUNT(*) > 1';
$result = db_query($sql, array(':threads' => $threads));
foreach ($result as $row) {
db_delete('pm_index')
->condition('mid', $row->mid)
->condition('recipient', $row->recipient)
->condition('type', $row->type)
->execute();
db_insert('pm_index')
->fields(array(
'mid' => $row->mid,
'thread_id' => $row->thread_id,
'recipient' => $row->recipient,
'type' => $row->type,
'is_new' => $row->is_new,
'deleted' => $row->deleted,
))
->execute();
}
$sandbox['current_thread_id'] = max($threads);
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current_thread_id'] / $sandbox['max']);
}
function privatemsg_update_7005() {
if (!db_index_exists('pm_index', 'PRIMARY')) {
db_add_primary_key('pm_index', array('mid', 'recipient', 'type'));
}
}
function privatemsg_update_7006() {
variable_set("date_format_privatemsg_current_day", 'g:i a');
variable_set("date_format_privatemsg_current_year", 'M j');
variable_set("date_format_privatemsg_years", 'n/j/y');
}