831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
***** IT IS HIGHLY RECCOMENDED THAT YOU RUN THIS SCRIPT ON A CONSOLE
|
|
|
6 |
***** PHP VERSION 4.2.0 OR HIGHER IS REQUIRED FOR RUNNING THIS SCRIPT
|
|
|
7 |
***** THE SCRIPT IS WRITTEN FOR UPGRADING PHORUM 3.4.x
|
|
|
8 |
|
|
|
9 |
This script will convert the data from a Phorum 3 database to a Phorum 5
|
|
|
10 |
database. It does not change any of the old phorum3-tables. The data is
|
|
|
11 |
only copied over to the new Phorum 5 tables.
|
|
|
12 |
|
|
|
13 |
Instructions:
|
|
|
14 |
|
|
|
15 |
1. Be sure your Phorum 3 is running a 3.4.x version. If you are running
|
|
|
16 |
an older version of Phorum 3, first upgrade to 3.4.x.
|
|
|
17 |
|
|
|
18 |
2. Copy or move this script one directory up, to the main Phorum 5 directory.
|
|
|
19 |
|
|
|
20 |
3. Edit the $CONVERT variables below to match the settings of your
|
|
|
21 |
phorum3 installation.
|
|
|
22 |
|
|
|
23 |
4. Install Phorum 5 as usual. For speed and reliability, preferably use the
|
|
|
24 |
same database as the database where Phorum 3 lives. Because Phorum 5 uses
|
|
|
25 |
a table prefix (typically "phorum_"), the tables for Phorum 3 and Phorum 5
|
|
|
26 |
can safely live next to each other in the same database.
|
|
|
27 |
|
|
|
28 |
5. Empty the phorum_messages and phorum_forums tables of the Phorum 5
|
|
|
29 |
installation. You can do this either by dropping all forums from the
|
|
|
30 |
Phorum 5 admin interface or by issuing the appropriate SQL queries from
|
|
|
31 |
the MySQL prompt or from a database tool like "phpmyadmin". The queries
|
|
|
32 |
to execute are (replace "phorum" with your own table_prefix if you changed
|
|
|
33 |
this during install):
|
|
|
34 |
|
|
|
35 |
DELETE FROM phorum_messages;
|
|
|
36 |
DELETE FROM phorum_forums;
|
|
|
37 |
|
|
|
38 |
I could do this from this script as well, but I would find that
|
|
|
39 |
a little bit rude ;-))
|
|
|
40 |
|
|
|
41 |
6. Turn off unneeded modules for the conversion. All modules hooking into common.php
|
|
|
42 |
or some other general hook will be run while doing the conversion which will lead to
|
|
|
43 |
at least a slowdown, unexpected side effects and some strange output.
|
|
|
44 |
|
|
|
45 |
7. If you have shell access to your webserver, run this script using the
|
|
|
46 |
shell from the command line. This is the preferred way of running the
|
|
|
47 |
upgrade:
|
|
|
48 |
|
|
|
49 |
php phorum3to5convert.php
|
|
|
50 |
|
|
|
51 |
If you do not have shell access, call the upgrade script from your browser:
|
|
|
52 |
|
|
|
53 |
<phorum5-url>/phorum3to5convert.php
|
|
|
54 |
|
|
|
55 |
*** THIS STEP MAY TAKE A WHILE ***
|
|
|
56 |
|
|
|
57 |
8. Take a look at the Phorum 5 forums to see if everything was converted
|
|
|
58 |
correctly.
|
|
|
59 |
|
|
|
60 |
9. Delete the upgrade script phorum3to5convert.php.
|
|
|
61 |
|
|
|
62 |
*/
|
|
|
63 |
|
|
|
64 |
ini_set ( "zlib.output_compression", "0");
|
|
|
65 |
ini_set ( "output_handler", "");
|
|
|
66 |
@ob_end_flush();
|
|
|
67 |
|
|
|
68 |
define("PHORUM5_CONVERSION", 1);
|
|
|
69 |
|
|
|
70 |
/***** CONFIGURATION FOR THE CONVERSION *****/
|
|
|
71 |
|
|
|
72 |
// The data for connecting to the old Phorum 3 database.
|
|
|
73 |
$CONVERT['old_dbhost'] = "localhost";
|
|
|
74 |
$CONVERT['old_dbuser'] = "phorum5";
|
|
|
75 |
$CONVERT['old_dbpass'] = "phorum5";
|
|
|
76 |
|
|
|
77 |
// The name of the old Phorum 3 database.
|
|
|
78 |
$CONVERT['olddb'] = "phorum";
|
|
|
79 |
|
|
|
80 |
// The main-table-name for phorum3 (default is "forums")
|
|
|
81 |
$CONVERT['forumstable'] = "forums";
|
|
|
82 |
|
|
|
83 |
// Separator character. If you are going to run this script from
|
|
|
84 |
// the web, make it "<br>\n". If you are going to run it from the
|
|
|
85 |
// shell prompt, make it "\n".
|
|
|
86 |
$CONVERT['lbr'] = "<br>\n";
|
|
|
87 |
|
|
|
88 |
// The full path to the directory where the attachments for Phorum 3.4.x
|
|
|
89 |
// are stored (like in the old admin).
|
|
|
90 |
$CONVERT['attachmentdir'] = "/full/path/to/files";
|
|
|
91 |
|
|
|
92 |
/***** THERE'S NO NEED TO CHANGE ANYTHING BELOW THIS LINE *****/
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
// we try to disable the execution timeout
|
|
|
96 |
// that command doesn't work in safe_mode :(
|
|
|
97 |
set_time_limit(0);
|
|
|
98 |
|
|
|
99 |
require './common.php';
|
|
|
100 |
require './include/thread_info.php';
|
|
|
101 |
require './scripts/phorum3_in.php';
|
|
|
102 |
|
|
|
103 |
// no need to change anything below this line
|
|
|
104 |
// establishing the first link to the old database
|
|
|
105 |
$oldlink = mysql_connect($CONVERT['old_dbhost'], $CONVERT['old_dbuser'], $CONVERT['old_dbpass'], true);
|
|
|
106 |
mysql_select_db($CONVERT['olddb'], $oldlink);
|
|
|
107 |
|
|
|
108 |
if (!$oldlink) {
|
|
|
109 |
print "Couldn't connect to the old database.".$CONVERT['lbr'];
|
|
|
110 |
exit();
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
// checking attachment-dir
|
|
|
114 |
if (!file_exists($CONVERT['attachmentdir']) || empty($CONVERT['attachmentdir'])) {
|
|
|
115 |
echo "Directory {$CONVERT['attachmentdir']} doesn't exist. Attachments won't be converted. (doesn't matter if you don't have message-attachments) {$CONVERT['lbr']}";
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$CONVERT['groups']=array();
|
|
|
119 |
$CONVERT['do_groups']=false;
|
|
|
120 |
|
|
|
121 |
// checking if the groups-table exists
|
|
|
122 |
if(phorum_convert_check_groups($oldlink)) {
|
|
|
123 |
// reading groups (should be not too much, therefore we keep the array for later use)
|
|
|
124 |
$CONVERT['groups'] = phorum_convert_getGroups($oldlink);
|
|
|
125 |
if(count($CONVERT['groups'])) {
|
|
|
126 |
echo "Writing groups ... {$CONVERT['lbr']}";
|
|
|
127 |
foreach($CONVERT['groups'] as $groupid => $groupdata) {
|
|
|
128 |
phorum_db_add_group($groupdata['name'],$groupid);
|
|
|
129 |
$CONVERT['groups'][$groupid]['group_id']=$groupid;
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
$CONVERT['do_groups']=true;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
$CONVERT['do_users']=false;
|
|
|
136 |
// checking if the users-table exists
|
|
|
137 |
if(phorum_convert_check_users($oldlink)) {
|
|
|
138 |
$CONVERT['do_users']=true;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// reading the forums
|
|
|
142 |
$forums = phorum_convert_getForums($oldlink);
|
|
|
143 |
|
|
|
144 |
// going through all the forums (and folders)
|
|
|
145 |
echo "Writing forumdata ... {$CONVERT['lbr']}";
|
|
|
146 |
flush();
|
|
|
147 |
$offsets=array();
|
|
|
148 |
|
|
|
149 |
foreach($forums as $forumid => $forumdata) {
|
|
|
150 |
$newforum = phorum_convert_prepareForum($forumdata);
|
|
|
151 |
|
|
|
152 |
phorum_db_add_forum($newforum);
|
|
|
153 |
|
|
|
154 |
if (!$forumdata['folder']) {
|
|
|
155 |
$PHORUM['forum_id'] = $forumid;
|
|
|
156 |
$CONVERT['forum_id'] = $forumid;
|
|
|
157 |
|
|
|
158 |
echo "Reading maximum message-id from messages-table... {$CONVERT['lbr']}";
|
|
|
159 |
flush();
|
|
|
160 |
$CONVERT['max_id'] = phorum_db_get_max_messageid();
|
|
|
161 |
$offsets[$forumid]=$CONVERT['max_id'];
|
|
|
162 |
|
|
|
163 |
if ($forumdata['allow_uploads']=='Y' && file_exists($CONVERT['attachmentdir']."/".$forumdata['table_name'])) {
|
|
|
164 |
$CONVERT['attachments']=phorum_convert_getAttachments($forumdata['table_name']);
|
|
|
165 |
echo "Reading attachments for forum " . $forumdata['name'] . "...{$CONVERT['lbr']}";
|
|
|
166 |
flush();
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
echo "Writing postings for forum " . $forumdata['name'] . "...{$CONVERT['lbr']}";
|
|
|
170 |
flush();
|
|
|
171 |
|
|
|
172 |
$count = 1;
|
|
|
173 |
$total = 0;
|
|
|
174 |
|
|
|
175 |
$res = phorum_convert_selectMessages($forumdata, $oldlink);
|
|
|
176 |
while ($newmessage = phorum_convert_getNextMessage($res,$forumdata['table_name'])) {
|
|
|
177 |
|
|
|
178 |
if(phorum_db_post_message($newmessage, true)) {
|
|
|
179 |
phorum_update_thread_info($newmessage['thread']);
|
|
|
180 |
echo "+";
|
|
|
181 |
flush();
|
|
|
182 |
if ($count == 50) {
|
|
|
183 |
$total += $count;
|
|
|
184 |
echo " $total from \"{$forumdata['name']}\"";
|
|
|
185 |
if($CONVERT['lbr']=="\n"){
|
|
|
186 |
// lets just go back on this line if we are on the console
|
|
|
187 |
echo "\r";
|
|
|
188 |
} else {
|
|
|
189 |
echo $CONVERT['lbr'];
|
|
|
190 |
}
|
|
|
191 |
flush();
|
|
|
192 |
$count = 0;
|
|
|
193 |
}
|
|
|
194 |
$count++;
|
|
|
195 |
} else {
|
|
|
196 |
print "Error in message: ".$CONVERT['lbr'];
|
|
|
197 |
print_var($newmessage);
|
|
|
198 |
print $CONVERT['lbr'];
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
echo "{$CONVERT['lbr']}Updating forum-statistics: {$CONVERT['lbr']}";
|
|
|
203 |
flush();
|
|
|
204 |
phorum_db_update_forum_stats(true);
|
|
|
205 |
echo $CONVERT['lbr'];
|
|
|
206 |
flush();
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
unset($forums);
|
|
|
210 |
|
|
|
211 |
// storing the offsets of the forums
|
|
|
212 |
phorum_db_update_settings(array("conversion_offsets"=>$offsets));
|
|
|
213 |
|
|
|
214 |
if($CONVERT['do_groups'] && count($CONVERT['groups'])) { // here we set the group-permissions
|
|
|
215 |
echo "Writing group-permissions ... {$CONVERT['lbr']}";
|
|
|
216 |
foreach($CONVERT['groups'] as $groupid => $groupdata) {
|
|
|
217 |
phorum_db_save_group($groupdata);
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
if($CONVERT['do_users']) {
|
|
|
222 |
echo "migrating users ...{$CONVERT['lbr']}";
|
|
|
223 |
flush();
|
|
|
224 |
$group_perms=phorum_convert_getUserGroups($oldlink);
|
|
|
225 |
$res = phorum_convert_selectUsers($oldlink);
|
|
|
226 |
|
|
|
227 |
if (!$res) {
|
|
|
228 |
echo "No users found, All done now.{$CONVERT['lbr']}";
|
|
|
229 |
flush();
|
|
|
230 |
exit;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
// there are users...
|
|
|
234 |
$count = 0;
|
|
|
235 |
$userdata["date_added"] = time();
|
|
|
236 |
$cur_time = time();
|
|
|
237 |
while ($cur_user = phorum_convert_getNextUser($res)) {
|
|
|
238 |
if (isset($cur_user['user_id'])) {
|
|
|
239 |
phorum_user_add($cur_user, -1);
|
|
|
240 |
$user_groups=$group_perms[$cur_user['user_id']];
|
|
|
241 |
if(count($user_groups)) { // setting the user's group-memberships
|
|
|
242 |
phorum_db_user_save_groups($cur_user['user_id'],$user_groups);
|
|
|
243 |
}
|
|
|
244 |
$count++;
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
unset($users);
|
|
|
248 |
print "$count users converted{$CONVERT['lbr']}";
|
|
|
249 |
}
|
|
|
250 |
echo "{$CONVERT['lbr']}Done.{$CONVERT['lbr']}";
|
|
|
251 |
flush();
|
|
|
252 |
|
|
|
253 |
?>
|