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 ) |
---|
44 | or die ( "Could not connect to database server" ); |
---|
45 | mysql_select_db( $cfgBase ) |
---|
46 | or die ( "Could not connect to database" ); |
---|
47 | // +-----------------------------------------------------------------------+ |
---|
48 | // | tricky output | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | echo '<!-- This is an HTML comment given in order to make IE outputs'; |
---|
51 | echo ' the code.'."\n"; |
---|
52 | echo ' Indeed, IE doesn\'t start to send output until a limit'; |
---|
53 | echo ' of XXX bytes '."\n"; |
---|
54 | echo str_repeat( ' ', 80 )."\n"; |
---|
55 | echo str_repeat( ' ', 80 )."\n"; |
---|
56 | echo str_repeat( ' ', 80 )."\n"; |
---|
57 | echo '-->'."\n"; |
---|
58 | flush(); |
---|
59 | // +-----------------------------------------------------------------------+ |
---|
60 | // | functions | |
---|
61 | // +-----------------------------------------------------------------------+ |
---|
62 | |
---|
63 | /** |
---|
64 | * list all tables in an array |
---|
65 | * |
---|
66 | * @return array |
---|
67 | */ |
---|
68 | function get_tables() |
---|
69 | { |
---|
70 | $tables = array(); |
---|
71 | |
---|
72 | $query = ' |
---|
73 | SHOW TABLES |
---|
74 | ;'; |
---|
75 | $result = mysql_query($query); |
---|
76 | |
---|
77 | while ($row = mysql_fetch_row($result)) |
---|
78 | { |
---|
79 | if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) |
---|
80 | { |
---|
81 | array_push($tables, $row[0]); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | return $tables; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * list all columns of each given table |
---|
90 | * |
---|
91 | * @return array of array |
---|
92 | */ |
---|
93 | function get_columns_of($tables) |
---|
94 | { |
---|
95 | $columns_of = array(); |
---|
96 | |
---|
97 | foreach ($tables as $table) |
---|
98 | { |
---|
99 | $query = ' |
---|
100 | DESC '.$table.' |
---|
101 | ;'; |
---|
102 | $result = mysql_query($query); |
---|
103 | |
---|
104 | $columns_of[$table] = array(); |
---|
105 | |
---|
106 | while ($row = mysql_fetch_row($result)) |
---|
107 | { |
---|
108 | array_push($columns_of[$table], $row[0]); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | return $columns_of; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | */ |
---|
117 | function print_time($message) |
---|
118 | { |
---|
119 | global $last_time; |
---|
120 | |
---|
121 | $new_time = get_moment(); |
---|
122 | echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; |
---|
123 | echo ' '.$message; |
---|
124 | echo '</pre>'; |
---|
125 | flush(); |
---|
126 | $last_time = $new_time; |
---|
127 | } |
---|
128 | |
---|
129 | // +-----------------------------------------------------------------------+ |
---|
130 | // | playing zone | |
---|
131 | // +-----------------------------------------------------------------------+ |
---|
132 | |
---|
133 | // echo implode('<br>', get_tables()); |
---|
134 | // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; |
---|
135 | |
---|
136 | // foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
137 | // { |
---|
138 | // echo $upgrade_id, '<br>'; |
---|
139 | // } |
---|
140 | |
---|
141 | // +-----------------------------------------------------------------------+ |
---|
142 | // | template initialization | |
---|
143 | // +-----------------------------------------------------------------------+ |
---|
144 | |
---|
145 | $template = new Template(PHPWG_ROOT_PATH.'template/yoga'); |
---|
146 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
147 | $template->assign('RELEASE', PHPWG_VERSION); |
---|
148 | |
---|
149 | // +-----------------------------------------------------------------------+ |
---|
150 | // | upgrade choice | |
---|
151 | // +-----------------------------------------------------------------------+ |
---|
152 | |
---|
153 | $tables = get_tables(); |
---|
154 | $columns_of = get_columns_of($tables); |
---|
155 | |
---|
156 | if (!isset($_GET['version'])) |
---|
157 | { |
---|
158 | // find the current release |
---|
159 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
160 | { |
---|
161 | // we're in branch 1.3, important upgrade, isn't it? |
---|
162 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
163 | { |
---|
164 | $current_release = '1.3.1'; |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | $current_release = '1.3.0'; |
---|
169 | } |
---|
170 | } |
---|
171 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
172 | { |
---|
173 | $current_release = '1.4.0'; |
---|
174 | } |
---|
175 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
176 | { |
---|
177 | $current_release = '1.5.0'; |
---|
178 | } |
---|
179 | else if ( !in_array(PREFIX_TABLE.'history_summary', $tables) ) |
---|
180 | { |
---|
181 | if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
182 | { |
---|
183 | $current_release = '1.6.0'; |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | $current_release = '1.6.2'; |
---|
188 | } |
---|
189 | } |
---|
190 | else |
---|
191 | { |
---|
192 | die('No upgrade required, the database structure is up to date'); |
---|
193 | } |
---|
194 | |
---|
195 | $template->assign( |
---|
196 | 'introduction', |
---|
197 | array( |
---|
198 | 'CURRENT_RELEASE' => $current_release, |
---|
199 | 'RUN_UPGRADE_URL' => |
---|
200 | PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, |
---|
201 | ) |
---|
202 | ); |
---|
203 | } |
---|
204 | |
---|
205 | // +-----------------------------------------------------------------------+ |
---|
206 | // | upgrade launch | |
---|
207 | // +-----------------------------------------------------------------------+ |
---|
208 | |
---|
209 | else |
---|
210 | { |
---|
211 | if (in_array(PREFIX_TABLE.'history_summary', $tables)) |
---|
212 | { |
---|
213 | die('No database upgrade required, do not refresh the page'); |
---|
214 | } |
---|
215 | |
---|
216 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; |
---|
217 | if (is_file($upgrade_file)) |
---|
218 | { |
---|
219 | $page['infos'] = array(); |
---|
220 | $page['upgrade_start'] = get_moment(); |
---|
221 | $conf['die_on_sql_error'] = false; |
---|
222 | include($upgrade_file); |
---|
223 | |
---|
224 | // Available upgrades must be ignored after a fresh installation. To |
---|
225 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
226 | // made. |
---|
227 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
228 | define('CURRENT_DATE', $dbnow); |
---|
229 | $datas = array(); |
---|
230 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
231 | { |
---|
232 | array_push( |
---|
233 | $datas, |
---|
234 | array( |
---|
235 | 'id' => $upgrade_id, |
---|
236 | 'applied' => CURRENT_DATE, |
---|
237 | 'description' => 'upgrade included in migration', |
---|
238 | ) |
---|
239 | ); |
---|
240 | } |
---|
241 | mass_inserts( |
---|
242 | UPGRADE_TABLE, |
---|
243 | array_keys($datas[0]), |
---|
244 | $datas |
---|
245 | ); |
---|
246 | |
---|
247 | // Create empty local files to avoid log errors |
---|
248 | create_empty_local_files(); |
---|
249 | |
---|
250 | $page['upgrade_end'] = get_moment(); |
---|
251 | |
---|
252 | $template->assign( |
---|
253 | 'upgrade', |
---|
254 | array( |
---|
255 | 'VERSION' => $_GET['version'], |
---|
256 | 'TOTAL_TIME' => get_elapsed_time( |
---|
257 | $page['upgrade_start'], |
---|
258 | $page['upgrade_end'] |
---|
259 | ), |
---|
260 | 'SQL_TIME' => number_format( |
---|
261 | $page['queries_time'], |
---|
262 | 3, |
---|
263 | '.', |
---|
264 | ' ' |
---|
265 | ).' s', |
---|
266 | 'NB_QUERIES' => $page['count_queries'] |
---|
267 | ) |
---|
268 | ); |
---|
269 | |
---|
270 | array_push( |
---|
271 | $page['infos'], |
---|
272 | '[security] delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" |
---|
273 | directory' |
---|
274 | ); |
---|
275 | |
---|
276 | array_push( |
---|
277 | $page['infos'], |
---|
278 | 'in include/mysql.inc.php, remove |
---|
279 | <pre style="background-color:lightgray"> |
---|
280 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
281 | </pre>' |
---|
282 | ); |
---|
283 | |
---|
284 | array_push( |
---|
285 | $page['infos'], |
---|
286 | 'Perform a maintenance check in [Administration>General>Maintenance] |
---|
287 | if you encounter any problem.' |
---|
288 | ); |
---|
289 | |
---|
290 | $template->assign('infos', $page['infos']); |
---|
291 | |
---|
292 | $query = ' |
---|
293 | UPDATE '.USER_CACHE_TABLE.' |
---|
294 | SET need_update = \'true\' |
---|
295 | ;'; |
---|
296 | |
---|
297 | pwg_query($query); |
---|
298 | $query = ' |
---|
299 | REPLACE INTO '.PLUGINS_TABLE.' |
---|
300 | (id, state) |
---|
301 | VALUES (\'c13y_upgrade\', \'active\') |
---|
302 | ;'; |
---|
303 | pwg_query($query); |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | die('Hacking attempt'); |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | // +-----------------------------------------------------------------------+ |
---|
312 | // | sending html code | |
---|
313 | // +-----------------------------------------------------------------------+ |
---|
314 | |
---|
315 | $template->pparse('upgrade'); |
---|
316 | ?> |
---|