diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-09-02 14:34:20 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-09-02 14:34:20 +0000 |
commit | 64af84dc6b5f352f766940e70774907f240960e3 (patch) | |
tree | 52b0562a3701f1e21f38a6b85f5033a6c552e68c /phpBB | |
parent | 609744041be8d00ab705b1cc4eec24fe717e15d9 (diff) | |
download | forums-64af84dc6b5f352f766940e70774907f240960e3.tar forums-64af84dc6b5f352f766940e70774907f240960e3.tar.gz forums-64af84dc6b5f352f766940e70774907f240960e3.tar.bz2 forums-64af84dc6b5f352f766940e70774907f240960e3.tar.xz forums-64af84dc6b5f352f766940e70774907f240960e3.zip |
the file updater. This is in CVS but the file is not able to be used without the correct update packages - no need to try.
Please note that even if the file is now in CVS it does not mean we provide an update path from Beta2 to any other version.
git-svn-id: file:///svn/phpbb/trunk@6349 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/adm/style/install_update.html | 278 | ||||
-rw-r--r-- | phpBB/adm/style/install_update_diff.html | 180 | ||||
-rw-r--r-- | phpBB/install/install_update.php | 1009 |
3 files changed, 1467 insertions, 0 deletions
diff --git a/phpBB/adm/style/install_update.html b/phpBB/adm/style/install_update.html new file mode 100644 index 0000000000..54e86ec788 --- /dev/null +++ b/phpBB/adm/style/install_update.html @@ -0,0 +1,278 @@ +<!-- INCLUDE install_header.html --> + +<!-- IF S_ERROR --> + <h1>{L_NOTICE}</h1> + <p style="color: red;">{ERROR_MSG}</p> +<!-- ENDIF --> + +<!-- IF S_INTRO --> + <form id="install_update" method="post" action="{U_ACTION}"> + + <h1>{L_UPDATE_INSTALLATION}</h1> + <p>{L_UPDATE_INSTALLATION_EXPLAIN}</p> + + <fieldset class="submit-buttons"> + <input class="button1" type="submit" name="submit" value="{L_NEXT}" /> + </fieldset> + + </form> + +<!-- ELSEIF S_UPLOAD_SUCCESS --> + + <form id="install_update" method="post" action="{U_ACTION}"> + + <h1>{L_UPDATE_SUCCESS}</h1> + <p>{L_UPDATE_SUCCESS_EXPLAIN}</p> + + <fieldset class="submit-buttons"> + <input class="button1" type="submit" name="submit" value="{L_CHECK_FILES_AGAIN}" /> + </fieldset> + + </form> + +<!-- ENDIF --> + +<!-- IF S_VERSION_CHECK --> + + <h1>{L_VERSION_CHECK}</h1> + + <p>{L_VERSION_CHECK_EXPLAIN}</p> + + <!-- IF S_UP_TO_DATE --> + <div class="successbox"> + <p>{L_VERSION_UP_TO_DATE}</p> + </div> + <!-- ELSE --> + <div class="errorbox"> + <p>{L_VERSION_NOT_UP_TO_DATE}</p> + </div> + <!-- ENDIF --> + + <fieldset> + <legend></legend> + <dl> + <dt><label>{L_CURRENT_VERSION}</label></dt> + <dd><b>{CURRENT_VERSION}</b></dd> + </dl> + <dl> + <dt><label>{L_LATEST_VERSION}</label></dt> + <dd><b>{LATEST_VERSION}</b></dd> + </dl> + </fieldset> + + <!-- IF not S_UP_TO_DATE --> + <form id="install_update" method="post" action="{U_ACTION}"> + + <fieldset class="submit-buttons"> + <p>{L_CHECK_FILES_EXPLAIN}</p> + <input class="button1" type="submit" name="submit" value="{L_CHECK_FILES}" /> + </fieldset> + + </form> + <!-- ELSE --> + <form id="install_update" method="post" action="{U_ACTION}"> + + <fieldset class="submit-buttons"> + <p>{L_CHECK_FILES_UP_TO_DATE}</p> + <input class="button1" type="submit" name="submit" value="{L_CHECK_FILES}" /> + </fieldset> + + </form> + <!-- ENDIF --> + +<!-- ELSEIF S_FILE_CHECK --> + + <h1>{L_COLLECTED_INFORMATIONS}</h1> + + <p>{L_COLLECTED_INFORMATIONS_EXPLAIN}</p> + + <!-- IF S_NO_UPDATE_FILES --> + <div class="errorbox"> + <h3>{L_NO_UPDATE_FILES}</h3> + + <p>{L_NO_UPDATE_FILES_EXPLAIN}</p><br /> + + <strong>{NO_UPDATE_FILES}</strong> + + </div> + <!-- ENDIF --> + + <form id="install_update" method="post" action="{U_UPDATE_ACTION}"> + + <!-- IF .files --> + <!-- BEGIN files --> + <!-- IF files.S_STATUS --> + <!-- IF not files.S_FIRST_ROW --> + </fieldset> + <!-- ENDIF --> + + <h2>{files.TITLE}</h2> + + <p>{files.EXPLAIN}</p> + + <!--table cellspacing="1"> + <col class="row1" /><col class="row2" /><col class="row2" /> + <tbody --> + <fieldset> + <legend><img src="{T_IMAGE_PATH}file_{files.STATUS}.gif" alt="{files.L_STATUS}" /></legend> + <!-- ELSE --> + <dl> + <!-- IF files.STATUS eq 'up_to_date' --> + <dd class="full" style="text-align: left;"><strong>{files.FILENAME}</strong></dd> + <!-- ELSE --> + <dt> + <strong>{files.FILENAME}</strong> + <!-- IF files.S_CUSTOM --> + <br /><span><em>{L_FILE_USED}: </em>{files.CUSTOM_ORIGINAL}</span> + <!-- ENDIF --> + <!-- IF files.NUM_CONFLICTS --> + <br /><span>{L_NUM_CONFLICTS}: {files.NUM_CONFLICTS}</span> + <!-- ENDIF --> + </dt> + <dd>[ <a href="{files.U_SHOW_DIFF}" target="diff">{files.L_SHOW_DIFF}</a> ]</dd> + <!-- IF files.S_CUSTOM --> + <dd><input type="checkbox" name="no_update[]" value="{files.FILENAME}" class="radio" /> {L_DO_NOT_UPDATE}</dd> + <!-- ENDIF --> + <!-- IF files.STATUS eq 'conflict' --> + <dd><input type="radio" class="radio" name="conflict[{files.FILENAME}]" value="1" checked="checked" /> {L_MERGE_NEW_FILE_OPTION}<br /><input type="radio" class="radio" name="conflict[{files.FILENAME}]" value="2" /> {L_MERGE_MOD_FILE_OPTION}</dd> + <!-- ENDIF --> + <!-- ENDIF --> + </dl> + <!-- ENDIF --> + <!-- END files --> + + </fieldset> + <!-- ENDIF --> + + <br /> + + <fieldset class="quick"> + <input class="button1" type="submit" name="check_again" value="{L_CHECK_FILES_AGAIN}" /> + </fieldset> + + <br /> + + <!-- IF S_ALL_UP_TO_DATE --> + </form> + + <!-- IF S_VERSION_UP_TO_DATE --> + <p>{L_NO_DATABASE_UPDATE_NEEDED}</p> + <!-- ELSE --> + <form id="install_dbupdate" method="post" action="{U_DB_UPDATE_ACTION}"> + + <fieldset class="submit-buttons"> + <p>{L_ALL_FILES_UP_TO_DATE}</p> + <input class="button1" type="submit" name="db_update" value="{L_UPDATE_DATABASE}" /> + </fieldset> + <!-- ENDIF --> + + <!-- ELSE --> + <h1>{L_UPDATE_METHOD}</h1> + + <p>{L_UPDATE_METHOD_EXPLAIN}</p> + + <fieldset class="submit-buttons"> + <input class="button1" type="submit" name="ftp_upload" value="{L_FTP_UPDATE_METHOD}" /> <input class="button1" type="submit" name="download" value="{L_DOWNLOAD_UPDATE_METHOD}" /> + </fieldset> + + <!-- ENDIF --> + + </form> + +<!-- ELSEIF S_DOWNLOAD_FILES --> + + <h1>{L_SELECT_DOWNLOAD_FORMAT}</h1> + + <p>{L_DOWNLOAD_UPDATE_METHOD_EXPLAIN}</p> + + <p>{L_MAPPING_FILE_STRUCTURE}</p> + + <table cellspacing="1"> + <col class="row1" /><col class="row2" /><col class="row1" /> + <thead> + <tr> + <th style="width: 49%">{L_ARCHIVE_FILE}</th> + <th style="width: 2%"> </th> + <th style="width: 49%">{L_DESTINATION}</th> + </tr> + </thead> + <tbody> + <!-- BEGIN location --> + <tr> + <td>{location.SOURCE}</td> + <td><strong>»</strong></td> + <td>{location.DESTINATION}</td> + </tr> + <!-- END location --> + </tbody> + </table> + + <form id="install_update" method="post" action="{U_ACTION}"> + + <fieldset> + <legend>{L_DOWNLOAD_AS}</legend> + <dl> + <dt><label for="use_method">{L_DOWNLOAD_AS}:</label></dt> + <dd>{RADIO_BUTTONS}</dd> + </dl> + </fieldset> + + <fieldset class="submit-buttons"> + {S_HIDDEN_FIELDS} + <input type="submit" class="button2" value="{L_CHECK_FILES_AGAIN}" name="check_again" /> <input type="submit" class="button1" value="{L_DOWNLOAD}" name="download" /> + </fieldset> + + </form> + +<!-- ELSEIF S_FTP_UPLOAD --> + + <h1>{L_SELECT_FTP_SETTINGS}</h1> + + <form id="install_update" method="post" action="{U_ACTION}"> + + <!-- IF S_CONNECTION_SUCCESS --> + <div class="successbox"> + <p>{L_CONNECTION_SUCCESS}</p> + </div> + <!-- ELSEIF S_CONNECTION_FAILED --> + <div class="errorbox"> + <p>{L_CONNECTION_FAILED}<br />{ERROR_MSG}</p> + </div> + <!-- ENDIF --> + + <fieldset> + <legend>{L_FTP_SETTINGS}</legend> + <dl> + <dt><label>{L_UPLOAD_METHOD}:</label></dt> + <dd><b>{UPLOAD_METHOD}</b></dd> + </dl> + <!-- BEGIN data --> + <dl> + <dt><label for="{data.DATA}">{data.NAME}:</label><br /><span>{data.EXPLAIN}</span></dt> + <dd><input type="text" id="{data.DATA}" name="{data.DATA}" value="{data.DEFAULT}" /></dd> + </dl> + <!-- END data --> + </fieldset> + + <fieldset class="submit-buttons"> + {S_HIDDEN_FIELDS} + <input class="button2" type="submit" name="check_again" value="{L_BACK}" /> + <input class="button1" type="submit" name="test_connection" value="{L_TEST_CONNECTION}" /> + <input class="button1" type="submit" name="submit" value="{L_UPDATE_FILES}" /> + </fieldset> + + </form> + +<!-- ELSEIF S_DB_UPDATE --> + + <h1>{L_PERFORM_DATABASE_UPDATE}</h1> + + <p> + {L_PERFORM_DATABASE_UPDATE_EXPLAIN}<br /> + <br /> + <a href="{U_DB_UPDATE}"><strong>» {L_RUN_DATABASE_SCRIPT} «</strong></a> + </p> + +<!-- ENDIF --> + +<!-- INCLUDE install_footer.html --> diff --git a/phpBB/adm/style/install_update_diff.html b/phpBB/adm/style/install_update_diff.html new file mode 100644 index 0000000000..293645788f --- /dev/null +++ b/phpBB/adm/style/install_update_diff.html @@ -0,0 +1,180 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" dir="{S_CONTENT_DIRECTION}"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset={S_CONTENT_ENCODING}" /> +<meta http-equiv="Content-Style-Type" content="text/css" /> +<meta http-equiv="imagetoolbar" content="no" /> +<!-- IF META -->{META}<!-- ENDIF --> +<title>{PAGE_TITLE}</title> + +<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" /> + +<style type="text/css"> +<!-- + +#main { + font-size: 1.25em; + line-height: 0.7em; + margin: 0; + padding: 0; + width: 99%; +} + +<!-- IF not S_DIFF_NEW_FILE --> + +/** +* Unified Diff +*/ +.file { + border: 1px solid #eee; + line-height: .7em; +} + +.diff { + margin: 0; +} + +.added { + background-color: #dfd; +} + +.removed { + background-color: #fdd; +} + +.info { + color: #888; +} + +.context { + background-color: #eee; +} + +/** +* Inline Diff +*/ +.ins { + background-color: #dfd; + text-decoration: underline; +} + +.del { + background-color: #fdd; + text-decoration: line-through; +} + +/** +* Column Diff +*/ +table.hrdiff { + width: 99%; + margin: 0 0 8px 5px; +} + +table.hrdiff th { + text-align: left; + width: 50%; + color: #333; + font-family: Verdana,Helvetica,sans-serif; + font-size: 11px; + border-bottom: 1px solid #999; + background: transparent; +} + +table.hrdiff thead th { + font-weight: bold; + font-size: 110%; + padding: 2px; +} + +table.hrdiff tbody th { + padding: 2em 1px 1px 1px; + font-size: 80%; +} + +table.hrdiff .unmodified { + background: #fff; +} + +table.hrdiff .added { + background: #9f9; +} + +table.hrdiff .added_empty { + background: #cfc; +} + +table.hrdiff .modified { + background: #fd9; +} + +table.hrdiff .removed { + background: #f99; +} + +table.hrdiff .removed_empty { + background: #fcc; +} + +table.hrdiff caption { + caption-side: top; + text-align: left; + margin: 0 0 8px 5px; + font-size: 90%; + font-weight: bold; + padding: 5px; +} + +table.hrdiff caption span { + height: 10px; + width: 10px; + line-height: 10px; + letter-spacing: 10px; + border: 1px solid #000; + margin-left: 0.5em; + vertical-align: baseline; +} + +<!-- ENDIF --> + +//--> +</style> + +</head> + +<body> + +<div id="wrap"> + <div id="page-header"> +<!-- IF S_DIFF_NEW_FILE --> + <h1>{L_VIEWING_FILE_CONTENTS}</h1> +<!-- ELSE --> + <h1>{L_VIEWING_FILE_DIFF}</h1> +<!-- ENDIF --> +<!-- IF not S_DIFF_NEW_FILE --> + <br /> + <form method="post"> + <label for="diff_mode">{L_SELECT_DIFF_MODE}:</label> + <select name="diff_mode" id="diff_mode">{S_DIFF_MODE_OPTIONS}</select> + <input class="button1" type="submit" id="submit" name="submit" value="{L_CHANGE}" /> + </form> +<!-- ENDIF --> + </div> + + <div id="page-body"> + <div class="panel"> + <span class="corners-top"><span></span></span> + <div id="content"> + <div id="main"> +<!-- IF S_DIFF_CONFLICT_FILE --> + <div style="float: right;"><strong>{L_NUM_CONFLICTS}: {NUM_CONFLICTS}</strong></div> +<!-- ENDIF --> + {DIFF_CONTENT} + </div> + </div> + <span class="corners-bottom"><span></span></span> + </div> + </div> + +<!-- INCLUDE simple_footer.html -->
\ No newline at end of file diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php new file mode 100644 index 0000000000..75ff84fcbb --- /dev/null +++ b/phpBB/install/install_update.php @@ -0,0 +1,1009 @@ +<?php +/** +* +* @package install +* @version $Id$ +* @copyright (c) 2006 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +*/ +if (!defined('IN_INSTALL')) +{ + // Someone has tried to access the file directly. This is not a good idea, so exit + exit; +} + +if (!empty($setmodules)) +{ + // If phpBB is not installed we do not include this module + if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !@file_exists($phpbb_root_path . 'cache/install_lock')) + { + include_once($phpbb_root_path . 'config.' . $phpEx); + + if (!defined('PHPBB_INSTALLED')) + { + return; + } + } + else + { + return; + } + + $module[] = array( + 'module_type' => 'update', + 'module_title' => 'UPDATE', + 'module_filename' => substr(basename(__FILE__), 0, -strlen($phpEx)-1), + 'module_order' => 20, + 'module_subs' => '', + 'module_stages' => array('INTRO', 'VERSION_CHECK', 'FILE_CHECK', 'UPDATE_FILES', 'UPDATE_DB'), + 'module_reqs' => '' + ); +} + +/** +* Update Installation +* @package install +*/ +class install_update extends module +{ + var $p_master; + var $update_info; + + var $old_location; + var $new_location; + var $latest_version; + var $current_version; + + function install_update(&$p_master) + { + $this->p_master = &$p_master; + } + + function main($mode, $sub) + { + global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth; + + $this->tpl_name = 'install_update'; + $this->old_location = $phpbb_root_path . 'install/update/old/'; + $this->new_location = $phpbb_root_path . 'install/update/new/'; + + // Init DB + require($phpbb_root_path . 'config.' . $phpEx); + require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); + require($phpbb_root_path . 'includes/constants.' . $phpEx); + + $db = new $sql_db(); + + // Connect to DB + $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false); + + // We do not need this any longer, unset for safety purposes + unset($dbpasswd); + + $config = $cache->obtain_config(); + + // First of all, init the user session + $user->session_begin(); + $auth->acl($user->data); + $user->setup('install'); + + include_once($phpbb_root_path . 'includes/diff/diff.' . $phpEx); + + // Check for user session + if (!$user->data['is_registered']) + { + login_box('', $user->lang['LOGIN_UPDATE_EXPLAIN']); + } + + if (!$auth->acl_get('a_')) + { + trigger_error($user->lang['NO_AUTH_UPDATE']); + } + + // If we are within the intro page we need to make sure we get up-to-date version info + if ($sub == 'intro') + { + $cache->destroy('_version_info'); + } + + // Set custom template again. ;) + $template->set_custom_template('../adm/style', 'admin'); + + // Get current and latest version + $this->current_version = $config['version']; + + if (($latest_version = $cache->get('_version_info')) === false) + { + $this->latest_version = $this->get_file('version_info'); + $cache->put('_version_info', $this->latest_version); + } + else + { + $this->latest_version = $latest_version; + } + + $up_to_date = (version_compare(strtolower($this->current_version), strtolower($this->latest_version), '<')) ? false : true; + + // Check for a valid update directory, else point the user to the phpbb.com website + if (!file_exists($phpbb_root_path . 'install/update') || !file_exists($phpbb_root_path . 'install/update/index.' . $phpEx) || !file_exists($this->old_location) || !file_exists($this->new_location)) + { + $template->assign_vars(array( + 'S_ERROR' => true, + 'ERROR_MSG' => ($up_to_date) ? $user->lang['NO_UPDATE_FILES_UP_TO_DATE'] : sprintf($user->lang['NO_UPDATE_FILES_OUTDATED'], $config['version'], $this->current_version, $this->latest_version)) + ); + + return; + } + + $this->update_info = $this->get_file('update_info'); + + // Make sure the update directory holds the correct information + // Since admins are able to run the update/checks more than once we only check if the current version is lower or equal than the version to which we update to. + if (version_compare(strtolower($this->current_version), strtolower($this->update_info['version']['to']), '>')) + { + $template->assign_vars(array( + 'S_ERROR' => true, + 'ERROR_MSG' => sprintf($user->lang['INCOMPATIBLE_UPDATE_FILES'], $config['version'], $this->update_info['version']['from'], $this->update_info['version']['to'])) + ); + + return; + } + + // Check if the update files stored are for the latest version... + if ($this->latest_version != $this->update_info['version']['to']) + { + $template->assign_vars(array( + 'S_ERROR' => true, + 'ERROR_MSG' => sprintf($user->lang['OLD_UPDATE_FILES'], $this->update_info['version']['from'], $this->update_info['version']['to'], $this->latest_version)) + ); + + return; + } + + // Make sure we stay at the file check if checking the files again + if (!empty($_POST['check_again'])) + { + $sub = $this->p_master->sub = 'file_check'; + } + + switch ($sub) + { + case 'intro': + $this->page_title = 'UPDATE_INSTALLATION'; + + $template->assign_vars(array( + 'S_INTRO' => true, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=version_check"), + )); + + // Make sure the update list is destroyed. + $cache->destroy('_update_list'); + break; + + case 'version_check': + $this->page_title = 'STAGE_VERSION_CHECK'; + + $template->assign_vars(array( + 'S_UP_TO_DATE' => $up_to_date, + 'S_VERSION_CHECK' => true, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), + + 'LATEST_VERSION' => $this->latest_version, + 'CURRENT_VERSION' => $config['version']) + ); + + break; + + case 'file_check': + + $this->page_title = 'STAGE_FILE_CHECK'; + + // Now make sure our update list is correct if the admin refreshes + $action = request_var('action', ''); + + // We are directly within an update. To make sure our update list is correct we check its status. + $update_list = (!empty($_POST['check_again'])) ? false : $cache->get('_update_list'); + $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0; + + // Make sure the list is up-to-date + if ($update_list !== false) + { + $get_new_list = false; + foreach ($this->update_info['files'] as $file) + { + if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) + { + $get_new_list = true; + break; + } + } + } + else + { + $get_new_list = true; + } + + if ($get_new_list) + { + $update_list = $this->get_update_structure(); + $cache->put('_update_list', $update_list); + } + + if ($action == 'diff') + { + $this->show_diff($update_list); + return; + } + + if (sizeof($update_list['no_update'])) + { + $template->assign_vars(array( + 'S_NO_UPDATE_FILES' => true, + 'NO_UPDATE_FILES' => implode(', ', array_map('htmlspecialchars', $update_list['no_update']))) + ); + } + + // Now assign the list to the template + foreach ($update_list as $status => $filelist) + { + if ($status == 'no_update' || !sizeof($filelist)) + { + continue; + } + + $template->assign_block_vars('files', array( + 'S_STATUS' => true, + 'STATUS' => $status, + 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], + 'TITLE' => $user->lang['FILES_' . strtoupper($status)], + 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN'], + ) + ); + + foreach ($filelist as $file_struct) + { + $template->assign_block_vars('files', array( + 'STATUS' => $status, + + 'FILENAME' => htmlspecialchars($file_struct['filename']), + 'NUM_CONFLICTS' => (isset($file_struct['conflicts'])) ? $file_struct['conflicts'] : 0, + + 'S_CUSTOM' => ($file_struct['custom']) ? true : false, + 'CUSTOM_ORIGINAL' => ($file_struct['custom']) ? $file_struct['original'] : '', + + 'U_SHOW_DIFF' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check&action=diff&status=$status&file=" . urlencode($file_struct['filename'])), + 'L_SHOW_DIFF' => ($status != 'up_to_date') ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', + )); + } + } + + $all_up_to_date = true; + foreach ($update_list as $status => $filelist) + { + if ($status != 'up_to_date' && $status != 'custom' && sizeof($filelist)) + { + $all_up_to_date = false; + break; + } + } + + $template->assign_vars(array( + 'S_FILE_CHECK' => true, + 'S_ALL_UP_TO_DATE' => $all_up_to_date, + 'S_VERSION_UP_TO_DATE' => $up_to_date, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), + 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), + 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), + )); + + break; + + case 'update_files': + + $this->page_title = 'STAGE_UPDATE_FILES'; + + $s_hidden_fields = ''; + foreach (request_var('conflict', array('' => 0)) as $filename => $merge_option) + { + $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; + } + + $no_update = request_var('no_update', array(0 => '')); + + foreach ($no_update as $index => $filename) + { + $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />'; + } + + if (!empty($_POST['download'])) + { + include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx); + + $use_method = request_var('use_method', ''); + $methods = array('.tar'); + + $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); + foreach ($available_methods as $type => $module) + { + if (!@extension_loaded($module)) + { + continue; + } + + $methods[] = $type; + } + + // Let the user decide in which format he wants to have the pack + if (!$use_method) + { + $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; + + $radio_buttons = ''; + foreach ($methods as $method) + { + $radio_buttons .= '<input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . ' '; + } + + $template->assign_vars(array( + 'S_DOWNLOAD_FILES' => true, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), + 'RADIO_BUTTONS' => $radio_buttons, + 'S_HIDDEN_FIELDS' => $s_hidden_fields) + ); + + // To ease the update process create a file location map + $update_list = $cache->get('_update_list'); + + foreach ($update_list as $status => $files) + { + if ($status == 'up_to_date' || $status == 'no_update') + { + continue; + } + + foreach ($files as $file_struct) + { + if (in_array($file_struct['filename'], $no_update)) + { + continue; + } + + $template->assign_block_vars('location', array( + 'SOURCE' => htmlspecialchars($file_struct['filename']), + 'DESTINATION' => $user->page['root_script_path'] . htmlspecialchars($file_struct['filename']), + )); + } + } + + return; + } + + if (!in_array($use_method, $methods)) + { + $use_method = '.tar'; + } + + $update_mode = 'download'; + } + else + { + include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx); + + // Choose FTP, if not available use fsock... + $method = request_var('method', ''); + $submit = (isset($_POST['submit'])) ? true : false; + $test_ftp_connection = request_var('test_connection', ''); + + if (!$method) + { + $method = 'ftp'; + $methods = transfer::methods(); + + if (!in_array('ftp', $methods)) + { + $method = $methods[0]; + } + } + + $test_connection = false; + if ($test_ftp_connection || $submit) + { + $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $test_connection = $transfer->open_session(); + + // Make sure that the directory is correct by checking for the existence of common.php + if ($test_connection === true) + { + // Check for common.php file + if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) + { + $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; + } + } + + $transfer->close_session(); + + // Make sure the login details are correct before continuing + if ($submit && $test_connection !== true) + { + $submit = false; + $test_ftp_connection = true; + } + } + + if (!$submit) + { + $this->page_title = 'SELECT_FTP_SETTINGS'; + + $requested_data = call_user_func(array($method, 'data')); + foreach ($requested_data as $data => $default) + { + $template->assign_block_vars('data', array( + 'DATA' => $data, + 'NAME' => $user->lang[strtoupper($method . '_' . $data)], + 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], + 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default + )); + } + + $s_hidden_fields .= build_hidden_fields(array('method' => $method)); + + $template->assign_vars(array( + 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, + 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, + 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? $user->lang[$test_connection] : '', + + 'S_FTP_UPLOAD' => true, + 'UPLOAD_METHOD' => $method, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), + 'S_HIDDEN_FIELDS' => $s_hidden_fields) + ); + + return; + } + + $update_mode = 'upload'; + } + + // Now update the installation or download the archive... + $archive_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; + $update_list = $cache->get('_update_list'); + $conflicts = request_var('conflict', array('' => 0)); + + if ($update_list === false) + { + trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR); + } + + // Check if the conflicts data is valid + if (sizeof($conflicts)) + { + $conflict_filenames = array(); + foreach ($update_list['conflict'] as $files) + { + $conflict_filenames[] = $files['filename']; + } + + $new_conflicts = array(); + foreach ($conflicts as $filename => $diff_method) + { + if (in_array($filename, $conflict_filenames)) + { + $new_conflicts[$filename] = $diff_method; + } + } + + $conflicts = $new_conflicts; + } + + if (sizeof($update_list['conflict']) != sizeof($conflicts)) + { + trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR); + } + + // Now init the connection + if ($update_mode == 'download') + { + if ($use_method == '.zip') + { + $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method); + } + else + { + $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method); + } + } + else + { + $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer->open_session(); + } + + // Ok, go through the update list and do the operations based on their status + foreach ($update_list as $status => $files) + { + foreach ($files as $file_struct) + { + // Skip this file if the user selected to not update it + if (in_array($file_struct['filename'], $no_update)) + { + continue; + } + + $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; + + switch ($status) + { + case 'new': + case 'new_conflict': + case 'not_modified': + if ($update_mode == 'download') + { + $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); + } + else + { + if ($status != 'new') + { + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + } + $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); + } + break; + + case 'modified': + $diff = &new diff3(file($this->old_location . $original_filename), file($phpbb_root_path . $file_struct['filename']), file($this->new_location . $original_filename)); + $contents = implode("\n", $diff->merged_output()); + + if ($update_mode == 'download') + { + $compress->add_data($contents, $file_struct['filename']); + } + else + { + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + $transfer->write_file($file_struct['filename'], $contents); + } + break; + + case 'conflict': + $diff = &new diff3(file($this->old_location . $original_filename), file($phpbb_root_path . $file_struct['filename']), file($this->new_location . $original_filename)); + + if ($conflicts[$file_struct['filename']] == 1) + { + $contents = implode("\n", $diff->merged_new_output()); + } + else if ($conflicts[$file_struct['filename']] == 2) + { + $contents = implode("\n", $diff->merged_orig_output()); + } + else + { + break; + } + + if ($update_mode == 'download') + { + $compress->add_data($contents, $file_struct['filename']); + } + else + { + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + $transfer->write_file($file_struct['filename'], $contents); + } + break; + } + } + } + + if ($update_mode == 'download') + { + $compress->close(); + + $compress->download($archive_filename); + @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method); + + exit; + } + else + { + $transfer->close_session(); + + $template->assign_vars(array( + 'S_UPLOAD_SUCCESS' => true, + 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check")) + ); + return; + } + + break; + + case 'update_db': + + // Make sure the database update is valid for the latest version + $valid = false; + $updates_to_version = ''; + + if (file_exists($phpbb_root_path . 'install/database_update.' . $phpEx)) + { + include_once($phpbb_root_path . 'install/database_update.' . $phpEx); + + if ($updates_to_version === $this->latest_version) + { + $valid = true; + } + } + + // Should not happen at all + if (!$valid) + { + trigger_error($user->lang['DATABASE_UPDATE_INFO_OLD'], E_USER_ERROR); + } + + // Because we are done with the file update we purge the cache directory + $cache->purge(); + + // Redirect the user to the database update script with some explanations... + $template->assign_vars(array( + 'S_DB_UPDATE' => true, + 'U_DB_UPDATE' => $phpbb_root_path . 'install/database_update.' . $phpEx) + ); + + break; + } + } + + /** + * Show file diff + */ + function show_diff(&$update_list) + { + global $phpbb_root_path, $template, $user; + + $this->tpl_name = 'install_update_diff'; + $this->page_title = 'VIEWING_FILE_DIFF'; + + $status = request_var('status', ''); + $file = request_var('file', ''); + $diff_mode = request_var('diff_mode', 'side_by_side'); + + // First of all make sure the file is within our file update list with the correct status + $found_entry = array(); + foreach ($update_list[$status] as $index => $file_struct) + { + if ($file_struct['filename'] === $file) + { + $found_entry = $update_list[$status][$index]; + } + } + + if (empty($found_entry)) + { + trigger_error('File not allowed to be diffed', E_USER_ERROR); + } + + // If the status is 'up_to_date' then we do not need to show a diff + if ($status == 'up_to_date') + { + trigger_error($user->lang['FILE_ALREADY_UP_TO_DATE'], E_USER_ERROR); + } + + $original_file = ($found_entry['custom']) ? $found_entry['original'] : $file; + + // Get the correct diff + switch ($status) + { + case 'conflict': + $diff = &new diff3(file($this->old_location . $original_file), file($phpbb_root_path . $file), file($this->new_location . $original_file)); + + $template->assign_vars(array( + 'S_DIFF_CONFLICT_FILE' => true, + 'NUM_CONFLICTS' => $diff->merged_output(false, false, false, true)) + ); + break; + + case 'modified': + $diff = &new diff3(file($this->old_location . $original_file), file($phpbb_root_path . $original_file), file($this->new_location . $file)); + break; + + case 'not_modified': + case 'new_conflict': + $diff = &new diff(file($phpbb_root_path . $file), file($this->new_location . $original_file)); + break; + + case 'new': + $diff = &new diff(array(), file($this->new_location . $original_file)); + $template->assign_var('S_DIFF_NEW_FILE', true); + $diff_mode = 'inline'; + $this->page_title = 'VIEWING_FILE_CONTENTS'; + break; + } + + $diff_mode_options = ''; + foreach (array('side_by_side', 'inline', 'unified', 'raw') as $option) + { + $diff_mode_options .= '<option value="' . $option . '"' . (($diff_mode == $option) ? ' selected="selected"' : '') . '>' . $user->lang['DIFF_' . strtoupper($option)] . '</option>'; + } + + // Now the correct renderer + $render_class = 'diff_renderer_' . $diff_mode; + + if (!class_exists($render_class)) + { + trigger_error('Chosen diff mode is not supported', E_USER_ERROR); + } + + $renderer = &new $render_class(); + + $template->assign_vars(array( + 'DIFF_CONTENT' => $renderer->get_diff_content($diff), + 'S_DIFF_MODE_OPTIONS' => $diff_mode_options, + 'S_SHOW_DIFF' => true, + )); + } + + /** + * Collect all file status infos we need for the update by diffing all files + */ + function get_update_structure() + { + global $phpbb_root_path, $phpEx, $user; + + $update_list = array( + 'up_to_date' => array(), + 'new' => array(), + 'not_modified' => array(), + 'modified' => array(), + 'new_conflict' => array(), + 'conflict' => array(), + 'no_update' => array(), + ); + + // Get a list of those files which are completely new by checking with file_exists... + foreach ($this->update_info['files'] as $index => $file) + { + if (!file_exists($phpbb_root_path . $file)) + { + // Make sure the update files are consistent by checking if the file is in new_files... + if (!file_exists($this->new_location . $file)) + { + trigger_error($user->lang['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR); + } + + // If the file exists within the old directory the file got removed and we will write it back + // not a biggie, but we might want to state this circumstance seperatly later. + // if (file_exists($this->old_location . $file)) + // { + // $update_list['removed'][] = $file; + // } + + // Only include a new file as new if the underlying path exist + // The path normally do not exist if the original style or language has been removed + if (file_exists($phpbb_root_path . dirname($file))) + { + $this->get_custom_info($update_list['new'], $file); + $update_list['new'][] = array('filename' => $file, 'custom' => false); + } + else + { + $update_list['no_update'][] = $file; + } + unset($this->update_info['files'][$index]); + } + } + + if (!sizeof($this->update_info['files'])) + { + return $update_list; + } + + // Now diff the remaining files to get informations about their status (not modified/modified/up-to-date) + + // not modified? + foreach ($this->update_info['files'] as $index => $file) + { + $this->make_update_diff($update_list, $file, $file); + } + + // Now to the styles... + if (empty($this->update_info['custom'])) + { + return $update_list; + } + + foreach ($this->update_info['custom'] as $original_file => $file_ary) + { + foreach ($file_ary as $index => $file) + { + $this->make_update_diff($update_list, $original_file, $file, true); + } + } + + return $update_list; + } + + /** + * Compare files for storage in update_list + */ + function make_update_diff(&$update_list, $original_file, $file, $custom = false) + { + global $phpbb_root_path, $user; + + $update_ary = array('filename' => $file, 'custom' => $custom); + + if ($custom) + { + $update_ary['original'] = $original_file; + } + + // On a successfull update the new location file exists but the old one does not exist. + // Check for this circumstance, the new file need to be up-to-date with the current file then... + if (!file_exists($this->old_location . $original_file) && file_exists($this->new_location . $original_file) && file_exists($phpbb_root_path . $file)) + { + // We need to diff the contents here to make sure the file is really the one we expect + $diff = &new diff(file($this->new_location . $original_file), file($phpbb_root_path . $file)); + + // if there are no differences we have an up-to-date file... + if ($diff->is_empty()) + { + $update_list['up_to_date'][] = $update_ary; + return; + } + + // If no other status matches we have another file in the way... + $update_list['new_conflict'][] = $update_ary; + return; + } + + // Check for existance, else abort immediatly + if (!file_exists($this->old_location . $original_file) || !file_exists($this->new_location . $original_file)) + { + trigger_error($user->lang['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR); + } + + $diff = &new diff(file($this->old_location . $original_file), file($phpbb_root_path . $file)); + + // If the file is not modified we are finished here... + if ($diff->is_empty()) + { + $update_list['not_modified'][] = $update_ary; + return; + } + + // If the file had been modified then we need to check if it is already up to date + $diff = &new diff(file($this->new_location . $original_file), file($phpbb_root_path . $file)); + + // if there are no differences we have an up-to-date file... + if ($diff->is_empty()) + { + $update_list['up_to_date'][] = $update_ary; + return; + } + + // if the file is modified we try to make sure a merge succeed + $diff = &new diff3(file($this->old_location . $original_file), file($phpbb_root_path . $file), file($this->new_location . $original_file)); + + if ($diff->merged_output(false, false, false, true)) + { + $update_ary['conflicts'] = $diff->_conflicting_blocks; + $update_list['conflict'][] = $update_ary; + return; + } + + // now compare the merged output with the original file to see if the modified file is up to date + $diff = &new diff(file($phpbb_root_path . $file), $diff->merged_output()); + + if ($diff->is_empty()) + { + $update_list['up_to_date'][] = $update_ary; + return; + } + + // If no other status matches we have a modified file... + $update_list['modified'][] = $update_ary; + } + + /** + * Update update_list with custom new files + */ + function get_custom_info(&$update_list, $file) + { + if (empty($this->update_info['custom'])) + { + return; + } + + if (in_array($file, array_keys($this->update_info['custom']))) + { + foreach ($this->update_info['custom'][$file] as $_file) + { + $update_list[] = array('filename' => $_file, 'custom' => true, 'original' => $file); + } + } + } + + /** + * Get remote file + */ + function get_file($mode) + { + global $user, $db; + + $errstr = ''; + $errno = 0; + + switch ($mode) + { + case 'version_info': + $info = get_remote_file('www.phpbb.com', '/updatecheck', '30x.txt', $errstr, $errno); + + if ($info !== false) + { + $info = explode("\n", $info); + $info = trim($info[0]); + } + break; + + case 'update_info': + global $phpbb_root_path, $phpEx; + + $update_info = array(); + include($phpbb_root_path . 'install/update/index.php'); + + $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; + $errstr = ($info === false) ? $user->lang['WRONG_INFO_FILE_FORMAT'] : ''; + + if ($info !== false) + { + // Adjust the update info file to hold some specific style-related informations + $info['custom'] = array(); + + // Get custom installed styles... + $sql = 'SELECT template_name, template_path + FROM ' . STYLES_TEMPLATE_TABLE . " + WHERE template_name NOT IN ('subSilver', 'BLABLA')"; + $result = $db->sql_query($sql); + + $templates = array(); + while ($row = $db->sql_fetchrow($result)) + { + $templates[] = $row; + } + $db->sql_freeresult($result); + + if (sizeof($templates)) + { + foreach ($info['files'] as $filename) + { + // Template update? + if (strpos($filename, 'styles/subSilver/template/') === 0) + { + foreach ($templates as $row) + { + $info['custom'][$filename][] = str_replace('/subSilver/', '/' . $row['template_path'] . '/', $filename); + } + } + } + } + } + break; + + default: + trigger_error('Mode for getting remote file not specified', E_USER_ERROR); + break; + } + + if ($info === false) + { + trigger_error($errstr, E_USER_ERROR); + } + + return $info; + } +} + +?>
\ No newline at end of file |