[1927] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 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 |
---|
[5213] | 27 | $config_file = PHPWG_ROOT_PATH.'local/config/database.inc.php'; |
---|
[2863] | 28 | $config_file_contents = @file_get_contents($config_file); |
---|
| 29 | if ($config_file_contents === false) |
---|
[2836] | 30 | { |
---|
[2863] | 31 | die('Cannot load '.$config_file); |
---|
[2836] | 32 | } |
---|
[2863] | 33 | $php_end_tag = strrpos($config_file_contents, '?'.'>'); |
---|
| 34 | if ($php_end_tag === false) |
---|
| 35 | { |
---|
| 36 | die('Cannot find php end tag in '.$config_file); |
---|
| 37 | } |
---|
[2836] | 38 | |
---|
[1927] | 39 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
| 40 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 41 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); |
---|
| 42 | |
---|
[5213] | 43 | include(PHPWG_ROOT_PATH.'local/config/database.inc.php'); |
---|
[1927] | 44 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
[5215] | 45 | @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php'); |
---|
[4385] | 46 | include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php'); |
---|
[1927] | 47 | |
---|
[2096] | 48 | prepare_conf_upgrade(); |
---|
[1927] | 49 | |
---|
| 50 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
| 51 | define('PREFIX_TABLE', $prefixeTable); |
---|
| 52 | |
---|
| 53 | // Database connection |
---|
[5236] | 54 | try |
---|
| 55 | { |
---|
| 56 | $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'], |
---|
| 57 | $conf['db_password'], $conf['db_base']); |
---|
| 58 | } |
---|
| 59 | catch (Exception $e) |
---|
| 60 | { |
---|
[5238] | 61 | my_error(l10n($e->getMessage(), true)); |
---|
[5236] | 62 | } |
---|
[2512] | 63 | |
---|
[4325] | 64 | pwg_db_check_charset(); |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
| 151 | if (isset($_GET['language'])) |
---|
| 152 | { |
---|
| 153 | $language = strip_tags($_GET['language']); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | $language = 'en_UK'; |
---|
| 158 | // Try to get browser language |
---|
| 159 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
| 160 | { |
---|
| 161 | if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) |
---|
| 162 | { |
---|
| 163 | $language = $language_code; |
---|
| 164 | break; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
[3203] | 169 | if ('fr_FR' == $language) { |
---|
| 170 | define('PHPWG_DOMAIN', 'fr.piwigo.org'); |
---|
| 171 | } |
---|
[5234] | 172 | else if ('it_IT' == $language) { |
---|
| 173 | define('PHPWG_DOMAIN', 'it.piwigo.org'); |
---|
| 174 | } |
---|
| 175 | else if ('de_DE' == $language) { |
---|
| 176 | define('PHPWG_DOMAIN', 'de.piwigo.org'); |
---|
| 177 | } |
---|
| 178 | else if ('es_ES' == $language) { |
---|
| 179 | define('PHPWG_DOMAIN', 'es.piwigo.org'); |
---|
| 180 | } |
---|
[4816] | 181 | else if ('pl_PL' == $language) { |
---|
| 182 | define('PHPWG_DOMAIN', 'pl.piwigo.org'); |
---|
| 183 | } |
---|
| 184 | else if ('zh_CN' == $language) { |
---|
| 185 | define('PHPWG_DOMAIN', 'cn.piwigo.org'); |
---|
| 186 | } |
---|
[5234] | 187 | else if ('hu_HU' == $language) { |
---|
| 188 | define('PHPWG_DOMAIN', 'hu.piwigo.org'); |
---|
| 189 | } |
---|
| 190 | else if ('ru_RU' == $language) { |
---|
| 191 | define('PHPWG_DOMAIN', 'ru.piwigo.org'); |
---|
| 192 | } |
---|
[3203] | 193 | else { |
---|
| 194 | define('PHPWG_DOMAIN', 'piwigo.org'); |
---|
| 195 | } |
---|
| 196 | define('PHPWG_URL', 'http://'.PHPWG_DOMAIN); |
---|
| 197 | |
---|
[2836] | 198 | load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
| 199 | load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[3203] | 200 | load_language( 'install.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2836] | 201 | load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2819] | 202 | |
---|
[3203] | 203 | // check php version |
---|
| 204 | if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) |
---|
| 205 | { |
---|
| 206 | include(PHPWG_ROOT_PATH.'install/php5_apache_configuration.php'); |
---|
| 207 | } |
---|
| 208 | |
---|
[2819] | 209 | // +-----------------------------------------------------------------------+ |
---|
[1927] | 210 | // | template initialization | |
---|
| 211 | // +-----------------------------------------------------------------------+ |
---|
| 212 | |
---|
[3203] | 213 | include( PHPWG_ROOT_PATH .'include/template.class.php'); |
---|
[5123] | 214 | $template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'roma'); |
---|
[1927] | 215 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
[3203] | 216 | $template->assign(array( |
---|
| 217 | 'RELEASE' => PHPWG_VERSION, |
---|
[5207] | 218 | 'L_UPGRADE_HELP' => sprintf(l10n('Need help ? Ask your question on <a href="%s">Piwigo message board</a>.'), PHPWG_URL.'/forum'), |
---|
[3203] | 219 | ) |
---|
| 220 | ); |
---|
[1927] | 221 | |
---|
| 222 | // +-----------------------------------------------------------------------+ |
---|
| 223 | // | upgrade choice | |
---|
| 224 | // +-----------------------------------------------------------------------+ |
---|
| 225 | |
---|
[1999] | 226 | $tables = get_tables(); |
---|
| 227 | $columns_of = get_columns_of($tables); |
---|
| 228 | |
---|
[2836] | 229 | // find the current release |
---|
| 230 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
[1927] | 231 | { |
---|
[2836] | 232 | // we're in branch 1.3, important upgrade, isn't it? |
---|
| 233 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
[1927] | 234 | { |
---|
[2836] | 235 | $current_release = '1.3.1'; |
---|
[1927] | 236 | } |
---|
[2836] | 237 | else |
---|
[1927] | 238 | { |
---|
[2836] | 239 | $current_release = '1.3.0'; |
---|
[1927] | 240 | } |
---|
[2836] | 241 | } |
---|
| 242 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
| 243 | { |
---|
| 244 | $current_release = '1.4.0'; |
---|
| 245 | } |
---|
| 246 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
| 247 | { |
---|
| 248 | $current_release = '1.5.0'; |
---|
| 249 | } |
---|
[2862] | 250 | else if ( !in_array(PREFIX_TABLE.'plugins', $tables) ) |
---|
[2836] | 251 | { |
---|
| 252 | if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
[1927] | 253 | { |
---|
[2836] | 254 | $current_release = '1.6.0'; |
---|
[1927] | 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
[2836] | 258 | $current_release = '1.6.2'; |
---|
[1927] | 259 | } |
---|
| 260 | } |
---|
[2836] | 261 | else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) |
---|
| 262 | { |
---|
| 263 | $current_release = '1.7.0'; |
---|
| 264 | } |
---|
| 265 | else |
---|
| 266 | { |
---|
| 267 | die('No upgrade required, the database structure is up to date'); |
---|
| 268 | } |
---|
[1927] | 269 | |
---|
| 270 | // +-----------------------------------------------------------------------+ |
---|
| 271 | // | upgrade launch | |
---|
| 272 | // +-----------------------------------------------------------------------+ |
---|
[2836] | 273 | $page['infos'] = array(); |
---|
| 274 | $page['errors'] = array(); |
---|
[2863] | 275 | $mysql_changes = array(); |
---|
[1927] | 276 | |
---|
[2836] | 277 | if (isset($_POST['username']) and isset($_POST['password'])) |
---|
[1927] | 278 | { |
---|
[2836] | 279 | check_upgrade_access_rights($current_release, $_POST['username'], $_POST['password']); |
---|
| 280 | } |
---|
[2254] | 281 | |
---|
[2836] | 282 | if (isset($_POST['submit']) and check_upgrade()) |
---|
| 283 | { |
---|
| 284 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$current_release.'.php'; |
---|
[1927] | 285 | if (is_file($upgrade_file)) |
---|
| 286 | { |
---|
| 287 | $page['upgrade_start'] = get_moment(); |
---|
| 288 | $conf['die_on_sql_error'] = false; |
---|
| 289 | include($upgrade_file); |
---|
| 290 | |
---|
[5213] | 291 | // Something to add in database.inc.php? |
---|
[2863] | 292 | if (!empty($mysql_changes)) |
---|
| 293 | { |
---|
| 294 | $config_file_contents = |
---|
| 295 | substr($config_file_contents, 0, $php_end_tag) . "\r\n" |
---|
[2865] | 296 | . implode("\r\n" , $mysql_changes) . "\r\n" |
---|
[2863] | 297 | . substr($config_file_contents, $php_end_tag); |
---|
| 298 | |
---|
| 299 | if (!@file_put_contents($config_file, $config_file_contents)) |
---|
| 300 | { |
---|
| 301 | array_push($page['infos'], |
---|
[5021] | 302 | l10n_args('in <i>%s</i>, before <b>?></b>, insert:', |
---|
[5213] | 303 | 'local/config/database.inc.php') . |
---|
[5021] | 304 | '<p><textarea rows="4" cols="40">' . |
---|
| 305 | implode("\r\n" , $mysql_changes).'</textarea></p>' |
---|
| 306 | ); |
---|
[2863] | 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
[2787] | 310 | // Plugins deactivation |
---|
| 311 | if (in_array(PREFIX_TABLE.'plugins', $tables)) |
---|
| 312 | { |
---|
[2815] | 313 | deactivate_non_standard_plugins(); |
---|
[2787] | 314 | } |
---|
| 315 | |
---|
[1927] | 316 | $page['upgrade_end'] = get_moment(); |
---|
| 317 | |
---|
[2254] | 318 | $template->assign( |
---|
[1927] | 319 | 'upgrade', |
---|
| 320 | array( |
---|
[2836] | 321 | 'VERSION' => $current_release, |
---|
[1927] | 322 | 'TOTAL_TIME' => get_elapsed_time( |
---|
| 323 | $page['upgrade_start'], |
---|
| 324 | $page['upgrade_end'] |
---|
| 325 | ), |
---|
| 326 | 'SQL_TIME' => number_format( |
---|
| 327 | $page['queries_time'], |
---|
| 328 | 3, |
---|
| 329 | '.', |
---|
| 330 | ' ' |
---|
| 331 | ).' s', |
---|
| 332 | 'NB_QUERIES' => $page['count_queries'] |
---|
| 333 | ) |
---|
| 334 | ); |
---|
| 335 | |
---|
[2819] | 336 | array_push($page['infos'], |
---|
[5021] | 337 | l10n('Perform a maintenance check in [Administration>Specials>Maintenance] if you encounter any problem.') |
---|
[1927] | 338 | ); |
---|
| 339 | |
---|
[3072] | 340 | // Save $page['infos'] in order to restore after maintenance actions |
---|
| 341 | $page['infos_sav'] = $page['infos']; |
---|
| 342 | $page['infos'] = array(); |
---|
| 343 | |
---|
[2812] | 344 | // c13y_upgrade plugin means "check integrity after upgrade", so it |
---|
| 345 | // becomes useful just after an upgrade |
---|
[2808] | 346 | $query = ' |
---|
| 347 | REPLACE INTO '.PLUGINS_TABLE.' |
---|
| 348 | (id, state) |
---|
| 349 | VALUES (\'c13y_upgrade\', \'active\') |
---|
| 350 | ;'; |
---|
| 351 | pwg_query($query); |
---|
[2890] | 352 | |
---|
| 353 | // Delete cache data |
---|
| 354 | invalidate_user_cache(true); |
---|
| 355 | $template->delete_compiled_templates(); |
---|
| 356 | |
---|
| 357 | // Tables Maintenance |
---|
| 358 | do_maintenance_all_tables(); |
---|
| 359 | |
---|
[3072] | 360 | // Restore $page['infos'] in order to hide informations messages from functions calles |
---|
| 361 | // errors messages are not hide |
---|
| 362 | $page['infos'] = $page['infos_sav']; |
---|
| 363 | |
---|
[1927] | 364 | } |
---|
[2836] | 365 | } |
---|
| 366 | |
---|
| 367 | // +-----------------------------------------------------------------------+ |
---|
| 368 | // | start template output | |
---|
| 369 | // +-----------------------------------------------------------------------+ |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
[1927] | 373 | { |
---|
[2836] | 374 | if ($language == $language_code) |
---|
| 375 | { |
---|
| 376 | $template->assign('language_selection', $language_code); |
---|
| 377 | } |
---|
| 378 | $languages_options[$language_code] = $language_name; |
---|
[1927] | 379 | } |
---|
[2836] | 380 | $template->assign('language_options', $languages_options); |
---|
| 381 | |
---|
| 382 | $template->assign('introduction', array( |
---|
| 383 | 'CURRENT_RELEASE' => $current_release, |
---|
| 384 | 'F_ACTION' => 'upgrade.php?language=' . $language)); |
---|
| 385 | |
---|
| 386 | if (!check_upgrade()) |
---|
| 387 | { |
---|
| 388 | $template->assign('login', true); |
---|
| 389 | } |
---|
[1927] | 390 | } |
---|
| 391 | |
---|
[2836] | 392 | if (count($page['errors']) != 0) |
---|
| 393 | { |
---|
| 394 | $template->assign('errors', $page['errors']); |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | if (count($page['infos']) != 0) |
---|
| 398 | { |
---|
| 399 | $template->assign('infos', $page['infos']); |
---|
| 400 | } |
---|
| 401 | |
---|
[1927] | 402 | // +-----------------------------------------------------------------------+ |
---|
| 403 | // | sending html code | |
---|
| 404 | // +-----------------------------------------------------------------------+ |
---|
| 405 | |
---|
| 406 | $template->pparse('upgrade'); |
---|
| 407 | ?> |
---|