[672] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1075] | 5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[672] | 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-11-09 22:13:33 +0000 (Thu, 09 Nov 2006) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 1599 $ |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | |
---|
| 28 | define('PHPWG_ROOT_PATH', './'); |
---|
| 29 | |
---|
| 30 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
| 31 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[1174] | 32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); |
---|
[672] | 33 | include(PHPWG_ROOT_PATH.'include/template.php'); |
---|
[682] | 34 | |
---|
[672] | 35 | include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); |
---|
[1174] | 36 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
| 37 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
[682] | 38 | |
---|
[1075] | 39 | check_upgrade(); |
---|
| 40 | |
---|
[870] | 41 | // concerning upgrade, we use the default users table |
---|
| 42 | $conf['users_table'] = $prefixeTable.'users'; |
---|
| 43 | |
---|
[672] | 44 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
[681] | 45 | define('PREFIX_TABLE', $prefixeTable); |
---|
[672] | 46 | |
---|
| 47 | // Database connection |
---|
[681] | 48 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
[672] | 49 | or die ( "Could not connect to database server" ); |
---|
[681] | 50 | mysql_select_db( $cfgBase ) |
---|
[672] | 51 | or die ( "Could not connect to database" ); |
---|
| 52 | // +-----------------------------------------------------------------------+ |
---|
| 53 | // | tricky output | |
---|
| 54 | // +-----------------------------------------------------------------------+ |
---|
| 55 | echo '<!-- This is an HTML comment given in order to make IE outputs'; |
---|
| 56 | echo ' the code.'."\n"; |
---|
| 57 | echo ' Indeed, IE doesn\'t start to send output until a limit'; |
---|
| 58 | echo ' of XXX bytes '."\n"; |
---|
| 59 | echo str_repeat( ' ', 80 )."\n"; |
---|
| 60 | echo str_repeat( ' ', 80 )."\n"; |
---|
| 61 | echo str_repeat( ' ', 80 )."\n"; |
---|
| 62 | echo '-->'."\n"; |
---|
| 63 | flush(); |
---|
| 64 | // +-----------------------------------------------------------------------+ |
---|
| 65 | // | functions | |
---|
| 66 | // +-----------------------------------------------------------------------+ |
---|
| 67 | |
---|
| 68 | /** |
---|
[1174] | 69 | * list all tables in an array |
---|
[672] | 70 | * |
---|
[1174] | 71 | * @return array |
---|
| 72 | */ |
---|
| 73 | function get_tables() |
---|
| 74 | { |
---|
| 75 | $tables = array(); |
---|
| 76 | |
---|
| 77 | $query = ' |
---|
| 78 | SHOW TABLES |
---|
| 79 | ;'; |
---|
| 80 | $result = mysql_query($query); |
---|
| 81 | |
---|
| 82 | while ($row = mysql_fetch_row($result)) |
---|
| 83 | { |
---|
[1319] | 84 | if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) |
---|
| 85 | { |
---|
| 86 | array_push($tables, $row[0]); |
---|
| 87 | } |
---|
[1174] | 88 | } |
---|
| 89 | |
---|
| 90 | return $tables; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * list all columns of each given table |
---|
[672] | 95 | * |
---|
[1174] | 96 | * @return array of array |
---|
[672] | 97 | */ |
---|
[1174] | 98 | function get_columns_of($tables) |
---|
[672] | 99 | { |
---|
[1174] | 100 | $columns_of = array(); |
---|
| 101 | |
---|
| 102 | foreach ($tables as $table) |
---|
[672] | 103 | { |
---|
[1174] | 104 | $query = ' |
---|
[1319] | 105 | DESC '.$table.' |
---|
[1174] | 106 | ;'; |
---|
| 107 | $result = mysql_query($query); |
---|
| 108 | |
---|
| 109 | $columns_of[$table] = array(); |
---|
| 110 | |
---|
| 111 | while ($row = mysql_fetch_row($result)) |
---|
[672] | 112 | { |
---|
[1174] | 113 | array_push($columns_of[$table], $row[0]); |
---|
[672] | 114 | } |
---|
[1174] | 115 | } |
---|
| 116 | |
---|
| 117 | return $columns_of; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | */ |
---|
| 122 | function print_time($message) |
---|
| 123 | { |
---|
| 124 | global $last_time; |
---|
| 125 | |
---|
| 126 | $new_time = get_moment(); |
---|
| 127 | echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; |
---|
| 128 | echo ' '.$message; |
---|
| 129 | echo '</pre>'; |
---|
| 130 | flush(); |
---|
| 131 | $last_time = $new_time; |
---|
| 132 | } |
---|
| 133 | |
---|
[672] | 134 | // +-----------------------------------------------------------------------+ |
---|
[1174] | 135 | // | playing zone | |
---|
| 136 | // +-----------------------------------------------------------------------+ |
---|
| 137 | |
---|
| 138 | // echo implode('<br>', get_tables()); |
---|
| 139 | // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; |
---|
| 140 | |
---|
[1209] | 141 | // foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
| 142 | // { |
---|
| 143 | // echo $upgrade_id, '<br>'; |
---|
| 144 | // } |
---|
| 145 | |
---|
[1174] | 146 | // +-----------------------------------------------------------------------+ |
---|
[672] | 147 | // | template initialization | |
---|
| 148 | // +-----------------------------------------------------------------------+ |
---|
[870] | 149 | |
---|
| 150 | $template = new Template(PHPWG_ROOT_PATH.'template/yoga'); |
---|
[672] | 151 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
| 152 | $template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); |
---|
[870] | 153 | |
---|
[672] | 154 | // +-----------------------------------------------------------------------+ |
---|
[1174] | 155 | // | upgrade choice | |
---|
[672] | 156 | // +-----------------------------------------------------------------------+ |
---|
[1174] | 157 | |
---|
| 158 | if (!isset($_GET['version'])) |
---|
[672] | 159 | { |
---|
[1174] | 160 | // find the current release |
---|
| 161 | $tables = get_tables(); |
---|
| 162 | $columns_of = get_columns_of($tables); |
---|
| 163 | |
---|
[1319] | 164 | if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) |
---|
[672] | 165 | { |
---|
[1174] | 166 | // we're in branch 1.3, important upgrade, isn't it? |
---|
[1319] | 167 | if (in_array(PREFIX_TABLE.'user_category', $tables)) |
---|
[672] | 168 | { |
---|
[1174] | 169 | $current_release = '1.3.1'; |
---|
[672] | 170 | } |
---|
[1174] | 171 | else |
---|
| 172 | { |
---|
| 173 | $current_release = '1.3.0'; |
---|
| 174 | } |
---|
[672] | 175 | } |
---|
[1319] | 176 | else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) |
---|
[672] | 177 | { |
---|
[1174] | 178 | $current_release = '1.4.0'; |
---|
[672] | 179 | } |
---|
[1319] | 180 | else if (!in_array(PREFIX_TABLE.'tags', $tables)) |
---|
[1174] | 181 | { |
---|
| 182 | $current_release = '1.5.0'; |
---|
| 183 | } |
---|
[1599] | 184 | else if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) |
---|
| 185 | { |
---|
| 186 | $current_release = '1.6.0'; |
---|
| 187 | } |
---|
[1174] | 188 | else |
---|
| 189 | { |
---|
[1599] | 190 | die('No upgrade required, the database structure is up to date'); |
---|
[1174] | 191 | } |
---|
| 192 | |
---|
| 193 | $template->assign_block_vars( |
---|
| 194 | 'introduction', |
---|
| 195 | array( |
---|
| 196 | 'CURRENT_RELEASE' => $current_release, |
---|
| 197 | 'RUN_UPGRADE_URL' => |
---|
| 198 | PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, |
---|
| 199 | ) |
---|
| 200 | ); |
---|
[672] | 201 | } |
---|
[1174] | 202 | |
---|
[672] | 203 | // +-----------------------------------------------------------------------+ |
---|
| 204 | // | upgrade launch | |
---|
| 205 | // +-----------------------------------------------------------------------+ |
---|
[1174] | 206 | |
---|
[672] | 207 | else |
---|
| 208 | { |
---|
[1174] | 209 | $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; |
---|
[672] | 210 | if (is_file($upgrade_file)) |
---|
| 211 | { |
---|
[1209] | 212 | $page['infos'] = array(); |
---|
[672] | 213 | $page['upgrade_start'] = get_moment(); |
---|
[1174] | 214 | $conf['die_on_sql_error'] = false; |
---|
[672] | 215 | include($upgrade_file); |
---|
[1209] | 216 | |
---|
| 217 | // Available upgrades must be ignored after a fresh installation. To |
---|
| 218 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
| 219 | // made. |
---|
| 220 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 221 | define('CURRENT_DATE', $dbnow); |
---|
| 222 | $datas = array(); |
---|
| 223 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
| 224 | { |
---|
| 225 | array_push( |
---|
| 226 | $datas, |
---|
| 227 | array( |
---|
| 228 | 'id' => $upgrade_id, |
---|
| 229 | 'applied' => CURRENT_DATE, |
---|
[1599] | 230 | 'description' => 'upgrade included in migration', |
---|
[1209] | 231 | ) |
---|
| 232 | ); |
---|
| 233 | } |
---|
| 234 | mass_inserts( |
---|
| 235 | UPGRADE_TABLE, |
---|
| 236 | array_keys($datas[0]), |
---|
| 237 | $datas |
---|
| 238 | ); |
---|
| 239 | |
---|
[672] | 240 | $page['upgrade_end'] = get_moment(); |
---|
| 241 | |
---|
| 242 | $template->assign_block_vars( |
---|
| 243 | 'upgrade', |
---|
| 244 | array( |
---|
| 245 | 'VERSION' => $_GET['version'], |
---|
[1174] | 246 | 'TOTAL_TIME' => get_elapsed_time( |
---|
| 247 | $page['upgrade_start'], |
---|
| 248 | $page['upgrade_end'] |
---|
| 249 | ), |
---|
| 250 | 'SQL_TIME' => number_format( |
---|
| 251 | $page['queries_time'], |
---|
| 252 | 3, |
---|
| 253 | '.', |
---|
| 254 | ' ' |
---|
| 255 | ).' s', |
---|
[672] | 256 | 'NB_QUERIES' => $page['count_queries'] |
---|
[1174] | 257 | ) |
---|
| 258 | ); |
---|
[672] | 259 | |
---|
| 260 | array_push( |
---|
[1209] | 261 | $page['infos'], |
---|
[672] | 262 | '[security] delete files "upgrade.php", "install.php" and "install" |
---|
[870] | 263 | directory' |
---|
| 264 | ); |
---|
| 265 | |
---|
| 266 | array_push( |
---|
[1209] | 267 | $page['infos'], |
---|
[870] | 268 | 'in include/mysql.inc.php, remove |
---|
| 269 | <pre style="background-color:lightgray"> |
---|
| 270 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
| 271 | </pre>' |
---|
| 272 | ); |
---|
[971] | 273 | |
---|
| 274 | array_push( |
---|
[1209] | 275 | $page['infos'], |
---|
[971] | 276 | 'Perform a maintenance check in [Administration>General>Maintenance] |
---|
| 277 | if you encounter any problem.' |
---|
| 278 | ); |
---|
[672] | 279 | |
---|
| 280 | $template->assign_block_vars('upgrade.infos', array()); |
---|
| 281 | |
---|
[1209] | 282 | foreach ($page['infos'] as $info) |
---|
[672] | 283 | { |
---|
[1174] | 284 | $template->assign_block_vars( |
---|
| 285 | 'upgrade.infos.info', |
---|
| 286 | array( |
---|
| 287 | 'CONTENT' => $info, |
---|
| 288 | ) |
---|
| 289 | ); |
---|
[672] | 290 | } |
---|
[1209] | 291 | |
---|
| 292 | $query = ' |
---|
| 293 | UPDATE '.USER_CACHE_TABLE.' |
---|
| 294 | SET need_update = \'true\' |
---|
| 295 | ;'; |
---|
| 296 | pwg_query($query); |
---|
[672] | 297 | } |
---|
| 298 | else |
---|
| 299 | { |
---|
| 300 | die('Hacking attempt'); |
---|
| 301 | } |
---|
| 302 | } |
---|
[1174] | 303 | |
---|
[672] | 304 | // +-----------------------------------------------------------------------+ |
---|
| 305 | // | sending html code | |
---|
| 306 | // +-----------------------------------------------------------------------+ |
---|
[1174] | 307 | |
---|
[672] | 308 | $template->pparse('upgrade'); |
---|
[1319] | 309 | ?> |
---|