function privatemsg_update_6000 in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg.install \privatemsg_update_6000()
1 string reference to 'privatemsg_update_6000'
- privatemsg_update_6003 in ./privatemsg.install
- Update function to resolve "forever new" messages.
File
- ./privatemsg.install, line 163
- Install file for privatemsg.module
Code
function privatemsg_update_6000() {
set_time_limit(0);
$schema = array();
$schema['pm_index'] = array(
'description' => '{pm_index} holds indexing information about messages and recepients 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,
),
'uid' => array(
'description' => 'UID of either the author or the recipient',
'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,
),
),
'indexes' => array(
'mid' => array(
'mid',
),
'thread_id' => array(
'thread_id',
),
'uid' => array(
'uid',
),
'is_new' => array(
'mid',
'uid',
'is_new',
),
),
);
$schema['temp_pm_index'] = array(
'description' => '{pm_index} holds indexing information about messages and recepients for fast retrieval',
'fields' => array(
'mid' => array(
'description' => 'Private Message ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'folder' => array(
'description' => 'ID of drupal 5 folder',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'thread' => array(
'description' => 'Messages old thread ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'thread_id' => array(
'description' => 'Messages new thread ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'uid' => array(
'description' => 'UID of either the author or the recipient',
'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,
),
),
'indexes' => array(
'mid' => array(
'mid',
),
'thread_id' => array(
'thread_id',
),
'uid' => array(
'uid',
),
),
);
$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',
),
'timestamp' => array(
'description' => 'Time when the message was sent',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array(
'mid',
),
'indexes' => array(
'author' => array(
'author',
),
'subject' => array(
array(
'subject',
20,
),
),
'timestamp' => array(
'timestamp',
),
),
);
$ret = array();
if (!db_table_exists('pm_message')) {
db_create_table($ret, 'pm_message', $schema['pm_message']);
}
if (!db_table_exists('pm_index')) {
db_create_table($ret, 'pm_index', $schema['pm_index']);
}
if (!db_table_exists('temp_pm_index')) {
db_create_table($ret, 'temp_pm_index', $schema['temp_pm_index']);
}
if (!module_exists('privatemsg')) {
module_enable('privatemsg');
}
$modules = array();
if (!module_exists('privatemsg_filter')) {
$modules[] = 'privatemsg_filter';
}
if (!module_exists('pm_block_user')) {
$modules[] = 'pm_block_user';
}
if (count($modules) > 0) {
drupal_install_modules($modules);
}
db_query('INSERT INTO {pm_tags} (tag) SELECT DISTINCT name FROM {privatemsg_folder}');
if (db_table_exists('privatemsg_block_user')) {
db_query('INSERT INTO {pm_block_user} (author, recipient) SELECT author, recipient FROM privatemsg_block_user');
}
foreach (array(
"privatemsg_archive",
"privatemsg",
) as $old_message_table) {
$recipient_del = 'recipient_del';
$author_del = 'author_del';
$newmsg = 'newmsg';
if ($old_message_table == 'privatemsg_archive') {
$recipient_del = 1;
$author_del = 1;
$newmsg = '0';
}
if (db_table_exists($old_message_table)) {
db_query("INSERT INTO {pm_message} (mid, author, subject, body, timestamp)\n SELECT id,author,subject,message,timestamp\n FROM {$old_message_table} WHERE author <> recipient");
db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted)\n SELECT id, thread, folder, id, recipient, {$newmsg}, {$recipient_del}\n FROM {$old_message_table} WHERE thread = 0");
db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted)\n SELECT id, thread, folder, 0, recipient, {$newmsg}, {$recipient_del}\n FROM {$old_message_table} WHERE thread <> 0");
db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted)\n SELECT id, thread, 0, id, author, 0, {$author_del}\n FROM {$old_message_table} WHERE thread = 0");
db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted)\n SELECT id, thread, 0, 0, author, 0, {$author_del}\n FROM {$old_message_table} WHERE thread <> 0");
}
}
$temptable = 'temp_pm_thread_min';
db_query_temporary('SELECT thread, min(mid) as mid FROM {temp_pm_index} WHERE thread_id = 0 GROUP BY thread', $temptable);
db_query("create index t2 on {$temptable} (thread)");
db_query("create index t1 on temp_pm_index (thread_id)");
db_query("create index t2 on temp_pm_index (thread)");
db_query("UPDATE temp_pm_index i, {$temptable} t SET i.thread_id = t.mid WHERE i.thread_id = 0 and i.thread = t.thread");
db_query("INSERT INTO {pm_tags_index}\n SELECT distinct pmf.uid, t.tag_id, thread_id\n FROM {pm_tags} t INNER JOIN {privatemsg_folder} pmf ON t.tag = pmf.name, temp_pm_index tmp\n WHERE pmf.fid = tmp.folder and tmp.folder <> 0");
db_query("INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) SELECT mid, thread_id, uid, is_new, deleted FROM {temp_pm_index}");
db_drop_table($ret, 'privatemsg');
db_drop_table($ret, 'privatemsg_archive');
db_drop_table($ret, 'privatemsg_folder');
if (db_table_exists('privatemsg_block_user')) {
db_drop_table($ret, 'privatemsg_block_user');
}
db_drop_table($ret, 'temp_pm_index');
variable_set('privatemsg_update_6000', 1);
return $ret;
}