831 |
florian |
1 |
<?php
|
|
|
2 |
if(!defined("PHORUM_ADMIN")) return;
|
|
|
3 |
|
|
|
4 |
// Create tables for the new PM system.
|
|
|
5 |
|
|
|
6 |
$upgrade_queries[]= "CREATE TABLE {$PHORUM["pm_messages_table"]} (
|
|
|
7 |
pm_message_id int(10) unsigned NOT NULL auto_increment,
|
|
|
8 |
from_user_id int(10) unsigned NOT NULL default '0',
|
|
|
9 |
from_username varchar(50) NOT NULL default '',
|
|
|
10 |
subject varchar(100) NOT NULL default '',
|
|
|
11 |
message text NOT NULL default '',
|
|
|
12 |
datestamp int(10) unsigned NOT NULL default '0',
|
|
|
13 |
meta mediumtext NOT NULL default '',
|
|
|
14 |
PRIMARY KEY (pm_message_id)
|
|
|
15 |
) TYPE=MyISAM";
|
|
|
16 |
|
|
|
17 |
$upgrade_queries[] = "CREATE TABLE {$PHORUM["pm_folders_table"]} (
|
|
|
18 |
pm_folder_id int(10) unsigned NOT NULL auto_increment,
|
|
|
19 |
user_id int(10) unsigned NOT NULL default '0',
|
|
|
20 |
foldername varchar(20) NOT NULL default '',
|
|
|
21 |
KEY user_id (user_id),
|
|
|
22 |
PRIMARY KEY (pm_folder_id)
|
|
|
23 |
) TYPE=MyISAM";
|
|
|
24 |
|
|
|
25 |
$upgrade_queries[] = "CREATE TABLE {$PHORUM["pm_xref_table"]} (
|
|
|
26 |
pm_xref_id int(10) unsigned NOT NULL auto_increment,
|
|
|
27 |
user_id int(10) unsigned NOT NULL default '0',
|
|
|
28 |
pm_folder_id int(10) unsigned NOT NULL default '0',
|
|
|
29 |
special_folder varchar(10),
|
|
|
30 |
pm_message_id int(10) unsigned NOT NULL default '0',
|
|
|
31 |
read_flag tinyint(1) NOT NULL default '0',
|
|
|
32 |
reply_flag tinyint(1) NOT NULL default '0',
|
|
|
33 |
PRIMARY KEY (pm_xref_id),
|
|
|
34 |
KEY xref (user_id,pm_folder_id,pm_message_id),
|
|
|
35 |
KEY read_flag (read_flag)
|
|
|
36 |
) TYPE=MyISAM";
|
|
|
37 |
|
|
|
38 |
// converting the old PM system to the new one.
|
|
|
39 |
$old_table = "{$PHORUM['DBCONFIG']['table_prefix']}_private_messages";
|
|
|
40 |
$res=mysql_query("SELECT * FROM $old_table");
|
|
|
41 |
while($row=mysql_fetch_assoc($res))
|
|
|
42 |
{
|
|
|
43 |
// Put the message in the message table.
|
|
|
44 |
$meta = serialize(array(
|
|
|
45 |
'recipients' => array(
|
|
|
46 |
$row["to_user_id"] => array (
|
|
|
47 |
'user_id' => $row["to_user_id"],
|
|
|
48 |
'username' => $row["to_username"],
|
|
|
49 |
'read_flag' => $row["read_flag"],
|
|
|
50 |
)
|
|
|
51 |
)
|
|
|
52 |
));
|
|
|
53 |
$sql = "INSERT INTO {$PHORUM["pm_messages_table"]} SET " .
|
|
|
54 |
"pm_message_id = {$row["private_message_id"]}, " .
|
|
|
55 |
"from_user_id = {$row["from_user_id"]}, " .
|
|
|
56 |
"from_username = '" . addslashes($row["from_username"]) . "', " .
|
|
|
57 |
"subject = '" . addslashes($row['subject']) . "', " .
|
|
|
58 |
"message = '" . addslashes($row['message']) . "', " .
|
|
|
59 |
"datestamp = {$row["datestamp"]}, " .
|
|
|
60 |
"meta = '" . addslashes($meta) . "'";
|
|
|
61 |
$upgrade_queries[] = $sql;
|
|
|
62 |
|
|
|
63 |
// Link message to recipient inbox.
|
|
|
64 |
if (! $row["to_del_flag"]) {
|
|
|
65 |
$sql = "INSERT INTO {$PHORUM["pm_xref_table"]} SET " .
|
|
|
66 |
"user_id = {$row["to_user_id"]}, " .
|
|
|
67 |
"pm_folder_id = 0, " .
|
|
|
68 |
"special_folder = '" . PHORUM_PM_INBOX . "', " .
|
|
|
69 |
"pm_message_id = {$row["private_message_id"]}, " .
|
|
|
70 |
"read_flag = {$row["read_flag"]}, " .
|
|
|
71 |
"reply_flag = {$row["reply_flag"]}";
|
|
|
72 |
$upgrade_queries[] = $sql;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
// Link message to sender outbox.
|
|
|
76 |
if (! $row["from_del_flag"]) {
|
|
|
77 |
$sql = "INSERT INTO {$PHORUM["pm_xref_table"]} SET " .
|
|
|
78 |
"user_id = {$row["from_user_id"]}, " .
|
|
|
79 |
"pm_folder_id = 0, " .
|
|
|
80 |
"special_folder = '" . PHORUM_PM_OUTBOX . "', " .
|
|
|
81 |
"pm_message_id = {$row["private_message_id"]}, " .
|
|
|
82 |
"read_flag = 1, " .
|
|
|
83 |
"reply_flag = 0";
|
|
|
84 |
$upgrade_queries[] = $sql;
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
?>
|