diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php
index e70e890..e55fd56 100644
--- a/config/dmsDefaults.php
+++ b/config/dmsDefaults.php
@@ -38,6 +38,9 @@
*
*/
+// stuff in the new installer section database upgrade fails without this
+global $default;
+
if (defined('DMS_DEFAULTS_INCLUDED'))
{
return;
@@ -662,5 +665,4 @@ if (!extension_loaded('mbstring'))
require_once(KT_LIB_DIR . '/templating/kt3template.inc.php');
$GLOBALS['main'] =new KTPage();
-
?>
diff --git a/setup/upgrade/config/config.xml b/setup/upgrade/config/config.xml
new file mode 100644
index 0000000..aa11286
--- /dev/null
+++ b/setup/upgrade/config/config.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+ The mysqldump utility was not found in the subdirectory.
+
+
+
+ The backup file
It appears as though the backup has been successful. +
+ + Manually, you would do the following to restore the backup: +
+
|
+ + + The mysql backup utility could not be found automatically. Please edit the config.ini and update the backup/mysql Directory entry. + + If you need to restore from this backup, you should be able to use the following statements: + +
+ We appologise for the inconvenience. + +
+ + + + + + get('db/dbAdminUser'); + $adminPwd = $oKTConfig->get('db/dbAdminPass'); + $dbHost = $oKTConfig->get('db/dbHost'); + $dbName = $oKTConfig->get('db/dbName'); + + $dbPort = trim($oKTConfig->get('db/dbPort')); + if (empty($dbPort) || $dbPort=='default') $dbPort = get_cfg_var('mysql.default_port'); + if (empty($dbPort)) $dbPort='3306'; + $dbSocket = trim($oKTConfig->get('db/dbSocket')); + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; + + $date=date('Y-m-d-H-i-s'); + + $dir=$this->resolveMysqlDir(); + + $info['dir']=$dir; + + $prefix=''; + if (OS_UNIX) + { + $prefix .= "./"; + } + + if (@stat($dbSocket) !== false) + { + $mechanism="--socket=\"$dbSocket\""; + } + else + { + $mechanism="--port=\"$dbPort\""; + } + + $tmpdir=$this->resolveTempDir(); + + if (is_null($targetfile)) + { + $targetfile="$tmpdir/kt-backup-$date.sql"; + } + + $stmt = $prefix . "mysqldump --user=\"$adminUser\" -p $mechanism \"$dbName\" > \"$targetfile\""; + $info['display']=$stmt; + $info['target']=$targetfile; + + + $stmt = $prefix. "mysqldump --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" > \"$targetfile\""; + $info['cmd']=$stmt; + return $info; +} + +function resolveMysqlDir() +{ + // possibly detect existing installations: + + if (OS_UNIX) + { + $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); + $mysqlname ='mysql'; + } + else + { + $dirs = explode(';', $_SERVER['PATH']); + $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; + $dirs[] = 'c:/program files/ktdms/mysql/bin'; + $mysqlname ='mysql.exe'; + } + + $oKTConfig =& KTConfig::getSingleton(); + $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); + $dirs[] = $mysqldir; + + if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) + { + $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); + } + + foreach($dirs as $dir) + { + if (is_file($dir . '/' . $mysqlname)) + { + return $dir; + } + } + + return ''; +} + +function resolveTempDir() +{ + + if (OS_UNIX) + { + $dir='/tmp/kt-db-backup'; + } + else + { + $dir='c:/kt-db-backup'; + } + $oKTConfig =& KTConfig::getSingleton(); + $dir = $oKTConfig->get('backup/backupDirectory',$dir); + + if (!is_dir($dir)) + { + mkdir($dir); + } + return $dir; +} + + +function backupConfirm() +{ + $stmt = $this->create_backup_stmt(); + $_SESSION['backupFile'] = $stmt['target']; + + $dir = $stmt['dir']; + $this->temp_variables['dir'] = $dir; + $this->temp_variables['display'] = $stmt['display']; +} + + + +} +?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php new file mode 100644 index 0000000..edba512 --- /dev/null +++ b/setup/upgrade/steps/upgradeComplete.php @@ -0,0 +1,82 @@ +. +* +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, +* California 94120-7775, or email info@knowledgetree.com. +* +* The interactive user interfaces in modified source and object code versions +* of this program must display Appropriate Legal Notices, as required under +* Section 5 of the GNU General Public License version 3. +* +* In accordance with Section 7(b) of the GNU General Public License version 3, +* these Appropriate Legal Notices must retain the display of the "Powered by +* KnowledgeTree" logo and retain the original copyright notice. If the display of the +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices +* must display the words "Powered by KnowledgeTree" and retain the original +* copyright notice. +* +* @copyright 2008-2009, KnowledgeTree Inc. +* @license GNU General Public License version 3 +* @author KnowledgeTree Team +* @package Upgrader +* @version Version 0.1 +*/ + +class upgradeComplete extends Step { + + /** + * Reference to Database object + * + * @author KnowledgeTree Team + * @access private + * @var object + */ + private $_dbhandler = null; + + private $privileges_check = 'tick'; + private $database_check = 'tick'; + protected $silent = true; + + protected $util = null; + + public function __construct() { + $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); + $this->_dbhandler = new dbUtil(); + $this->util = new UpgradeUtil(); + } + + function doStep() { + $this->doRun(); + return 'landing'; + } + + function doRun() { + $this->storeSilent();// Set silent mode variables + } + + /** + * Set all silent mode varibles + * + */ + private function storeSilent() { + } +} +?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeDatabase.php b/setup/upgrade/steps/upgradeDatabase.php new file mode 100644 index 0000000..2898ebb --- /dev/null +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -0,0 +1,564 @@ +. +* +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, +* California 94120-7775, or email info@knowledgetree.com. +* +* The interactive user interfaces in modified source and object code versions +* of this program must display Appropriate Legal Notices, as required under +* Section 5 of the GNU General Public License version 3. +* +* In accordance with Section 7(b) of the GNU General Public License version 3, +* these Appropriate Legal Notices must retain the display of the "Powered by +* KnowledgeTree" logo and retain the original copyright notice. If the display of the +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices +* must display the words "Powered by KnowledgeTree" and retain the original +* copyright notice. +* +* @copyright 2008-2009, KnowledgeTree Inc. +* @license GNU General Public License version 3 +* @author KnowledgeTree Team +* @package Upgrader +* @version Version 0.1 +*/ + +// include defaults +require '../../config/dmsDefaults.php'; +require_once KT_LIB_DIR . '/config/config.inc.php'; +include KT_LIB_DIR . '/upgrades/upgrade.inc.php'; + +class upgradeDatabase extends Step +{ + /** + * Reference to Database object + * + * @author KnowledgeTree Team + * @access public + * @var object + */ + public $_dbhandler = null; + + /** + * Reference to Database object + * + * @author KnowledgeTree Team + * @access public + * @var object + */ + public $_util = null; + + /** + * Database type + * + * @author KnowledgeTree Team + * @access private + * @var array + */ + private $dtype = ''; + + /** + * Database types + * + * @author KnowledgeTree Team + * @access private + * @var array + */ + private $dtypes = array(); + + /** + * Database host + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dhost = ''; + + /** + * Database port + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dport = ''; + + /** + * Database name + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dname = ''; + + /** + * Database root username + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $duname = ''; + + /** + * Database root password + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dpassword = ''; + + /** + * Database dms username + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dmsname = ''; + + /** + * Database dms password + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dmspassword = ''; + + /** + * Default dms user username + * + * @author KnowledgeTree Team + * @access private + * @var boolean + */ + private $dmsusername = ''; + + /** + * Default dms user password + * + * @author KnowledgeTree Team + * @access private + * @var boolean + */ + private $dmsuserpassword = ''; + + /** + * Location of database binaries. + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $mysqlDir; // TODO:multiple databases + + /** + * Name of database binary. + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $dbbinary = ''; // TODO:multiple databases + + /** + * Database table prefix + * + * @author KnowledgeTree Team + * @access private + * @var string + */ + private $tprefix = ''; + + /** + * Flag to drop database + * + * @author KnowledgeTree Team + * @access private + * @var boolean + */ + private $ddrop = false; + + /** + * List of errors encountered + * + * @author KnowledgeTree Team + * @access public + * @var array + */ + public $error = array(); + + /** + * List of errors used in template + * + * @author KnowledgeTree Team + * @access public + * @var array + */ + public $templateErrors = array('dmspassword', 'dmsuserpassword', 'con', 'dname', 'dtype', 'duname', 'dpassword'); + + /** + * Flag to store class information in session + * + * @author KnowledgeTree Team + * @access public + * @var array + */ + public $storeInSession = true; + + /** + * Flag if step needs to be upgraded + * + * @author KnowledgeTree Team + * @access public + * @var array + */ + protected $runUpgrade = true; + + /** + * Flag if step needs to run silently + * + * @author KnowledgeTree Team + * @access public + * @var array + */ + protected $silent = true; + + /** + * Constructs database object + * + * @author KnowledgeTree Team + * @access public + * @param none + */ + public function __construct() { + $this->temp_variables = array("step_name"=>"database", "silent"=>$this->silent); + $this->_dbhandler = new UpgradedbUtil(); + $this->_util = new UpgradeUtil(); + if(WINDOWS_OS) + $this->mysqlDir = MYSQL_BIN; + } + + /** + * Main control of database setup + * + * @author KnowledgeTree Team + * @param none + * @access public + * @return string + */ + public function doStep() { + parent::doStep(); + $this->initErrors(); + $this->setDetails(); // Set any posted variables + if(!$this->inStep("database")) { + $this->doRun(); + return 'landing'; + } + if($this->next()) { + if ($this->doRun()) { + return 'next'; + } + } else if($this->previous()) { + return 'previous'; + } + else if ($this->backup()) { + return 'backup'; + } + else if ($this->restore()) { + return 'restore'; + } + else if ($this->upgrading()) { + $this->doRun('runUpgrade'); + return 'next'; + } + else if ($this->confirm()) { + if ($this->doRun('confirm')) { + return 'next'; + } + return 'error'; + } + + $this->doRun(); + return 'landing'; + } + + function backup() { + return isset($_POST['Backup']); + } + + function restore() { + return isset($_POST['Restore']); + } + + function upgrading() { + return isset($_POST['RunUpgrade']); + } + + function doRun($action = null) { + $this->readConfig(KTConfig::getConfigFilename()); + + if($this->dbSettings['dbPort'] == '') { + $con = $this->_dbhandler->load($this->dbSettings['dbHost'], $this->dbSettings['dbUser'], + $this->dbSettings['dbPass'], $this->dbSettings['dbName']); + } else { + $con = $this->_dbhandler->load($this->dbSettings['dbHost'].":".$this->dbSettings['dbPort'], $this->dbSettings['dbUser'], + $this->dbSettings['dbPass'], $this->dbSettings['dbName']); + } + + if (is_null($action) || ($action == 'preview')) { + $this->temp_variables['action'] = 'preview'; + $this->temp_variables['title'] = 'Preview Upgrade'; + $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); + } + else if ($action == 'runUpgrade') { + $this->temp_variables['action'] = 'runUpgrade'; + $this->temp_variables['title'] = 'Confirm Upgrade'; + $this->temp_variables['upgradeTable'] = $this->upgradeConfirm(); + } + else if ($action == 'confirm') { + $this->temp_variables['action'] = 'confirm'; + $this->temp_variables['title'] = 'Upgrade In Progress'; + if (!$this->upgrade()) { + $this->temp_variables['upgradeTable'] = $this->upgradeErrors(); + return false; + } + } + + return true; + } + + public function generateUpgradeTable() { + global $default; + + $this->temp_variables['systemVersion'] = $default->systemVersion; + $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table); + + $result = $this->_dbhandler->query($query); + if ($result) { + $lastVersionObj = $this->_dbhandler->fetchNextObject($result); + $lastVersion = $lastVersionObj->value; + } + $currentVersion = $default->systemVersion; + + $upgrades = describeUpgrade($lastVersion, $currentVersion); + + $ret = "
The table below describes the upgrades that have occurred to
+ upgrade your installation to systemVersion;?>.
+
+
+Pre-Upgrade actions failed.
+Pre-Upgrade actions succeeded. + +Upgrade failed. + + +Upgrade succeeded. + +
+
+Post-Upgrade actions failed.
+Post-Upgrade actions succeeded.
+ The mysql utility was not found in the subdirectory.
+
+
+
+ The restore of + It appears as though the restore has been successful. + + + + + +It appears as though the restore process has failed. +Unfortunately, it is difficult to diagnose these problems automatically +and would recommend that you try to do the backup process manually. + +We appologise for the inconvenience. + +
+ + + +get('db/dbAdminUser'); + $adminPwd = $oKTConfig->get('db/dbAdminPass'); + $dbHost = $oKTConfig->get('db/dbHost'); + $dbName = $oKTConfig->get('db/dbName'); + $dbPort = trim($oKTConfig->get('db/dbPort')); + if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); + if (empty($dbPort)) $dbPort='3306'; + $dbSocket = trim($oKTConfig->get('db/dbSocket')); + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; + + $dir = $this->resolveMysqlDir(); + + $info['dir']=$dir; + + $prefix=''; + if (OS_UNIX) + { + $prefix .= "./"; + } + + if (@stat($dbSocket) !== false) + { + $mechanism="--socket=\"$dbSocket\""; + } + else + { + $mechanism="--port=\"$dbPort\""; + } + + $tmpdir = $this->resolveTempDir(); + + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\" "; + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\" "; + + + $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n"; + $info['display']=$stmt; + + + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n"; + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n"; + + $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\""; + $info['cmd']=$stmt; + return $info; +} + +function resolveMysqlDir() +{ + // possibly detect existing installations: + + if (OS_UNIX) + { + $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); + $mysqlname ='mysql'; + } + else + { + $dirs = explode(';', $_SERVER['PATH']); + $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; + $dirs[] = 'c:/program files/ktdms/mysql/bin'; + $mysqlname ='mysql.exe'; + } + + $oKTConfig =& KTConfig::getSingleton(); + $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); + $dirs[] = $mysqldir; + + if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) + { + $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); + } + + foreach($dirs as $dir) + { + if (is_file($dir . '/' . $mysqlname)) + { + return $dir; + } + } + + return ''; +} + +function resolveTempDir() +{ + + if (OS_UNIX) + { + $dir='/tmp/kt-db-backup'; + } + else + { + $dir='c:/kt-db-backup'; + } + $oKTConfig =& KTConfig::getSingleton(); + $dir = $oKTConfig->get('backup/backupDirectory',$dir); + + if (!is_dir($dir)) + { + mkdir($dir); + } + return $dir; +} + + +function restoreSelect() +{ +// title('Select Backup to Restore'); + + $dir = $this->resolveTempDir(); + + $files = array(); + if ($dh = opendir($dir)) + { + while (($file = readdir($dh)) !== false) + { + if (!preg_match('/kt-backup.+\.sql/',$file)) + { + continue; + } + $files[] = $file; + } + closedir($dh); + } + + if (count($files) == 0) + { + ?> + There don't seem to be any backups to restore from the "" directory. + + + Select a backup to restore from the list below: + + + + ++ + resolveTempDir(); + $_SESSION['backupFile'] = $dir . '/' . $file; +?> +restoreSelect(); + exit; + } + + $status = $_SESSION['backupStatus']; + $filename=$_SESSION['backupFile']; + $stmt = $this->create_restore_stmt($filename); + + $this->temp_variables['dir'] = $stmt['dir']; + $this->temp_variables['display'] = $stmt['display']; +} + + + + +} +?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeWelcome.php b/setup/upgrade/steps/upgradeWelcome.php new file mode 100644 index 0000000..b311bcd --- /dev/null +++ b/setup/upgrade/steps/upgradeWelcome.php @@ -0,0 +1,110 @@ +. +* +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, +* California 94120-7775, or email info@knowledgetree.com. +* +* The interactive user interfaces in modified source and object code versions +* of this program must display Appropriate Legal Notices, as required under +* Section 5 of the GNU General Public License version 3. +* +* In accordance with Section 7(b) of the GNU General Public License version 3, +* these Appropriate Legal Notices must retain the display of the "Powered by +* KnowledgeTree" logo and retain the original copyright notice. If the display of the +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices +* must display the words "Powered by KnowledgeTree" and retain the original +* copyright notice. +* +* @copyright 2008-2009, KnowledgeTree Inc. +* @license GNU General Public License version 3 +* @author KnowledgeTree Team +* @package Upgrader +* @version Version 0.1 +*/ + +global $default; +// include defaults +include '../../config/dmsDefaults.php'; +require_once KT_LIB_DIR . '/authentication/authenticationutil.inc.php'; + +class upgradeWelcome extends step { + + protected $silent = true; + + public function __construct() { + $this->temp_variables = array("step_name"=>"welcome"); + } + + public function doStep() { + if($this->next()) { + if ($this->doRun()) { + return 'next'; + } + else { + return 'error'; + } + } + + return 'landing'; + } + + private function doRun() { + // attempt login + $username = $_REQUEST['username']; + $password = $_REQUEST['password']; + + $authenticated = $this->checkPassword($username, $password); + + if (!$authenticated) + { + session_unset(); +// loginFailed(_kt('Could not authenticate administrative user')); + return false; + } + + $_SESSION['setup_user'] = $username; + + return true; + } + + private function checkPassword($username, $password) { + global $default; + + $sTable = KTUtil::getTableName('users'); + $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE username = ? AND password = ?"; + $aParams = array($username, md5($password)); + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'match_count'); + if (PEAR::isError($res)) { return false; } + else { + $sTable = KTUtil::getTableName('users_groups_link'); + $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE user_id = ? AND group_id = 1"; + $aParams = array($res); + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'match_count'); + if (PEAR::isError($res)) { return false; } + else { + return ($res == 1); + } + } + } + +} + +?> \ No newline at end of file diff --git a/setup/upgrade/template.php b/setup/upgrade/template.php new file mode 100644 index 0000000..f266686 --- /dev/null +++ b/setup/upgrade/template.php @@ -0,0 +1,111 @@ +. +* +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, +* California 94120-7775, or email info@knowledgetree.com. +* +* The interactive user interfaces in modified source and object code versions +* of this program must display Appropriate Legal Notices, as required under +* Section 5 of the GNU General Public License version 3. +* +* In accordance with Section 7(b) of the GNU General Public License version 3, +* these Appropriate Legal Notices must retain the display of the "Powered by +* KnowledgeTree" logo and retain the original copyright notice. If the display of the +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices +* must display the words "Powered by KnowledgeTree" and retain the original +* copyright notice. +* +* @copyright 2008-2009, KnowledgeTree Inc. +* @license GNU General Public License version 3 +* @author KnowledgeTree Team +* @package Upgrader +* @version Version 0.1 +*/ + +class Template +{ + /** + * Hold all the variables that are going to be imported into the template file + * @var array + */ + var $template_vars = Array(); + + + /** + * Constructor + * + * @author KnowledgeTree Team + * @param string $file the file name you want to load + * @access public + * @return void + */ + public function Template($file = null) + { + $this->file = $file; + } + + + /** + * Set a variable into the template + * If the variable is a template object, go and call its template::fetch() method + * + * @author KnowledgeTree Team + * @param string $name The name for this value in the template file + * @param string $value The value to show in the template file + * @access public + * @return void + */ + public function set($name, $value) + { + //if(is_a($value, 'Template')) { + $class = 'Template'; + $isA = $value instanceof $class; + if($isA) { + $value = $value->fetch(); + } + $this->template_vars[$name] = $value; + } + + + /** + * Create the template and import its variables + * + * @author KnowledgeTree Team + * @param string $file The file to use as the template + * @access public + * @return string The parsed template + */ + public function fetch($file = null) + { + if (is_null($file)) $file = $this->file; + if (!file_exists($file)) { + trigger_error('Template file '.$file.' does not exist ', E_USER_ERROR); + } + extract($this->template_vars); // Extract the vars to local namespace + ob_start(); + include($file); + $contents = ob_get_contents(); + ob_end_clean(); + return $contents; + } + +} +?> \ No newline at end of file diff --git a/setup/upgrade/templates/backup.tpl b/setup/upgrade/templates/backup.tpl new file mode 100644 index 0000000..8ade6b5 --- /dev/null +++ b/setup/upgrade/templates/backup.tpl @@ -0,0 +1,58 @@ + |