| [Top level directory] [Classes] [Functions] [Constants] [Variables] |
XMB Open Source Forum Software - PHP Cross Reference |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * eXtreme Message Board 4 * XMB 1.9.11 5 * 6 * Developed And Maintained By The XMB Group 7 * Copyright (c) 2001-2010, The XMB Group 8 * http://www.xmbforum.com 9 * 10 * Sponsored By iEntry, Inc. 11 * http://www.ientry.com 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 2 16 * of the License, or (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program. If not, see <http://www.gnu.org/licenses/>. 25 * 26 **/ 27 28 ignore_user_abort(TRUE); 29 30 //Script constants 31 define('MYSQL_MIN_VER', '4.1.7'); 32 define('PHP_MIN_VER', '4.3.0'); 33 define('X_SCRIPT', 'upgrade.php'); 34 define('XMB_SCHEMA_VER', 3); 35 36 //Check location 37 if (!(is_file('header.php') And is_dir('include'))) { 38 echo 'Could not find XMB!<br />' 39 .'Please make sure the upgrade.php file is in the same folder as index.php and header.php.<br />'; 40 trigger_error('Attempted upgrade by '.$_SERVER['REMOTE_ADDR'].' from wrong location.', E_USER_ERROR); 41 } 42 43 //Authenticate Browser 44 require ('header.php'); 45 echo "<html><head><title>XMB Upgrade Script</title><body>Database Connection Established<br />\n"; 46 if (DEBUG) { 47 echo 'Debug Mode Enabled'; 48 } else { 49 echo 'Debug is False - You will not see any errors.'; 50 } 51 52 if (!defined('X_SADMIN') Or !X_SADMIN) { 53 echo '<br /><br />This script may be run only by a Super Administrator.<br />' 54 .'Please <a href="misc.php?action=login">Log In</a> first to begin the upgrade successfully.<br />'; 55 trigger_error('Unauthenticated upgrade attempt by '.$_SERVER['REMOTE_ADDR'], E_USER_ERROR); 56 } 57 58 //Check Server Version 59 $current = array_map('intval', explode('.', phpversion())); 60 $min = array_map('intval', explode('.', PHP_MIN_VER)); 61 if ($current[0] < $min[0] || ($current[0] == $min[0] && ($current[1] < $min[1] || ($current[1] == $min[1] && $current[2] < $min[2])))) { 62 echo '<br /><br />XMB requires PHP version '.PHP_MIN_VER.' or higher to work properly. Version '.phpversion().' is running.'; 63 trigger_error('Admin attempted upgrade with obsolete PHP engine.', E_USER_ERROR); 64 } 65 $sqlver = mysql_get_server_info($db->link); 66 $current = array_map('intval', explode('.', $sqlver)); 67 $min = array_map('intval', explode('.', MYSQL_MIN_VER)); 68 if ($current[0] < $min[0] || ($current[0] == $min[0] && ($current[1] < $min[1] || ($current[1] == $min[1] && $current[2] < $min[2])))) { 69 echo '<br /><br />XMB requires MySQL version '.MYSQL_MIN_VER.' or higher to work properly. Version '.$sqlver.' is running.'; 70 trigger_error('Admin attempted upgrade with obsolete MySQL engine.', E_USER_ERROR); 71 } 72 73 74 if (!isset($_GET['step']) Or $_GET['step'] == 1) { 75 ?> 76 <h1>XMB 1.9.10 to 1.9.11 Upgrade Script</h1> 77 78 <p>This script is also compatible with XMB 1.9.9 as well as XMB 1.9.11 Betas. 79 80 <p>This script is NOT compatible with XMB 1.9.8. 81 82 <h2>Instructions</h2> 83 <ol> 84 <li>BACKUP YOUR DATABASE - This script cannot be undone! 85 <li>Copy your config.php settings into the new file. 86 <li>Confirm your forum database account is granted ALTER, CREATE, and LOCK privileges. 87 <li>Disable your forums using the Board Status setting. 88 <li>Upload the XMB 1.9.11 files. 89 <li>Upload and run this script to complete your database upgrade. 90 <li>Enable your forums using the Board Status setting. 91 </ol> 92 93 <script type="text/javascript"> 94 <!--//--><![CDATA[//><!-- 95 function disableButton() { 96 var newAttr = document.createAttribute("disabled"); 97 newAttr.nodeValue = "disabled"; 98 document.getElementById("submit1").setAttributeNode(newAttr); 99 return true; 100 } 101 //--><!]]> 102 </script> 103 104 <form method="get" onsubmit="disableButton();"> 105 <input type="hidden" name="step" value="2" /> 106 <p>When you are ready, <input type="submit" value="Click Here if you already have a backup and want to begin the upgrade" id="submit1" />. 107 </form> 108 <?php 109 110 } else if ($_GET['step'] == 2) { 111 112 ?> 113 <h1>XMB 1.9.10 to 1.9.11 Upgrade Script</h1> 114 <h2>Status Information</h2> 115 <?php 116 117 echo 'Confirming the upgrade files are present...<br />'; 118 if (is_dir('upgrade') Or is_dir('Upgrade') Or is_dir('install') Or is_dir('Install')) { 119 echo 'Wrong files present!<br />' 120 .'Please delete any folders named install or upgrade.<br />'; 121 trigger_error('Admin attempted upgrade while non-upgrade files were present.', E_USER_ERROR); 122 } 123 if (!is_file('templates.xmb')) { 124 echo 'Files missing!<br />' 125 .'Please make sure to upload the templates.xmb file.<br />'; 126 trigger_error('Admin attempted upgrade with templates.xmb missing.', E_USER_ERROR); 127 } 128 if (!is_file('lang/English.lang.php')) { 129 echo 'Files missing!<br />' 130 .'Please make sure to upload the lang/English.lang.php file.<br />'; 131 trigger_error('Admin attempted upgrade with English.lang.php missing.', E_USER_ERROR); 132 } 133 134 echo 'Confirming forums are turned off...<br />'; 135 if ($SETTINGS['bbstatus'] != 'off') { 136 $db->query("UPDATE ".X_PREFIX."settings SET bbstatus = 'off'"); 137 echo '<b>Your forums were turned off by the upgrader to prevent damage.<br />' 138 .'They will remain unavailable to your members until you reset the Board Status setting in the Admin Panel.</b><br />'; 139 trigger_error('Admin attempted upgrade without turning off the board. Board now turned off.', E_USER_WARNING); 140 } 141 142 echo 'Determining the database schema version...<br />'; 143 if (!isset($SETTINGS['schema_version'])) { 144 $SETTINGS['schema_version'] = 0; 145 } 146 switch ($SETTINGS['schema_version']) { 147 case XMB_SCHEMA_VER: 148 echo 'Database schema is current, skipping ALTER commands...<br />'; 149 break; 150 case 0: 151 case 1: 152 upgrade_schema_to_v2(); 153 //No break. 154 case 2: 155 upgrade_schema_to_v3(); 156 case 3: 157 //Future use. Break only before case default. 158 break; 159 default: 160 echo 'Unrecognized Database!<br />' 161 .'This upgrade utility is not compatible with your version of XMB. Upgrade halted to prevent damage.<br />'; 162 trigger_error('Admin attempted upgrade with obsolete upgrade utility.', E_USER_ERROR); 163 break; 164 } 165 echo 'Database schema is now current...<br />'; 166 167 echo 'Initializing the new translation system...<br />'; 168 require_once ('include/translation.inc.php'); 169 $upload = file_get_contents('lang/English.lang.php'); 170 171 echo 'Installing English.lang.php...<br />'; 172 installNewTranslation($upload); 173 unset($upload); 174 175 echo 'Opening the templates file...<br />'; 176 $templates = explode("|#*XMB TEMPLATE FILE*#|", file_get_contents('templates.xmb')); 177 178 echo 'Resetting the templates table...<br />'; 179 $db->query('TRUNCATE TABLE '.X_PREFIX.'templates'); 180 181 echo 'Requesting to lock the templates table...<br />'; 182 $db->query('LOCK TABLES '.X_PREFIX."templates WRITE"); 183 184 echo 'Saving the new templates...<br />'; 185 $values = array(); 186 foreach($templates as $val) { 187 $template = explode("|#*XMB TEMPLATE*#|", $val); 188 if (isset($template[1])) { 189 $template[1] = addslashes(ltrim($template[1])); 190 } else { 191 $template[1] = ''; 192 } 193 $values[] = "('".$db->escape_var($template[0])."', '".$db->escape_var($template[1])."')"; 194 } 195 unset($templates); 196 if (count($values) > 0) { 197 $values = implode(', ', $values); 198 $db->query("INSERT INTO `".X_PREFIX."templates` (`name`, `template`) VALUES $values"); 199 } 200 unset($values); 201 $db->query("DELETE FROM `".X_PREFIX."templates` WHERE name=''"); 202 203 echo 'Releasing the lock on the templates table...<br />'; 204 $db->query('UNLOCK TABLES'); 205 206 echo 'Deleting the templates.xmb file...<br />'; 207 unlink('templates.xmb'); 208 209 210 echo 'Checking for new themes...'; 211 $query = $db->query("SELECT themeid FROM ".X_PREFIX."themes WHERE name='XMB Davis'"); 212 if ($db->num_rows($query) == 0 And is_dir('images/davis')) { 213 echo 'Adding Davis as the new default theme...<br />'; 214 $db->query("INSERT INTO ".X_PREFIX."themes (`name`, `bgcolor`, `altbg1`, `altbg2`, `link`, `bordercolor`, `header`, `headertext`, `top`, `catcolor`, `tabletext`, `text`, `borderwidth`, `tablewidth`, `tablespace`, `font`, `fontsize`, `boardimg`, `imgdir`, `smdir`, `cattext`) " 215 ."VALUES ('XMB Davis', 'bg.gif', '#FFFFFF', '#f4f7f8', '#24404b', '#86a9b6', '#d3dfe4', '#24404b', 'topbg.gif', 'catbar.gif', '#000000', '#000000', '1px', '97%', '5px', 'Tahoma, Arial, Helvetica, Verdana', '11px', 'logo.gif', 'images/davis', 'images/smilies', '#163c4b');"); 216 $newTheme = $db->insert_id(); 217 $db->query("UPDATE ".X_PREFIX."settings SET theme=$newTheme"); 218 } 219 $db->free_result($query); 220 221 echo 'Deleting the upgrade.php file...<br />'; 222 unlink('upgrade.php'); 223 224 echo '<b>Done! :D</b><br />Now <a href="cp.php?action=settings#1">reset the Board Status setting to turn your board back on</a>.<br />'; 225 } 226 227 echo "\n</body></html>"; 228 229 /** 230 * Performs all tasks needed to raise the database schema_version number to 2. 231 * 232 * This function is officially compatible with schema_version 1 as well as the following 233 * XMB versions that did not have a schema_version number: 1.9.9, 1.9.10, and 1.9.11 Alpha (all). 234 * 235 * @author Robert Chapin (miqrogroove) 236 * @since 1.9.11 Beta 3 237 */ 238 function upgrade_schema_to_v2() { 239 global $db; 240 241 echo 'Beginning schema upgrade to version number 2...<br />'; 242 243 echo 'Requesting to lock the settings table...<br />'; 244 $db->query('LOCK TABLES '.X_PREFIX."settings WRITE"); 245 246 echo 'Gathering schema information from the settings table...<br />'; 247 $sql = array(); 248 $table = 'settings'; 249 $columns = array( 250 'boardurl'); 251 foreach($columns as $colname) { 252 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 253 if ($db->num_rows($query) == 1) { 254 $sql[] = 'DROP COLUMN '.$colname; 255 } 256 $db->free_result($query); 257 } 258 $columns = array( 259 'attach_remote_images' => "SET('on', 'off') NOT NULL DEFAULT 'off'", 260 'captcha_search_status' => "SET('on', 'off') NOT NULL DEFAULT 'off'", 261 'files_min_disk_size' => "MEDIUMINT NOT NULL DEFAULT '9216'", 262 'files_storage_path' => "VARCHAR( 100 ) NOT NULL", 263 'files_subdir_format' => "TINYINT NOT NULL DEFAULT '1'", 264 'file_url_format' => "TINYINT NOT NULL DEFAULT '1'", 265 'files_virtual_url' => "VARCHAR(60) NOT NULL", 266 'filesperpost' => "TINYINT NOT NULL DEFAULT '10'", 267 'ip_banning' => "SET('on', 'off') NOT NULL DEFAULT 'on'", 268 'max_image_size' => "VARCHAR(9) NOT NULL DEFAULT '1000x1000'", 269 'max_thumb_size' => "VARCHAR(9) NOT NULL DEFAULT '200x200'", 270 'schema_version' => "TINYINT UNSIGNED NOT NULL DEFAULT ".XMB_SCHEMA_VER); 271 foreach($columns as $colname => $coltype) { 272 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 273 if ($db->num_rows($query) == 0) { 274 $sql[] = 'ADD COLUMN '.$colname.' '.$coltype; 275 } 276 $db->free_result($query); 277 } 278 279 if (count($sql) > 0) { 280 echo 'Adding/Deleting columns in the settings table...<br />'; 281 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 282 $db->query($sql); 283 } 284 285 echo 'Requesting to lock the attachments table...<br />'; 286 $db->query('LOCK TABLES '.X_PREFIX."attachments WRITE"); 287 288 echo 'Gathering schema information from the attachments table...<br />'; 289 $sql = array(); 290 $table = 'attachments'; 291 $columns = array( 292 'tid'); 293 foreach($columns as $colname) { 294 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 295 if ($db->num_rows($query) == 1) { 296 $sql[] = 'DROP COLUMN '.$colname; 297 } 298 $db->free_result($query); 299 } 300 $columns = array( 301 'img_size' => "VARCHAR(9) NOT NULL", 302 'parentid' => "INT NOT NULL DEFAULT '0'", 303 'subdir' => "VARCHAR(15) NOT NULL", 304 'uid' => "INT NOT NULL DEFAULT '0'", 305 'updatetime' => "TIMESTAMP NOT NULL default current_timestamp"); 306 foreach($columns as $colname => $coltype) { 307 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 308 if ($db->num_rows($query) == 0) { 309 $sql[] = 'ADD COLUMN '.$colname.' '.$coltype; 310 } 311 $db->free_result($query); 312 } 313 $columns = array( 314 'parentid', 315 'uid'); 316 foreach($columns as $colname) { 317 $query = $db->query('SHOW INDEX FROM '.X_PREFIX."$table WHERE Column_name = '$colname'"); 318 if ($db->num_rows($query) == 0) { 319 $sql[] = "ADD INDEX ($colname)"; 320 } 321 $db->free_result($query); 322 } 323 324 if (count($sql) > 0) { 325 echo 'Adding/Deleting columns in the attachments table...<br />'; 326 // Important to do this all in one step because MySQL copies the entire table after every ALTER command. 327 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 328 $db->query($sql); 329 } 330 331 echo 'Requesting to lock the members table...<br />'; 332 $db->query('LOCK TABLES '.X_PREFIX."members WRITE"); 333 334 echo 'Gathering schema information from the members table...<br />'; 335 $sql = array(); 336 $table = 'members'; 337 $columns = array( 338 'u2ualert' => "TINYINT NOT NULL DEFAULT '0'"); 339 foreach($columns as $colname => $coltype) { 340 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 341 if ($db->num_rows($query) == 0) { 342 $sql[] = 'ADD COLUMN '.$colname.' '.$coltype; 343 } 344 $db->free_result($query); 345 } 346 $columns = array( 347 'postnum' => "postnum MEDIUMINT NOT NULL DEFAULT 0"); 348 foreach($columns as $colname => $coltype) { 349 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 350 if ($db->num_rows($query) == 1) { 351 $sql[] = 'CHANGE '.$colname.' '.$coltype; 352 } 353 $db->free_result($query); 354 } 355 356 if (count($sql) > 0) { 357 echo 'Adding/Deleting columns in the members table...<br />'; 358 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 359 $db->query($sql); 360 } 361 362 echo 'Requesting to lock the ranks table...<br />'; 363 $db->query('LOCK TABLES '.X_PREFIX."ranks WRITE"); 364 365 echo 'Gathering schema information from the ranks table...<br />'; 366 $sql = array(); 367 $table = 'ranks'; 368 $columns = array( 369 'posts' => "posts MEDIUMINT DEFAULT 0"); 370 foreach($columns as $colname => $coltype) { 371 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 372 if ($db->num_rows($query) == 1) { 373 $sql[] = 'CHANGE '.$colname.' '.$coltype; 374 } 375 $db->free_result($query); 376 } 377 378 if (count($sql) > 0) { 379 echo 'Adding/Deleting columns in the ranks table...<br />'; 380 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 381 $db->query($sql); 382 } 383 384 echo 'Requesting to lock the themes table...<br />'; 385 $db->query('LOCK TABLES '.X_PREFIX."themes WRITE"); 386 387 echo 'Gathering schema information from the themes table...<br />'; 388 $sql = array(); 389 $table = 'themes'; 390 $columns = array( 391 'admdir' => "VARCHAR( 120 ) NOT NULL DEFAULT 'images/admin'"); 392 foreach($columns as $colname => $coltype) { 393 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 394 if ($db->num_rows($query) == 0) { 395 $sql[] = 'ADD COLUMN '.$colname.' '.$coltype; 396 } 397 $db->free_result($query); 398 } 399 400 if (count($sql) > 0) { 401 echo 'Adding/Deleting columns in the themes table...<br />'; 402 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 403 $db->query($sql); 404 } 405 406 echo 'Requesting to lock the vote_desc table...<br />'; 407 $db->query('LOCK TABLES '.X_PREFIX."vote_desc WRITE"); 408 409 echo 'Gathering schema information from the vote_desc table...<br />'; 410 $sql = array(); 411 $table = 'vote_desc'; 412 $columns = array( 413 'topic_id' => "topic_id INT UNSIGNED NOT NULL"); 414 foreach($columns as $colname => $coltype) { 415 $query = $db->query('DESCRIBE '.X_PREFIX.$table.' '.$colname); 416 if ($db->num_rows($query) == 1) { 417 $sql[] = 'CHANGE '.$colname.' '.$coltype; 418 } 419 $db->free_result($query); 420 } 421 422 if (count($sql) > 0) { 423 echo 'Adding/Deleting columns in the vote_desc table...<br />'; 424 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 425 $db->query($sql); 426 } 427 428 echo 'Releasing the lock on the vote_desc table...<br />'; 429 $db->query('UNLOCK TABLES'); 430 431 echo 'Adding new tables...<br />'; 432 $db->query("CREATE TABLE IF NOT EXISTS ".X_PREFIX."lang_base ( 433 `langid` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 434 `devname` VARCHAR( 20 ) NOT NULL , 435 UNIQUE ( `devname` ) 436 ) TYPE=MyISAM COMMENT = 'List of Installed Languages'"); 437 $db->query("CREATE TABLE IF NOT EXISTS ".X_PREFIX."lang_keys ( 438 `phraseid` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 439 `langkey` VARCHAR( 30 ) NOT NULL , 440 UNIQUE ( `langkey` ) 441 ) TYPE=MyISAM COMMENT = 'List of Translation Variables'"); 442 $db->query("CREATE TABLE IF NOT EXISTS ".X_PREFIX."lang_text ( 443 `langid` TINYINT UNSIGNED NOT NULL , 444 `phraseid` SMALLINT UNSIGNED NOT NULL , 445 `cdata` BLOB NOT NULL , 446 PRIMARY KEY `langid` ( `langid` , `phraseid` ) , 447 INDEX ( `phraseid` ) 448 ) TYPE=MyISAM COMMENT = 'Translation Table'"); 449 450 echo 'Resetting the schema version number...<br />'; 451 $db->query("UPDATE ".X_PREFIX."settings SET schema_version = 2"); 452 } 453 454 /** 455 * Performs all tasks needed to raise the database schema_version number to 3. 456 * 457 * This function is officially compatible with schema_version 2 only. 458 * 459 * @since 1.9.11 Beta 4 460 */ 461 function upgrade_schema_to_v3() { 462 global $db; 463 464 echo 'Beginning schema upgrade to version number 3...<br />'; 465 466 echo 'Requesting to lock the logs table...<br />'; 467 $db->query('LOCK TABLES '.X_PREFIX."logs WRITE"); 468 469 echo 'Gathering schema information from the logs table...<br />'; 470 $sql = array(); 471 $table = 'logs'; 472 $columns = array( 473 'date', 474 'tid'); 475 foreach($columns as $colname) { 476 $query = $db->query('SHOW INDEX FROM '.X_PREFIX."$table WHERE Column_name = '$colname'"); 477 if ($db->num_rows($query) == 0) { 478 $sql[] = "ADD INDEX ($colname)"; 479 } 480 $db->free_result($query); 481 } 482 483 if (count($sql) > 0) { 484 echo 'Adding indexes to the logs table...<br />'; 485 $sql = 'ALTER TABLE '.X_PREFIX.$table.' '.implode(', ', $sql); 486 $db->query($sql); 487 } 488 489 echo 'Releasing the lock on the logs table...<br />'; 490 $db->query('UNLOCK TABLES'); 491 492 echo 'Resetting the schema version number...<br />'; 493 $db->query("UPDATE ".X_PREFIX."settings SET schema_version = 3"); 494 } 495 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Jan 26 20:11:23 2010 | Home | Forum | Download | SVN | Bug Tracker | Documentation | Cross-referenced by PHPXref 0.7 |