Commit 1b78c4c07216a15fa8281429c488ae594e093735
1 parent
6726e93d
Story Id:1166880 VM Merge
Committed by: Jarrett Jordaan Reviewed by: Prince Mbekwa
Showing
14 changed files
with
201 additions
and
284 deletions
setup/migrate/ini.php deleted
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * $Id:$ | ||
| 4 | - * | ||
| 5 | - * KnowledgeTree Community Edition | ||
| 6 | - * Document Management Made Simple | ||
| 7 | - * Copyright (C) 2008, 2009 KnowledgeTree Inc. | ||
| 8 | - * Portions copyright The Jam Warehouse Software (Pty) Limited | ||
| 9 | - * | ||
| 10 | - * This program is free software; you can redistribute it and/or modify it under | ||
| 11 | - * the terms of the GNU General Public License version 3 as published by the | ||
| 12 | - * Free Software Foundation. | ||
| 13 | - * | ||
| 14 | - * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 15 | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 16 | - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 17 | - * details. | ||
| 18 | - * | ||
| 19 | - * You should have received a copy of the GNU General Public License | ||
| 20 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | - * | ||
| 22 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 23 | - * California 94120-7775, or email info@knowledgetree.com. | ||
| 24 | - * | ||
| 25 | - * The interactive user interfaces in modified source and object code versions | ||
| 26 | - * of this program must display Appropriate Legal Notices, as required under | ||
| 27 | - * Section 5 of the GNU General Public License version 3. | ||
| 28 | - * | ||
| 29 | - * In accordance with Section 7(b) of the GNU General Public License version 3, | ||
| 30 | - * these Appropriate Legal Notices must retain the display of the "Powered by | ||
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | ||
| 32 | - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | ||
| 34 | - * copyright notice. | ||
| 35 | - * Contributor( s): ______________________________________ | ||
| 36 | - * | ||
| 37 | - */ | ||
| 38 | - | ||
| 39 | -class Ini { | ||
| 40 | - | ||
| 41 | - private $cleanArray = array(); | ||
| 42 | - private $iniFile = ''; | ||
| 43 | - private $lineNum = 0; | ||
| 44 | - private $exists = ''; | ||
| 45 | - | ||
| 46 | - function Ini($iniFile = '../../config.ini') { | ||
| 47 | - $this->iniFile = $iniFile; | ||
| 48 | - $this->backupIni($iniFile); | ||
| 49 | - $this->read($iniFile); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - /** | ||
| 53 | - * Create a backup with the date as an extension in the same location as the original config.ini | ||
| 54 | - * | ||
| 55 | - * @param string $iniFile | ||
| 56 | - * @return boolean | ||
| 57 | - */ | ||
| 58 | - function backupIni($iniFile) | ||
| 59 | - { | ||
| 60 | - $content = file_get_contents($iniFile); | ||
| 61 | - if ($content === false) | ||
| 62 | - { | ||
| 63 | - return false; | ||
| 64 | - } | ||
| 65 | - $date = date('YmdHis'); | ||
| 66 | - | ||
| 67 | - $backupFile = $iniFile . '.' .$date; | ||
| 68 | - if (is_writeable($backupFile)) { | ||
| 69 | - file_put_contents($backupFile, $content); | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - function read($iniFile) { | ||
| 74 | - | ||
| 75 | - $iniArray = file($iniFile); | ||
| 76 | - $section = ''; | ||
| 77 | - foreach($iniArray as $iniLine) { | ||
| 78 | - $this->lineNum++; | ||
| 79 | - $iniLine = trim($iniLine); | ||
| 80 | - $firstChar = substr($iniLine, 0, 1); | ||
| 81 | - if($firstChar == ';') { | ||
| 82 | - if($section == ''){ | ||
| 83 | - $this->cleanArray['_comment_'.$this->lineNum]=$iniLine; | ||
| 84 | - }else { | ||
| 85 | - $this->cleanArray[$section]['_comment_'.$this->lineNum]=$iniLine; | ||
| 86 | - } | ||
| 87 | - continue; | ||
| 88 | - } | ||
| 89 | - if($iniLine == '') { | ||
| 90 | - if($section == ''){ | ||
| 91 | - $this->cleanArray['_blankline_'.$this->lineNum]=''; | ||
| 92 | - }else { | ||
| 93 | - $this->cleanArray[$section]['_blankline_'.$this->lineNum]=''; | ||
| 94 | - } | ||
| 95 | - continue; | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - if ($firstChar == '[' && substr($iniLine, -1, 1) == ']') { | ||
| 99 | - $section = substr($iniLine, 1, -1); | ||
| 100 | - $this->sections[] = $section; | ||
| 101 | - } else { | ||
| 102 | - $equalsPos = strpos($iniLine, '='); | ||
| 103 | - if ($equalsPos > 0 && $equalsPos != sizeof($iniLine)) { | ||
| 104 | - $key = trim(substr($iniLine, 0, $equalsPos)); | ||
| 105 | - $value = trim(substr($iniLine, $equalsPos+1)); | ||
| 106 | - if (substr($value, 1, 1) == '"' && substr( $value, -1, 1) == '"') { | ||
| 107 | - $value = substr($value, 1, -1); | ||
| 108 | - } | ||
| 109 | - $this->cleanArray[$section][$key] = stripcslashes($value); | ||
| 110 | - } else { | ||
| 111 | - $this->cleanArray[$section][trim($iniLine)]=''; | ||
| 112 | - } | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - return $this->cleanArray; | ||
| 116 | - } | ||
| 117 | - | ||
| 118 | - function write($iniFile = "") { | ||
| 119 | - | ||
| 120 | - if(empty($iniFile)) { | ||
| 121 | - $iniFile = $this->iniFile; | ||
| 122 | - } | ||
| 123 | - if (!is_writeable($iniFile)) { | ||
| 124 | - return; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - $fileHandle = fopen($iniFile, 'wb'); | ||
| 128 | - foreach ($this->cleanArray as $section => $items) { | ||
| 129 | - if (substr($section, 0, strlen('_blankline_')) === '_blankline_' ) { | ||
| 130 | - fwrite ($fileHandle, "\r\n"); | ||
| 131 | - continue; | ||
| 132 | - } | ||
| 133 | - if (substr($section, 0, strlen('_comment_')) === '_comment_' ) { | ||
| 134 | - fwrite ($fileHandle, "$items\r\n"); | ||
| 135 | - continue; | ||
| 136 | - } | ||
| 137 | - fwrite ($fileHandle, "[".$section."]\r\n"); | ||
| 138 | - foreach ($items as $key => $value) { | ||
| 139 | - if (substr($key, 0, strlen('_blankline_')) === '_blankline_' ) { | ||
| 140 | - fwrite ($fileHandle, "\r\n"); | ||
| 141 | - continue; | ||
| 142 | - } | ||
| 143 | - if (substr($key, 0, strlen('_comment_')) === '_comment_' ) { | ||
| 144 | - fwrite ($fileHandle, "$value\r\n"); | ||
| 145 | - continue; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - $value = addcslashes($value,''); | ||
| 149 | - //fwrite ($fileHandle, $key.' = "'.$value."\"\r\n"); | ||
| 150 | - fwrite ($fileHandle, $key.' = '.$value."\r\n"); | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - fclose($fileHandle); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - function itemExists($checkSection, $checkItem) { | ||
| 157 | - | ||
| 158 | - $this->exists = ''; | ||
| 159 | - foreach($this->cleanArray as $section => $items) { | ||
| 160 | - if($section == $checkSection) { | ||
| 161 | - $this->exists = 'section'; | ||
| 162 | - foreach ($items as $key => $value) { | ||
| 163 | - if($key == $checkItem) { | ||
| 164 | - return true; | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - } | ||
| 168 | - } | ||
| 169 | - return false; | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | - function addItem($addSection, $addItem, $value, $itemComment = '', $sectionComment = '') { | ||
| 173 | - | ||
| 174 | - if($this->itemExists($addSection, $addItem)) { | ||
| 175 | - $this->delItem($addSection, $addItem); | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - if($this->exists != 'section') { | ||
| 179 | - $this->cleanArray['_blankline_'.$this->lineNum++]=''; | ||
| 180 | - if(!empty($sectionComment)) $this->cleanArray['_comment_'.$this->lineNum++] = '; '.$sectionComment; | ||
| 181 | - } | ||
| 182 | - if(!empty($itemComment)) { | ||
| 183 | - $this->cleanArray[$addSection]['_comment_'.$this->lineNum++] = '; '.$itemComment; | ||
| 184 | - } | ||
| 185 | - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); | ||
| 186 | - return true; | ||
| 187 | - } | ||
| 188 | - | ||
| 189 | - function updateItem($addSection, $addItem, $value) { | ||
| 190 | - | ||
| 191 | - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); | ||
| 192 | - return true; | ||
| 193 | - } | ||
| 194 | - | ||
| 195 | - function delItem($delSection, $delItem) { | ||
| 196 | - | ||
| 197 | - if(!$this->itemExists($delSection, $delItem)) return false; | ||
| 198 | - | ||
| 199 | - unset($this->cleanArray[$delSection][$delItem]); | ||
| 200 | - return true; | ||
| 201 | - } | ||
| 202 | - | ||
| 203 | - function delSection($delSection) { | ||
| 204 | - | ||
| 205 | - unset($this->cleanArray[$delSection]); | ||
| 206 | - return true; | ||
| 207 | - } | ||
| 208 | - | ||
| 209 | - // Return file line by line | ||
| 210 | - public function getFileByLine() { | ||
| 211 | - $data = $this->read($this->iniFile); | ||
| 212 | - return $data['']; | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - public function getSection($section) { | ||
| 216 | - if (isset($this->cleanArray[$section])) { | ||
| 217 | - return $this->cleanArray[$section]; | ||
| 218 | - } | ||
| 219 | - | ||
| 220 | - return false; | ||
| 221 | - } | ||
| 222 | -} | ||
| 223 | -?> |
setup/migrate/migrateUtil.php
| @@ -142,6 +142,11 @@ class MigrateUtil { | @@ -142,6 +142,11 @@ class MigrateUtil { | ||
| 142 | return new $serviceName(); | 142 | return new $serviceName(); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | + public function loadInstallIni($path) { | ||
| 146 | + require_once("../wizard/ini.php"); | ||
| 147 | + return new Ini($path); | ||
| 148 | + } | ||
| 149 | + | ||
| 145 | public function redirect($url, $exit = true, $rfc2616 = false) | 150 | public function redirect($url, $exit = true, $rfc2616 = false) |
| 146 | { | 151 | { |
| 147 | return $this->bootstrap->redirect($url, $exit = true, $rfc2616 = false); | 152 | return $this->bootstrap->redirect($url, $exit = true, $rfc2616 = false); |
setup/migrate/migrater.php
| @@ -510,6 +510,9 @@ class Migrater { | @@ -510,6 +510,9 @@ class Migrater { | ||
| 510 | } elseif (isset($_POST['BInstall'])) { | 510 | } elseif (isset($_POST['BInstall'])) { |
| 511 | $this->migraterAction = 'binstall'; | 511 | $this->migraterAction = 'binstall'; |
| 512 | $this->response = 'binstall'; | 512 | $this->response = 'binstall'; |
| 513 | +// } elseif (isset($_POST['Backup'])) { | ||
| 514 | +// $this->migraterAction = 'backup'; | ||
| 515 | +// $this->response = 'backup'; | ||
| 513 | } else { | 516 | } else { |
| 514 | $this->response = ''; | 517 | $this->response = ''; |
| 515 | $this->migraterAction = ''; | 518 | $this->migraterAction = ''; |
| @@ -545,8 +548,8 @@ class Migrater { | @@ -545,8 +548,8 @@ class Migrater { | ||
| 545 | } | 548 | } |
| 546 | break; | 549 | break; |
| 547 | case 'previous': | 550 | case 'previous': |
| 548 | - $this->_backward(); // Load previous page | ||
| 549 | - break; | 551 | + $this->_backward(); // Load previous page |
| 552 | + break; | ||
| 550 | case 'install': | 553 | case 'install': |
| 551 | $iutil = new MigrateUtil(); | 554 | $iutil = new MigrateUtil(); |
| 552 | $iutil->redirect('../wizard/index.php?step_name=installtype'); | 555 | $iutil->redirect('../wizard/index.php?step_name=installtype'); |
| @@ -555,6 +558,11 @@ class Migrater { | @@ -555,6 +558,11 @@ class Migrater { | ||
| 555 | $iutil = new MigrateUtil(); | 558 | $iutil = new MigrateUtil(); |
| 556 | $iutil->redirect('../wizard/index.php?step_name=dependencies'); | 559 | $iutil->redirect('../wizard/index.php?step_name=dependencies'); |
| 557 | break; | 560 | break; |
| 561 | +// case 'backup': | ||
| 562 | +// $iutil = new MigrateUtil(); | ||
| 563 | +// $iutil->redirect('../upgrade/index.php?step_name=backup'); | ||
| 564 | +// $iutil->redirect("..".DS."upgrade".DS."index.php?step_name=backup"); | ||
| 565 | +// break; | ||
| 558 | default: | 566 | default: |
| 559 | // TODO : handle silent | 567 | // TODO : handle silent |
| 560 | $this->_landing(); | 568 | $this->_landing(); |
setup/migrate/steps/migrateComplete.php
| @@ -82,8 +82,12 @@ class migrateComplete extends Step { | @@ -82,8 +82,12 @@ class migrateComplete extends Step { | ||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | private function checkSqlDump() { | 84 | private function checkSqlDump() { |
| 85 | - $tmpFolder = "/tmp/knowledgtree"; | ||
| 86 | - $sqlFile = $tmpFolder."dms.sql"; | 85 | + $database = $this->getDataFromSession("database"); // Get installation directory |
| 86 | + // TODO | ||
| 87 | + $sqlFile = $_SESSION['database']['dumpLocation']; | ||
| 88 | +// $tmpFolder = $database['dumpLocation']; | ||
| 89 | +// $sqlFile = $tmpFolder."dms.sql"; | ||
| 90 | + //echo $sqlFile; | ||
| 87 | if(file_exists($sqlFile)) { | 91 | if(file_exists($sqlFile)) { |
| 88 | $this->temp_variables['sql']['class'] = "tick"; | 92 | $this->temp_variables['sql']['class'] = "tick"; |
| 89 | $this->temp_variables['sql']['name'] = "dms.sql"; | 93 | $this->temp_variables['sql']['name'] = "dms.sql"; |
setup/migrate/steps/migrateDatabase.php
| @@ -52,14 +52,13 @@ class migrateDatabase extends Step | @@ -52,14 +52,13 @@ class migrateDatabase extends Step | ||
| 52 | public $_dbhandler = null; | 52 | public $_dbhandler = null; |
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | - * Reference to Database object | 55 | + * Reference to Utility object |
| 56 | * | 56 | * |
| 57 | * @author KnowledgeTree Team | 57 | * @author KnowledgeTree Team |
| 58 | * @access public | 58 | * @access public |
| 59 | * @var object | 59 | * @var object |
| 60 | */ | 60 | */ |
| 61 | - public $_util = null; | ||
| 62 | - | 61 | + public $util = null; |
| 63 | 62 | ||
| 64 | /** | 63 | /** |
| 65 | * List of errors encountered | 64 | * List of errors encountered |
| @@ -95,7 +94,7 @@ class migrateDatabase extends Step | @@ -95,7 +94,7 @@ class migrateDatabase extends Step | ||
| 95 | * @access public | 94 | * @access public |
| 96 | * @var array | 95 | * @var array |
| 97 | */ | 96 | */ |
| 98 | - protected $silent = true; | 97 | + protected $silent = false; |
| 99 | 98 | ||
| 100 | /** | 99 | /** |
| 101 | * List of errors used in template | 100 | * List of errors used in template |
| @@ -105,7 +104,7 @@ class migrateDatabase extends Step | @@ -105,7 +104,7 @@ class migrateDatabase extends Step | ||
| 105 | * @var array | 104 | * @var array |
| 106 | */ | 105 | */ |
| 107 | public $templateErrors = array('dmspassword', 'dmsuserpassword', 'con', 'dname', 'dtype', 'duname', 'dpassword'); | 106 | public $templateErrors = array('dmspassword', 'dmsuserpassword', 'con', 'dname', 'dtype', 'duname', 'dpassword'); |
| 108 | - | 107 | + private $sqlDumpFile = ''; |
| 109 | /** | 108 | /** |
| 110 | * Constructs database object | 109 | * Constructs database object |
| 111 | * | 110 | * |
| @@ -137,6 +136,7 @@ class migrateDatabase extends Step | @@ -137,6 +136,7 @@ class migrateDatabase extends Step | ||
| 137 | } | 136 | } |
| 138 | if($this->next()) { | 137 | if($this->next()) { |
| 139 | if($this->exportDatabase()) { | 138 | if($this->exportDatabase()) { |
| 139 | + $this->storeSilent(); | ||
| 140 | return 'next'; | 140 | return 'next'; |
| 141 | } | 141 | } |
| 142 | } else if($this->previous()) { | 142 | } else if($this->previous()) { |
| @@ -147,26 +147,53 @@ class migrateDatabase extends Step | @@ -147,26 +147,53 @@ class migrateDatabase extends Step | ||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | public function exportDatabase() { | 149 | public function exportDatabase() { |
| 150 | - if(WINDOWS_OS) { | ||
| 151 | - $tmpFolder = "../"; | ||
| 152 | - } else { | ||
| 153 | - $tmpFolder = "/tmp/knowledgtree"; | 150 | + if($this->doTest()) { |
| 151 | + $installation = $this->getDataFromSession("installation"); // Get installation directory | ||
| 152 | + $dbSettings = $installation['dbSettings']; | ||
| 153 | + $location = $installation['location']; | ||
| 154 | + $uname = $this->temp_variables['duname']; | ||
| 155 | + $pwrd = $this->temp_variables['dpassword']; | ||
| 156 | + if(WINDOWS_OS) { | ||
| 157 | + $tmpFolder = "tmp/"; | ||
| 158 | + $exe = "\"$location\mysql\bin\mysqldump.exe\""; // Location of dump | ||
| 159 | + } else { | ||
| 160 | + $tmpFolder = "/tmp/"; | ||
| 161 | + $exe = "'$location/mysql/bin/mysqldump'"; // Location of dump | ||
| 162 | + } | ||
| 163 | + $sqlFile = $tmpFolder."dms.sql"; | ||
| 164 | + $dbAdminUser = $dbSettings['dbAdminUser']; | ||
| 165 | + $dbAdminPass = $dbSettings['dbAdminPass']; | ||
| 166 | + $dbName = $dbSettings['dbName']; | ||
| 167 | + $cmd = "$exe -u{$dbAdminUser} -p{$dbAdminPass} $dbName > ".$sqlFile; | ||
| 168 | + $response = $this->util->pexec($cmd); | ||
| 169 | + if(file_exists($sqlFile)) { | ||
| 170 | + $fileContents = file_get_contents($sqlFile); | ||
| 171 | + if(!empty($fileContents)) { | ||
| 172 | + $this->sqlDumpFile = realpath($sqlFile); // Store location of dump | ||
| 173 | + return true; | ||
| 174 | + } | ||
| 175 | + } | ||
| 154 | } | 176 | } |
| 155 | - @mkdir($tmpFolder); | 177 | + |
| 178 | + return false; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public function doTest() { | ||
| 182 | + return true; | ||
| 156 | $installation = $this->getDataFromSession("installation"); // Get installation directory | 183 | $installation = $this->getDataFromSession("installation"); // Get installation directory |
| 157 | $dbSettings = $installation['dbSettings']; | 184 | $dbSettings = $installation['dbSettings']; |
| 185 | + $location = $installation['location']; | ||
| 158 | $uname = $this->temp_variables['duname']; | 186 | $uname = $this->temp_variables['duname']; |
| 159 | $pwrd = $this->temp_variables['dpassword']; | 187 | $pwrd = $this->temp_variables['dpassword']; |
| 160 | - $sqlFile = $tmpFolder."dms.sql"; | ||
| 161 | - $dbName = $dbSettings['dbName']; | ||
| 162 | - $cmd = "mysqldump -u{$uname} -p{$pwrd} {$dbName} > ".$sqlFile; | ||
| 163 | - echo $cmd; | ||
| 164 | - $response = $this->util->pexec($cmd); | ||
| 165 | - if(file_exists($sqlFile)) { | ||
| 166 | - return true; | ||
| 167 | - } else { | ||
| 168 | - return false; | ||
| 169 | - } | 188 | + //dmsadmin //clean1 // 3316 // TODO |
| 189 | + $dbhandler = $this->util->loadInstallDBUtil(); | ||
| 190 | + $dbhandler->load("localhost:3316",$uname, $pwrd, "dms"); | ||
| 191 | + if (!$dbhandler->getDatabaseLink()) { | ||
| 192 | + $this->error['con'] = "Could not connect to the database, please check username and password"; | ||
| 193 | + return false; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + return true; | ||
| 170 | } | 197 | } |
| 171 | 198 | ||
| 172 | /** | 199 | /** |
| @@ -180,6 +207,7 @@ class migrateDatabase extends Step | @@ -180,6 +207,7 @@ class migrateDatabase extends Step | ||
| 180 | private function setDetails() { | 207 | private function setDetails() { |
| 181 | $this->temp_variables['duname'] = $this->getPostSafe('duname'); | 208 | $this->temp_variables['duname'] = $this->getPostSafe('duname'); |
| 182 | $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword'); | 209 | $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword'); |
| 210 | + $this->temp_variables['dumpLocation'] = $this->getPostSafe('dumpLocation'); | ||
| 183 | // create lock file to indicate migration mode | 211 | // create lock file to indicate migration mode |
| 184 | $this->createMigrateFile(); | 212 | $this->createMigrateFile(); |
| 185 | } | 213 | } |
| @@ -245,5 +273,12 @@ class migrateDatabase extends Step | @@ -245,5 +273,12 @@ class migrateDatabase extends Step | ||
| 245 | $this->error[$e] = false; | 273 | $this->error[$e] = false; |
| 246 | } | 274 | } |
| 247 | } | 275 | } |
| 276 | + | ||
| 277 | + private function storeSilent() { | ||
| 278 | + // TODO | ||
| 279 | + $_SESSION['database']['dumpLocation'] = $this->sqlDumpFile; | ||
| 280 | + $this->temp_variables['dumpLocation'] = $this->sqlDumpFile; | ||
| 281 | + } | ||
| 282 | + | ||
| 248 | } | 283 | } |
| 249 | ?> | 284 | ?> |
| 250 | \ No newline at end of file | 285 | \ No newline at end of file |
setup/migrate/steps/migrateInstallation.php
| @@ -78,15 +78,37 @@ class migrateInstallation extends step | @@ -78,15 +78,37 @@ class migrateInstallation extends step | ||
| 78 | */ | 78 | */ |
| 79 | protected $silent = false; | 79 | protected $silent = false; |
| 80 | 80 | ||
| 81 | + /** | ||
| 82 | + * Reference to Utility object | ||
| 83 | + * | ||
| 84 | + * @author KnowledgeTree Team | ||
| 85 | + * @access public | ||
| 86 | + * @var object | ||
| 87 | + */ | ||
| 88 | + public $util = null; | ||
| 89 | + | ||
| 81 | private $location = ''; | 90 | private $location = ''; |
| 82 | private $dbSettings = array(); | 91 | private $dbSettings = array(); |
| 83 | private $ktSettings = array(); | 92 | private $ktSettings = array(); |
| 84 | private $urlPaths = array(); | 93 | private $urlPaths = array(); |
| 85 | 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"); | 94 | 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"); |
| 86 | - private $knownUnixLocations = array("/opt/ktdms"=>"/opt/ktdms/knowledgeTree/config/config-path","/var/www/ktdms"=>"/var/www/ktdms/knowledgeTree/config/config-path"); | ||
| 87 | - | 95 | + private $knownUnixLocations = array("/opt/ktdms","/var/www/ktdms"); |
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Installation Settings | ||
| 99 | + * | ||
| 100 | + * @author KnowledgeTree Team | ||
| 101 | + * @access public | ||
| 102 | + * @var object | ||
| 103 | + */ | ||
| 104 | + private $settings = array(); | ||
| 105 | + private $supportedVersion = '3.6.1'; | ||
| 106 | + private $foundVersion = 'Unknown'; | ||
| 107 | + private $versionError = false; | ||
| 108 | + | ||
| 88 | function __construct() { | 109 | function __construct() { |
| 89 | $this->temp_variables = array("step_name"=>"installation", "silent"=>$this->silent); | 110 | $this->temp_variables = array("step_name"=>"installation", "silent"=>$this->silent); |
| 111 | + $this->util = new MigrateUtil(); | ||
| 90 | } | 112 | } |
| 91 | 113 | ||
| 92 | public function doStep() { | 114 | public function doStep() { |
| @@ -128,6 +150,44 @@ class migrateInstallation extends step | @@ -128,6 +150,44 @@ class migrateInstallation extends step | ||
| 128 | } | 150 | } |
| 129 | 151 | ||
| 130 | public function doRun() { | 152 | public function doRun() { |
| 153 | + if(!$this->readConfig()) { | ||
| 154 | + $this->storeSilent(); | ||
| 155 | + return false; | ||
| 156 | + } else { | ||
| 157 | + if($this->readVersion()) { | ||
| 158 | + $this->checkVersion(); | ||
| 159 | + } | ||
| 160 | + $this->storeSilent(); | ||
| 161 | + return true; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + | ||
| 167 | + | ||
| 168 | + | ||
| 169 | + public function checkVersion() { | ||
| 170 | + if($this->foundVersion <= $this->supportedVersion) { | ||
| 171 | + $this->versionError = true; | ||
| 172 | + $this->error[] = "KT installation needs to be 3.6.1 or higher"; | ||
| 173 | + } else { | ||
| 174 | + return true; | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public function readVersion() { | ||
| 179 | + $verFile = $this->location."/knowledgeTree/docs/VERSION.txt"; | ||
| 180 | + if(file_exists($verFile)) { | ||
| 181 | + $this->foundVersion = file_get_contents($verFile); | ||
| 182 | + return true; | ||
| 183 | + } else { | ||
| 184 | + $this->error[] = "KT installation version not found"; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + return false; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public function readConfig() { | ||
| 131 | $ktInstallPath = isset($_POST['location']) ? $_POST['location']: ''; | 191 | $ktInstallPath = isset($_POST['location']) ? $_POST['location']: ''; |
| 132 | if($ktInstallPath != '') { | 192 | if($ktInstallPath != '') { |
| 133 | $this->location = $ktInstallPath; | 193 | $this->location = $ktInstallPath; |
| @@ -136,7 +196,7 @@ class migrateInstallation extends step | @@ -136,7 +196,7 @@ class migrateInstallation extends step | ||
| 136 | if(file_exists($configPath)) { | 196 | if(file_exists($configPath)) { |
| 137 | $configFilePath = file_get_contents($configPath); | 197 | $configFilePath = file_get_contents($configPath); |
| 138 | if(file_exists($configFilePath)) { // For 3.7 and after | 198 | if(file_exists($configFilePath)) { // For 3.7 and after |
| 139 | - $this->readConfig($configFilePath); | 199 | + $this->loadConfig($configFilePath); |
| 140 | $this->storeSilent(); | 200 | $this->storeSilent(); |
| 141 | 201 | ||
| 142 | return true; | 202 | return true; |
| @@ -144,7 +204,7 @@ class migrateInstallation extends step | @@ -144,7 +204,7 @@ class migrateInstallation extends step | ||
| 144 | $configFilePath = $ktInstallPath.DS."knowledgeTree".DS.$configFilePath; // For older than 3.6.2 | 204 | $configFilePath = $ktInstallPath.DS."knowledgeTree".DS.$configFilePath; // For older than 3.6.2 |
| 145 | $configFilePath = trim($configFilePath); | 205 | $configFilePath = trim($configFilePath); |
| 146 | if(file_exists($configFilePath)) { | 206 | if(file_exists($configFilePath)) { |
| 147 | - $this->readConfig($configFilePath); | 207 | + $this->loadConfig($configFilePath); |
| 148 | $this->storeSilent(); | 208 | $this->storeSilent(); |
| 149 | 209 | ||
| 150 | return true; | 210 | return true; |
| @@ -158,19 +218,18 @@ class migrateInstallation extends step | @@ -158,19 +218,18 @@ class migrateInstallation extends step | ||
| 158 | $this->error[] = "KT installation not found"; | 218 | $this->error[] = "KT installation not found"; |
| 159 | } | 219 | } |
| 160 | } | 220 | } |
| 161 | - $this->storeSilent(); | ||
| 162 | 221 | ||
| 163 | return false; | 222 | return false; |
| 164 | } | 223 | } |
| 165 | 224 | ||
| 166 | - private function readConfig($path) { | ||
| 167 | - $ini = new Ini($path); | 225 | + private function loadConfig($path) { |
| 226 | + $ini = $this->util->loadInstallIni($path);//new Ini($path); | ||
| 168 | $dbSettings = $ini->getSection('db'); | 227 | $dbSettings = $ini->getSection('db'); |
| 169 | $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], | 228 | $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], |
| 170 | 'dbName'=> $dbSettings['dbName'], | 229 | 'dbName'=> $dbSettings['dbName'], |
| 171 | 'dbUser'=> $dbSettings['dbUser'], | 230 | 'dbUser'=> $dbSettings['dbUser'], |
| 172 | 'dbPass'=> $dbSettings['dbPass'], | 231 | 'dbPass'=> $dbSettings['dbPass'], |
| 173 | - 'dbPort'=> $dbSettings['dbPort'], | 232 | + 'dbPort'=> $dbSettings['dbPort'] == 'default' ? "3306":"", |
| 174 | 'dbAdminUser'=> $dbSettings['dbAdminUser'], | 233 | 'dbAdminUser'=> $dbSettings['dbAdminUser'], |
| 175 | 'dbAdminPass'=> $dbSettings['dbAdminPass'], | 234 | 'dbAdminPass'=> $dbSettings['dbAdminPass'], |
| 176 | ); | 235 | ); |
| @@ -197,7 +256,9 @@ class migrateInstallation extends step | @@ -197,7 +256,9 @@ class migrateInstallation extends step | ||
| 197 | private function setDetails() { | 256 | private function setDetails() { |
| 198 | $inst = $this->getDataFromSession("installation"); | 257 | $inst = $this->getDataFromSession("installation"); |
| 199 | if ($inst) { | 258 | if ($inst) { |
| 200 | - $this->location = $inst['location']; | 259 | + if(file_exists($this->location)) { |
| 260 | + $this->location = $inst['location']; | ||
| 261 | + } | ||
| 201 | } | 262 | } |
| 202 | } | 263 | } |
| 203 | 264 | ||
| @@ -210,9 +271,11 @@ class migrateInstallation extends step | @@ -210,9 +271,11 @@ class migrateInstallation extends step | ||
| 210 | } | 271 | } |
| 211 | 272 | ||
| 212 | public function storeSilent() { | 273 | public function storeSilent() { |
| 274 | + if($this->location==1) { $this->location = '';} | ||
| 213 | $this->temp_variables['location'] = $this->location; | 275 | $this->temp_variables['location'] = $this->location; |
| 214 | - | ||
| 215 | - } | ||
| 216 | - | 276 | + $this->temp_variables['foundVersion'] = $this->foundVersion; |
| 277 | + $this->temp_variables['versionError'] = $this->versionError; | ||
| 278 | + $this->temp_variables['settings'] = $this->settings; | ||
| 279 | + } | ||
| 217 | } | 280 | } |
| 218 | ?> | 281 | ?> |
| 219 | \ No newline at end of file | 282 | \ No newline at end of file |
setup/migrate/templates/database.tpl
| @@ -6,6 +6,12 @@ | @@ -6,6 +6,12 @@ | ||
| 6 | user on the database server are required in order to be able to configure and migrate the database. | 6 | user on the database server are required in order to be able to configure and migrate the database. |
| 7 | </div> | 7 | </div> |
| 8 | <div id="step_content_database" class="step"> | 8 | <div id="step_content_database" class="step"> |
| 9 | + <span class="error"> <?php if($errors['con']) { echo $errors['con']."<br/><br/>"; } ?> </span> | ||
| 10 | + <span class="error">!!NB!! You are advised to backup your database before proceeding. !!NB!!</span> | ||
| 11 | + <br/><br/> | ||
| 12 | + <p class="empty_space"> | ||
| 13 | + Database Details | ||
| 14 | + </p> | ||
| 9 | <table class="dbconf"> | 15 | <table class="dbconf"> |
| 10 | <?php | 16 | <?php |
| 11 | $input_size = '35'; | 17 | $input_size = '35'; |
| @@ -25,8 +31,9 @@ | @@ -25,8 +31,9 @@ | ||
| 25 | </table> | 31 | </table> |
| 26 | </div> | 32 | </div> |
| 27 | </div> | 33 | </div> |
| 28 | - <input type="button" name="Previous" value="previous" class="button_previous"/> | ||
| 29 | - <input type="submit" name="Next" value="next" class="button_next"/> | 34 | + <input type="submit" name="Previous" value="Previous" class="button_previous"/> |
| 35 | + <input type="submit" name="Next" value="Next" class="button_next"/> | ||
| 36 | +<!-- <input type="submit" name="Backup" value="Backup" class="button_next"/>--> | ||
| 30 | </form> | 37 | </form> |
| 31 | <script type="text/javascript"> | 38 | <script type="text/javascript"> |
| 32 | $("#duname").focus(); | 39 | $("#duname").focus(); |
setup/migrate/templates/installation.tpl
| @@ -25,13 +25,11 @@ | @@ -25,13 +25,11 @@ | ||
| 25 | <a href="http://wiki.knowledgetree.com/Web_Based_Migrater#Current_Installation" target="_blank">Click here for help on overcoming installation detection issues</a> | 25 | <a href="http://wiki.knowledgetree.com/Web_Based_Migrater#Current_Installation" target="_blank">Click here for help on overcoming installation detection issues</a> |
| 26 | <?php } ?> | 26 | <?php } ?> |
| 27 | <div id="step_content" class="step"> | 27 | <div id="step_content" class="step"> |
| 28 | - <br/> | ||
| 29 | - <br/> | ||
| 30 | <p class="empty_space"> | 28 | <p class="empty_space"> |
| 31 | Please verify the location of your current installation. | 29 | Please verify the location of your current installation. |
| 32 | </p> | 30 | </p> |
| 33 | 31 | ||
| 34 | - <input id="location" name="location" type="text" style="width:430px; float:left" value="<?php echo $location; ?>"> | 32 | + <input id="location" name="location" type="text" style="width:430px; float:left" value="<?php if($location) echo $location; ?>"> |
| 35 | <br/><br/> | 33 | <br/><br/> |
| 36 | <?php | 34 | <?php |
| 37 | if($errors) { | 35 | if($errors) { |
setup/migrate/templates/installation_confirm.tpl
| @@ -26,11 +26,26 @@ | @@ -26,11 +26,26 @@ | ||
| 26 | <?php } ?> | 26 | <?php } ?> |
| 27 | <!--Content--> | 27 | <!--Content--> |
| 28 | <div id="step_content" class="step"> | 28 | <div id="step_content" class="step"> |
| 29 | - <br/> | ||
| 30 | - <br/> | ||
| 31 | <p class="empty_space"> | 29 | <p class="empty_space"> |
| 32 | Please verify your current installation settings. | 30 | Please verify your current installation settings. |
| 33 | </p> | 31 | </p> |
| 32 | + <h3>Installation Settings</h3> | ||
| 33 | + <table class="conf_paths"> | ||
| 34 | + <tr> | ||
| 35 | + <?php | ||
| 36 | + if($versionError) { | ||
| 37 | + $w = '26%'; | ||
| 38 | + $x = '10%'; | ||
| 39 | + } else { | ||
| 40 | + $w = '22%'; | ||
| 41 | + $x = '50%'; | ||
| 42 | + } | ||
| 43 | + ?> | ||
| 44 | + <td width="<?php echo $w; ?>">KnowledgeTree Version: </td> | ||
| 45 | + <td width="<?php echo $x; ?>"><?php echo $foundVersion; ?></td> | ||
| 46 | + <?php if($versionError) { ?> <td class="error" width="50%"> KnowledgeTree installation needs to be 3.6.1 or higher </td> <?php } ?> | ||
| 47 | + </tr> | ||
| 48 | + </table> | ||
| 34 | 49 | ||
| 35 | <h3>Database Settings</h3> | 50 | <h3>Database Settings</h3> |
| 36 | <table class="conf_paths"> | 51 | <table class="conf_paths"> |
setup/wizard/config/databases.xml
| @@ -14,8 +14,8 @@ | @@ -14,8 +14,8 @@ | ||
| 14 | <dhost>localhost</dhost> | 14 | <dhost>localhost</dhost> |
| 15 | <dport>3306</dport> | 15 | <dport>3306</dport> |
| 16 | <dname>dms</dname> | 16 | <dname>dms</dname> |
| 17 | - <duname>root</duname> | ||
| 18 | - <dmsadminuser>dmsadminuser</dmsadminuser> | 17 | + <duname>dms</duname> |
| 18 | + <dmsadminuser>dmsadmin</dmsadminuser> | ||
| 19 | <dmsaupass>js9281djw</dmsaupass> | 19 | <dmsaupass>js9281djw</dmsaupass> |
| 20 | <dmsuser>dmsuser</dmsuser> | 20 | <dmsuser>dmsuser</dmsuser> |
| 21 | <dmsupass>djw9281js</dmsupass> | 21 | <dmsupass>djw9281js</dmsupass> |
setup/wizard/dbUtil.php
| @@ -146,8 +146,8 @@ class dbUtil { | @@ -146,8 +146,8 @@ class dbUtil { | ||
| 146 | * @return object The result of the query. | 146 | * @return object The result of the query. |
| 147 | */ | 147 | */ |
| 148 | public function query($query) { | 148 | public function query($query) { |
| 149 | - $this->useDb(); | ||
| 150 | - $result = mysql_query($query, $this->dbconnection); | 149 | + $this->useDb(); |
| 150 | + $result = mysql_query($query, $this->dbconnection); | ||
| 151 | if($result) { | 151 | if($result) { |
| 152 | return $result; | 152 | return $result; |
| 153 | } else { | 153 | } else { |
| @@ -165,13 +165,12 @@ class dbUtil { | @@ -165,13 +165,12 @@ class dbUtil { | ||
| 165 | */ | 165 | */ |
| 166 | public function execute($query) { | 166 | public function execute($query) { |
| 167 | $this->useDb(); | 167 | $this->useDb(); |
| 168 | - $result = @mysql_query($query, $this->dbconnection); | ||
| 169 | - if($result) { | ||
| 170 | - return true; | ||
| 171 | - } else { | 168 | + $result = @mysql_query($query, $this->dbconnection); |
| 169 | + if(!$result) { | ||
| 172 | $this->error[] = @mysql_error($this->dbconnection); | 170 | $this->error[] = @mysql_error($this->dbconnection); |
| 173 | - return false; | ||
| 174 | } | 171 | } |
| 172 | + | ||
| 173 | + return $result; | ||
| 175 | } | 174 | } |
| 176 | 175 | ||
| 177 | /** | 176 | /** |
| @@ -200,10 +199,7 @@ class dbUtil { | @@ -200,10 +199,7 @@ class dbUtil { | ||
| 200 | if ($result == NULL || @mysql_num_rows($result) < 1) | 199 | if ($result == NULL || @mysql_num_rows($result) < 1) |
| 201 | return NULL; | 200 | return NULL; |
| 202 | else { | 201 | else { |
| 203 | - $row = @mysql_fetch_assoc($result); | ||
| 204 | - while ($row) { | ||
| 205 | - $r[] = $row; | ||
| 206 | - } | 202 | + while(($r[] = mysql_fetch_assoc($result)) || array_pop($r)); |
| 207 | return $r; | 203 | return $r; |
| 208 | } | 204 | } |
| 209 | } | 205 | } |
setup/wizard/ini.php
| @@ -206,9 +206,18 @@ class Ini { | @@ -206,9 +206,18 @@ class Ini { | ||
| 206 | return true; | 206 | return true; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | + // Return file line by line | ||
| 209 | public function getFileByLine() { | 210 | public function getFileByLine() { |
| 210 | $data = $this->read($this->iniFile); | 211 | $data = $this->read($this->iniFile); |
| 211 | return $data['']; | 212 | return $data['']; |
| 212 | } | 213 | } |
| 214 | + | ||
| 215 | + public function getSection($section) { | ||
| 216 | + if (isset($this->cleanArray[$section])) { | ||
| 217 | + return $this->cleanArray[$section]; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + return false; | ||
| 221 | + } | ||
| 213 | } | 222 | } |
| 214 | -?> | 223 | -?> |
| 224 | +?> | ||
| 215 | \ No newline at end of file | 225 | \ No newline at end of file |
setup/wizard/steps/configuration.php
| @@ -296,8 +296,8 @@ class configuration extends Step | @@ -296,8 +296,8 @@ class configuration extends Step | ||
| 296 | */ | 296 | */ |
| 297 | public function registerDBConfig($server, $dbconf) { // Adjust server variables | 297 | public function registerDBConfig($server, $dbconf) { // Adjust server variables |
| 298 | $server['dbName'] = array('where'=>'file', 'name'=>ucwords($dbconf['dname']), 'section'=>'db', 'value'=>$dbconf['dname'], 'setting'=>'dbName'); | 298 | $server['dbName'] = array('where'=>'file', 'name'=>ucwords($dbconf['dname']), 'section'=>'db', 'value'=>$dbconf['dname'], 'setting'=>'dbName'); |
| 299 | - $server['dbUser'] = array('where'=>'file', 'name'=>ucwords($dbconf['duname']), 'section'=>'db', 'value'=>$dbconf['duname'], 'setting'=>'dbUser'); | ||
| 300 | - $server['dbPass'] = array('where'=>'file', 'name'=>ucwords($dbconf['dpassword']), 'section'=>'db', 'value'=>$dbconf['dpassword'], 'setting'=>'dbPass'); | 299 | + $server['dbUser'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmsname']), 'section'=>'db', 'value'=>$dbconf['dmsname'], 'setting'=>'dbUser'); |
| 300 | + $server['dbPass'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmspassword']), 'section'=>'db', 'value'=>$dbconf['dmspassword'], 'setting'=>'dbPass'); | ||
| 301 | $server['dbPort'] = array('where'=>'file', 'name'=>ucwords($dbconf['dport']), 'section'=>'db', 'value'=>$dbconf['dport'], 'setting'=>'dbPort'); | 301 | $server['dbPort'] = array('where'=>'file', 'name'=>ucwords($dbconf['dport']), 'section'=>'db', 'value'=>$dbconf['dport'], 'setting'=>'dbPort'); |
| 302 | $server['dbAdminUser'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmsname']), 'section'=>'db', 'value'=>$dbconf['dmsname'], 'setting'=>'dbAdminUser'); | 302 | $server['dbAdminUser'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmsname']), 'section'=>'db', 'value'=>$dbconf['dmsname'], 'setting'=>'dbAdminUser'); |
| 303 | $server['dbAdminPass'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmspassword']), 'section'=>'db', 'value'=>$dbconf['dmspassword'], 'setting'=>'dbAdminPass'); | 303 | $server['dbAdminPass'] = array('where'=>'file', 'name'=>ucwords($dbconf['dmspassword']), 'section'=>'db', 'value'=>$dbconf['dmspassword'], 'setting'=>'dbAdminPass'); |
setup/wizard/steps/database.php
| @@ -755,7 +755,7 @@ class database extends Step | @@ -755,7 +755,7 @@ class database extends Step | ||
| 755 | } else { | 755 | } else { |
| 756 | $user1 = "GRANT SELECT, INSERT, UPDATE, DELETE ON {$this->dname}.* TO {$this->dmsusername}@{$this->dhost} IDENTIFIED BY \"{$this->dmsuserpassword}\";"; | 756 | $user1 = "GRANT SELECT, INSERT, UPDATE, DELETE ON {$this->dname}.* TO {$this->dmsusername}@{$this->dhost} IDENTIFIED BY \"{$this->dmsuserpassword}\";"; |
| 757 | $user2 = "GRANT ALL PRIVILEGES ON {$this->dname}.* TO {$this->dmsname}@{$this->dhost} IDENTIFIED BY \"{$this->dmspassword}\";"; | 757 | $user2 = "GRANT ALL PRIVILEGES ON {$this->dname}.* TO {$this->dmsname}@{$this->dhost} IDENTIFIED BY \"{$this->dmspassword}\";"; |
| 758 | - if ($this->_dbhandler->execute($user1) && $this->_dbhandler->execute($user2)) { | 758 | + if ($this->_dbhandler->query($user1) && $this->_dbhandler->query($user2)) { |
| 759 | return true; | 759 | return true; |
| 760 | } else { | 760 | } else { |
| 761 | $this->error['con'] = "Could not create users for database: {$this->dname}"; | 761 | $this->error['con'] = "Could not create users for database: {$this->dname}"; |
| @@ -784,7 +784,7 @@ class database extends Step | @@ -784,7 +784,7 @@ class database extends Step | ||
| 784 | while (!feof($handle)) { | 784 | while (!feof($handle)) { |
| 785 | $query.= fgets($handle, 4096); | 785 | $query.= fgets($handle, 4096); |
| 786 | if (substr(rtrim($query), -1) == ';') { | 786 | if (substr(rtrim($query), -1) == ';') { |
| 787 | - $this->_dbhandler->execute($query); | 787 | + $this->_dbhandler->query($query); |
| 788 | $query = ''; | 788 | $query = ''; |
| 789 | } | 789 | } |
| 790 | } | 790 | } |