root / tags / milestone_3 / phpBB / develop / merge_attachment_tables.php
History | View | Annotate | Download (2.3 kB)
| 1 | 4635 | acydburn | <?php
|
|---|---|---|---|
| 2 | 4635 | acydburn | // -------------------------------------------------------------
|
| 3 | 4635 | acydburn | //
|
| 4 | 4635 | acydburn | // $Id$
|
| 5 | 4635 | acydburn | //
|
| 6 | 4635 | acydburn | // FILENAME : merge_attachment_tables.php
|
| 7 | 4635 | acydburn | // STARTED : Tue Nov 04, 2003
|
| 8 | 4635 | acydburn | // COPYRIGHT : © 2001, 2003 phpBB Group
|
| 9 | 4635 | acydburn | // WWW : http://www.phpbb.com/
|
| 10 | 4635 | acydburn | // LICENCE : GPL vs2.0 [ see /docs/COPYING ]
|
| 11 | 4635 | acydburn | //
|
| 12 | 4635 | acydburn | // -------------------------------------------------------------
|
| 13 | 4635 | acydburn | |
| 14 | 4635 | acydburn | //
|
| 15 | 4635 | acydburn | // Security message:
|
| 16 | 4635 | acydburn | //
|
| 17 | 4635 | acydburn | // This script is potentially dangerous.
|
| 18 | 4635 | acydburn | // Remove or comment the next line (die(".... ) to enable this script.
|
| 19 | 4635 | acydburn | // Do NOT FORGET to either remove this script or disable it after you have used it.
|
| 20 | 4635 | acydburn | //
|
| 21 | 4635 | acydburn | die("Please read the first lines of this script for instructions on how to enable it"); |
| 22 | 4635 | acydburn | |
| 23 | 4635 | acydburn | $db = $dbhost = $dbuser = $dbpasswd = $dbport = $dbname = ''; |
| 24 | 4635 | acydburn | |
| 25 | 4635 | acydburn | define('IN_PHPBB', 1); |
| 26 | 4635 | acydburn | define('ANONYMOUS', 1); |
| 27 | 4635 | acydburn | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 28 | 4635 | acydburn | $phpbb_root_path='./../'; |
| 29 | 4635 | acydburn | include($phpbb_root_path . 'config.'.$phpEx); |
| 30 | 4635 | acydburn | require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.'.$phpEx); |
| 31 | 4635 | acydburn | require($phpbb_root_path . 'includes/db/' . $dbms . '.'.$phpEx); |
| 32 | 4635 | acydburn | include($phpbb_root_path . 'includes/functions.'.$phpEx); |
| 33 | 4635 | acydburn | |
| 34 | 4635 | acydburn | $cache = new acm(); |
| 35 | 4635 | acydburn | $db = new sql_db(); |
| 36 | 4635 | acydburn | |
| 37 | 4635 | acydburn | // Connect to DB
|
| 38 | 4635 | acydburn | $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false); |
| 39 | 4635 | acydburn | |
| 40 | 4635 | acydburn | // Rename the attachments table...
|
| 41 | 4635 | acydburn | $sql = "RENAME TABLE {$table_prefix}attachments TO {$table_prefix}attach_temp"; |
| 42 | 4635 | acydburn | $db->sql_query($sql); |
| 43 | 4635 | acydburn | |
| 44 | 4635 | acydburn | $sql = "CREATE TABLE {$table_prefix}attachments |
| 45 | 4635 | acydburn | SELECT d.*, a.post_id, a.user_id_from as poster_id, p.topic_id |
| 46 | 4635 | acydburn | FROM {$table_prefix}attach_desc d, {$table_prefix}attach_temp a, {$table_prefix}posts p |
| 47 | 4635 | acydburn | WHERE a.attach_id = d.attach_id |
| 48 | 4635 | acydburn | AND a.post_id = p.post_id";
|
| 49 | 4635 | acydburn | $db->sql_query($sql); |
| 50 | 4635 | acydburn | |
| 51 | 4635 | acydburn | switch (SQL_LAYER) |
| 52 | 4635 | acydburn | {
|
| 53 | 4635 | acydburn | case 'mysql': |
| 54 | 4635 | acydburn | case 'mysql4': |
| 55 | 4635 | acydburn | $sql = 'ALTER TABLE ' . $table_prefix . 'attachments |
| 56 | 4635 | acydburn | ADD PRIMARY KEY (attach_id), |
| 57 | 4635 | acydburn | ADD INDEX filetime (filetime), |
| 58 | 4635 | acydburn | ADD INDEX post_id (post_id), |
| 59 | 4635 | acydburn | ADD INDEX poster_id (poster_id), |
| 60 | 4635 | acydburn | ADD INDEX physical_filename (physical_filename(10)), |
| 61 | 4635 | acydburn | ADD INDEX filesize (filesize), |
| 62 | 4635 | acydburn | ADD INDEX topic_id (topic_id), |
| 63 | 4635 | acydburn | MODIFY COLUMN attach_id mediumint(8) UNSIGNED NOT NULL auto_increment';
|
| 64 | 4635 | acydburn | break;
|
| 65 | 4635 | acydburn | |
| 66 | 4635 | acydburn | case 'mssql': |
| 67 | 4635 | acydburn | case 'mssql-odbc': |
| 68 | 4635 | acydburn | case 'msaccess': |
| 69 | 4635 | acydburn | break;
|
| 70 | 4635 | acydburn | |
| 71 | 4635 | acydburn | case 'postgresql': |
| 72 | 4635 | acydburn | break;
|
| 73 | 4635 | acydburn | } |
| 74 | 4635 | acydburn | $db->sql_query($sql); |
| 75 | 4635 | acydburn | |
| 76 | 4635 | acydburn | //$db->sql_query("DROP TABLE {$table_prefix}attach_temp");
|
| 77 | 4635 | acydburn | |
| 78 | 4635 | acydburn | echo "<p><b>Done</b></p>\n"; |
| 79 | 4635 | acydburn | |
| 80 | 4635 | acydburn | ?> |

