1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: upgrade.php 1943 2007-04-07 15:55:19Z rub $ |
---|
8 | // | last update : $Date: 2007-04-07 15:55:19 +0000 (Sat, 07 Apr 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 1943 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | define('PHPWG_ROOT_PATH', './'); |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
30 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
31 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); |
---|
32 | include(PHPWG_ROOT_PATH.'include/template.php'); |
---|
33 | |
---|
34 | include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); |
---|
35 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
36 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
37 | |
---|
38 | check_upgrade(); |
---|
39 | |
---|
40 | // concerning upgrade, we use the default users table |
---|
41 | $conf['users_table'] = $prefixeTable.'users'; |
---|
42 | |
---|
43 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
44 | define('PREFIX_TABLE', $prefixeTable); |
---|
45 | |
---|
46 | // Database connection |
---|
47 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
48 | or die ( "Could not connect to database server" ); |
---|
49 | mysql_select_db( $cfgBase ) |
---|
50 | or die ( "Could not connect to database" ); |
---|
51 | // +-----------------------------------------------------------------------+ |
---|
52 | // | tricky output | |
---|
53 | // +-----------------------------------------------------------------------+ |
---|
54 | echo '<!-- This is an HTML comment given in order to make IE outputs'; |
---|
55 | echo ' the code.'."\n"; |
---|
56 | echo ' Indeed, IE doesn\'t start to send output until a limit'; |
---|
57 | echo ' of XXX bytes '."\n"; |
---|
58 | echo str_repeat( ' ', 80 )."\n"; |
---|
59 | echo str_repeat( ' ', 80 )."\n"; |
---|
60 | echo str_repeat( ' ', 80 )."\n"; |
---|
61 | echo '-->'."\n"; |
---|
62 | flush(); |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | // | functions | |
---|
65 | // +-----------------------------------------------------------------------+ |
---|
66 | |
---|
67 | /** |
---|
68 | * list all tables in an array |
---|
69 | * |
---|
70 | * @return array |
---|
71 | */ |
---|
72 | function get_tables() |
---|
73 | { |
---|
74 | $tables = array(); |
---|
75 | |
---|
76 | $query = ' |
---|
77 | SHOW TABLES |
---|
78 | ;'; |
---|
79 | $result = mysql_query($query); |
---|
80 | |
---|
81 | while ($row = mysql_fetch_row($result)) |
---|
82 | { |
---|
83 | if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) |
---|
84 | { |
---|
85 | array_push($tables, $row[0]); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | return $tables; |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * list all columns of each given table |
---|
94 | * |
---|
95 | * @return array of array |
---|
96 | */ |
---|
97 | function get_columns_of($tables) |
---|
98 | { |
---|
99 | $columns_of = array(); |
---|
100 | |
---|
101 | foreach ($tables as $table) |
---|
102 | { |
---|
103 | $query = ' |
---|
104 | DESC '.$table.' |
---|
105 | ;'; |
---|
106 | $result = mysql_query($query); |
---|
107 | |
---|
108 | $columns_of[$table] = array(); |
---|
109 | |
---|
110 | while ($row = mysql_fetch_row($result)) |
---|
111 | { |
---|
112 | array_push($columns_of[$table], $row[0]); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | return $columns_of; |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | */ |
---|
121 | function print_time($message) |
---|
122 | { |
---|
123 | global $last_time; |
---|
124 | |
---|
125 | $new_time = get_moment(); |
---|
126 | echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; |
---|
127 | echo ' '.$message; |
---|
128 | echo '</pre>'; |
---|
129 | flush(); |
---|
130 | $last_time = $new_time; |
---|
131 | } |
---|
132 | |
---|
133 | // +-----------------------------------------------------------------------+ |
---|
134 | // | playing zone | |
---|
135 | // +-----------------------------------------------------------------------+ |
---|
136 | |
---|
137 | // echo implode('<br>', get_tables()); |
---|
138 | // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; |
---|
139 | |
---|
140 | // foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
141 | // { |
---|
142 | // echo $upgrade_id, '<br>'; |
---|
143 | // } |
---|
144 | |
---|
145 | // +-----------------------------------------------------------------------+ |
---|
146 | // | template initialization | |
---|
147 | // +-----------------------------------------------------------------------+ |
---|
148 | |
---|
149 | $template = new Template(PHPWG_ROOT_PATH.'template/yoga'); |
---|
150 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
151 | $template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); |
---|
152 | |
---|
153 | // +-----------------------------------------------------------------------+ |
---|
154 | // | upgrade choice | |
---|
155 | // +-----------------------------------------------------------------------+ |
---|
156 | |
---|
157 | if (!isset($_GET['version'])) |
---|
158 | { |
---|
159 | // find the current release |
---|
160 | $tables = get_tables(); |
---|
161 | $columns_of = get_columns_of($tables); |
---|
162 | |
---|
163 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
164 | { |
---|
165 | // we're in branch 1.3, important upgrade, isn't it? |
---|
166 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
167 | { |
---|
168 | $current_release = '1.3.1'; |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | $current_release = '1.3.0'; |
---|
173 | } |
---|
174 | } |
---|
175 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
176 | { |
---|
177 | $current_release = '1.4.0'; |
---|
178 | } |
---|
179 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
180 | { |
---|
181 | $current_release = '1.5.0'; |
---|
182 | } |
---|
183 | else if (!in_array(PREFIX_TABLE.'history_summary', $tables)) |
---|
184 | { |
---|
185 | if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
186 | { |
---|
187 | $current_release = '1.6.0'; |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | $current_release = '1.6.2'; |
---|
192 | } |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | die('No upgrade required, the database structure is up to date'); |
---|
197 | } |
---|
198 | |
---|
199 | $template->assign_block_vars( |
---|
200 | 'introduction', |
---|
201 | array( |
---|
202 | 'CURRENT_RELEASE' => $current_release, |
---|
203 | 'RUN_UPGRADE_URL' => |
---|
204 | PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, |
---|
205 | ) |
---|
206 | ); |
---|
207 | } |
---|
208 | |
---|
209 | // +-----------------------------------------------------------------------+ |
---|
210 | // | upgrade launch | |
---|
211 | // +-----------------------------------------------------------------------+ |
---|
212 | |
---|
213 | else |
---|
214 | { |
---|
215 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; |
---|
216 | if (is_file($upgrade_file)) |
---|
217 | { |
---|
218 | $page['infos'] = array(); |
---|
219 | $page['upgrade_start'] = get_moment(); |
---|
220 | $conf['die_on_sql_error'] = false; |
---|
221 | include($upgrade_file); |
---|
222 | |
---|
223 | // Available upgrades must be ignored after a fresh installation. To |
---|
224 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
225 | // made. |
---|
226 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
227 | define('CURRENT_DATE', $dbnow); |
---|
228 | $datas = array(); |
---|
229 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
230 | { |
---|
231 | array_push( |
---|
232 | $datas, |
---|
233 | array( |
---|
234 | 'id' => $upgrade_id, |
---|
235 | 'applied' => CURRENT_DATE, |
---|
236 | 'description' => 'upgrade included in migration', |
---|
237 | ) |
---|
238 | ); |
---|
239 | } |
---|
240 | mass_inserts( |
---|
241 | UPGRADE_TABLE, |
---|
242 | array_keys($datas[0]), |
---|
243 | $datas |
---|
244 | ); |
---|
245 | |
---|
246 | $page['upgrade_end'] = get_moment(); |
---|
247 | |
---|
248 | $template->assign_block_vars( |
---|
249 | 'upgrade', |
---|
250 | array( |
---|
251 | 'VERSION' => $_GET['version'], |
---|
252 | 'TOTAL_TIME' => get_elapsed_time( |
---|
253 | $page['upgrade_start'], |
---|
254 | $page['upgrade_end'] |
---|
255 | ), |
---|
256 | 'SQL_TIME' => number_format( |
---|
257 | $page['queries_time'], |
---|
258 | 3, |
---|
259 | '.', |
---|
260 | ' ' |
---|
261 | ).' s', |
---|
262 | 'NB_QUERIES' => $page['count_queries'] |
---|
263 | ) |
---|
264 | ); |
---|
265 | |
---|
266 | array_push( |
---|
267 | $page['infos'], |
---|
268 | '[security] delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" |
---|
269 | directory' |
---|
270 | ); |
---|
271 | |
---|
272 | array_push( |
---|
273 | $page['infos'], |
---|
274 | 'in include/mysql.inc.php, remove |
---|
275 | <pre style="background-color:lightgray"> |
---|
276 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
277 | </pre>' |
---|
278 | ); |
---|
279 | |
---|
280 | array_push( |
---|
281 | $page['infos'], |
---|
282 | 'Perform a maintenance check in [Administration>General>Maintenance] |
---|
283 | if you encounter any problem.' |
---|
284 | ); |
---|
285 | |
---|
286 | $template->assign_block_vars('upgrade.infos', array()); |
---|
287 | |
---|
288 | foreach ($page['infos'] as $info) |
---|
289 | { |
---|
290 | $template->assign_block_vars( |
---|
291 | 'upgrade.infos.info', |
---|
292 | array( |
---|
293 | 'CONTENT' => $info, |
---|
294 | ) |
---|
295 | ); |
---|
296 | } |
---|
297 | |
---|
298 | $query = ' |
---|
299 | UPDATE '.USER_CACHE_TABLE.' |
---|
300 | SET need_update = \'true\' |
---|
301 | ;'; |
---|
302 | pwg_query($query); |
---|
303 | } |
---|
304 | else |
---|
305 | { |
---|
306 | die('Hacking attempt'); |
---|
307 | } |
---|
308 | } |
---|
309 | |
---|
310 | // +-----------------------------------------------------------------------+ |
---|
311 | // | sending html code | |
---|
312 | // +-----------------------------------------------------------------------+ |
---|
313 | |
---|
314 | $template->pparse('upgrade'); |
---|
315 | ?> |
---|