[1927] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1927] | 23 | |
---|
| 24 | define('PHPWG_ROOT_PATH', './'); |
---|
| 25 | |
---|
[2863] | 26 | // load config file |
---|
[8722] | 27 | if (is_file(PHPWG_ROOT_PATH .'local/config/multisite.inc.php')) |
---|
| 28 | { |
---|
| 29 | include(PHPWG_ROOT_PATH .'local/config/multisite.inc.php'); |
---|
| 30 | define('PWG_LOCAL_DIR', $conf['local_dir_site']); |
---|
| 31 | } |
---|
| 32 | else |
---|
| 33 | { |
---|
| 34 | define('PWG_LOCAL_DIR', 'local/'); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | $config_file = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'config/database.inc.php'; |
---|
[2863] | 38 | $config_file_contents = @file_get_contents($config_file); |
---|
| 39 | if ($config_file_contents === false) |
---|
[2836] | 40 | { |
---|
[2863] | 41 | die('Cannot load '.$config_file); |
---|
[2836] | 42 | } |
---|
[2863] | 43 | $php_end_tag = strrpos($config_file_contents, '?'.'>'); |
---|
| 44 | if ($php_end_tag === false) |
---|
| 45 | { |
---|
| 46 | die('Cannot find php end tag in '.$config_file); |
---|
| 47 | } |
---|
[2836] | 48 | |
---|
[8722] | 49 | include($config_file); |
---|
[1927] | 50 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
[5215] | 51 | @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php'); |
---|
[8722] | 52 | if (isset($conf['local_dir_site'])) |
---|
| 53 | { |
---|
| 54 | @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php'); |
---|
| 55 | } |
---|
[1927] | 56 | |
---|
[5387] | 57 | // $conf is not used for users tables - define cannot be re-defined |
---|
| 58 | define('USERS_TABLE', $prefixeTable.'users'); |
---|
[1927] | 59 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
| 60 | define('PREFIX_TABLE', $prefixeTable); |
---|
[5982] | 61 | define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db'); |
---|
[1927] | 62 | |
---|
[6110] | 63 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
| 64 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 65 | |
---|
[1927] | 66 | // +-----------------------------------------------------------------------+ |
---|
| 67 | // | functions | |
---|
| 68 | // +-----------------------------------------------------------------------+ |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * list all tables in an array |
---|
| 72 | * |
---|
| 73 | * @return array |
---|
| 74 | */ |
---|
| 75 | function get_tables() |
---|
| 76 | { |
---|
| 77 | $tables = array(); |
---|
[2290] | 78 | |
---|
[1927] | 79 | $query = ' |
---|
| 80 | SHOW TABLES |
---|
| 81 | ;'; |
---|
[2884] | 82 | $result = pwg_query($query); |
---|
[1927] | 83 | |
---|
[4325] | 84 | while ($row = pwg_db_fetch_row($result)) |
---|
[1927] | 85 | { |
---|
| 86 | if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) |
---|
| 87 | { |
---|
| 88 | array_push($tables, $row[0]); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | return $tables; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * list all columns of each given table |
---|
| 97 | * |
---|
| 98 | * @return array of array |
---|
| 99 | */ |
---|
| 100 | function get_columns_of($tables) |
---|
| 101 | { |
---|
| 102 | $columns_of = array(); |
---|
| 103 | |
---|
| 104 | foreach ($tables as $table) |
---|
| 105 | { |
---|
| 106 | $query = ' |
---|
| 107 | DESC '.$table.' |
---|
| 108 | ;'; |
---|
[2884] | 109 | $result = pwg_query($query); |
---|
[1927] | 110 | |
---|
| 111 | $columns_of[$table] = array(); |
---|
| 112 | |
---|
[4325] | 113 | while ($row = pwg_db_fetch_row($result)) |
---|
[1927] | 114 | { |
---|
| 115 | array_push($columns_of[$table], $row[0]); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return $columns_of; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | */ |
---|
| 124 | function print_time($message) |
---|
| 125 | { |
---|
| 126 | global $last_time; |
---|
[2290] | 127 | |
---|
[1927] | 128 | $new_time = get_moment(); |
---|
| 129 | echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; |
---|
| 130 | echo ' '.$message; |
---|
| 131 | echo '</pre>'; |
---|
| 132 | flush(); |
---|
| 133 | $last_time = $new_time; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // +-----------------------------------------------------------------------+ |
---|
| 137 | // | playing zone | |
---|
| 138 | // +-----------------------------------------------------------------------+ |
---|
| 139 | |
---|
| 140 | // echo implode('<br>', get_tables()); |
---|
| 141 | // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; |
---|
| 142 | |
---|
| 143 | // foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
| 144 | // { |
---|
| 145 | // echo $upgrade_id, '<br>'; |
---|
| 146 | // } |
---|
| 147 | |
---|
| 148 | // +-----------------------------------------------------------------------+ |
---|
[2819] | 149 | // | language | |
---|
| 150 | // +-----------------------------------------------------------------------+ |
---|
[5387] | 151 | include(PHPWG_ROOT_PATH . 'admin/include/languages.class.php'); |
---|
| 152 | $languages = new languages('utf-8'); |
---|
| 153 | |
---|
[2819] | 154 | if (isset($_GET['language'])) |
---|
| 155 | { |
---|
| 156 | $language = strip_tags($_GET['language']); |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | $language = 'en_UK'; |
---|
| 161 | // Try to get browser language |
---|
[5387] | 162 | foreach ($languages->fs_languages as $language_code => $language_name) |
---|
[2819] | 163 | { |
---|
| 164 | if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) |
---|
| 165 | { |
---|
| 166 | $language = $language_code; |
---|
| 167 | break; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
[3203] | 172 | if ('fr_FR' == $language) { |
---|
| 173 | define('PHPWG_DOMAIN', 'fr.piwigo.org'); |
---|
| 174 | } |
---|
[5234] | 175 | else if ('it_IT' == $language) { |
---|
| 176 | define('PHPWG_DOMAIN', 'it.piwigo.org'); |
---|
| 177 | } |
---|
| 178 | else if ('de_DE' == $language) { |
---|
| 179 | define('PHPWG_DOMAIN', 'de.piwigo.org'); |
---|
| 180 | } |
---|
| 181 | else if ('es_ES' == $language) { |
---|
| 182 | define('PHPWG_DOMAIN', 'es.piwigo.org'); |
---|
| 183 | } |
---|
[4816] | 184 | else if ('pl_PL' == $language) { |
---|
| 185 | define('PHPWG_DOMAIN', 'pl.piwigo.org'); |
---|
| 186 | } |
---|
| 187 | else if ('zh_CN' == $language) { |
---|
| 188 | define('PHPWG_DOMAIN', 'cn.piwigo.org'); |
---|
| 189 | } |
---|
[5234] | 190 | else if ('hu_HU' == $language) { |
---|
| 191 | define('PHPWG_DOMAIN', 'hu.piwigo.org'); |
---|
| 192 | } |
---|
| 193 | else if ('ru_RU' == $language) { |
---|
| 194 | define('PHPWG_DOMAIN', 'ru.piwigo.org'); |
---|
| 195 | } |
---|
[6152] | 196 | else if ('nl_NL' == $language) { |
---|
| 197 | define('PHPWG_DOMAIN', 'nl.piwigo.org'); |
---|
| 198 | } |
---|
[3203] | 199 | else { |
---|
| 200 | define('PHPWG_DOMAIN', 'piwigo.org'); |
---|
| 201 | } |
---|
| 202 | define('PHPWG_URL', 'http://'.PHPWG_DOMAIN); |
---|
| 203 | |
---|
[2836] | 204 | load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
| 205 | load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[3203] | 206 | load_language( 'install.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2836] | 207 | load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2819] | 208 | |
---|
[3203] | 209 | // check php version |
---|
| 210 | if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) |
---|
| 211 | { |
---|
| 212 | include(PHPWG_ROOT_PATH.'install/php5_apache_configuration.php'); |
---|
| 213 | } |
---|
| 214 | |
---|
[2819] | 215 | // +-----------------------------------------------------------------------+ |
---|
[5387] | 216 | // | database connection | |
---|
| 217 | // +-----------------------------------------------------------------------+ |
---|
| 218 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); |
---|
| 219 | include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php'); |
---|
| 220 | |
---|
| 221 | upgrade_db_connect(); |
---|
| 222 | pwg_db_check_charset(); |
---|
| 223 | |
---|
[5982] | 224 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 225 | define('CURRENT_DATE', $dbnow); |
---|
| 226 | |
---|
[5387] | 227 | // +-----------------------------------------------------------------------+ |
---|
[1927] | 228 | // | template initialization | |
---|
| 229 | // +-----------------------------------------------------------------------+ |
---|
| 230 | |
---|
[3203] | 231 | include( PHPWG_ROOT_PATH .'include/template.class.php'); |
---|
[5123] | 232 | $template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'roma'); |
---|
[1927] | 233 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
[3203] | 234 | $template->assign(array( |
---|
| 235 | 'RELEASE' => PHPWG_VERSION, |
---|
[5207] | 236 | 'L_UPGRADE_HELP' => sprintf(l10n('Need help ? Ask your question on <a href="%s">Piwigo message board</a>.'), PHPWG_URL.'/forum'), |
---|
[3203] | 237 | ) |
---|
| 238 | ); |
---|
[1927] | 239 | |
---|
| 240 | // +-----------------------------------------------------------------------+ |
---|
| 241 | // | upgrade choice | |
---|
| 242 | // +-----------------------------------------------------------------------+ |
---|
| 243 | |
---|
[1999] | 244 | $tables = get_tables(); |
---|
| 245 | $columns_of = get_columns_of($tables); |
---|
| 246 | |
---|
[2836] | 247 | // find the current release |
---|
| 248 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
[1927] | 249 | { |
---|
[2836] | 250 | // we're in branch 1.3, important upgrade, isn't it? |
---|
| 251 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
[1927] | 252 | { |
---|
[2836] | 253 | $current_release = '1.3.1'; |
---|
[1927] | 254 | } |
---|
[2836] | 255 | else |
---|
[1927] | 256 | { |
---|
[2836] | 257 | $current_release = '1.3.0'; |
---|
[1927] | 258 | } |
---|
[2836] | 259 | } |
---|
| 260 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
| 261 | { |
---|
| 262 | $current_release = '1.4.0'; |
---|
| 263 | } |
---|
| 264 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
| 265 | { |
---|
| 266 | $current_release = '1.5.0'; |
---|
| 267 | } |
---|
[2862] | 268 | else if ( !in_array(PREFIX_TABLE.'plugins', $tables) ) |
---|
[2836] | 269 | { |
---|
| 270 | if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
[1927] | 271 | { |
---|
[2836] | 272 | $current_release = '1.6.0'; |
---|
[1927] | 273 | } |
---|
| 274 | else |
---|
| 275 | { |
---|
[2836] | 276 | $current_release = '1.6.2'; |
---|
[1927] | 277 | } |
---|
| 278 | } |
---|
[2836] | 279 | else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) |
---|
| 280 | { |
---|
| 281 | $current_release = '1.7.0'; |
---|
| 282 | } |
---|
[5982] | 283 | else if (!in_array(PREFIX_TABLE.'themes', $tables)) |
---|
| 284 | { |
---|
| 285 | $current_release = '2.0.0'; |
---|
| 286 | } |
---|
[2836] | 287 | else |
---|
| 288 | { |
---|
| 289 | die('No upgrade required, the database structure is up to date'); |
---|
| 290 | } |
---|
[1927] | 291 | |
---|
| 292 | // +-----------------------------------------------------------------------+ |
---|
| 293 | // | upgrade launch | |
---|
| 294 | // +-----------------------------------------------------------------------+ |
---|
[2836] | 295 | $page['infos'] = array(); |
---|
| 296 | $page['errors'] = array(); |
---|
[2863] | 297 | $mysql_changes = array(); |
---|
[1927] | 298 | |
---|
[6110] | 299 | check_upgrade_access_rights(); |
---|
[2254] | 300 | |
---|
[6110] | 301 | if ((isset($_POST['submit']) or isset($_GET['now'])) |
---|
| 302 | and check_upgrade()) |
---|
[2836] | 303 | { |
---|
| 304 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$current_release.'.php'; |
---|
[1927] | 305 | if (is_file($upgrade_file)) |
---|
| 306 | { |
---|
| 307 | $page['upgrade_start'] = get_moment(); |
---|
| 308 | $conf['die_on_sql_error'] = false; |
---|
| 309 | include($upgrade_file); |
---|
| 310 | |
---|
[5213] | 311 | // Something to add in database.inc.php? |
---|
[2863] | 312 | if (!empty($mysql_changes)) |
---|
| 313 | { |
---|
| 314 | $config_file_contents = |
---|
| 315 | substr($config_file_contents, 0, $php_end_tag) . "\r\n" |
---|
[2865] | 316 | . implode("\r\n" , $mysql_changes) . "\r\n" |
---|
[2863] | 317 | . substr($config_file_contents, $php_end_tag); |
---|
| 318 | |
---|
| 319 | if (!@file_put_contents($config_file, $config_file_contents)) |
---|
| 320 | { |
---|
[5982] | 321 | array_push( |
---|
| 322 | $page['infos'], |
---|
| 323 | sprintf( |
---|
| 324 | l10n('In <i>%s</i>, before <b>?></b>, insert:'), |
---|
[8722] | 325 | PWG_LOCAL_DIR.'config/database.inc.php' |
---|
[5982] | 326 | ) |
---|
| 327 | .'<p><textarea rows="4" cols="40">' |
---|
| 328 | .implode("\r\n" , $mysql_changes).'</textarea></p>' |
---|
| 329 | ); |
---|
[2863] | 330 | } |
---|
| 331 | } |
---|
| 332 | |
---|
[2787] | 333 | // Plugins deactivation |
---|
| 334 | if (in_array(PREFIX_TABLE.'plugins', $tables)) |
---|
| 335 | { |
---|
[2815] | 336 | deactivate_non_standard_plugins(); |
---|
[2787] | 337 | } |
---|
| 338 | |
---|
[1927] | 339 | $page['upgrade_end'] = get_moment(); |
---|
| 340 | |
---|
[2254] | 341 | $template->assign( |
---|
[1927] | 342 | 'upgrade', |
---|
| 343 | array( |
---|
[2836] | 344 | 'VERSION' => $current_release, |
---|
[1927] | 345 | 'TOTAL_TIME' => get_elapsed_time( |
---|
| 346 | $page['upgrade_start'], |
---|
| 347 | $page['upgrade_end'] |
---|
| 348 | ), |
---|
| 349 | 'SQL_TIME' => number_format( |
---|
| 350 | $page['queries_time'], |
---|
| 351 | 3, |
---|
| 352 | '.', |
---|
| 353 | ' ' |
---|
| 354 | ).' s', |
---|
| 355 | 'NB_QUERIES' => $page['count_queries'] |
---|
| 356 | ) |
---|
| 357 | ); |
---|
| 358 | |
---|
[2819] | 359 | array_push($page['infos'], |
---|
[6335] | 360 | l10n('Perform a maintenance check in [Administration>Tools>Maintenance] if you encounter any problem.') |
---|
[1927] | 361 | ); |
---|
| 362 | |
---|
[3072] | 363 | // Save $page['infos'] in order to restore after maintenance actions |
---|
| 364 | $page['infos_sav'] = $page['infos']; |
---|
| 365 | $page['infos'] = array(); |
---|
| 366 | |
---|
[2812] | 367 | // c13y_upgrade plugin means "check integrity after upgrade", so it |
---|
| 368 | // becomes useful just after an upgrade |
---|
[2808] | 369 | $query = ' |
---|
| 370 | REPLACE INTO '.PLUGINS_TABLE.' |
---|
| 371 | (id, state) |
---|
| 372 | VALUES (\'c13y_upgrade\', \'active\') |
---|
| 373 | ;'; |
---|
| 374 | pwg_query($query); |
---|
[2890] | 375 | |
---|
| 376 | // Delete cache data |
---|
| 377 | invalidate_user_cache(true); |
---|
| 378 | $template->delete_compiled_templates(); |
---|
| 379 | |
---|
| 380 | // Tables Maintenance |
---|
| 381 | do_maintenance_all_tables(); |
---|
| 382 | |
---|
[3072] | 383 | // Restore $page['infos'] in order to hide informations messages from functions calles |
---|
| 384 | // errors messages are not hide |
---|
| 385 | $page['infos'] = $page['infos_sav']; |
---|
| 386 | |
---|
[1927] | 387 | } |
---|
[2836] | 388 | } |
---|
| 389 | |
---|
| 390 | // +-----------------------------------------------------------------------+ |
---|
| 391 | // | start template output | |
---|
| 392 | // +-----------------------------------------------------------------------+ |
---|
| 393 | else |
---|
| 394 | { |
---|
[5982] | 395 | if (!defined('PWG_CHARSET')) |
---|
[1927] | 396 | { |
---|
[5982] | 397 | define('PWG_CHARSET', 'utf-8'); |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); |
---|
| 401 | $languages = new languages(); |
---|
| 402 | |
---|
| 403 | foreach ($languages->fs_languages as $language_code => $language_name) |
---|
| 404 | { |
---|
[2836] | 405 | if ($language == $language_code) |
---|
| 406 | { |
---|
| 407 | $template->assign('language_selection', $language_code); |
---|
| 408 | } |
---|
| 409 | $languages_options[$language_code] = $language_name; |
---|
[1927] | 410 | } |
---|
[2836] | 411 | $template->assign('language_options', $languages_options); |
---|
| 412 | |
---|
| 413 | $template->assign('introduction', array( |
---|
| 414 | 'CURRENT_RELEASE' => $current_release, |
---|
| 415 | 'F_ACTION' => 'upgrade.php?language=' . $language)); |
---|
| 416 | |
---|
| 417 | if (!check_upgrade()) |
---|
| 418 | { |
---|
| 419 | $template->assign('login', true); |
---|
| 420 | } |
---|
[1927] | 421 | } |
---|
| 422 | |
---|
[2836] | 423 | if (count($page['errors']) != 0) |
---|
| 424 | { |
---|
| 425 | $template->assign('errors', $page['errors']); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | if (count($page['infos']) != 0) |
---|
| 429 | { |
---|
| 430 | $template->assign('infos', $page['infos']); |
---|
| 431 | } |
---|
| 432 | |
---|
[1927] | 433 | // +-----------------------------------------------------------------------+ |
---|
| 434 | // | sending html code | |
---|
| 435 | // +-----------------------------------------------------------------------+ |
---|
| 436 | |
---|
| 437 | $template->pparse('upgrade'); |
---|
| 438 | ?> |
---|