[1927] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 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 | |
---|
[2864] | 26 | // load config file |
---|
| 27 | $config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php'; |
---|
| 28 | $config_file_contents = @file_get_contents($config_file); |
---|
| 29 | if ($config_file_contents === false) |
---|
[2837] | 30 | { |
---|
[2864] | 31 | die('Cannot load '.$config_file); |
---|
[2837] | 32 | } |
---|
[2864] | 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 | } |
---|
[2837] | 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 | |
---|
| 43 | include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); |
---|
| 44 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
| 45 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
| 46 | |
---|
[2096] | 47 | prepare_conf_upgrade(); |
---|
[1927] | 48 | |
---|
| 49 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
| 50 | define('PREFIX_TABLE', $prefixeTable); |
---|
| 51 | |
---|
| 52 | // Database connection |
---|
[2512] | 53 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) or die ( "Could not connect to database server" ); |
---|
| 54 | mysql_select_db( $cfgBase ) or die ( "Could not connect to database" ); |
---|
| 55 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') |
---|
| 56 | and defined('DB_CHARSET') and DB_CHARSET!='' ) |
---|
| 57 | { |
---|
| 58 | pwg_query('SET NAMES "'.DB_CHARSET.'"'); |
---|
| 59 | } |
---|
| 60 | |
---|
[1927] | 61 | // +-----------------------------------------------------------------------+ |
---|
| 62 | // | functions | |
---|
| 63 | // +-----------------------------------------------------------------------+ |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * list all tables in an array |
---|
| 67 | * |
---|
| 68 | * @return array |
---|
| 69 | */ |
---|
| 70 | function get_tables() |
---|
| 71 | { |
---|
| 72 | $tables = array(); |
---|
[2290] | 73 | |
---|
[1927] | 74 | $query = ' |
---|
| 75 | SHOW TABLES |
---|
| 76 | ;'; |
---|
[2885] | 77 | $result = pwg_query($query); |
---|
[1927] | 78 | |
---|
| 79 | while ($row = mysql_fetch_row($result)) |
---|
| 80 | { |
---|
| 81 | if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) |
---|
| 82 | { |
---|
| 83 | array_push($tables, $row[0]); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | return $tables; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * list all columns of each given table |
---|
| 92 | * |
---|
| 93 | * @return array of array |
---|
| 94 | */ |
---|
| 95 | function get_columns_of($tables) |
---|
| 96 | { |
---|
| 97 | $columns_of = array(); |
---|
| 98 | |
---|
| 99 | foreach ($tables as $table) |
---|
| 100 | { |
---|
| 101 | $query = ' |
---|
| 102 | DESC '.$table.' |
---|
| 103 | ;'; |
---|
[2885] | 104 | $result = pwg_query($query); |
---|
[1927] | 105 | |
---|
| 106 | $columns_of[$table] = array(); |
---|
| 107 | |
---|
| 108 | while ($row = mysql_fetch_row($result)) |
---|
| 109 | { |
---|
| 110 | array_push($columns_of[$table], $row[0]); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | return $columns_of; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | */ |
---|
| 119 | function print_time($message) |
---|
| 120 | { |
---|
| 121 | global $last_time; |
---|
[2290] | 122 | |
---|
[1927] | 123 | $new_time = get_moment(); |
---|
| 124 | echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; |
---|
| 125 | echo ' '.$message; |
---|
| 126 | echo '</pre>'; |
---|
| 127 | flush(); |
---|
| 128 | $last_time = $new_time; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | // +-----------------------------------------------------------------------+ |
---|
| 132 | // | playing zone | |
---|
| 133 | // +-----------------------------------------------------------------------+ |
---|
| 134 | |
---|
| 135 | // echo implode('<br>', get_tables()); |
---|
| 136 | // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; |
---|
| 137 | |
---|
| 138 | // foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
| 139 | // { |
---|
| 140 | // echo $upgrade_id, '<br>'; |
---|
| 141 | // } |
---|
| 142 | |
---|
| 143 | // +-----------------------------------------------------------------------+ |
---|
[2820] | 144 | // | language | |
---|
| 145 | // +-----------------------------------------------------------------------+ |
---|
| 146 | if (isset($_GET['language'])) |
---|
| 147 | { |
---|
| 148 | $language = strip_tags($_GET['language']); |
---|
| 149 | } |
---|
| 150 | else |
---|
| 151 | { |
---|
| 152 | $language = 'en_UK'; |
---|
| 153 | // Try to get browser language |
---|
| 154 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
| 155 | { |
---|
| 156 | if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) |
---|
| 157 | { |
---|
| 158 | $language = $language_code; |
---|
| 159 | break; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
[3204] | 164 | if ('fr_FR' == $language) { |
---|
| 165 | define('PHPWG_DOMAIN', 'fr.piwigo.org'); |
---|
| 166 | } |
---|
[4189] | 167 | else if ('it_IT' == $language) { |
---|
| 168 | define('PHPWG_DOMAIN', 'it.piwigo.org'); |
---|
| 169 | } |
---|
| 170 | else if ('de_DE' == $language) { |
---|
| 171 | define('PHPWG_DOMAIN', 'de.piwigo.org'); |
---|
| 172 | } |
---|
| 173 | else if ('es_ES' == $language) { |
---|
| 174 | define('PHPWG_DOMAIN', 'es.piwigo.org'); |
---|
| 175 | } |
---|
[4758] | 176 | else if ('pl_PL' == $language) { |
---|
| 177 | define('PHPWG_DOMAIN', 'pl.piwigo.org'); |
---|
| 178 | } |
---|
| 179 | else if ('zh_CN' == $language) { |
---|
| 180 | define('PHPWG_DOMAIN', 'cn.piwigo.org'); |
---|
| 181 | } |
---|
[3204] | 182 | else { |
---|
| 183 | define('PHPWG_DOMAIN', 'piwigo.org'); |
---|
| 184 | } |
---|
| 185 | define('PHPWG_URL', 'http://'.PHPWG_DOMAIN); |
---|
| 186 | |
---|
[2837] | 187 | load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
| 188 | load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[3204] | 189 | load_language( 'install.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2837] | 190 | load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); |
---|
[2820] | 191 | |
---|
[3204] | 192 | // check php version |
---|
| 193 | if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) |
---|
| 194 | { |
---|
| 195 | include(PHPWG_ROOT_PATH.'install/php5_apache_configuration.php'); |
---|
| 196 | } |
---|
| 197 | |
---|
[2820] | 198 | // +-----------------------------------------------------------------------+ |
---|
[1927] | 199 | // | template initialization | |
---|
| 200 | // +-----------------------------------------------------------------------+ |
---|
| 201 | |
---|
[3204] | 202 | include( PHPWG_ROOT_PATH .'include/template.class.php'); |
---|
[2820] | 203 | $template = new Template(PHPWG_ROOT_PATH.'admin/template/goto', 'roma'); |
---|
[1927] | 204 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
[3204] | 205 | $template->assign(array( |
---|
| 206 | 'RELEASE' => PHPWG_VERSION, |
---|
| 207 | 'L_UPGRADE_HELP' => sprintf(l10n('install_help'), PHPWG_URL.'/forum'), |
---|
| 208 | ) |
---|
| 209 | ); |
---|
[1927] | 210 | |
---|
| 211 | // +-----------------------------------------------------------------------+ |
---|
| 212 | // | upgrade choice | |
---|
| 213 | // +-----------------------------------------------------------------------+ |
---|
| 214 | |
---|
[1999] | 215 | $tables = get_tables(); |
---|
| 216 | $columns_of = get_columns_of($tables); |
---|
| 217 | |
---|
[2837] | 218 | // find the current release |
---|
| 219 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
[1927] | 220 | { |
---|
[2837] | 221 | // we're in branch 1.3, important upgrade, isn't it? |
---|
| 222 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
[1927] | 223 | { |
---|
[2837] | 224 | $current_release = '1.3.1'; |
---|
[1927] | 225 | } |
---|
[2837] | 226 | else |
---|
[1927] | 227 | { |
---|
[2837] | 228 | $current_release = '1.3.0'; |
---|
[1927] | 229 | } |
---|
[2837] | 230 | } |
---|
| 231 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
| 232 | { |
---|
| 233 | $current_release = '1.4.0'; |
---|
| 234 | } |
---|
| 235 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
| 236 | { |
---|
| 237 | $current_release = '1.5.0'; |
---|
| 238 | } |
---|
[2861] | 239 | else if ( !in_array(PREFIX_TABLE.'plugins', $tables) ) |
---|
[2837] | 240 | { |
---|
| 241 | if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
[1927] | 242 | { |
---|
[2837] | 243 | $current_release = '1.6.0'; |
---|
[1927] | 244 | } |
---|
| 245 | else |
---|
| 246 | { |
---|
[2837] | 247 | $current_release = '1.6.2'; |
---|
[1927] | 248 | } |
---|
| 249 | } |
---|
[2837] | 250 | else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) |
---|
| 251 | { |
---|
| 252 | $current_release = '1.7.0'; |
---|
| 253 | } |
---|
| 254 | else |
---|
| 255 | { |
---|
| 256 | die('No upgrade required, the database structure is up to date'); |
---|
| 257 | } |
---|
[1927] | 258 | |
---|
| 259 | // +-----------------------------------------------------------------------+ |
---|
| 260 | // | upgrade launch | |
---|
| 261 | // +-----------------------------------------------------------------------+ |
---|
[2837] | 262 | $page['infos'] = array(); |
---|
| 263 | $page['errors'] = array(); |
---|
[2864] | 264 | $mysql_changes = array(); |
---|
[1927] | 265 | |
---|
[2837] | 266 | if (isset($_POST['username']) and isset($_POST['password'])) |
---|
[1927] | 267 | { |
---|
[2837] | 268 | check_upgrade_access_rights($current_release, $_POST['username'], $_POST['password']); |
---|
| 269 | } |
---|
[2254] | 270 | |
---|
[2837] | 271 | if (isset($_POST['submit']) and check_upgrade()) |
---|
| 272 | { |
---|
| 273 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$current_release.'.php'; |
---|
[1927] | 274 | if (is_file($upgrade_file)) |
---|
| 275 | { |
---|
| 276 | $page['upgrade_start'] = get_moment(); |
---|
| 277 | $conf['die_on_sql_error'] = false; |
---|
| 278 | include($upgrade_file); |
---|
| 279 | |
---|
[2864] | 280 | // Something to add in mysql.inc.php? |
---|
| 281 | if (!empty($mysql_changes)) |
---|
| 282 | { |
---|
| 283 | $config_file_contents = |
---|
| 284 | substr($config_file_contents, 0, $php_end_tag) . "\r\n" |
---|
[2866] | 285 | . implode("\r\n" , $mysql_changes) . "\r\n" |
---|
[2864] | 286 | . substr($config_file_contents, $php_end_tag); |
---|
| 287 | |
---|
| 288 | if (!@file_put_contents($config_file, $config_file_contents)) |
---|
| 289 | { |
---|
| 290 | array_push($page['infos'], |
---|
| 291 | l10n('in include/mysql.inc.php, before ?>, insert:') . ' |
---|
[2866] | 292 | <p><textarea rows="4" cols="40">'.implode("\r\n" , $mysql_changes).'</textarea></p>' |
---|
[2864] | 293 | ); |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | |
---|
[2788] | 297 | // Plugins deactivation |
---|
| 298 | if (in_array(PREFIX_TABLE.'plugins', $tables)) |
---|
| 299 | { |
---|
[2816] | 300 | deactivate_non_standard_plugins(); |
---|
[2788] | 301 | } |
---|
| 302 | |
---|
[2102] | 303 | // Create empty local files to avoid log errors |
---|
| 304 | create_empty_local_files(); |
---|
[2254] | 305 | |
---|
[1927] | 306 | $page['upgrade_end'] = get_moment(); |
---|
| 307 | |
---|
[2254] | 308 | $template->assign( |
---|
[1927] | 309 | 'upgrade', |
---|
| 310 | array( |
---|
[2837] | 311 | 'VERSION' => $current_release, |
---|
[1927] | 312 | 'TOTAL_TIME' => get_elapsed_time( |
---|
| 313 | $page['upgrade_start'], |
---|
| 314 | $page['upgrade_end'] |
---|
| 315 | ), |
---|
| 316 | 'SQL_TIME' => number_format( |
---|
| 317 | $page['queries_time'], |
---|
| 318 | 3, |
---|
| 319 | '.', |
---|
| 320 | ' ' |
---|
| 321 | ).' s', |
---|
| 322 | 'NB_QUERIES' => $page['count_queries'] |
---|
| 323 | ) |
---|
| 324 | ); |
---|
| 325 | |
---|
[2820] | 326 | array_push($page['infos'], |
---|
| 327 | l10n('perform a maintenance check') |
---|
[1927] | 328 | ); |
---|
| 329 | |
---|
[3073] | 330 | // Save $page['infos'] in order to restore after maintenance actions |
---|
| 331 | $page['infos_sav'] = $page['infos']; |
---|
| 332 | $page['infos'] = array(); |
---|
| 333 | |
---|
[2811] | 334 | // c13y_upgrade plugin means "check integrity after upgrade", so it |
---|
| 335 | // becomes useful just after an upgrade |
---|
[2809] | 336 | $query = ' |
---|
| 337 | REPLACE INTO '.PLUGINS_TABLE.' |
---|
| 338 | (id, state) |
---|
| 339 | VALUES (\'c13y_upgrade\', \'active\') |
---|
| 340 | ;'; |
---|
| 341 | pwg_query($query); |
---|
[2891] | 342 | |
---|
| 343 | // Delete cache data |
---|
| 344 | invalidate_user_cache(true); |
---|
| 345 | $template->delete_compiled_templates(); |
---|
| 346 | |
---|
| 347 | // Tables Maintenance |
---|
[3076] | 348 | // Disabled optimization table for branch 2.0 only |
---|
| 349 | //do_maintenance_all_tables(); |
---|
[2891] | 350 | |
---|
[3073] | 351 | // Restore $page['infos'] in order to hide informations messages from functions calles |
---|
| 352 | // errors messages are not hide |
---|
| 353 | $page['infos'] = $page['infos_sav']; |
---|
| 354 | |
---|
[1927] | 355 | } |
---|
[2837] | 356 | } |
---|
| 357 | |
---|
| 358 | // +-----------------------------------------------------------------------+ |
---|
| 359 | // | start template output | |
---|
| 360 | // +-----------------------------------------------------------------------+ |
---|
| 361 | else |
---|
| 362 | { |
---|
| 363 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
[1927] | 364 | { |
---|
[2837] | 365 | if ($language == $language_code) |
---|
| 366 | { |
---|
| 367 | $template->assign('language_selection', $language_code); |
---|
| 368 | } |
---|
| 369 | $languages_options[$language_code] = $language_name; |
---|
[1927] | 370 | } |
---|
[2837] | 371 | $template->assign('language_options', $languages_options); |
---|
| 372 | |
---|
| 373 | $template->assign('introduction', array( |
---|
| 374 | 'CURRENT_RELEASE' => $current_release, |
---|
| 375 | 'F_ACTION' => 'upgrade.php?language=' . $language)); |
---|
| 376 | |
---|
| 377 | if (!check_upgrade()) |
---|
| 378 | { |
---|
| 379 | $template->assign('login', true); |
---|
| 380 | } |
---|
[1927] | 381 | } |
---|
| 382 | |
---|
[2837] | 383 | if (count($page['errors']) != 0) |
---|
| 384 | { |
---|
| 385 | $template->assign('errors', $page['errors']); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | if (count($page['infos']) != 0) |
---|
| 389 | { |
---|
| 390 | $template->assign('infos', $page['infos']); |
---|
| 391 | } |
---|
| 392 | |
---|
[1927] | 393 | // +-----------------------------------------------------------------------+ |
---|
| 394 | // | sending html code | |
---|
| 395 | // +-----------------------------------------------------------------------+ |
---|
| 396 | |
---|
| 397 | $template->pparse('upgrade'); |
---|
| 398 | ?> |
---|