diff --git a/bin/system_info.php b/bin/system_info.php new file mode 100644 index 0000000..8c3ae59 --- /dev/null +++ b/bin/system_info.php @@ -0,0 +1,176 @@ +. + * + * 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. + * Contributor( s): ______________________________________ + */ + +/* +* Script to collect system information as part of a call home mechanism, no identifying information is stored. +* +* The following data is collected: +* Unique installation information: installation GUID, number of users in repository, number of documents in repository, +* operating system (platform, platform version, flavor if Linux), version and edition. +*/ +chdir(realpath(dirname(__FILE__))); +require_once('../config/dmsDefaults.php'); + +global $default; +$default->log->debug('System information collection script starting...'); + +// Get installation guid +function getGuid() +{ + $guid = KTUtil::getSystemIdentifier(); + + if(PEAR::isError($guid)){ + $guid = ''; + } + return $guid; +} + +// Get the number of users in the repository +function getUserCnt() +{ + $query = 'select count(*) as cnt, disabled from users where id > 0 group by disabled;'; + $result = DBUtil::getResultArray($query); + + if(empty($result) || PEAR::isError($result)){ + return ''; + } + $users = ''; + + foreach ($result as $row){ + $str = ''; + switch($row['disabled']){ + case 0: $str = 'Enabled'; break; + case 1: $str = 'Disabled'; break; + case 2: $str = 'Deleted'; break; + } + + $str .= ': '.$row['cnt']; + + $users .= (!empty($users)) ? '; ' : ''; + $users .= $str; + } + return $users; +} + +// Get the number of documents in the repository +function getDocCnt() +{ + $query = 'select count(*) as cnt, s.name from documents d, status_lookup s WHERE s.id = d.status_id group by d.status_id;'; + $result2 = DBUtil::getResultArray($query); + + if(empty($result2) || PEAR::isError($result2)){ + return ''; + } + $docs = ''; + + foreach ($result2 as $row){ + $docs .= (!empty($docs)) ? '; ' : ''; + $docs .= $row['name'].': '.$row['cnt']; + } + return $docs; +} + +// Get the version of KT +function getKTVersion() +{ + $version = KTUtil::getSystemSetting('knowledgeTreeVersion'); + if(empty($version) || PEAR::isError($version)){ + $version = file_get_contents(KT_DIR . 'docs/VERSION.txt'); + } + // remove newline that is in the version file + $version = str_replace("\n", '', $version); + return $version; +} + +// Get the edition of KT +function getKTEdition() +{ + $edition = 'Community'; + if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { + $path = KTPluginUtil::getPluginPath('ktdms.wintools'); + require_once($path . 'baobabkeyutil.inc.php'); + $edition = BaobabKeyUtil::getName(); + + // Remove the brackets around the name + $edition = substr($edition, 1); + $edition = substr($edition, 0, strlen($edition)-1); + } + return $edition; +} + + +// Get OS info - platform, version, linux flavour +function getOSInfo() +{ + $server = php_uname(); + + if(strpos($server, 'Darwin') !== false){ + $os = 'Mac OS X'; + }else if(strpos($server, 'Win') !== false){ + $os = 'Windows'; + }else { + $os = 'Linux'; + } + + return $os; +} + +function sendForm($data) +{ + $url = 'http://ktnetwork.knowledgetree.com/call_home.php'; + //$url = 'http://10.33.20.250/knowledgetree/call_home.php'; + $data = http_build_query($data); + + $ch = curl_init($url); + curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_exec($ch); + curl_close($ch); +} + +$post_str = getGuid() .'|'. getUserCnt() .'|'. getDocCnt() .'|'. getKTVersion() .'|'. getKTEdition() .'|'. getOSInfo(); +$data['system_info'] = $post_str; + +sendForm($data); + +$default->log->debug('System information collection script finishing.'); +exit(0); +?> diff --git a/setup/migrate/ini.php b/setup/migrate/ini.php deleted file mode 100644 index 9820950..0000000 --- a/setup/migrate/ini.php +++ /dev/null @@ -1,223 +0,0 @@ -. - * - * 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. - * Contributor( s): ______________________________________ - * - */ - -class Ini { - - private $cleanArray = array(); - private $iniFile = ''; - private $lineNum = 0; - private $exists = ''; - - function Ini($iniFile = '../../config.ini') { - $this->iniFile = $iniFile; - $this->backupIni($iniFile); - $this->read($iniFile); - } - - /** - * Create a backup with the date as an extension in the same location as the original config.ini - * - * @param string $iniFile - * @return boolean - */ - function backupIni($iniFile) - { - $content = file_get_contents($iniFile); - if ($content === false) - { - return false; - } - $date = date('YmdHis'); - - $backupFile = $iniFile . '.' .$date; - if (is_writeable($backupFile)) { - file_put_contents($backupFile, $content); - } - } - - function read($iniFile) { - - $iniArray = file($iniFile); - $section = ''; - foreach($iniArray as $iniLine) { - $this->lineNum++; - $iniLine = trim($iniLine); - $firstChar = substr($iniLine, 0, 1); - if($firstChar == ';') { - if($section == ''){ - $this->cleanArray['_comment_'.$this->lineNum]=$iniLine; - }else { - $this->cleanArray[$section]['_comment_'.$this->lineNum]=$iniLine; - } - continue; - } - if($iniLine == '') { - if($section == ''){ - $this->cleanArray['_blankline_'.$this->lineNum]=''; - }else { - $this->cleanArray[$section]['_blankline_'.$this->lineNum]=''; - } - continue; - } - - if ($firstChar == '[' && substr($iniLine, -1, 1) == ']') { - $section = substr($iniLine, 1, -1); - $this->sections[] = $section; - } else { - $equalsPos = strpos($iniLine, '='); - if ($equalsPos > 0 && $equalsPos != sizeof($iniLine)) { - $key = trim(substr($iniLine, 0, $equalsPos)); - $value = trim(substr($iniLine, $equalsPos+1)); - if (substr($value, 1, 1) == '"' && substr( $value, -1, 1) == '"') { - $value = substr($value, 1, -1); - } - $this->cleanArray[$section][$key] = stripcslashes($value); - } else { - $this->cleanArray[$section][trim($iniLine)]=''; - } - } - } - return $this->cleanArray; - } - - function write($iniFile = "") { - - if(empty($iniFile)) { - $iniFile = $this->iniFile; - } - if (!is_writeable($iniFile)) { - return; - } - - $fileHandle = fopen($iniFile, 'wb'); - foreach ($this->cleanArray as $section => $items) { - if (substr($section, 0, strlen('_blankline_')) === '_blankline_' ) { - fwrite ($fileHandle, "\r\n"); - continue; - } - if (substr($section, 0, strlen('_comment_')) === '_comment_' ) { - fwrite ($fileHandle, "$items\r\n"); - continue; - } - fwrite ($fileHandle, "[".$section."]\r\n"); - foreach ($items as $key => $value) { - if (substr($key, 0, strlen('_blankline_')) === '_blankline_' ) { - fwrite ($fileHandle, "\r\n"); - continue; - } - if (substr($key, 0, strlen('_comment_')) === '_comment_' ) { - fwrite ($fileHandle, "$value\r\n"); - continue; - } - - $value = addcslashes($value,''); - //fwrite ($fileHandle, $key.' = "'.$value."\"\r\n"); - fwrite ($fileHandle, $key.' = '.$value."\r\n"); - } - } - fclose($fileHandle); - } - - function itemExists($checkSection, $checkItem) { - - $this->exists = ''; - foreach($this->cleanArray as $section => $items) { - if($section == $checkSection) { - $this->exists = 'section'; - foreach ($items as $key => $value) { - if($key == $checkItem) { - return true; - } - } - } - } - return false; - } - - function addItem($addSection, $addItem, $value, $itemComment = '', $sectionComment = '') { - - if($this->itemExists($addSection, $addItem)) { - $this->delItem($addSection, $addItem); - } - - if($this->exists != 'section') { - $this->cleanArray['_blankline_'.$this->lineNum++]=''; - if(!empty($sectionComment)) $this->cleanArray['_comment_'.$this->lineNum++] = '; '.$sectionComment; - } - if(!empty($itemComment)) { - $this->cleanArray[$addSection]['_comment_'.$this->lineNum++] = '; '.$itemComment; - } - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); - return true; - } - - function updateItem($addSection, $addItem, $value) { - - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); - return true; - } - - function delItem($delSection, $delItem) { - - if(!$this->itemExists($delSection, $delItem)) return false; - - unset($this->cleanArray[$delSection][$delItem]); - return true; - } - - function delSection($delSection) { - - unset($this->cleanArray[$delSection]); - return true; - } - - // Return file line by line - public function getFileByLine() { - $data = $this->read($this->iniFile); - return $data['']; - } - - public function getSection($section) { - if (isset($this->cleanArray[$section])) { - return $this->cleanArray[$section]; - } - - return false; - } -} -?> diff --git a/setup/migrate/migrateUtil.php b/setup/migrate/migrateUtil.php index 7bf3000..4c42972 100644 --- a/setup/migrate/migrateUtil.php +++ b/setup/migrate/migrateUtil.php @@ -142,6 +142,11 @@ class MigrateUtil { return new $serviceName(); } + public function loadInstallIni($path) { + require_once("../wizard/ini.php"); + return new Ini($path); + } + public function redirect($url, $exit = true, $rfc2616 = false) { return $this->bootstrap->redirect($url, $exit = true, $rfc2616 = false); diff --git a/setup/migrate/migrater.php b/setup/migrate/migrater.php index f329caf..4c8fd81 100644 --- a/setup/migrate/migrater.php +++ b/setup/migrate/migrater.php @@ -510,6 +510,9 @@ class Migrater { } elseif (isset($_POST['BInstall'])) { $this->migraterAction = 'binstall'; $this->response = 'binstall'; +// } elseif (isset($_POST['Backup'])) { +// $this->migraterAction = 'backup'; +// $this->response = 'backup'; } else { $this->response = ''; $this->migraterAction = ''; @@ -545,8 +548,8 @@ class Migrater { } break; case 'previous': - $this->_backward(); // Load previous page - break; + $this->_backward(); // Load previous page + break; case 'install': $iutil = new MigrateUtil(); $iutil->redirect('../wizard/index.php?step_name=installtype'); @@ -555,6 +558,11 @@ class Migrater { $iutil = new MigrateUtil(); $iutil->redirect('../wizard/index.php?step_name=dependencies'); break; +// case 'backup': +// $iutil = new MigrateUtil(); +// $iutil->redirect('../upgrade/index.php?step_name=backup'); +// $iutil->redirect("..".DS."upgrade".DS."index.php?step_name=backup"); +// break; default: // TODO : handle silent $this->_landing(); diff --git a/setup/migrate/path.php b/setup/migrate/path.php deleted file mode 100644 index 09d142d..0000000 --- a/setup/migrate/path.php +++ /dev/null @@ -1,135 +0,0 @@ -. -* -* 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 Migrater -* @version Version 0.1 -*/ - // Define installer environment - define('DEBUG', 0); - define('AJAX', 0); - // Define migrater environment - if (substr(php_uname(), 0, 7) == "Windows"){ - define('WINDOWS_OS', true); - define('UNIX_OS', false); - define('OS', 'windows'); - } else { - define('WINDOWS_OS', false); - define('UNIX_OS', true); - define('OS', 'unix'); - } - if(WINDOWS_OS) { - define('DS', '\\'); - } else { - define('DS', '/'); - } - // Define environment root - $wizard = realpath(dirname(__FILE__)); - $xdir = explode(DS, $wizard); - array_pop($xdir); - array_pop($xdir); - $sys = ''; - foreach ($xdir as $k=>$v) { - $sys .= $v.DS; - } - // Define paths to wizard - define('MIGRATE_DIR', $wizard.DS); - define('WIZARD_LIB', MIGRATE_DIR."lib".DS); - define('SERVICE_LIB', WIZARD_LIB."services".DS); - define('SQL_DIR', MIGRATE_DIR."sql".DS); - define('SQL_UPGRADE_DIR', SQL_DIR."upgrades".DS); - define('CONF_DIR', MIGRATE_DIR."config".DS); - define('RES_DIR', MIGRATE_DIR."resources".DS); - define('STEP_DIR', MIGRATE_DIR."steps".DS); - define('TEMP_DIR', MIGRATE_DIR."templates".DS); - define('SHELL_DIR', MIGRATE_DIR."shells".DS); - define('OUTPUT_DIR', MIGRATE_DIR."output".DS); - // Define paths to system webroot - define('SYSTEM_DIR', $sys); - define('SYS_VAR_DIR', SYSTEM_DIR."var".DS); - define('SYS_BIN_DIR', SYSTEM_DIR."bin".DS); - define('SYS_LOG_DIR', SYS_VAR_DIR."log".DS); - define('SYS_OUT_DIR', SYS_VAR_DIR); - define('VAR_BIN_DIR', SYS_VAR_DIR."bin".DS); - // Define paths to system - array_pop($xdir); - $asys = ''; - foreach ($xdir as $k=>$v) { - $asys .= $v.DS; - } - define('SYSTEM_ROOT', $asys); - // Migrate Type - preg_match('/Zend/', $sys, $matches); // TODO: Dirty - if($matches) { - $sysdir = explode(DS, $sys); - array_pop($sysdir); - array_pop($sysdir); - array_pop($sysdir); - array_pop($sysdir); - $zendsys = ''; - foreach ($sysdir as $k=>$v) { - $zendsys .= $v.DS; - } - define('INSTALL_TYPE', 'Zend'); - define('PHP_DIR', $zendsys."ZendServer".DS."bin".DS); - } else { - $modules = get_loaded_extensions(); - // TODO: Dirty - if(in_array('Zend Download Server', $modules) || in_array('Zend Monitor', $modules) || in_array('Zend Utils', $modules) || in_array('Zend Page Cache', $modules)) { - define('INSTALL_TYPE', 'Zend'); - define('PHP_DIR', ''); - } else { - define('INSTALL_TYPE', ''); - define('PHP_DIR', ''); - } - } - // Other - date_default_timezone_set('Africa/Johannesburg'); - if(WINDOWS_OS) { // Mysql bin [Windows] - $serverPaths = explode(';',$_SERVER['PATH']); - foreach ($serverPaths as $apath) { - preg_match('/mysql/i', $apath, $matches); - if($matches) { - define('MYSQL_BIN', $apath.DS); - break; - } - } - } else { - define('MYSQL_BIN', ''); // Assume its linux and can be executed from command line - } - -?> diff --git a/setup/migrate/session.php b/setup/migrate/session.php index cea3d4b..35e7a7a 100644 --- a/setup/migrate/session.php +++ b/setup/migrate/session.php @@ -175,7 +175,7 @@ class Session * @access public * @return void */ - public function destroy() { + public function destroyMigrate() { $this->startSession(); unset($_SESSION[$this->salt]); session_destroy(); diff --git a/setup/migrate/steps/migrateComplete.php b/setup/migrate/steps/migrateComplete.php index a38a7af..b341586 100644 --- a/setup/migrate/steps/migrateComplete.php +++ b/setup/migrate/steps/migrateComplete.php @@ -82,8 +82,9 @@ class migrateComplete extends Step { } private function checkSqlDump() { - $tmpFolder = "/tmp/knowledgtree"; - $sqlFile = $tmpFolder."dms.sql"; + $database = $this->getDataFromSession("database"); // Get installation directory + // TODO + $sqlFile = $_SESSION['migrate']['database']['dumpLocation']; if(file_exists($sqlFile)) { $this->temp_variables['sql']['class'] = "tick"; $this->temp_variables['sql']['name'] = "dms.sql"; diff --git a/setup/migrate/steps/migrateDatabase.php b/setup/migrate/steps/migrateDatabase.php index 334e014..267f363 100644 --- a/setup/migrate/steps/migrateDatabase.php +++ b/setup/migrate/steps/migrateDatabase.php @@ -52,14 +52,13 @@ class migrateDatabase extends Step public $_dbhandler = null; /** - * Reference to Database object + * Reference to Utility object * * @author KnowledgeTree Team * @access public * @var object */ - public $_util = null; - + public $util = null; /** * List of errors encountered @@ -95,7 +94,7 @@ class migrateDatabase extends Step * @access public * @var array */ - protected $silent = true; + protected $silent = false; /** * List of errors used in template @@ -105,7 +104,7 @@ class migrateDatabase extends Step * @var array */ public $templateErrors = array('dmspassword', 'dmsuserpassword', 'con', 'dname', 'dtype', 'duname', 'dpassword'); - + private $sqlDumpFile = ''; /** * Constructs database object * @@ -137,6 +136,7 @@ class migrateDatabase extends Step } if($this->next()) { if($this->exportDatabase()) { + $this->storeSilent(); return 'next'; } } else if($this->previous()) { @@ -147,26 +147,78 @@ class migrateDatabase extends Step } public function exportDatabase() { - if(WINDOWS_OS) { - $tmpFolder = "../"; - } else { - $tmpFolder = "/tmp/knowledgtree"; + if($this->doTest()) { + $installation = $this->getDataFromSession("installation"); // Get installation directory + $dbSettings = $installation['dbSettings']; + $location = $installation['location']; + $uname = $this->temp_variables['duname']; + $pwrd = $this->temp_variables['dpassword']; + $tmpFolder = $this->resolveTempDir(); + if(WINDOWS_OS) { +// $tmpFolder = "tmp/"; + $exe = "\"$location\mysql\bin\mysqldump.exe\""; // Location of dump + } else { +// $tmpFolder = "/tmp/"; + $exe = "'$location/mysql/bin/mysqldump'"; // Location of dump + } + $sqlFile = $tmpFolder."/dms_migrate.sql"; + $dbAdminUser = $dbSettings['dbAdminUser']; + $dbAdminPass = $dbSettings['dbAdminPass']; + $dbName = $dbSettings['dbName']; + $cmd = "$exe -u{$dbAdminUser} -p{$dbAdminPass} $dbName > ".$sqlFile; +// echo $cmd; +// die; + $response = $this->util->pexec($cmd); + if(file_exists($sqlFile)) { + $fileContents = file_get_contents($sqlFile); + if(!empty($fileContents)) { + $this->sqlDumpFile = realpath($sqlFile); // Store location of dump + return true; + } + } } - @mkdir($tmpFolder); + + return false; + } + + // TODO +function resolveTempDir() +{ + + if (!WINDOWS_OS) + { + $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; +} + + public function doTest() { + return true; $installation = $this->getDataFromSession("installation"); // Get installation directory $dbSettings = $installation['dbSettings']; + $location = $installation['location']; $uname = $this->temp_variables['duname']; $pwrd = $this->temp_variables['dpassword']; - $sqlFile = $tmpFolder."dms.sql"; - $dbName = $dbSettings['dbName']; - $cmd = "mysqldump -u{$uname} -p{$pwrd} {$dbName} > ".$sqlFile; - echo $cmd; - $response = $this->util->pexec($cmd); - if(file_exists($sqlFile)) { - return true; - } else { - return false; - } + //dmsadmin //clean1 // 3316 // TODO + $dbhandler = $this->util->loadInstallDBUtil(); + $dbhandler->load("localhost:3316",$uname, $pwrd, "dms"); + if (!$dbhandler->getDatabaseLink()) { + $this->error['con'] = "Could not connect to the database, please check username and password"; + return false; + } + + return true; } /** @@ -180,6 +232,7 @@ class migrateDatabase extends Step private function setDetails() { $this->temp_variables['duname'] = $this->getPostSafe('duname'); $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword'); + $this->temp_variables['dumpLocation'] = $this->getPostSafe('dumpLocation'); // create lock file to indicate migration mode $this->createMigrateFile(); } @@ -245,5 +298,12 @@ class migrateDatabase extends Step $this->error[$e] = false; } } + + private function storeSilent() { + // TODO + $_SESSION['migrate']['database']['dumpLocation'] = $this->sqlDumpFile; + $this->temp_variables['dumpLocation'] = $this->sqlDumpFile; + } + } ?> \ No newline at end of file diff --git a/setup/migrate/steps/migrateInstallation.php b/setup/migrate/steps/migrateInstallation.php index be8eedf..94f0f9b 100644 --- a/setup/migrate/steps/migrateInstallation.php +++ b/setup/migrate/steps/migrateInstallation.php @@ -78,15 +78,37 @@ class migrateInstallation extends step */ protected $silent = false; + /** + * Reference to Utility object + * + * @author KnowledgeTree Team + * @access public + * @var object + */ + public $util = null; + private $location = ''; private $dbSettings = array(); private $ktSettings = array(); private $urlPaths = array(); private $knownWindowsLocations = array("C:\Program Files\ktdms"=>"C:\Program Files\ktdms\knowledgeTree\config\config-path","C:\Program Files x86\ktdms"=>"C:\Program Files x86\ktdms\knowledgeTree\config\config-path","C:\ktdms"=>"C:\ktdms\knowledgeTree\config\config-path"); private $knownUnixLocations = array("/opt/ktdms","/var/www/ktdms"); - + + /** + * Installation Settings + * + * @author KnowledgeTree Team + * @access public + * @var object + */ + private $settings = array(); + private $supportedVersion = '3.6.1'; + private $foundVersion = 'Unknown'; + private $versionError = false; + function __construct() { $this->temp_variables = array("step_name"=>"installation", "silent"=>$this->silent); + $this->util = new MigrateUtil(); } public function doStep() { @@ -120,7 +142,7 @@ class migrateInstallation extends step $this->location = $loc; } } else { - foreach ($this->knownUnixLocations as $loc) { + foreach ($this->knownUnixLocations as $loc=>$configPath) { if(file_exists($configPath)) $this->location = $loc; } @@ -128,6 +150,44 @@ class migrateInstallation extends step } public function doRun() { + if(!$this->readConfig()) { + $this->storeSilent(); + return false; + } else { + if($this->readVersion()) { + $this->checkVersion(); + } + $this->storeSilent(); + return true; + } + + } + + + + + public function checkVersion() { + if($this->foundVersion <= $this->supportedVersion) { + $this->versionError = true; + $this->error[] = "KT installation needs to be 3.6.1 or higher"; + } else { + return true; + } + } + + public function readVersion() { + $verFile = $this->location."/knowledgeTree/docs/VERSION.txt"; + if(file_exists($verFile)) { + $this->foundVersion = file_get_contents($verFile); + return true; + } else { + $this->error[] = "KT installation version not found"; + } + + return false; + } + + public function readConfig() { $ktInstallPath = isset($_POST['location']) ? $_POST['location']: ''; if($ktInstallPath != '') { $this->location = $ktInstallPath; @@ -136,7 +196,7 @@ class migrateInstallation extends step if(file_exists($configPath)) { $configFilePath = file_get_contents($configPath); if(file_exists($configFilePath)) { // For 3.7 and after - $this->readConfig($configFilePath); + $this->loadConfig($configFilePath); $this->storeSilent(); return true; @@ -144,7 +204,7 @@ class migrateInstallation extends step $configFilePath = $ktInstallPath.DS."knowledgeTree".DS.$configFilePath; // For older than 3.6.2 $configFilePath = trim($configFilePath); if(file_exists($configFilePath)) { - $this->readConfig($configFilePath); + $this->loadConfig($configFilePath); $this->storeSilent(); return true; @@ -158,19 +218,18 @@ class migrateInstallation extends step $this->error[] = "KT installation not found"; } } - $this->storeSilent(); return false; } - private function readConfig($path) { - $ini = new Ini($path); + private function loadConfig($path) { + $ini = $this->util->loadInstallIni($path);//new Ini($path); $dbSettings = $ini->getSection('db'); $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], 'dbName'=> $dbSettings['dbName'], 'dbUser'=> $dbSettings['dbUser'], 'dbPass'=> $dbSettings['dbPass'], - 'dbPort'=> $dbSettings['dbPort'], + 'dbPort'=> $dbSettings['dbPort'] == 'default' ? "3306":"", 'dbAdminUser'=> $dbSettings['dbAdminUser'], 'dbAdminPass'=> $dbSettings['dbAdminPass'], ); @@ -197,7 +256,9 @@ class migrateInstallation extends step private function setDetails() { $inst = $this->getDataFromSession("installation"); if ($inst) { - $this->location = $inst['location']; + if(file_exists($this->location)) { + $this->location = $inst['location']; + } } } @@ -210,9 +271,11 @@ class migrateInstallation extends step } public function storeSilent() { + if($this->location==1) { $this->location = '';} $this->temp_variables['location'] = $this->location; - - } - + $this->temp_variables['foundVersion'] = $this->foundVersion; + $this->temp_variables['versionError'] = $this->versionError; + $this->temp_variables['settings'] = $this->settings; + } } ?> \ No newline at end of file diff --git a/setup/migrate/templates/database.tpl b/setup/migrate/templates/database.tpl index c5da9c0..eca620e 100644 --- a/setup/migrate/templates/database.tpl +++ b/setup/migrate/templates/database.tpl @@ -2,31 +2,40 @@
Migrate Database
-The database upgrade wizard completes the upgrade process on an existing installation. It applies -any upgrades to the database that may be required. -
-Only administrator users may access the upgrade wizard. -
- -
-$message"; - login(); -} - -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 create_backup_stmt($targetfile=null) -{ - $oKTConfig =& KTConfig::getSingleton(); - - $adminUser = $oKTConfig->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=resolveMysqlDir(); - - $info['dir']=$dir; - - $prefix=''; - if (OS_UNIX) - { - $prefix .= "./"; - } - - if (@stat($dbSocket) !== false) - { - $mechanism="--socket=\"$dbSocket\""; - } - else - { - $mechanism="--port=\"$dbPort\""; - } - - $tmpdir=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 create_restore_stmt($targetfile) -{ - $oKTConfig =& KTConfig::getSingleton(); - - $adminUser = $oKTConfig->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=resolveMysqlDir(); - - $info['dir']=$dir; - - $prefix=''; - if (OS_UNIX) - { - $prefix .= "./"; - } - - if (@stat($dbSocket) !== false) - { - $mechanism="--socket=\"$dbSocket\""; - } - else - { - $mechanism="--port=\"$dbPort\""; - } - - $tmpdir=resolveTempDir(); - - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"
-
-
-
-We are about to start the upgrade process. -
- - - - - - -Are you sure you want to perform the backup? - -
-Your mysql installation has been resolved. Manually, you would do the following: -
-
|
- - -The mysql backup utility could not be found automatically. Either do a manual backup, or edit the config.ini and update the backup/mysql Directory entry. - -You can continue to do the backup manually using the following process: - -
- - - - - - - - - - There don't seem to be any backups to restore from the "" directory. - - - Select a backup to restore from the list below: - - -
- - - - - - -Manually, you would do the following to restore the backup: - -
The table below describes the upgrades that have occurred to
- upgrade your installation to systemVersion;?>.
-
-
-Pre-Upgrade actions failed.
-Pre-Upgrade actions succeeded. The table below describes the upgrades that have occurred to
+ upgrade your KnowledgeTree installation to ' . $default->systemVersion . '';
+
+ $pre_res = $this->performPreUpgradeActions();
+ if (PEAR::isError($pre_res)) {
+ $this->temp_variables['preUpgrade'] = 'Pre-Upgrade actions failed.';
+ }
+ else {
+ $this->temp_variables['preUpgrade'] = 'Pre-Upgrade actions succeeded.';
+
+ }
+
+ $res = $this->performAllUpgrades();
+ if (PEAR::isError($res) || PEAR::isError($pres)) {
+ // TODO instantiate error details hideable section
+ $this->temp_variables['upgradeStatus'] = 'Database upgrade failed
+ - -Upgrade failed. -cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock'; + touch($lockFile); + return true; + } - else - { -?> - -Upgrade succeeded. -proxyCacheDirectory; + KTUtil::deleteDirectory($proxyDir); + + $oKTCache = new KTCache(); + $oKTCache->deleteAllCaches(); + + // Clear the configuration cache, it'll regenerate on next load + $oKTConfig = new KTConfig(); + $oKTConfig->clearCache(); + + // Unlock the scheduler + $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock'; + if(file_exists($lockFile)){ + @unlink($lockFile); + } + + return true; + } -?> -
-
-Post-Upgrade actions failed. %s ' . "\n", $class,
+ htmlspecialchars($upgrade->getDescription()));
+ ++$row;
+ $res = $upgrade->performUpgrade();
+ $this->temp_variables['upgradeTable'] .= sprintf('', $this->showResult($res));
+ $this->temp_variables['upgradeTable'] .= '' . "\n"; + $this->temp_variables['upgradeTable'] .= "
-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'); + // should be some sort of error checking, really + $this->restoreDone(); + } } - foreach($dirs as $dir) + private function restoreDone() { - if (is_file($dir . '/' . $mysqlname)) + $status = $_SESSION['restoreStatus']; + $filename = $_SESSION['backupFile']; + + if ($status) { - return $dir; + $this->temp_variables['display'] = 'The restore of + It appears as though the restore has been successful. + '; + + $this->temp_variables['title'] = 'Restore Complete'; + $this->temp_variables['restoreSuccessful'] = true; + } + else + { + $this->temp_variables['display'] = '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. + +
- Select a backup to restore from the list below: - - - util->resolveTempDir(); + $_SESSION['backupFile'] = $dir . '/' . $file; } - ?> - -- - resolveTempDir(); - $_SESSION['backupFile'] = $dir . '/' . $file; -?> -restoreSelect(); - exit; + if (!isset($_SESSION['backupFile']) || !is_file($_SESSION['backupFile']) || filesize($_SESSION['backupFile']) == 0) + { + $this->restoreSelect(); + return; + } + + $status = $_SESSION['backupStatus']; + $filename = $_SESSION['backupFile']; + $stmt = $this->util->create_restore_stmt($filename); + + $this->temp_variables['title'] = 'Confirm Restore'; + $this->temp_variables['dir'] = $stmt['dir']; + $this->temp_variables['display'] = $stmt['display']; + $this->temp_variables['availableBackups'] = true; + $this->temp_variables['selected'] = true; } - $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 index b311bcd..2450584 100644 --- a/setup/upgrade/steps/upgradeWelcome.php +++ b/setup/upgrade/steps/upgradeWelcome.php @@ -40,14 +40,13 @@ * @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; + protected $silent = false; + protected $temp_variables = array(); public function __construct() { $this->temp_variables = array("step_name"=>"welcome"); @@ -76,7 +75,6 @@ class upgradeWelcome extends step { if (!$authenticated) { session_unset(); -// loginFailed(_kt('Could not authenticate administrative user')); return false; } diff --git a/setup/upgrade/templates/backup.tpl b/setup/upgrade/templates/backup.tpl index 8ade6b5..28bc28e 100644 --- a/setup/upgrade/templates/backup.tpl +++ b/setup/upgrade/templates/backup.tpl @@ -1,5 +1,5 @@ |