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/steps/migrateComplete.php b/setup/migrate/steps/migrateComplete.php index a38a7af..6419327 100644 --- a/setup/migrate/steps/migrateComplete.php +++ b/setup/migrate/steps/migrateComplete.php @@ -82,8 +82,12 @@ class migrateComplete extends Step { } private function checkSqlDump() { - $tmpFolder = "/tmp/knowledgtree"; - $sqlFile = $tmpFolder."dms.sql"; + $database = $this->getDataFromSession("database"); // Get installation directory + // TODO + $sqlFile = $_SESSION['database']['dumpLocation']; +// $tmpFolder = $database['dumpLocation']; +// $sqlFile = $tmpFolder."dms.sql"; + //echo $sqlFile; 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..05ad7ef 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,53 @@ 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']; + 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.sql"; + $dbAdminUser = $dbSettings['dbAdminUser']; + $dbAdminPass = $dbSettings['dbAdminPass']; + $dbName = $dbSettings['dbName']; + $cmd = "$exe -u{$dbAdminUser} -p{$dbAdminPass} $dbName > ".$sqlFile; + $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; + } + + 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 +207,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 +273,12 @@ class migrateDatabase extends Step $this->error[$e] = false; } } + + private function storeSilent() { + // TODO + $_SESSION['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 6e1e994..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"=>"/opt/ktdms/knowledgeTree/config/config-path","/var/www/ktdms"=>"/var/www/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() { @@ -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..0678fa9 100644 --- a/setup/migrate/templates/database.tpl +++ b/setup/migrate/templates/database.tpl @@ -6,6 +6,12 @@ user on the database server are required in order to be able to configure and migrate the database.
+ Database Details +