/install/upgrade.php
PHP | 4467 lines | 3461 code | 597 blank | 409 comment | 721 complexity | 3fe4172b1f5f9edd38337f4143b567e3 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @name ElkArte Forum
- * @copyright ElkArte Forum contributors
- * @license BSD http://opensource.org/licenses/BSD-3-Clause
- *
- * This software is a derived product, based on:
- *
- * Simple Machines Forum (SMF)
- * copyright: 2011 Simple Machines (http://www.simplemachines.org)
- * license: BSD, See included LICENSE.TXT for terms and conditions.
- *
- * @version 1.0 Alpha
- *
- */
- // Version information...
- define('CURRENT_VERSION', '1.0 Alpha');
- define('CURRENT_LANG_VERSION', '1.0');
- $GLOBALS['required_php_version'] = '5.1.0';
- $GLOBALS['required_mysql_version'] = '4.0.18';
- $databases = array(
- 'mysql' => array(
- 'name' => 'MySQL',
- 'version' => '4.0.18',
- 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
- 'utf8_support' => true,
- 'utf8_version' => '4.1.0',
- 'utf8_version_check' => 'return mysql_get_server_info();',
- 'alter_support' => true,
- ),
- 'postgresql' => array(
- 'name' => 'PostgreSQL',
- 'version' => '8.0',
- 'version_check' => '$version = pg_version(); return $version[\'client\'];',
- 'always_has_db' => true,
- ),
- 'sqlite' => array(
- 'name' => 'SQLite',
- 'version' => '1',
- 'version_check' => 'return 1;',
- 'always_has_db' => true,
- ),
- );
- // General options for the script.
- $timeLimitThreshold = 3;
- $upgrade_path = dirname(__FILE__);
- $upgradeurl = $_SERVER['PHP_SELF'];
- // Where the images etc are kept.
- $oursite = 'http://www.elkarte.net';
- // Disable the need for admins to login?
- $disable_security = false;
- // How long, in seconds, must admin be inactive to allow someone else to run?
- $upcontext['inactive_timeout'] = 10;
- // All the steps in detail.
- // Number,Name,Function,Progress Weight.
- $upcontext['steps'] = array(
- 0 => array(1, 'Login', 'action_welcomeLogin', 2),
- 1 => array(2, 'Upgrade Options', 'action_upgradeOptions', 2),
- 2 => array(3, 'Backup', 'action_backupDatabase', 10),
- 3 => array(4, 'Database Changes', 'action_databaseChanges', 70),
- // This is removed as it doesn't really work right at the moment.
- //4 => array(5, 'Cleanup Mods', 'action_cleanupMods', 10),
- 4 => array(5, 'Delete Upgrade', 'action_deleteUpgrade', 1),
- );
- // Just to remember which one has files in it.
- $upcontext['database_step'] = 3;
- @set_time_limit(600);
- if (!ini_get('safe_mode'))
- {
- ini_set('mysql.connect_timeout', -1);
- ini_set('default_socket_timeout', 900);
- }
- // Clean the upgrade path if this is from the client.
- if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
- for ($i = 1; $i < $_SERVER['argc']; $i++)
- {
- if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
- $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
- }
- // Are we from the client?
- if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
- {
- $command_line = true;
- $disable_security = 1;
- }
- else
- $command_line = false;
- // Load this now just because we can.
- require_once($upgrade_path . '/Settings.php');
- // Are we logged in?
- if (isset($upgradeData))
- {
- $upcontext['user'] = unserialize(base64_decode($upgradeData));
- // Check for sensible values.
- if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
- $upcontext['user']['started'] = time();
- if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
- $upcontext['user']['updated'] = 0;
- $upcontext['started'] = $upcontext['user']['started'];
- $upcontext['updated'] = $upcontext['user']['updated'];
- }
- // Nothing sensible?
- if (empty($upcontext['updated']))
- {
- $upcontext['started'] = time();
- $upcontext['updated'] = 0;
- $upcontext['user'] = array(
- 'id' => 0,
- 'name' => 'Guest',
- 'pass' => 0,
- 'started' => $upcontext['started'],
- 'updated' => $upcontext['updated'],
- );
- }
- // Load up some essential data...
- loadEssentialData();
- // Are we going to be mimic'ing SSI at this point?
- if (isset($_GET['ssi']))
- {
- require_once(SOURCEDIR . '/Subs.php');
- require_once(SOURCEDIR . '/Errors.php');
- require_once(SOURCEDIR . '/Logging.php');
- require_once(SOURCEDIR . '/Load.php');
- require_once(SUBSDIR . '/Cache.subs.php');
- require_once(SOURCEDIR . '/Security.php');
- require_once(SUBSDIR . '/Package.subs.php');
- loadUserSettings();
- loadPermissions();
- }
- // All the non-SSI stuff.
- if (!function_exists('ip2range'))
- require_once(SOURCEDIR . '/Subs.php');
- if (!function_exists('un_htmlspecialchars'))
- {
- function un_htmlspecialchars($string)
- {
- return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' '));
- }
- }
- if (!function_exists('text2words'))
- {
- function text2words($text)
- {
- global $smcFunc;
- // Step 1: Remove entities/things we don't consider words:
- $words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
- // Step 2: Entities we left to letters, where applicable, lowercase.
- $words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
- // Step 3: Ready to split apart and index!
- $words = explode(' ', $words);
- $returned_words = array();
- foreach ($words as $word)
- {
- $word = trim($word, '-_\'');
- if ($word != '')
- $returned_words[] = substr($word, 0, 20);
- }
- return array_unique($returned_words);
- }
- }
- if (!function_exists('clean_cache'))
- {
- // Empty out the cache folder.
- function clean_cache($type = '')
- {
- // No directory = no game.
- if (!is_dir(CACHEDIR))
- return;
- // Remove the files in our own disk cache, if any
- $dh = opendir(CACHEDIR);
- while ($file = readdir($dh))
- {
- if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
- @unlink(CACHEDIR . '/' . $file);
- }
- closedir($dh);
- // Invalidate cache, to be sure!
- // ... as long as Load.php can be modified, anyway.
- @touch(SOURCEDIR . '/' . 'Load.php');
- clearstatcache();
- }
- }
- // MD5 Encryption.
- if (!function_exists('md5_hmac'))
- {
- function md5_hmac($data, $key)
- {
- if (strlen($key) > 64)
- $key = pack('H*', md5($key));
- $key = str_pad($key, 64, chr(0x00));
- $k_ipad = $key ^ str_repeat(chr(0x36), 64);
- $k_opad = $key ^ str_repeat(chr(0x5c), 64);
- return md5($k_opad . pack('H*', md5($k_ipad . $data)));
- }
- }
- // http://www.faqs.org/rfcs/rfc959.html
- if (!class_exists('Ftp_Connection'))
- {
- class Ftp_Connection
- {
- var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
- // Create a new FTP connection...
- function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@yourdomain.org')
- {
- if ($ftp_server !== null)
- $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
- }
- function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@yourdomain.org')
- {
- if (substr($ftp_server, 0, 6) == 'ftp://')
- $ftp_server = substr($ftp_server, 6);
- elseif (substr($ftp_server, 0, 7) == 'ftps://')
- $ftp_server = 'ssl://' . substr($ftp_server, 7);
- if (substr($ftp_server, 0, 7) == 'http://')
- $ftp_server = substr($ftp_server, 7);
- $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
- // Connect to the FTP server.
- $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
- if (!$this->connection)
- {
- $this->error = 'bad_server';
- return;
- }
- // Get the welcome message...
- if (!$this->check_response(220))
- {
- $this->error = 'bad_response';
- return;
- }
- // Send the username, it should ask for a password.
- fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
- if (!$this->check_response(331))
- {
- $this->error = 'bad_username';
- return;
- }
- // Now send the password... and hope it goes okay.
- fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
- if (!$this->check_response(230))
- {
- $this->error = 'bad_password';
- return;
- }
- }
- function chdir($ftp_path)
- {
- if (!is_resource($this->connection))
- return false;
- // No slash on the end, please...
- if (substr($ftp_path, -1) == '/' && $ftp_path !== '/')
- $ftp_path = substr($ftp_path, 0, -1);
- fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
- if (!$this->check_response(250))
- {
- $this->error = 'bad_path';
- return false;
- }
- return true;
- }
- function chmod($ftp_file, $chmod)
- {
- if (!is_resource($this->connection))
- return false;
- // Convert the chmod value from octal (0777) to text ("777").
- fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
- if (!$this->check_response(200))
- {
- $this->error = 'bad_file';
- return false;
- }
- return true;
- }
- function unlink($ftp_file)
- {
- // We are actually connected, right?
- if (!is_resource($this->connection))
- return false;
- // Delete file X.
- fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
- if (!$this->check_response(250))
- {
- fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
- // Still no love?
- if (!$this->check_response(250))
- {
- $this->error = 'bad_file';
- return false;
- }
- }
- return true;
- }
- function check_response($desired)
- {
- // Wait for a response that isn't continued with -, but don't wait too long.
- $time = time();
- do
- $this->last_message = fgets($this->connection, 1024);
- while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
- // Was the desired response returned?
- return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
- }
- function passive()
- {
- // We can't create a passive data connection without a primary one first being there.
- if (!is_resource($this->connection))
- return false;
- // Request a passive connection - this means, we'll talk to you, you don't talk to us.
- @fwrite($this->connection, 'PASV' . "\r\n");
- $time = time();
- do
- $response = fgets($this->connection, 1024);
- while (substr($response, 3, 1) != ' ' && time() - $time < 5);
- // If it's not 227, we weren't given an IP and port, which means it failed.
- if (substr($response, 0, 4) != '227 ')
- {
- $this->error = 'bad_response';
- return false;
- }
- // Snatch the IP and port information, or die horribly trying...
- if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
- {
- $this->error = 'bad_response';
- return false;
- }
- // This is pretty simple - store it for later use ;).
- $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
- return true;
- }
- function create_file($ftp_file)
- {
- // First, we have to be connected... very important.
- if (!is_resource($this->connection))
- return false;
- // I'd like one passive mode, please!
- if (!$this->passive())
- return false;
- // Seems logical enough, so far...
- fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
- // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
- $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
- if (!$fp || !$this->check_response(150))
- {
- $this->error = 'bad_file';
- @fclose($fp);
- return false;
- }
- // This may look strange, but we're just closing it to indicate a zero-byte upload.
- fclose($fp);
- if (!$this->check_response(226))
- {
- $this->error = 'bad_response';
- return false;
- }
- return true;
- }
- function list_dir($ftp_path = '', $search = false)
- {
- // Are we even connected...?
- if (!is_resource($this->connection))
- return false;
- // Passive... non-agressive...
- if (!$this->passive())
- return false;
- // Get the listing!
- fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
- // Connect, assuming we've got a connection.
- $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
- if (!$fp || !$this->check_response(array(150, 125)))
- {
- $this->error = 'bad_response';
- @fclose($fp);
- return false;
- }
- // Read in the file listing.
- $data = '';
- while (!feof($fp))
- $data .= fread($fp, 4096);
- fclose($fp);
- // Everything go okay?
- if (!$this->check_response(226))
- {
- $this->error = 'bad_response';
- return false;
- }
- return $data;
- }
- function locate($file, $listing = null)
- {
- if ($listing === null)
- $listing = $this->list_dir('', true);
- $listing = explode("\n", $listing);
- @fwrite($this->connection, 'PWD' . "\r\n");
- $time = time();
- do
- $response = fgets($this->connection, 1024);
- while (substr($response, 3, 1) != ' ' && time() - $time < 5);
- // Check for 257!
- if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
- $current_dir = strtr($match[1], array('""' => '"'));
- else
- $current_dir = '';
- for ($i = 0, $n = count($listing); $i < $n; $i++)
- {
- if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
- {
- $current_dir = substr(trim($listing[++$i]), 0, -1);
- $i++;
- }
- // Okay, this file's name is:
- $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
- if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
- return $listing[$i];
- if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
- return $listing[$i];
- if (basename($listing[$i]) == $file || $listing[$i] == $file)
- return $listing[$i];
- }
- return false;
- }
- function create_dir($ftp_dir)
- {
- // We must be connected to the server to do something.
- if (!is_resource($this->connection))
- return false;
- // Make this new beautiful directory!
- fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
- if (!$this->check_response(257))
- {
- $this->error = 'bad_file';
- return false;
- }
- return true;
- }
- function detect_path($filesystem_path, $lookup_file = null)
- {
- $username = '';
- if (isset($_SERVER['DOCUMENT_ROOT']))
- {
- if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
- {
- $username = $match[1];
- $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
- if (substr($path, -1) == '/')
- $path = substr($path, 0, -1);
- if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
- $path .= dirname($_SERVER['PHP_SELF']);
- }
- elseif (substr($filesystem_path, 0, 9) == '/var/www/')
- $path = substr($filesystem_path, 8);
- else
- $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
- }
- else
- $path = '';
- if (is_resource($this->connection) && $this->list_dir($path) == '')
- {
- $data = $this->list_dir('', true);
- if ($lookup_file === null)
- $lookup_file = $_SERVER['PHP_SELF'];
- $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
- if ($found_path == false)
- $found_path = dirname($this->locate(basename($lookup_file)));
- if ($found_path != false)
- $path = $found_path;
- }
- elseif (is_resource($this->connection))
- $found_path = true;
- return array($username, $path, isset($found_path));
- }
- function close()
- {
- // Goodbye!
- fwrite($this->connection, 'QUIT' . "\r\n");
- fclose($this->connection);
- return true;
- }
- }
- }
- // Don't do security check if on Yabbse
- if (!isset($modSettings['elkVersion']))
- $disable_security = true;
- // Does this exist?
- if (isset($modSettings['elkVersion']))
- {
- $request = $smcFunc['db_query']('', '
- SELECT variable, value
- FROM {db_prefix}themes
- WHERE id_theme = {int:id_theme}
- AND variable IN ({string:theme_url}, {string:theme_dir}, {string:images_url})',
- array(
- 'id_theme' => 1,
- 'theme_url' => 'theme_url',
- 'theme_dir' => 'theme_dir',
- 'images_url' => 'images_url',
- 'db_error_skip' => true,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $modSettings[$row['variable']] = $row['value'];
- $smcFunc['db_free_result']($request);
- }
- if (!isset($modSettings['theme_url']))
- {
- $modSettings['theme_dir'] = BOARDDIR . '/themes/default';
- $modSettings['theme_url'] = 'themes/default';
- $modSettings['images_url'] = 'themes/default/images';
- }
- if (!isset($settings['default_theme_url']))
- $settings['default_theme_url'] = $modSettings['theme_url'];
- if (!isset($settings['default_theme_dir']))
- $settings['default_theme_dir'] = $modSettings['theme_dir'];
- $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
- // Default title...
- $upcontext['page_title'] = isset($modSettings['elkVersion']) ? 'Updating Your Elkarte Install!' : isset($modSettings['smfVersion']) ? 'Upgrading from SMF!' : 'Upgrading from YaBB SE!';
- $upcontext['right_to_left'] = isset($txt['lang_rtl']) ? $txt['lang_rtl'] : false;
- // Have we got log data - if so use it (It will be clean!)
- if (isset($_GET['data']))
- {
- $upcontext['upgrade_status'] = unserialize(base64_decode($_GET['data']));
- $upcontext['current_step'] = $upcontext['upgrade_status']['curstep'];
- $upcontext['language'] = $upcontext['upgrade_status']['lang'];
- $upcontext['rid'] = $upcontext['upgrade_status']['rid'];
- $is_debug = $upcontext['upgrade_status']['debug'];
- $support_js = $upcontext['upgrade_status']['js'];
- // Load the language.
- if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
- require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
- }
- // Set the defaults.
- else
- {
- $upcontext['current_step'] = 0;
- $upcontext['rid'] = mt_rand(0, 5000);
- $upcontext['upgrade_status'] = array(
- 'curstep' => 0,
- 'lang' => isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng'),
- 'rid' => $upcontext['rid'],
- 'pass' => 0,
- 'debug' => 0,
- 'js' => 0,
- );
- $upcontext['language'] = $upcontext['upgrade_status']['lang'];
- }
- // If this isn't the first stage see whether they are logging in and resuming.
- if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
- checkLogin();
- if ($command_line)
- cmdStep0();
- // Don't error if we're using xml.
- if (isset($_GET['xml']))
- $upcontext['return_error'] = true;
- // Loop through all the steps doing each one as required.
- $upcontext['overall_percent'] = 0;
- foreach ($upcontext['steps'] as $num => $step)
- {
- if ($num >= $upcontext['current_step'])
- {
- // The current weight of this step in terms of overall progress.
- $upcontext['step_weight'] = $step[3];
- // Make sure we reset the skip button.
- $upcontext['skip'] = false;
- // We cannot proceed if we're not logged in.
- if ($num != 0 && !$disable_security && $upcontext['user']['pass'] != $upcontext['upgrade_status']['pass'])
- {
- $upcontext['steps'][0][2]();
- break;
- }
- // Call the step and if it returns false that means pause!
- if (function_exists($step[2]) && $step[2]() === false)
- break;
- elseif (function_exists($step[2]))
- $upcontext['current_step']++;
- }
- $upcontext['overall_percent'] += $step[3];
- }
- upgradeExit();
- // Exit the upgrade script.
- function upgradeExit($fallThrough = false)
- {
- global $upcontext, $upgradeurl, $command_line;
- // Save where we are...
- if (!empty($upcontext['current_step']) && !empty($upcontext['user']['id']))
- {
- $upcontext['user']['step'] = $upcontext['current_step'];
- $upcontext['user']['substep'] = $_GET['substep'];
- $upcontext['user']['updated'] = time();
- $upgradeData = base64_encode(serialize($upcontext['user']));
- copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php');
- changeSettings(array('upgradeData' => '"' . $upgradeData . '"'));
- updateLastError();
- }
- // Handle the progress of the step, if any.
- if (!empty($upcontext['step_progress']) && isset($upcontext['steps'][$upcontext['current_step']]))
- {
- $upcontext['step_progress'] = round($upcontext['step_progress'], 1);
- $upcontext['overall_percent'] += $upcontext['step_progress'] * ($upcontext['steps'][$upcontext['current_step']][3] / 100);
- }
- $upcontext['overall_percent'] = (int) $upcontext['overall_percent'];
- // We usually dump our templates out.
- if (!$fallThrough)
- {
- // This should not happen my dear... HELP ME DEVELOPERS!!
- if (!empty($command_line))
- {
- if (function_exists('debug_print_backtrace'))
- debug_print_backtrace();
- echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the Elkarte Community to tell the Developers that they\'ve made a doh!; they\'ll get you up and running again.';
- flush();
- die();
- }
- if (!isset($_GET['xml']))
- template_upgrade_above();
- else
- {
- header('Content-Type: text/xml; charset=ISO-8859-1');
- // Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
- $upcontext['get_data'] = array();
- foreach ($_GET as $k => $v)
- {
- if (substr($k, 0, 3) != 'amp' && !in_array($k, array('xml', 'substep', 'lang', 'data', 'step', 'filecount')))
- {
- $upcontext['get_data'][$k] = $v;
- }
- }
- template_xml_above();
- }
- // Call the template.
- if (isset($upcontext['sub_template']))
- {
- $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
- $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status']));
- // Custom stuff to pass back?
- if (!empty($upcontext['query_string']))
- $upcontext['form_url'] .= $upcontext['query_string'];
- call_user_func('template_' . $upcontext['sub_template']);
- }
- // Was there an error?
- if (!empty($upcontext['forced_error_message']))
- echo $upcontext['forced_error_message'];
- // Show the footer.
- if (!isset($_GET['xml']))
- template_upgrade_below();
- else
- template_xml_below();
- }
- // Bang - gone!
- die();
- }
- // Used to direct the user to another location.
- function redirectLocation($location, $addForm = true)
- {
- global $upgradeurl, $upcontext, $command_line;
- // Command line users can't be redirected.
- if ($command_line)
- upgradeExit(true);
- // Are we providing the core info?
- if ($addForm)
- {
- $upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
- $location = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])) . $location;
- }
- while (@ob_end_clean());
- header('Location: ' . strtr($location, array('&' => '&')));
- // Exit - saving status as we go.
- upgradeExit(true);
- }
- // Load all essential data and connect to the DB as this is pre SSI.php
- function loadEssentialData()
- {
- global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type;
- global $modSettings, $smcFunc, $upcontext;
- // Do the non-SSI stuff...
- @set_magic_quotes_runtime(0);
- error_reporting(E_ALL);
- define('ELKARTE', 1);
- // Start the session.
- if (@ini_get('session.save_handler') == 'user')
- @ini_set('session.save_handler', 'files');
- @session_start();
- if (empty($smcFunc))
- $smcFunc = array();
- // Initialize everything...
- initialize_inputs();
- // Get the database going!
- if (empty($db_type))
- $db_type = 'mysql';
- if (file_exists(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php'))
- {
- require_once(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php');
- // Make the connection...
- $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
- // Oh dear god!!
- if ($db_connection === null)
- die('Unable to connect to database - please check username and password are correct in Settings.php');
- if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
- $smcFunc['db_query']('', '
- SET NAMES ' . $db_character_set,
- array(
- 'db_error_skip' => true,
- )
- );
- // Load the modSettings data...
- $request = $smcFunc['db_query']('', '
- SELECT variable, value
- FROM {db_prefix}settings',
- array(
- 'db_error_skip' => true,
- )
- );
- $modSettings = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $modSettings[$row['variable']] = $row['value'];
- $smcFunc['db_free_result']($request);
- }
- else
- {
- return throw_error('Cannot find ' . SOURCEDIR . '/database/Db-' . $db_type . '.subs.php' . '. Please check you have uploaded all source files and have the correct paths set.');
- }
- // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars.
- if (file_exists(SOURCEDIR . '/QueryString.php'))
- {
- require_once(SOURCEDIR . '/QueryString.php');
- cleanRequest();
- }
- if (!isset($_GET['substep']))
- $_GET['substep'] = 0;
- }
- function initialize_inputs()
- {
- global $start_time, $upcontext, $db_type;
- $start_time = time();
- umask(0);
- // Fun. Low PHP version...
- if (!isset($_GET))
- {
- $GLOBALS['_GET']['step'] = 0;
- return;
- }
- ob_start();
- // Better to upgrade cleanly and fall apart than to screw everything up if things take too long.
- ignore_user_abort(true);
- // This is really quite simple; if ?delete is on the URL, delete the upgrader...
- if (isset($_GET['delete']))
- {
- deleteUpgrader();
- }
- // Are we calling the backup css file?
- if (isset($_GET['infile_css']))
- {
- header('Content-Type: text/css');
- template_css();
- exit;
- }
- // Something is causing this to happen, and it's annoying. Stop it.
- $temp = 'upgrade_php?step';
- while (strlen($temp) > 4)
- {
- if (isset($_GET[$temp]))
- unset($_GET[$temp]);
- $temp = substr($temp, 1);
- }
- // Force a step, defaulting to 0.
- $_GET['step'] = (int) @$_GET['step'];
- $_GET['substep'] = (int) @$_GET['substep'];
- }
- // Step 0 - Let's welcome them in and ask them to login!
- function action_welcomeLogin()
- {
- global $db_prefix, $language, $modSettings, $upgradeurl, $upcontext, $disable_security;
- global $smcFunc, $db_type, $databases, $txt;
- $upcontext['sub_template'] = 'welcome_message';
- // Check for some key files - one template, one language, and a new and an old source file.
- $check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
- && @file_exists(SOURCEDIR . '/QueryString.php')
- && @file_exists(SOURCEDIR . '/database/Db-' . $db_type . '.subs.php')
- && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
- // Need legacy scripts?
- if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] < 2.1)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
- if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] < 2.0)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
- if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] < 1.1)
- $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
- if (!$check)
- // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
- return throw_error('The upgrader was unable to find some crucial files.<br /><br />Please make sure you uploaded all of the files included in the package, including the themes, sources, and other directories.');
- // Do they meet the install requirements?
- if (!php_version_check())
- return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets ELKARTE\'s minimum installations requirements.<br /><br />Please ask your host to upgrade.');
- if (!db_version_check())
- return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of ELKARTE.<br /><br />Please ask your host to upgrade.');
- // Do they have ALTER privileges?
- if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
- return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br /><br />Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
- // Do a quick version spot check.
- $temp = substr(@implode('', @file(BOARDDIR . '/index.php')), 0, 4096);
- preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
- if (empty($match[1]) || $match[1] != CURRENT_VERSION)
- return throw_error('The upgrader found some old or outdated files.<br /><br />Please make certain you uploaded the new versions of all the files included in the package.');
- // What absolutely needs to be writable?
- $writable_files = array(
- BOARDDIR . '/Settings.php',
- BOARDDIR . '/Settings_bak.php',
- );
- require_once(SOURCEDIR . '/Security.php');
- $upcontext += createToken('login');
- // Check the cache directory.
- $CACHEDIR_temp = !defined('CACHEDIR') ? BOARDDIR . '/cache' : CACHEDIR;
- if (!file_exists($CACHEDIR_temp))
- @mkdir($CACHEDIR_temp);
- if (!file_exists($CACHEDIR_temp))
- return throw_error('The cache directory could not be found.<br /><br />Please make sure you have a directory called "cache" in your forum directory before continuing.');
- if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['elkVersion']) && !isset($_GET['lang']))
- return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br />ELKARTE will not work without the primary language files installed.<br /><br />Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
- elseif (!isset($_GET['skiplang']))
- {
- $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
- preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
- if (empty($match[1]) || $match[1] != CURRENT_LANG_VERSION)
- return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br /> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
- }
- // This needs to exist!
- if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
- return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br /> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
- else
- require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
- if (!makeFilesWritable($writable_files))
- return false;
- // Check agreement.txt. (it may not exist, in which case BOARDDIR must be writable.)
- if (isset($modSettings['agreement']) && (!is_writable(BOARDDIR) || file_exists(BOARDDIR . '/agreement.txt')) && !is_writable(BOARDDIR . '/agreement.txt'))
- return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br /><br />If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br />If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
- // Upgrade the agreement.
- elseif (isset($modSettings['agreement']))
- {
- $fp = fopen(BOARDDIR . '/agreement.txt', 'w');
- fwrite($fp, $modSettings['agreement']);
- fclose($fp);
- }
- // We're going to check that their board dir setting is right incase they've been moving stuff around.
- if (strtr(BOARDDIR, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
- $upcontext['warning'] = '
- It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . BOARDDIR . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br />
- <ul>
- <li>Board Directory: ' . BOARDDIR . '</li>
- <li>Source Directory: ' . BOARDDIR . '</li>
- <li>Cache Directory: ' . $CACHEDIR_temp . '</li>
- </ul>
- If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://github.com/emanuele45/tools/downloads">Repair Settings</a> tool from the Elkarte website before continuing.';
- // Either we're logged in or we're going to present the login.
- if (checkLogin())
- return true;
- return false;
- }
- // Step 0.5: Does the login work?
- function checkLogin()
- {
- global $db_prefix, $language, $modSettings, $upgradeurl, $upcontext, $disable_security;
- global $smcFunc, $db_type, $databases, $support_js, $txt;
- // Are we trying to login?
- if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security))
- {
- // If we've disabled security pick a suitable name!
- if (empty($_POST['user']))
- $_POST['user'] = 'Administrator';
- // Before 2.0 these column names were different!
- $oldDB = false;
- if (empty($db_type) || $db_type == 'mysql')
- {
- $request = $smcFunc['db_query']('', '
- SHOW COLUMNS
- FROM {db_prefix}members
- LIKE {string:member_name}',
- array(
- 'member_name' => 'memberName',
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) != 0)
- $oldDB = true;
- $smcFunc['db_free_result']($request);
- }
- // Get what we believe to be their details.
- if (!$disable_security)
- {
- if ($oldDB)
- $request = $smcFunc['db_query']('', '
- SELECT id_member, memberName AS member_name, passwd, id_group,
- additionalGroups AS additional_groups, lngfile
- FROM {db_prefix}members
- WHERE memberName = {string:member_name}',
- array(
- 'member_name' => $_POST['user'],
- 'db_error_skip' => true,
- )
- );
- else
- $request = $smcFunc['db_query']('', '
- SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
- FROM {db_prefix}members
- WHERE member_name = {string:member_name}',
- array(
- 'member_name' => $_POST['user'],
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) != 0)
- {
- list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
- $groups = explode(',', $addGroups);
- $groups[] = $id_group;
- foreach ($groups as $k => $v)
- $groups[$k] = (int) $v;
- // Figure out the password using our encryption - if what they typed is right.
- if (isset($_REQUEST['hash_passwrd']) && strlen($_REQUEST['hash_passwrd']) == 40)
- {
- // Challenge passed.
- if ($_REQUEST['hash_passwrd'] == sha1($password . $upcontext['rid']))
- $sha_passwd = $password;
- }
- else
- $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
- }
- else
- $upcontext['username_incorrect'] = true;
- $smcFunc['db_free_result']($request);
- }
- $upcontext['username'] = $_POST['user'];
- // Track whether javascript works!
- if (!empty($_POST['js_works']))
- {
- $upcontext['upgrade_status']['js'] = 1;
- $support_js = 1;
- }
- else
- $support_js = 0;
- // Note down the version we are coming from.
- if (!empty($modSettings['elkVersion']) && empty($upcontext['user']['version']))
- $upcontext['user']['version'] = $modSettings['elkVersion'];
- // Didn't get anywhere?
- if ((empty($sha_passwd) || $password != $sha_passwd) && empty($upcontext['username_incorrect']) && !$disable_security)
- {
- // MD5?
- $md5pass = md5_hmac($_REQUEST['passwrd'], strtolower($_POST['user']));
- if ($md5pass != $password)
- {
- $upcontext['password_failed'] = true;
- // Disable the hashing this time.
- $upcontext['disable_login_hashing'] = true;
- }
- }
- if ((empty($upcontext['password_failed']) && !empty($name)) || $disable_security)
- {
- // Set the password.
- if (!$disable_security)
- {
- // Do we actually have permission?
- if (!in_array(1, $groups))
- {
- $request = $smcFunc['db_query']('', '
- SELECT permission
- FROM {db_prefix}permissions
- WHERE id_group IN ({array_int:groups})
- AND permission = {string:admin_forum}',
- array(
- 'groups' => $groups,
- 'admin_forum' => 'admin_forum',
- 'db_error_skip' => true,
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- return throw_error('You need to be an admin to perform an upgrade!');
- $smcFunc['db_free_result']($request);
- }
- $upcontext['user']['id'] = $id_member;
- $upcontext['user']['name'] = $name;
- }
- else
- {
- $upcontext['user']['id'] = 1;
- $upcontext['user']['name'] = 'Administrator';
- }
- $upcontext['user']['pass'] = mt_rand(0,60000);
- // This basically is used to match the GET variables to Settings.php.
- $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass'];
- // Set the language to that of the user?
- if (isset($user_language) && $user_language != $upcontext['language'] && file_exists($modSettings['theme_dir'] . '/languages/index.' . basename($user_language, '.lng') . '.php'))
- {
- $user_language = basename($user_language, '.lng');
- $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
- preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
- if (empty($match[1]) || $match[1] != CURRENT_LANG_VERSION)
- $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
- elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
- $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
- else
- {
- // Set this as the new language.
- $upcontext['language'] = $user_language;
- $upcontext['upgrade_status']['lang'] = $upcontext['language'];
- // Include the file.
- require_once($modSettings['theme_dir'] . '/languages/Install.' . $user_language . '.php');
- }
- }
- // If we're resuming set the step and substep to be correct.
- if (isset($_POST['cont']))
- {
- $upcontext['current_step'] = $upcontext['user']['step'];
- $_GET['substep'] = $upcontext['user']['substep'];
- }
- return true;
- }
- }
- return false;
- }
- // Step 1: Do the maintenance and backup.
- function action_upgradeOptions()
- {
- global $db_prefix, $command_line, $modSettings, $is_debug, $smcFunc;
- global $boardurl, $maintenance, $mmessage, $upcontext, $db_type;
- $upcontext['sub_template'] = 'upgrade_options';
- $upcontext['page_title'] = 'Upgrade Options';
- // If we've not submitted then we're done.
- if (empty($_POST['upcont']))
- return false;
- // No one opts in so why collect incomplete stats
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}settings
- WHERE variable = {string:allow_sm_stats}',
- array(
- 'allow_sm_stats' => false,
- 'db_error_skip' => true,
- )
- );
- // Emptying the error log?
- if (!empty($_POST['empty_error']))
- $smcFunc['db_query']('truncate_table', '
- TRUNCATE {db_prefix}log_errors',
- array(
- )
- );
- $changes = array();
- // If we're overriding the language follow it through.
- if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
- $changes['language'] = '\'' . $_GET['lang'] . '\'';
- if (!empty($_POST['maint']))
- {
- $changes['maintenance'] = '2';
- // Remember what it was...
- $upcontext['user']['main'] = $maintenance;
- if (!empty($_POST['maintitle']))
- {
- $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
- $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
- }
- else
- {
- $changes['mtitle'] = '\'Upgrading the forum...\'';
- $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\'';
- }
- }
- if ($command_line)
- echo ' * Updating Settings.php...';
- // Backup the current one first.
- copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php');
- // Fix some old paths.
- if (substr(BOARDDIR, 0, 1) == '.')
- $changes['boarddir'] = '\'' . fixRelativePath(BOARDDIR) . '\'';
- if (substr(SOURCEDIR, 0, 1) == '.')
- $changes['sourcedir'] = '\'' . fixRelativePath(SOURCEDIR) . '\'';
- if (!defined('CACHEDIR') || substr(CACHEDIR, 0, 1) == '.')
- $changes['cachedir'] = '\'' . fixRelativePath(BOARDDIR) . '/cache\'';
- // Not had the database type added before?
- if (empty($db_type))
- $changes['db_type'] = 'mysql';
- // @todo Maybe change the cookie name if going to 1.1, too?
- // Update Settings.php with the new settings.
- changeSettings($changes);
- if ($command_line)
- echo ' Successful.' . "\n";
- // Are we doing debug?
- if (isset($_POST['debug']))
- {
- $upcontext['upgrade_status']['debug'] = true;
- $is_debug = true;
- }
- // If we're not backing up then jump one.
- if (empty($_POST['backup']))
- $upcontext['current_step']++;
- // If we've got here then let's proceed to the next step!
- return true;
- }
- // Backup the database - why not...
- function action_backupDatabase()
- {
- global $upcontext, $db_prefix, $command_line, $is_debug, $support_js, $file_steps, $smcFunc;
- $upcontext['sub_template'] = isset($_GET['xml']) ? 'backup_xml' : 'backup_database';
- $upcontext['page_title'] = 'Backup Database';
- // Done it already - js wise?
- if (!empty($_POST['backup_done']))
- return true;
- // Some useful stuff here.
- db_extend();
- // Get all the table names.
- $filter = str_replace('_', '\_', preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? $match[2] : $db_prefix) . '%';
- $db = preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? strtr($match[1], array('`' => '')) : false;
- $tables = $smcFunc['db_list_tables']($db, $filter);
- $table_names = array();
- foreach ($tables as $table)
- if (substr($table, 0, 7) !== 'backup_')
- $table_names[] = $table;
- $upcontext['table_count'] = count($table_names);
- $upcontext['cur_table_num'] = $_GET['substep'];
- $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$_GET['substep']]) ? $table_names[$_GET['substep']] : $table_names[0]);
- $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
- // For non-java auto submit...
- $file_steps = $upcontext['table_count'];
- // What ones have we already done?
- foreach ($table_names as $id => $table)
- if ($id < $_GET['substep'])
- $upcontext['previous_tables'][] = $table;
- if ($command_line)
- echo 'Backing Up Tables.';
- // If we don't support javascript we backup here.
- if (!$support_js || isset($_GET['xml']))
- {
- // Backup each table!
- for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++)
- {
- $upcontext['cur_table_name'] = str_replace($db_prefix, '', (isset($table_names[$substep + 1]) ? $table_names[$substep + 1] : $table_names[$substep]));
- $upcontext['cur_table_num'] = $substep + 1;
- $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
- // Do we need to pause?
- nextSubstep($substep);
- backupTable($table_names[$substep]);
- // If this is XML to keep it nice for the user do one table at a time anyway!
- if (isset($_GET['xml']))
- return upgradeExit();
- }
- if ($is_debug && $command_line)
- {
- echo "\n" . ' Successful.\'' . "\n";
- flush();
- }
- $upcontext['step_progress'] = 100;
- $_GET['substep'] = 0;
- // Make sure we move on!
- return true;
- }
- // Either way next place to post will be database changes!
- $_GET['substep'] = 0;
- return false;
- }
- // Backup one table...
- function backupTable($table)
- {
- global $is_debug, $command_line, $db_prefix, $smcFunc;
- if ($is_debug && $command_line)
- {
- echo "\n" . ' +++ Backing up \"' . str_replace($db_prefix, '', $table) . '"...';
- flush();
- }
- $smcFunc['db_backup_table']($table, 'backup_' . $table);
- if ($is_debug && $command_line)
- echo ' done.';
- }
- // Step 2: Everything.
- function action_databaseChanges()
- {
- global $db_prefix, $modSettings, $command_line, $smcFunc;
- global $language, $boardurl, $upcontext, $support_js, $db_type;
- // Have we just completed this?
- if (!empty($_POST['database_done']))
- return true;
- $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
- $upcontext['page_title'] = 'Database Changes';
- // All possible files.
- // Name, version, insert_on_complete.
- $files = array(
- array('upgrade_1-0.sql', '1.1', '1.1 RC0'),
- array('upgrade_1-1.sql', '2.0', '2.0 a'),
- array('upgrade_2-0_' . $db_type . '.sql', '2.1', '2.1 dev0'),
- // array('upgrade_2-1_' . $db_type . '.sql', '3.0', '3.0 dev0'),
- array('upgrade_dia_1-0_' . $db_type . '.sql', '1.1', CURRENT_VERSION),
- );
- // How many files are there in total?
- if (isset($_GET['filecount']))
- $upcontext['file_count'] = (int) $_GET['filecount'];
- else
- {
- $upcontext['file_count'] = 0;
- foreach ($files as $file)
- {
- if (!isset($modSettings['elkVersion']) && isset($modSettings['smfVersion']) && strpos($file[0], '_dia_') === false && $modSettings['smfVersion'] < $file[1])
- $upcontext['file_count']++;
- elseif (!isset($modSettings['elkVersion']) || (strpos($file[0], '_dia_') !== false && $modSettings['elkVersion'] < $file[1]))
- $upcontext['file_count']++;
- }
- }
- // Do each file!
- $did_not_do = count($files) - $upcontext['file_count'];
- $upcontext['step_progress'] = 0;
- $upcontext['cur_file_num'] = 0;
- foreach ($files as $file)
- {
- if ($did_not_do)
- $did_not_do--;
- else
- {
- $upcontext['cur_file_num']++;
- $upcontext['cur_file_name'] = $file[0];
- // Do we actually need to do this still?
- if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] < $file[1])
- {
- $nextFile = parse_sql(dirname(__FILE__) . '/' . $file[0]);
- if ($nextFile)
- {
- // Only update the version of this if complete.
- $smcFunc['db_insert']('replace',
- $db_prefix . 'settings',
- array('variable' => 'string', 'value' => 'string'),
- array('elkVersion', $file[2]),
- array('variable')
- );
- $modSettings['elkVersion'] = $file[2];
- }
- // If this is XML we only do this stuff once.
- if (isset($_GET['xml']))
- {
- // Flag to move on to the next.
- $upcontext['completed_step'] = true;
- // Did we complete the whole file?
- if ($nextFile)
- $upcontext['current_debug_item_num'] = -1;
- return upgradeExit();
- }
- elseif ($support_js)
- break;
- }
- // Set the progress bar to be right as if we had - even if we hadn't...
- $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
- }
- }
- $_GET['substep'] = 0;
- // So the template knows we're done.
- if (!$support_js)
- {
- $upcontext['changes_complete'] = true;
- // If this is the command line we can't do any more.
- if ($command_line)
- return action_deleteUpgrade();
- return true;
- }
- return false;
- }
- // Clean up any mods installed...
- function action_cleanupMods()
- {
- global $db_prefix, $modSettings, $upcontext, $settings, $smcFunc, $command_line;
- // Sorry. Not supported for command line users.
- if ($command_line)
- return true;
- // Skipping first?
- if (!empty($_POST['skip']))
- {
- unset($_POST['skip']);
- return true;
- }
- // If we get here withOUT SSI we need to redirect to ensure we get it!
- if (!isset($_GET['ssi']) || !function_exists('mktree'))
- redirectLocation('&ssi=1');
- $upcontext['sub_template'] = 'clean_mods';
- $upcontext['page_title'] = 'Cleanup Modifications';
- // This can be skipped.
- $upcontext['skip'] = true;
- // If we're on the second redirect continue...
- if (isset($_POST['cleandone2']))
- return true;
- // Do we already know about some writable files?
- if (isset($_POST['writable_files']))
- {
- $writable_files = unserialize(base64_decode($_POST['writable_files']));
- if (!makeFilesWritable($writable_files))
- {
- // What have we left?
- $upcontext['writable_files'] = $writable_files;
- return false;
- }
- }
- // Load all theme paths....
- $request = $smcFunc['db_query']('', '
- SELECT id_theme, variable, value
- FROM {db_prefix}themes
- WHERE id_member = {int:id_member}
- AND variable IN ({string:theme_dir}, {string:images_url})',
- array(
- 'id_member' => 0,
- 'theme_dir' => 'theme_dir',
- 'images_url' => 'images_url',
- 'db_error_skip' => true,
- )
- );
- $theme_paths = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if ($row['id_theme'] == 1)
- $settings['default_' . $row['variable']] = $row['value'];
- elseif ($row['variable'] == 'theme_dir')
- $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
- }
- $smcFunc['db_free_result']($request);
- // Are there are mods installed that may need uninstalling?
- $request = $smcFunc['db_query']('', '
- SELECT id_install, filename, name, themes_installed, version
- FRO…
Large files files are truncated, but you can click here to view the full file