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