| Commit | Line | Data |
|---|---|---|
| 738b232d | 1 | <?php |
| 4b3cbfb4 OT |
2 | // $Id$ |
| 3 | ||
| 4 | /** | |
| 5 | * @file | |
| 6 | * Install file for privatemsg.module | |
| 7 | */ | |
| 8 | ||
| 738b232d | 9 | |
| 3be9375b OT |
10 | function privatemsg_schema() { |
| 11 | $schema = array(); | |
| 12 | $schema['pm_index'] = array( | |
| e4b16a95 | 13 | 'description' => '{pm_index} holds indexing information about messages and recepients for fast retrieval', |
| 3be9375b | 14 | 'fields' => array( |
| 731ead94 | 15 | 'mid' => array( |
| e4b16a95 | 16 | 'description' => 'Private Message ID', |
| 3be9375b OT |
17 | 'type' => 'int', |
| 18 | 'not null' => TRUE, | |
| 19 | 'unsigned' => TRUE, | |
| 20 | ), | |
| 21 | 'thread_id' => array( | |
| e4b16a95 | 22 | 'description' => 'Messages thread ID', |
| 3be9375b OT |
23 | 'type' => 'int', |
| 24 | 'not null' => TRUE, | |
| 25 | 'unsigned' => TRUE, | |
| 26 | ), | |
| 129e8ef6 | 27 | 'uid' => array( |
| e4b16a95 | 28 | 'description' => 'UID of either the author or the recipient', |
| 3be9375b OT |
29 | 'type' => 'int', |
| 30 | 'not null' => TRUE, | |
| 31 | 'unsigned' => TRUE, | |
| 32 | ), | |
| 129e8ef6 | 33 | 'is_new' => array( |
| e4b16a95 | 34 | 'description' => 'Whether the user has read this message', |
| 2438324b | 35 | 'type' => 'int', |
| 129e8ef6 | 36 | 'default' => 1, |
| 2438324b OT |
37 | 'not null' => TRUE, |
| 38 | 'unsigned' => TRUE, | |
| 39 | ), | |
| 129e8ef6 | 40 | 'deleted' => array( |
| e4b16a95 | 41 | 'description' => 'Whether the user has deleted this message', |
| 129e8ef6 OT |
42 | 'type' => 'int', |
| 43 | 'unsigned' => TRUE, | |
| 44 | 'not null' => TRUE, | |
| 45 | 'default' => 0 | |
| 3be9375b | 46 | ), |
| 129e8ef6 | 47 | |
| 3be9375b OT |
48 | ), |
| 49 | 'indexes' => array( | |
| 129e8ef6 OT |
50 | 'mid' => array('mid'), |
| 51 | 'thread_id' => array('thread_id'), | |
| 52 | 'uid' => array('uid'), | |
| 4b3cbfb4 | 53 | 'is_new' => array('mid', 'uid', 'is_new', ), |
| 3be9375b OT |
54 | ), |
| 55 | ); | |
| 4b3cbfb4 | 56 | |
| 3be9375b | 57 | $schema['pm_message'] = array( |
| e4b16a95 | 58 | 'description' => '{pm_messages} holds the message information', |
| 3be9375b | 59 | 'fields' => array( |
| 731ead94 | 60 | 'mid' => array( |
| e4b16a95 | 61 | 'description' => 'Private Message ID', |
| 3be9375b OT |
62 | 'type' => 'serial', |
| 63 | 'not null' => TRUE, | |
| 64 | 'unsigned' => TRUE, | |
| 65 | ), | |
| 66 | 'author' => array( | |
| e4b16a95 | 67 | 'description' => 'UID of the author', |
| 3be9375b OT |
68 | 'type' => 'int', |
| 69 | 'not null' => TRUE, | |
| 70 | 'unsigned' => TRUE, | |
| 71 | ), | |
| 72 | 'subject' => array( | |
| e4b16a95 | 73 | 'description' => 'Subject text of the message', |
| 3be9375b OT |
74 | 'type' => 'varchar', |
| 75 | 'length' => 255, | |
| 76 | 'not null' => TRUE, | |
| 77 | ), | |
| 78 | 'body' => array( | |
| e4b16a95 | 79 | 'description' => 'Body of the message', |
| 3be9375b OT |
80 | 'type' => 'text', |
| 81 | 'not null' => TRUE, | |
| 82 | 'size' => 'big', | |
| 83 | ), | |
| 811e9fd5 SG |
84 | 'format' => array( |
| 85 | 'type' => 'int', | |
| 86 | 'size' => 'small', | |
| 87 | 'not null' => TRUE, | |
| 88 | 'default' => FILTER_FORMAT_DEFAULT, | |
| 89 | 'description' => 'The {filter_formats}.format of the message text.', | |
| 90 | ), | |
| 129e8ef6 | 91 | 'timestamp' => array( |
| e4b16a95 | 92 | 'description' => 'Time when the message was sent', |
| 129e8ef6 OT |
93 | 'type' => 'int', |
| 94 | 'not null' => TRUE, | |
| 95 | 'unsigned' => TRUE, | |
| 96 | ), | |
| 3be9375b | 97 | ), |
| 731ead94 | 98 | 'primary key' => array('mid'), |
| 3be9375b | 99 | 'indexes' => array( |
| 129e8ef6 OT |
100 | 'author' => array('author'), |
| 101 | 'subject' => array(array('subject', 20)), | |
| 102 | 'timestamp' => array('timestamp'), | |
| 3be9375b OT |
103 | ), |
| 104 | ); | |
| 4b3cbfb4 OT |
105 | |
| 106 | ||
| 3be9375b OT |
107 | return $schema; |
| 108 | } | |
| 738b232d | 109 | function privatemsg_install() { |
| 3be9375b | 110 | drupal_install_schema('privatemsg'); |
| 4b3cbfb4 | 111 | |
| 738b232d | 112 | } |
| 35f77f17 AH |
113 | |
| 114 | function privatemsg_uninstall() { | |
| b24e2440 OT |
115 | variable_del('private_message_view_template'); |
| 116 | variable_del('privatemsg_per_page'); | |
| 117 | variable_del('privatemsg_display_loginmessage'); | |
| 118 | variable_del('privatemsg_display_fields'); | |
| 14392929 SG |
119 | variable_del('privatemsg_view_default_amount'); |
| 120 | variable_del('privatemsg_view_max_amount'); | |
| 121 | variable_del('privatemsg_view_use_max_as_default'); | |
| 3be9375b | 122 | drupal_uninstall_schema('privatemsg'); |
| 41d3b6ad | 123 | } |
| 129e8ef6 | 124 | |
| 129e8ef6 OT |
125 | function privatemsg_update_6000() { |
| 126 | // Give update unlimited time to complete. | |
| 127 | set_time_limit(0); | |
| 4b3cbfb4 | 128 | |
| 129e8ef6 OT |
129 | // Update the database schema and transfer data to new tables. |
| 130 | $schema = array(); | |
| 131 | $schema['pm_index'] = array( | |
| e4b16a95 | 132 | 'description' => '{pm_index} holds indexing information about messages and recepients for fast retrieval', |
| 129e8ef6 OT |
133 | 'fields' => array( |
| 134 | 'mid' => array( | |
| e4b16a95 | 135 | 'description' => 'Private Message ID', |
| 129e8ef6 OT |
136 | 'type' => 'int', |
| 137 | 'not null' => TRUE, | |
| 138 | 'unsigned' => TRUE, | |
| 139 | ), | |
| 140 | 'thread_id' => array( | |
| e4b16a95 | 141 | 'description' => 'Messages thread ID', |
| 129e8ef6 OT |
142 | 'type' => 'int', |
| 143 | 'not null' => TRUE, | |
| 144 | 'unsigned' => TRUE, | |
| 145 | ), | |
| 146 | 'uid' => array( | |
| e4b16a95 | 147 | 'description' => 'UID of either the author or the recipient', |
| 129e8ef6 OT |
148 | 'type' => 'int', |
| 149 | 'not null' => TRUE, | |
| 150 | 'unsigned' => TRUE, | |
| 151 | ), | |
| 152 | 'is_new' => array( | |
| e4b16a95 | 153 | 'description' => 'Whether the user has read this message', |
| 129e8ef6 OT |
154 | 'type' => 'int', |
| 155 | 'default' => 1, | |
| 156 | 'not null' => TRUE, | |
| 157 | 'unsigned' => TRUE, | |
| 158 | ), | |
| 159 | 'deleted' => array( | |
| e4b16a95 | 160 | 'description' => 'Whether the user has deleted this message', |
| 129e8ef6 OT |
161 | 'type' => 'int', |
| 162 | 'unsigned' => TRUE, | |
| 163 | 'not null' => TRUE, | |
| 164 | 'default' => 0 | |
| 165 | ), | |
| 166 | ||
| 167 | ), | |
| 168 | 'indexes' => array( | |
| 169 | 'mid' => array('mid'), | |
| 170 | 'thread_id' => array('thread_id'), | |
| 171 | 'uid' => array('uid'), | |
| 4b3cbfb4 | 172 | 'is_new' => array('mid', 'uid', 'is_new', ), |
| 129e8ef6 OT |
173 | ), |
| 174 | ); | |
| 4b3cbfb4 | 175 | |
| 129e8ef6 | 176 | $schema['temp_pm_index'] = array( |
| e4b16a95 | 177 | 'description' => '{pm_index} holds indexing information about messages and recepients for fast retrieval', |
| 129e8ef6 OT |
178 | 'fields' => array( |
| 179 | 'mid' => array( | |
| e4b16a95 | 180 | 'description' => 'Private Message ID', |
| 129e8ef6 OT |
181 | 'type' => 'int', |
| 182 | 'not null' => TRUE, | |
| 183 | 'unsigned' => TRUE, | |
| 184 | ), | |
| 185 | 'folder' => array( | |
| e4b16a95 | 186 | 'description' => 'ID of drupal 5 folder', |
| 129e8ef6 OT |
187 | 'type' => 'int', |
| 188 | 'not null' => TRUE, | |
| 189 | 'unsigned' => TRUE, | |
| 190 | ), | |
| 191 | 'thread' => array( | |
| e4b16a95 | 192 | 'description' => 'Messages old thread ID', |
| 129e8ef6 OT |
193 | 'type' => 'int', |
| 194 | 'not null' => TRUE, | |
| 195 | 'unsigned' => TRUE, | |
| 196 | ), | |
| 197 | 'thread_id' => array( | |
| e4b16a95 | 198 | 'description' => 'Messages new thread ID', |
| 129e8ef6 OT |
199 | 'type' => 'int', |
| 200 | 'not null' => TRUE, | |
| 201 | 'unsigned' => TRUE, | |
| 202 | ), | |
| 203 | 'uid' => array( | |
| e4b16a95 | 204 | 'description' => 'UID of either the author or the recipient', |
| 129e8ef6 OT |
205 | 'type' => 'int', |
| 206 | 'not null' => TRUE, | |
| 207 | 'unsigned' => TRUE, | |
| 208 | ), | |
| 209 | 'is_new' => array( | |
| e4b16a95 | 210 | 'description' => 'Whether the user has read this message', |
| 129e8ef6 OT |
211 | 'type' => 'int', |
| 212 | 'default' => 1, | |
| 213 | 'not null' => TRUE, | |
| 214 | 'unsigned' => TRUE, | |
| 215 | ), | |
| 216 | 'deleted' => array( | |
| e4b16a95 | 217 | 'description' => 'Whether the user has deleted this message', |
| 129e8ef6 OT |
218 | 'type' => 'int', |
| 219 | 'unsigned' => TRUE, | |
| 220 | 'not null' => TRUE, | |
| 221 | 'default' => 0 | |
| 222 | ), | |
| 223 | ), | |
| 224 | ); | |
| 4b3cbfb4 | 225 | |
| 129e8ef6 | 226 | $schema['pm_message'] = array( |
| e4b16a95 | 227 | 'description' => '{pm_messages} holds the message information', |
| 129e8ef6 OT |
228 | 'fields' => array( |
| 229 | 'mid' => array( | |
| e4b16a95 | 230 | 'description' => 'Private Message ID', |
| 129e8ef6 OT |
231 | 'type' => 'serial', |
| 232 | 'not null' => TRUE, | |
| 233 | 'unsigned' => TRUE, | |
| 234 | ), | |
| 235 | 'author' => array( | |
| e4b16a95 | 236 | 'description' => 'UID of the author', |
| 129e8ef6 OT |
237 | 'type' => 'int', |
| 238 | 'not null' => TRUE, | |
| 239 | 'unsigned' => TRUE, | |
| 240 | ), | |
| 241 | 'subject' => array( | |
| e4b16a95 | 242 | 'description' => 'Subject text of the message', |
| 129e8ef6 OT |
243 | 'type' => 'varchar', |
| 244 | 'length' => 255, | |
| 245 | 'not null' => TRUE, | |
| 246 | ), | |
| 247 | 'body' => array( | |
| e4b16a95 | 248 | 'description' => 'Body of the message', |
| 129e8ef6 OT |
249 | 'type' => 'text', |
| 250 | 'not null' => TRUE, | |
| 251 | 'size' => 'big', | |
| 252 | ), | |
| 253 | 'timestamp' => array( | |
| e4b16a95 | 254 | 'description' => 'Time when the message was sent', |
| 129e8ef6 OT |
255 | 'type' => 'int', |
| 256 | 'not null' => TRUE, | |
| 257 | 'unsigned' => TRUE, | |
| 258 | ), | |
| 259 | ), | |
| 260 | 'primary key' => array('mid'), | |
| 261 | 'indexes' => array( | |
| 262 | 'author' => array('author'), | |
| 263 | 'subject' => array(array('subject', 20)), | |
| 264 | 'timestamp' => array('timestamp'), | |
| 265 | ), | |
| 266 | ); | |
| 267 | $ret = array(); | |
| 4b3cbfb4 | 268 | |
| fe52bf61 SG |
269 | // Step 1: Preparation |
| 270 | // Create the privatemsg tables. | |
| 129e8ef6 OT |
271 | if (!(db_table_exists('pm_message'))) { |
| 272 | db_create_table($ret, 'pm_message', $schema['pm_message']); | |
| 273 | } | |
| 274 | if (!(db_table_exists('pm_index'))) { | |
| 275 | db_create_table($ret, 'pm_index', $schema['pm_index']); | |
| 276 | } | |
| 277 | if (!(db_table_exists('temp_pm_index'))) { | |
| 278 | db_create_table($ret, 'temp_pm_index', $schema['temp_pm_index']); | |
| 279 | } | |
| fe52bf61 SG |
280 | // Enable the privatemsg module as otherwise the enable box will be unclickable after update. |
| 281 | if (!module_exists('privatemsg')) { | |
| 282 | module_enable('privatemsg'); | |
| 283 | } | |
| 284 | ||
| 285 | // Install relevant submodules as we need theit tables to drop the data into. | |
| 129e8ef6 | 286 | $modules = array(); |
| 4b3cbfb4 | 287 | if (!(module_exists('privatemsg_filter'))) { |
| 129e8ef6 OT |
288 | $modules[] = 'privatemsg_filter'; |
| 289 | } | |
| 4b3cbfb4 | 290 | if (!(module_exists('pm_block_user'))) { |
| 129e8ef6 OT |
291 | $modules[] = 'pm_block_user'; |
| 292 | } | |
| 293 | if (count($modules) > 0) { | |
| 294 | drupal_install_modules($modules); | |
| 295 | } | |
| 4b3cbfb4 | 296 | |
| 129e8ef6 | 297 | // Step 2: Get the data |
| 4b3cbfb4 | 298 | |
| 129e8ef6 OT |
299 | // Step 2a: get the folder/tagging data first. |
| 300 | if (db_table_exists('privatemsg_folder')) { | |
| 301 | $data = db_query("SELECT * FROM {privatemsg_folder}"); | |
| 302 | while ($result = db_fetch_array($data)) { | |
| fe52bf61 SG |
303 | if (db_result(db_query("SELECT COUNT(*) FROM {pm_tags} WHERE tag = '%s'", $result['name'])) == 0) { |
| 304 | db_query("INSERT INTO {pm_tags} (tag) VALUES ('%s')", $result['name']); | |
| 129e8ef6 OT |
305 | } |
| 306 | } | |
| 307 | } | |
| 4b3cbfb4 | 308 | |
| 8086d49e | 309 | // Step 2b: Next, copy the user blocking data. |
| 129e8ef6 OT |
310 | if (db_table_exists('privatemsg_block_user')) { |
| 311 | $data = db_query("SELECT * FROM {privatemsg_block_user}"); | |
| 312 | while ($result = db_fetch_array($data)) { | |
| 313 | db_query("INSERT INTO {pm_block_user} (author, recipient) VALUES ( %d, %d )", $result['author'], $result['recipient']); | |
| 314 | } | |
| 315 | } | |
| 4b3cbfb4 | 316 | |
| 8086d49e | 317 | // Step 2c: Next the data from the archive table - notice all these messages have been deleted both by the author and the recipient. |
| 129e8ef6 OT |
318 | if (db_table_exists('privatemsg_archive')) { |
| 319 | $data = db_query("SELECT * FROM {privatemsg_archive}"); | |
| 320 | while ($result = db_fetch_array($data)) { | |
| 321 | if ($result['thread'] == 0) { | |
| 322 | $result['thread_id'] = $result['id']; | |
| 323 | } | |
| 324 | else{ | |
| 325 | $result['thread_id'] = 0; | |
| 326 | } | |
| 327 | if ($result['author'] <> $result['recipient']) { | |
| 328 | db_query("INSERT INTO {pm_message} (mid, author, subject, body, timestamp) VALUES ( %d, %d, '%s', '%s', %d )", $result['id'], $result['author'], $result['subject'], $result['message'], $result['timestamp']); | |
| 329 | db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], $result['folder'], $result['thread_id'], $result['recipient'], 0, 1); | |
| 330 | } | |
| 331 | db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], 0, $result['thread_id'], $result['author'], 0, 1); | |
| 332 | } | |
| 333 | } | |
| 334 | ||
| 8086d49e | 335 | // Step 2d: Finally, get the data from the privatemsg table. |
| 129e8ef6 OT |
336 | if (db_table_exists('privatemsg')) { |
| 337 | $data = db_query("SELECT * FROM {privatemsg}"); | |
| 338 | while ($result = db_fetch_array($data)) { | |
| 339 | if ($result['thread'] == 0) { | |
| 340 | $result['thread_id'] = $result['id']; | |
| 341 | } | |
| 342 | else{ | |
| 343 | $result['thread_id'] = 0; | |
| 344 | } | |
| 345 | if ($result['author'] <> $result['recipient']) { | |
| 346 | db_query("INSERT INTO {pm_message} (mid, author, subject, body, timestamp) VALUES ( %d, %d, '%s', '%s', %d )", $result['id'], $result['author'], $result['subject'], $result['message'], $result['timestamp']); | |
| 347 | db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], $result['folder'], $result['thread_id'], $result['recipient'], $result['newmsg'], $result['recipient_del']); | |
| 348 | } | |
| 349 | db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], 0, $result['thread_id'], $result['author'], 0, $result['author_del']); | |
| 350 | } | |
| 351 | } | |
| 4b3cbfb4 | 352 | |
| 129e8ef6 OT |
353 | // Step 3: Process the Data. |
| 354 | // Step 3a: Fix the thread data. | |
| 355 | $data = db_query("SELECT thread, MIN(mid) as new_thread FROM {temp_pm_index} WHERE thread_id = %d GROUP BY thread", 0); | |
| 356 | while ($result = db_fetch_array($data)) { | |
| 357 | db_query("UPDATE {temp_pm_index} SET thread_id = %d WHERE thread = %d", $result['new_thread'], $result['thread']); | |
| 358 | } | |
| 4b3cbfb4 | 359 | |
| 129e8ef6 OT |
360 | // Step 3b: Fix and import the tagging data. |
| 361 | $data = db_query("SELECT thread_id, folder, uid FROM {temp_pm_index} WHERE folder <> %d", 0); | |
| 362 | while ($result = db_fetch_array($data)) { | |
| fe52bf61 SG |
363 | $tag_id = db_result(db_query('SELECT pmt.tag_id FROM {pm_tags} pmt INNER JOIN {privatemsg_folder} pmf ON pmt.tag = pmf.name WHERE pmf.fid = %d', $result['folder'])); |
| 364 | if (db_result(db_query("SELECT COUNT(*) FROM {pm_tags_index} WHERE uid = %d AND (thread_id = %d AND tag_id = %d)", $result['uid'], $result['thread_id'], $tag_id)) == 0) { | |
| 365 | db_query("INSERT INTO {pm_tags_index} (uid, tag_id, thread_id) VALUES (%d, %d, %d)", $result['uid'], $tag_id, $result['thread_id']); | |
| 129e8ef6 OT |
366 | } |
| 367 | } | |
| 4b3cbfb4 | 368 | |
| 129e8ef6 OT |
369 | // Step 3c: Copy the index data. |
| 370 | $data = db_query("SELECT * FROM {temp_pm_index}"); | |
| 371 | while ($result = db_fetch_array($data)) { | |
| 372 | db_query("INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d )", $result['mid'], $result['thread_id'], $result['uid'], $result['is_new'], $result['deleted']); | |
| 373 | } | |
| 4b3cbfb4 | 374 | |
| 129e8ef6 OT |
375 | // Step 4: Clean up. |
| 376 | db_drop_table($ret, 'privatemsg'); | |
| 377 | db_drop_table($ret, 'privatemsg_archive'); | |
| 378 | db_drop_table($ret, 'privatemsg_folder'); | |
| fe52bf61 SG |
379 | if (db_table_exists('privatemsg_block_user')) { |
| 380 | db_drop_table($ret, 'privatemsg_block_user'); | |
| 381 | } | |
| 129e8ef6 | 382 | db_drop_table($ret, 'temp_pm_index'); |
| 4b3cbfb4 | 383 | |
| 129e8ef6 | 384 | return $ret; |
| 7deb0c62 OT |
385 | } |
| 386 | ||
| 0ffefdb2 OT |
387 | function privatemsg_update_6001() { |
| 388 | $ret = array(); | |
| 389 | ||
| 390 | if (!db_column_exists('pm_index', 'is_new')) { | |
| 391 | ||
| 392 | if (db_column_exists('pm_index', 'new')) { | |
| 393 | $old_column = 'new'; | |
| 394 | } | |
| 395 | elseif (db_column_exists('pm_index', 'new_flag')) { | |
| 396 | $old_column = 'new_flag'; | |
| 397 | } | |
| 398 | else { | |
| 399 | return $ret; | |
| 400 | } | |
| 401 | ||
| 402 | db_drop_index($ret, 'pm_index', $old_column); | |
| 403 | db_change_field($ret, 'pm_index', $old_column, 'is_new', array( | |
| 404 | 'description' => 'Whether the user has read this message', | |
| 405 | 'type' => 'int', | |
| 406 | 'default' => 1, | |
| 407 | 'not null' => TRUE, | |
| 408 | 'unsigned' => TRUE)); | |
| 409 | db_add_index($ret, 'pm_index', 'is_new', array('mid', 'uid', 'is_new')); | |
| 410 | } | |
| 411 | ||
| 412 | return $ret; | |
| 413 | } | |
| 414 | ||
| 7deb0c62 OT |
415 | function privatemsg_update_6002() { |
| 416 | $ret = array(); | |
| 417 | // update_sql does not support parameters, we need to use db_query | |
| 418 | $sql = "UPDATE {blocks} SET cache = %d WHERE module='privatemsg'"; | |
| 419 | $result = db_query($sql, BLOCK_NO_CACHE); | |
| 420 | $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql)); | |
| 421 | return $ret; | |
| 0ffefdb2 OT |
422 | } |
| 423 | ||
| 424 | /** | |
| 8086d49e SG |
425 | * Update function to resolve "forever new" messages. |
| 426 | * | |
| 427 | * As described in http://drupal.org/node/490650 | |
| 0ffefdb2 OT |
428 | */ |
| 429 | function privatemsg_update_6003() { | |
| 430 | $ret = array(); | |
| 431 | // Find messages that have aformentioned problem | |
| 8086d49e | 432 | $sql = "SELECT DISTINCT p1.mid, p1.uid FROM {pm_index} p1 INNER JOIN {pm_index} p2 ON p1.thread_id = p2.thread_id AND p1.mid = p2.mid INNER JOIN {pm_message} pm ON p1.uid = pm.author AND p2.uid = pm.author WHERE p1.is_new <> p2.is_new"; |
| 0ffefdb2 | 433 | $result = db_query($sql); |
| 8086d49e | 434 | while ($row = db_fetch_object($result)) { |
| 0ffefdb2 OT |
435 | privatemsg_message_change_status($row->mid, PRIVATEMSG_READ, $row ); |
| 436 | } | |
| 437 | $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql)); | |
| 438 | return $ret; | |
| 811e9fd5 SG |
439 | } |
| 440 | ||
| 441 | /** | |
| 442 | * Create a format column. | |
| 443 | * | |
| 444 | * Copied from system_update_6051 | |
| 445 | */ | |
| 446 | function privatemsg_update_6004() { | |
| 447 | $ret = array(); | |
| 448 | if (!db_column_exists('pm_message', 'format')) { | |
| 449 | $schema = array( | |
| 450 | 'type' => 'int', | |
| 451 | 'size' => 'small', | |
| 452 | 'not null' => TRUE, | |
| 453 | 'default' => FILTER_FORMAT_DEFAULT, | |
| 454 | 'description' => 'The {filter_formats}.format of the message text.', | |
| 455 | ); | |
| 456 | ||
| 457 | db_add_field($ret, 'pm_message', 'format', $schema); | |
| 458 | ||
| 459 | // Set the format of existing signatures to the current default input format. | |
| 460 | if ($current_default_filter = (int)variable_get('filter_default_format', 1)) { | |
| 461 | $ret[] = update_sql("UPDATE {pm_message} SET format = ". $current_default_filter); | |
| 462 | } | |
| 463 | } | |
| 464 | return $ret; | |
| 465 | } | |
| a6aefc34 SG |
466 | |
| 467 | /** | |
| 468 | * Enable delete permission for all users that are allowed to read them. | |
| 469 | */ | |
| 470 | function privatemsg_update_6005() { | |
| 471 | $ret = array(); | |
| 472 | $ret[] = update_sql("UPDATE {permission} SET perm = REPLACE(perm, 'read privatemsg', 'read privatemsg, delete privatemsg') WHERE perm LIKE '%read privatemsg%'"); | |
| 473 | return $ret; | |
| 7bfff1e7 SG |
474 | } |
| 475 | ||
| 476 | /** | |
| 477 | * Set the deleted timestamp of all messages to now. | |
| 478 | */ | |
| 479 | function privatemsg_update_6006() { | |
| 480 | $ret = array(); | |
| 481 | ||
| 482 | $sql = "UPDATE {pm_index} SET deleted = %d WHERE deleted = 1"; | |
| 483 | $result = db_query($sql, time()); | |
| 484 | $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql)); | |
| 485 | return $ret; | |
| a6aefc34 | 486 | } |