1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | define('PHPWG_ROOT_PATH', './'); |
---|
25 | |
---|
26 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
27 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
28 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); |
---|
29 | include(PHPWG_ROOT_PATH.'include/template.class.php'); |
---|
30 | |
---|
31 | include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); |
---|
32 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
33 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
34 | |
---|
35 | check_upgrade(); |
---|
36 | |
---|
37 | prepare_conf_upgrade(); |
---|
38 | |
---|
39 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
40 | define('PREFIX_TABLE', $prefixeTable); |
---|
41 | |
---|
42 | // Database connection |
---|
43 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) or die ( "Could not connect to database server" ); |
---|
44 | mysql_select_db( $cfgBase ) or die ( "Could not connect to database" ); |
---|
45 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') |
---|
46 | and defined('DB_CHARSET') and DB_CHARSET!='' ) |
---|
47 | { |
---|
48 | pwg_query('SET NAMES "'.DB_CHARSET.'"'); |
---|
49 | } |
---|
50 | |
---|
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('RELEASE', PHPWG_VERSION); |
---|
152 | |
---|
153 | // +-----------------------------------------------------------------------+ |
---|
154 | // | upgrade choice | |
---|
155 | // +-----------------------------------------------------------------------+ |
---|
156 | |
---|
157 | $tables = get_tables(); |
---|
158 | $columns_of = get_columns_of($tables); |
---|
159 | |
---|
160 | if (!isset($_GET['version'])) |
---|
161 | { |
---|
162 | // find the current release |
---|
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( |
---|
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 | if (in_array(PREFIX_TABLE.'history_summary', $tables)) |
---|
216 | { |
---|
217 | die('No database upgrade required, do not refresh the page'); |
---|
218 | } |
---|
219 | |
---|
220 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; |
---|
221 | if (is_file($upgrade_file)) |
---|
222 | { |
---|
223 | $page['infos'] = array(); |
---|
224 | $page['upgrade_start'] = get_moment(); |
---|
225 | $conf['die_on_sql_error'] = false; |
---|
226 | include($upgrade_file); |
---|
227 | |
---|
228 | // Available upgrades must be ignored after a fresh installation. To |
---|
229 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
230 | // made. |
---|
231 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
232 | define('CURRENT_DATE', $dbnow); |
---|
233 | $datas = array(); |
---|
234 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
235 | { |
---|
236 | array_push( |
---|
237 | $datas, |
---|
238 | array( |
---|
239 | 'id' => $upgrade_id, |
---|
240 | 'applied' => CURRENT_DATE, |
---|
241 | 'description' => 'upgrade included in migration', |
---|
242 | ) |
---|
243 | ); |
---|
244 | } |
---|
245 | mass_inserts( |
---|
246 | UPGRADE_TABLE, |
---|
247 | array_keys($datas[0]), |
---|
248 | $datas |
---|
249 | ); |
---|
250 | |
---|
251 | // Create empty local files to avoid log errors |
---|
252 | create_empty_local_files(); |
---|
253 | |
---|
254 | $page['upgrade_end'] = get_moment(); |
---|
255 | |
---|
256 | $template->assign( |
---|
257 | 'upgrade', |
---|
258 | array( |
---|
259 | 'VERSION' => $_GET['version'], |
---|
260 | 'TOTAL_TIME' => get_elapsed_time( |
---|
261 | $page['upgrade_start'], |
---|
262 | $page['upgrade_end'] |
---|
263 | ), |
---|
264 | 'SQL_TIME' => number_format( |
---|
265 | $page['queries_time'], |
---|
266 | 3, |
---|
267 | '.', |
---|
268 | ' ' |
---|
269 | ).' s', |
---|
270 | 'NB_QUERIES' => $page['count_queries'] |
---|
271 | ) |
---|
272 | ); |
---|
273 | |
---|
274 | array_push( |
---|
275 | $page['infos'], |
---|
276 | '[security] delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" |
---|
277 | directory' |
---|
278 | ); |
---|
279 | |
---|
280 | array_push( |
---|
281 | $page['infos'], |
---|
282 | 'in include/mysql.inc.php, remove |
---|
283 | <pre style="background-color:lightgray"> |
---|
284 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
285 | </pre>' |
---|
286 | ); |
---|
287 | |
---|
288 | array_push( |
---|
289 | $page['infos'], |
---|
290 | 'Perform a maintenance check in [Administration>General>Maintenance] |
---|
291 | if you encounter any problem.' |
---|
292 | ); |
---|
293 | |
---|
294 | $template->assign('infos', $page['infos']); |
---|
295 | |
---|
296 | $query = ' |
---|
297 | UPDATE '.USER_CACHE_TABLE.' |
---|
298 | SET need_update = \'true\' |
---|
299 | ;'; |
---|
300 | |
---|
301 | pwg_query($query); |
---|
302 | $query = ' |
---|
303 | REPLACE INTO '.PLUGINS_TABLE.' |
---|
304 | (id, state) |
---|
305 | VALUES (\'c13y_upgrade\', \'active\') |
---|
306 | ;'; |
---|
307 | pwg_query($query); |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | die('Hacking attempt'); |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | // +-----------------------------------------------------------------------+ |
---|
316 | // | sending html code | |
---|
317 | // +-----------------------------------------------------------------------+ |
---|
318 | |
---|
319 | $template->pparse('upgrade'); |
---|
320 | ?> |
---|