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