Commit 7c0c0a5b0a85d67687fb76351609b211ab2b9e32

Authored by Megan Watson
2 parents 320167ce 6ac190cc

Merge branch 'edge' of git@github.com:ktgit/knowledgetree into edge

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,78 @@ class migrateDatabase extends Step @@ -147,26 +147,78 @@ 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 + $tmpFolder = $this->resolveTempDir();
  157 + if(WINDOWS_OS) {
  158 +// $tmpFolder = "tmp/";
  159 + $exe = "\"$location\mysql\bin\mysqldump.exe\""; // Location of dump
  160 + } else {
  161 +// $tmpFolder = "/tmp/";
  162 + $exe = "'$location/mysql/bin/mysqldump'"; // Location of dump
  163 + }
  164 + $sqlFile = $tmpFolder."/dms_migrate.sql";
  165 + $dbAdminUser = $dbSettings['dbAdminUser'];
  166 + $dbAdminPass = $dbSettings['dbAdminPass'];
  167 + $dbName = $dbSettings['dbName'];
  168 + $cmd = "$exe -u{$dbAdminUser} -p{$dbAdminPass} $dbName > ".$sqlFile;
  169 +// echo $cmd;
  170 +// die;
  171 + $response = $this->util->pexec($cmd);
  172 + if(file_exists($sqlFile)) {
  173 + $fileContents = file_get_contents($sqlFile);
  174 + if(!empty($fileContents)) {
  175 + $this->sqlDumpFile = realpath($sqlFile); // Store location of dump
  176 + return true;
  177 + }
  178 + }
154 } 179 }
155 - @mkdir($tmpFolder); 180 +
  181 + return false;
  182 + }
  183 +
  184 + // TODO
  185 +function resolveTempDir()
  186 +{
  187 +
  188 + if (!WINDOWS_OS)
  189 + {
  190 + $dir='/tmp/kt-db-backup';
  191 + }
  192 + else
  193 + {
  194 + $dir='c:/kt-db-backup';
  195 + }
  196 +// $oKTConfig =& KTConfig::getSingleton();
  197 +// $dir = $oKTConfig->get('backup/backupDirectory',$dir);
  198 +
  199 + if (!is_dir($dir))
  200 + {
  201 + mkdir($dir);
  202 + }
  203 + return $dir;
  204 +}
  205 +
  206 + public function doTest() {
  207 + return true;
156 $installation = $this->getDataFromSession("installation"); // Get installation directory 208 $installation = $this->getDataFromSession("installation"); // Get installation directory
157 $dbSettings = $installation['dbSettings']; 209 $dbSettings = $installation['dbSettings'];
  210 + $location = $installation['location'];
158 $uname = $this->temp_variables['duname']; 211 $uname = $this->temp_variables['duname'];
159 $pwrd = $this->temp_variables['dpassword']; 212 $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 - } 213 + //dmsadmin //clean1 // 3316 // TODO
  214 + $dbhandler = $this->util->loadInstallDBUtil();
  215 + $dbhandler->load("localhost:3316",$uname, $pwrd, "dms");
  216 + if (!$dbhandler->getDatabaseLink()) {
  217 + $this->error['con'] = "Could not connect to the database, please check username and password";
  218 + return false;
  219 + }
  220 +
  221 + return true;
170 } 222 }
171 223
172 /** 224 /**
@@ -180,6 +232,7 @@ class migrateDatabase extends Step @@ -180,6 +232,7 @@ class migrateDatabase extends Step
180 private function setDetails() { 232 private function setDetails() {
181 $this->temp_variables['duname'] = $this->getPostSafe('duname'); 233 $this->temp_variables['duname'] = $this->getPostSafe('duname');
182 $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword'); 234 $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword');
  235 + $this->temp_variables['dumpLocation'] = $this->getPostSafe('dumpLocation');
183 // create lock file to indicate migration mode 236 // create lock file to indicate migration mode
184 $this->createMigrateFile(); 237 $this->createMigrateFile();
185 } 238 }
@@ -245,5 +298,12 @@ class migrateDatabase extends Step @@ -245,5 +298,12 @@ class migrateDatabase extends Step
245 $this->error[$e] = false; 298 $this->error[$e] = false;
246 } 299 }
247 } 300 }
  301 +
  302 + private function storeSilent() {
  303 + // TODO
  304 + $_SESSION['database']['dumpLocation'] = $this->sqlDumpFile;
  305 + $this->temp_variables['dumpLocation'] = $this->sqlDumpFile;
  306 + }
  307 +
248 } 308 }
249 ?> 309 ?>
250 \ No newline at end of file 310 \ 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
@@ -2,31 +2,40 @@ @@ -2,31 +2,40 @@
2 <p class="title">Migrate Database</p> 2 <p class="title">Migrate Database</p>
3 <div id="database" class="step1" style="display:block;"> 3 <div id="database" class="step1" style="display:block;">
4 <div class="description"> 4 <div class="description">
5 - This step configures the connection to the database server and migrates the database. The details for an administrative <br/>  
6 - user on the database server are required in order to be able to configure and migrate the database. 5 + This step configures the connection to the database server and migrates the database.
  6 +<!-- The details for an administrative <br/>-->
  7 +<!-- user on the database server are required in order to be able to configure and migrate the database.-->
7 </div> 8 </div>
8 <div id="step_content_database" class="step"> 9 <div id="step_content_database" class="step">
  10 + <br/><br/>
  11 + <span class="error">!!NB!! You are advised to backup your database before proceeding. !!NB!!</span>
  12 +<!-- <span class="error"> <?php if($errors['con']) { echo $errors['con']."<br/><br/>"; } ?> </span>
  13 +
  14 +
  15 + <p class="empty_space">
  16 + Database Details
  17 + </p>
9 <table class="dbconf"> 18 <table class="dbconf">
10 <?php 19 <?php
11 - $input_size = '35';  
12 - $align = 'left'; 20 +// $input_size = '35';
  21 +// $align = 'left';
13 ?> 22 ?>
14 - <!-- TODO: Different Databases-->  
15 <tr> 23 <tr>
16 <td><label for='duname'>Enter Database Administrative username: </label></td> 24 <td><label for='duname'>Enter Database Administrative username: </label></td>
17 - <td><input type='text' value="<?php echo $duname?>" id='duname' name='duname' size='<?php echo $input_size; ?>' style="float:left"/></td>  
18 - <td id="error" class="error"><?php if($errors['duname']) echo $errors['duname']; ?></td> 25 + <td><input type='text' value="<?php //echo $duname?>" id='duname' name='duname' size='<?php //echo $input_size; ?>' style="float:left"/></td>
  26 + <td id="error" class="error"><?php //if($errors['duname']) echo $errors['duname']; ?></td>
19 </tr> 27 </tr>
20 <tr> 28 <tr>
21 <td><label for='dpassword'>Enter the password for the Administrator: </label></td> 29 <td><label for='dpassword'>Enter the password for the Administrator: </label></td>
22 - <td><input type='password' value="<?php echo $dpassword?>" id='dpassword' name='dpassword' size='<?php echo $input_size; ?>' style="float:left"/></td>  
23 - <td id="error" class="error"><?php if($errors['dpassword']) echo $errors['dpassword']; ?></td> 30 + <td><input type='password' value="<?php //echo $dpassword?>" id='dpassword' name='dpassword' size='<?php //echo $input_size; ?>' style="float:left"/></td>
  31 + <td id="error" class="error"><?php //if($errors['dpassword']) echo $errors['dpassword']; ?></td>
24 </tr> 32 </tr>
25 </table> 33 </table>
26 - </div> 34 + </div>-->
27 </div> 35 </div>
28 - <input type="button" name="Previous" value="previous" class="button_previous"/>  
29 - <input type="submit" name="Next" value="next" class="button_next"/> 36 + <input type="submit" name="Previous" value="Previous" class="button_previous"/>
  37 + <input type="submit" name="Next" value="Next" class="button_next"/>
  38 +<!-- <input type="submit" name="Backup" value="Backup" class="button_next"/>-->
30 </form> 39 </form>
31 <script type="text/javascript"> 40 <script type="text/javascript">
32 $("#duname").focus(); 41 $("#duname").focus();
setup/migrate/templates/installation.tpl
@@ -25,13 +25,11 @@ @@ -25,13 +25,11 @@
25 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://wiki.knowledgetree.com/Web_Based_Migrater#Current_Installation" target="_blank">Click here for help on overcoming installation detection issues</a> 25 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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/upgrade/index.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Upgrader Index. 3 +* Database Upgrader Index.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
setup/upgrade/step.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Step . 3 +* Step Controller.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
@@ -119,10 +119,10 @@ class Step @@ -119,10 +119,10 @@ class Step
119 { 119 {
120 // if not authenticated, return to step 1 120 // if not authenticated, return to step 1
121 if (!isset($_SESSION['setup_user'])) { 121 if (!isset($_SESSION['setup_user'])) {
122 - header('index.php?step=welcome'); 122 + header('Location: index.php?step=welcome');
123 exit; 123 exit;
124 } 124 }
125 - 125 +
126 return ''; 126 return '';
127 } 127 }
128 128
@@ -254,38 +254,31 @@ class Step @@ -254,38 +254,31 @@ class Step
254 254
255 return false; 255 return false;
256 } 256 }
257 -  
258 - /**  
259 - * Checks if Confirm button has been clicked  
260 - *  
261 - * @author KnowledgeTree Team  
262 - * @param none  
263 - * @access public  
264 - * @return boolean  
265 - */ 257 +
  258 + /**
  259 + * Checks if Upgrade button has been clicked
  260 + *
  261 + * @author KnowledgeTree Team
  262 + * @param none
  263 + * @access public
  264 + * @return boolean
  265 + */
266 function upgrade() { 266 function upgrade() {
267 - if(isset($_POST['Upgrade'])) {  
268 - return true;  
269 - }  
270 -  
271 - return false; 267 + return isset($_POST['Upgrade']);
272 } 268 }
273 -  
274 - /**  
275 - * Checks if Confirm button has been clicked  
276 - *  
277 - * @author KnowledgeTree Team  
278 - * @param none  
279 - * @access public  
280 - * @return boolean  
281 - */  
282 - function installer() {  
283 - if(isset($_POST['Install'])) {  
284 - return true;  
285 - }  
286 -  
287 - return false; 269 +
  270 + /**
  271 + * Checks if Upgrade button has been clicked
  272 + *
  273 + * @author KnowledgeTree Team
  274 + * @param none
  275 + * @access public
  276 + * @return boolean
  277 + */
  278 + function restore() {
  279 + return isset($_POST['Restore']);
288 } 280 }
  281 +
289 /** 282 /**
290 * Checks if we are currently in this class step 283 * Checks if we are currently in this class step
291 * 284 *
setup/upgrade/steps/upgradeBackup.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Complete Step Controller. 3 +* Backup Step Controller.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
@@ -52,12 +52,9 @@ class upgradeBackup extends Step { @@ -52,12 +52,9 @@ class upgradeBackup extends Step {
52 * @var object 52 * @var object
53 */ 53 */
54 private $_dbhandler = null; 54 private $_dbhandler = null;
55 -  
56 - private $privileges_check = 'tick';  
57 - private $database_check = 'tick';  
58 - protected $silent = true;  
59 -  
60 protected $util = null; 55 protected $util = null;
  56 + protected $silent = false;
  57 + protected $temp_variables = array();
61 58
62 public function __construct() { 59 public function __construct() {
63 $this->temp_variables = array("step_name"=>"backup", "silent"=>$this->silent); 60 $this->temp_variables = array("step_name"=>"backup", "silent"=>$this->silent);
@@ -65,7 +62,7 @@ class upgradeBackup extends Step { @@ -65,7 +62,7 @@ class upgradeBackup extends Step {
65 $this->util = new UpgradeUtil(); 62 $this->util = new UpgradeUtil();
66 } 63 }
67 64
68 - function doStep() { 65 + public function doStep() {
69 parent::doStep(); 66 parent::doStep();
70 if(!$this->inStep("backup")) { 67 if(!$this->inStep("backup")) {
71 $this->doRun(); 68 $this->doRun();
@@ -92,17 +89,21 @@ class upgradeBackup extends Step { @@ -92,17 +89,21 @@ class upgradeBackup extends Step {
92 else if($this->previous()) { 89 else if($this->previous()) {
93 return 'previous'; 90 return 'previous';
94 } 91 }
  92 + else if ($this->upgrade()) {
  93 + header('Location: index.php?step_name=database');
  94 + exit;
  95 + }
95 96
96 $this->doRun(); 97 $this->doRun();
97 return 'landing'; 98 return 'landing';
98 } 99 }
99 100
100 - function backupNow() 101 + private function backupNow()
101 { 102 {
102 return isset($_POST['BackupNow']); 103 return isset($_POST['BackupNow']);
103 } 104 }
104 105
105 - function doRun($action = null) { 106 + private function doRun($action = null) {
106 $this->temp_variables['action'] = $action; 107 $this->temp_variables['action'] = $action;
107 108
108 if (is_null($action) || ($action == 'confirm')) { 109 if (is_null($action) || ($action == 'confirm')) {
@@ -127,29 +128,7 @@ class upgradeBackup extends Step { @@ -127,29 +128,7 @@ class upgradeBackup extends Step {
127 private function storeSilent() { 128 private function storeSilent() {
128 } 129 }
129 130
130 - /*  
131 - // these belong in a shared lib  
132 - function set_state($value)  
133 -{  
134 - $_SESSION['state'] = $value;  
135 -}  
136 -function check_state($value, $state='Home')  
137 -{  
138 - if ($_SESSION['state'] != $value)  
139 - {  
140 - ?>  
141 - <script type="text/javascript">  
142 - document.location="?go=<?php echo $state;?>";  
143 - </script>  
144 - <?php  
145 - exit;  
146 - }  
147 -}  
148 -*/  
149 -  
150 private function backup() { 131 private function backup() {
151 -// $this->check_state(1);  
152 -// $this->set_state(2);  
153 $targetfile = $_SESSION['backupFile']; 132 $targetfile = $_SESSION['backupFile'];
154 $stmt = $this->create_backup_stmt($targetfile); 133 $stmt = $this->create_backup_stmt($targetfile);
155 $dir = $stmt['dir']; 134 $dir = $stmt['dir'];
@@ -163,7 +142,7 @@ function check_state($value, $state=&#39;Home&#39;) @@ -163,7 +142,7 @@ function check_state($value, $state=&#39;Home&#39;)
163 $read = fread($handle, 10240); 142 $read = fread($handle, 10240);
164 pclose($handle); 143 pclose($handle);
165 $_SESSION['backupOutput']=$read; 144 $_SESSION['backupOutput']=$read;
166 - $dir = $this->resolveTempDir(); 145 + $dir = $this->util->resolveTempDir();
167 $_SESSION['backupFile'] = $stmt['target']; 146 $_SESSION['backupFile'] = $stmt['target'];
168 147
169 if (OS_UNIX) { 148 if (OS_UNIX) {
@@ -177,21 +156,9 @@ function check_state($value, $state=&#39;Home&#39;) @@ -177,21 +156,9 @@ function check_state($value, $state=&#39;Home&#39;)
177 $_SESSION['backupStatus'] = false; 156 $_SESSION['backupStatus'] = false;
178 } 157 }
179 } 158 }
180 - else  
181 - {  
182 - ?>  
183 - <P>  
184 - The <i>mysqldump</i> utility was not found in the <?php echo $dir;?> subdirectory.  
185 -  
186 - &nbsp;&nbsp; &nbsp; &nbsp; <input type=button value="back" onclick="javascript:do_start('welcome')">  
187 - <?php  
188 - }  
189 } 159 }
190 160
191 private function backupDone() { 161 private function backupDone() {
192 -// $this->check_state(2);  
193 -// $this->set_state(3);  
194 -// title('Backup Status');  
195 $status = $_SESSION['backupStatus']; 162 $status = $_SESSION['backupStatus'];
196 $filename = $_SESSION['backupFile']; 163 $filename = $_SESSION['backupFile'];
197 164
@@ -200,7 +167,7 @@ function check_state($value, $state=&#39;Home&#39;) @@ -200,7 +167,7 @@ function check_state($value, $state=&#39;Home&#39;)
200 if ($status) 167 if ($status)
201 { 168 {
202 $stmt = $this->util->create_restore_stmt($filename); 169 $stmt = $this->util->create_restore_stmt($filename);
203 - $this->temp_variables['display'] = 'The backup file <nobr><i>"<?php echo $filename;?>"</i></nobr> has been created. 170 + $this->temp_variables['display'] = 'The backup file <nobr><i>"' . $filename . '"</i></nobr> has been created.
204 <P> It appears as though the <font color=green>backup has been successful</font>. 171 <P> It appears as though the <font color=green>backup has been successful</font>.
205 <P>'; 172 <P>';
206 if ($stmt['dir'] != '') 173 if ($stmt['dir'] != '')
@@ -230,136 +197,78 @@ function check_state($value, $state=&#39;Home&#39;) @@ -230,136 +197,78 @@ function check_state($value, $state=&#39;Home&#39;)
230 else 197 else
231 { 198 {
232 $this->temp_variables['display'] .= 'It appears as though <font color=red>the backup process has failed</font>.<P></P> Unfortunately, it is difficult to diagnose these problems automatically 199 $this->temp_variables['display'] .= 'It appears as though <font color=red>the backup process has failed</font>.<P></P> Unfortunately, it is difficult to diagnose these problems automatically
233 - and would recommend that you try to do the backup process manually.  
234 - <P>  
235 - We appologise for the inconvenience.  
236 - <P>  
237 - <table bgcolor="lightgrey">  
238 - <tr>  
239 - <td>' . $_SESSION['backupOutput'] . '</table>'; 200 + and would recommend that you try to do the backup process manually.
  201 + <P>
  202 + We appologise for the inconvenience.
  203 + <P>
  204 + <table bgcolor="lightgrey">
  205 + <tr>
  206 + <td>' . $_SESSION['backupOutput'] . '</table>';
240 } 207 }
241 -}  
242 -  
243 -function create_backup_stmt($targetfile=null)  
244 -{  
245 - $oKTConfig =& KTConfig::getSingleton();  
246 -  
247 - $adminUser = $oKTConfig->get('db/dbAdminUser');  
248 - $adminPwd = $oKTConfig->get('db/dbAdminPass');  
249 - $dbHost = $oKTConfig->get('db/dbHost');  
250 - $dbName = $oKTConfig->get('db/dbName');  
251 -  
252 - $dbPort = trim($oKTConfig->get('db/dbPort'));  
253 - if (empty($dbPort) || $dbPort=='default') $dbPort = get_cfg_var('mysql.default_port');  
254 - if (empty($dbPort)) $dbPort='3306';  
255 - $dbSocket = trim($oKTConfig->get('db/dbSocket'));  
256 - if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket');  
257 - if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock';  
258 -  
259 - $date=date('Y-m-d-H-i-s');  
260 -  
261 - $dir=$this->resolveMysqlDir();  
262 -  
263 - $info['dir']=$dir;  
264 -  
265 - $prefix='';  
266 - if (OS_UNIX)  
267 - {  
268 - $prefix .= "./";  
269 - }  
270 -  
271 - if (@stat($dbSocket) !== false)  
272 - {  
273 - $mechanism="--socket=\"$dbSocket\"";  
274 - }  
275 - else  
276 - {  
277 - $mechanism="--port=\"$dbPort\"";  
278 - }  
279 -  
280 - $tmpdir=$this->resolveTempDir();  
281 -  
282 - if (is_null($targetfile))  
283 - {  
284 - $targetfile="$tmpdir/kt-backup-$date.sql";  
285 - }  
286 -  
287 - $stmt = $prefix . "mysqldump --user=\"$adminUser\" -p $mechanism \"$dbName\" > \"$targetfile\"";  
288 - $info['display']=$stmt;  
289 - $info['target']=$targetfile;  
290 -  
291 -  
292 - $stmt = $prefix. "mysqldump --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" > \"$targetfile\"";  
293 - $info['cmd']=$stmt;  
294 - return $info;  
295 -}  
296 -  
297 -function resolveMysqlDir()  
298 -{  
299 - // possibly detect existing installations:  
300 -  
301 - if (OS_UNIX)  
302 - {  
303 - $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin');  
304 - $mysqlname ='mysql';  
305 - }  
306 - else  
307 - {  
308 - $dirs = explode(';', $_SERVER['PATH']);  
309 - $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin';  
310 - $dirs[] = 'c:/program files/ktdms/mysql/bin';  
311 - $mysqlname ='mysql.exe';  
312 - }  
313 -  
314 - $oKTConfig =& KTConfig::getSingleton();  
315 - $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir);  
316 - $dirs[] = $mysqldir;  
317 -  
318 - if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false)  
319 - {  
320 - $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin');  
321 } 208 }
322 209
323 - foreach($dirs as $dir) 210 + private function create_backup_stmt($targetfile=null)
324 { 211 {
325 - if (is_file($dir . '/' . $mysqlname)) 212 + $oKTConfig =& KTConfig::getSingleton();
  213 +
  214 + $adminUser = $oKTConfig->get('db/dbAdminUser');
  215 + $adminPwd = $oKTConfig->get('db/dbAdminPass');
  216 + $dbHost = $oKTConfig->get('db/dbHost');
  217 + $dbName = $oKTConfig->get('db/dbName');
  218 +
  219 + $dbPort = trim($oKTConfig->get('db/dbPort'));
  220 + if (empty($dbPort) || $dbPort=='default') $dbPort = get_cfg_var('mysql.default_port');
  221 + if (empty($dbPort)) $dbPort='3306';
  222 + $dbSocket = trim($oKTConfig->get('db/dbSocket'));
  223 + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket');
  224 + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock';
  225 +
  226 + $date=date('Y-m-d-H-i-s');
  227 +
  228 + $dir=$this->util->resolveMysqlDir();
  229 +
  230 + $info['dir']=$dir;
  231 +
  232 + $prefix='';
  233 + if (OS_UNIX)
326 { 234 {
327 - return $dir; 235 + $prefix .= "./";
328 } 236 }
  237 +
  238 + if (@stat($dbSocket) !== false)
  239 + {
  240 + $mechanism="--socket=\"$dbSocket\"";
  241 + }
  242 + else
  243 + {
  244 + $mechanism="--port=\"$dbPort\"";
  245 + }
  246 +
  247 + $tmpdir=$this->util->resolveTempDir();
  248 +
  249 + if (is_null($targetfile))
  250 + {
  251 + $targetfile="$tmpdir/kt-backup-$date.sql";
  252 + }
  253 +
  254 + $stmt = $prefix . "mysqldump --user=\"$adminUser\" -p $mechanism \"$dbName\" > \"$targetfile\"";
  255 + $info['display']=$stmt;
  256 + $info['target']=$targetfile;
  257 +
  258 +
  259 + $stmt = $prefix. "mysqldump --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" > \"$targetfile\"";
  260 + $info['cmd']=$stmt;
  261 + return $info;
329 } 262 }
330 263
331 - return '';  
332 -}  
333 -  
334 -function resolveTempDir()  
335 -{  
336 - if (OS_UNIX) {  
337 - $dir='/tmp/kt-db-backup';  
338 - }  
339 - else {  
340 - $dir='c:/kt-db-backup';  
341 - }  
342 - $oKTConfig =& KTConfig::getSingleton();  
343 - $dir = $oKTConfig->get('backup/backupDirectory',$dir);  
344 -  
345 - if (!is_dir($dir)) {  
346 - mkdir($dir); 264 + private function backupConfirm()
  265 + {
  266 + $stmt = $this->create_backup_stmt();
  267 + $_SESSION['backupFile'] = $stmt['target'];
  268 +
  269 + $dir = $stmt['dir'];
  270 + $this->temp_variables['dir'] = $dir;
  271 + $this->temp_variables['display'] = $stmt['display'];
347 } 272 }
348 - return $dir;  
349 -}  
350 -  
351 -  
352 -function backupConfirm()  
353 -{  
354 - $stmt = $this->create_backup_stmt();  
355 - $_SESSION['backupFile'] = $stmt['target'];  
356 -  
357 - $dir = $stmt['dir'];  
358 - $this->temp_variables['dir'] = $dir;  
359 - $this->temp_variables['display'] = $stmt['display'];  
360 -}  
361 -  
362 -  
363 -  
364 } 273 }
365 ?> 274 ?>
366 \ No newline at end of file 275 \ No newline at end of file
setup/upgrade/steps/upgradeComplete.php
@@ -44,20 +44,20 @@ require &#39;../../config/dmsDefaults.php&#39;; @@ -44,20 +44,20 @@ require &#39;../../config/dmsDefaults.php&#39;;
44 44
45 class upgradeComplete extends Step { 45 class upgradeComplete extends Step {
46 46
47 - protected $silent = true;  
48 -  
49 protected $util = null; 47 protected $util = null;
  48 + protected $silent = false;
  49 + protected $temp_variables = array();
50 50
51 public function __construct() { 51 public function __construct() {
52 $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); 52 $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent);
53 } 53 }
54 54
55 - function doStep() { 55 + public function doStep() {
56 $this->doRun(); 56 $this->doRun();
57 return 'landing'; 57 return 'landing';
58 } 58 }
59 59
60 - function doRun() { 60 + private function doRun() {
61 $this->storeSilent();// Set silent mode variables 61 $this->storeSilent();// Set silent mode variables
62 } 62 }
63 63
setup/upgrade/steps/upgradeDatabase.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Database Step Controller. 3 +* Upgrade Step Controller.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
@@ -40,7 +40,6 @@ @@ -40,7 +40,6 @@
40 * @version Version 0.1 40 * @version Version 0.1
41 */ 41 */
42 42
43 -// include defaults  
44 require '../../config/dmsDefaults.php'; 43 require '../../config/dmsDefaults.php';
45 require_once KT_LIB_DIR . '/config/config.inc.php'; 44 require_once KT_LIB_DIR . '/config/config.inc.php';
46 require_once KT_LIB_DIR . '/plugins/pluginutil.inc.php'; 45 require_once KT_LIB_DIR . '/plugins/pluginutil.inc.php';
@@ -67,105 +66,6 @@ class upgradeDatabase extends Step @@ -67,105 +66,6 @@ class upgradeDatabase extends Step
67 public $_util = null; 66 public $_util = null;
68 67
69 /** 68 /**
70 - * Database type  
71 - *  
72 - * @author KnowledgeTree Team  
73 - * @access private  
74 - * @var array  
75 - */  
76 - private $dtype = '';  
77 -  
78 - /**  
79 - * Database types  
80 - *  
81 - * @author KnowledgeTree Team  
82 - * @access private  
83 - * @var array  
84 - */  
85 - private $dtypes = array();  
86 -  
87 - /**  
88 - * Database host  
89 - *  
90 - * @author KnowledgeTree Team  
91 - * @access private  
92 - * @var string  
93 - */  
94 - private $dhost = '';  
95 -  
96 - /**  
97 - * Database port  
98 - *  
99 - * @author KnowledgeTree Team  
100 - * @access private  
101 - * @var string  
102 - */  
103 - private $dport = '';  
104 -  
105 - /**  
106 - * Database name  
107 - *  
108 - * @author KnowledgeTree Team  
109 - * @access private  
110 - * @var string  
111 - */  
112 - private $dname = '';  
113 -  
114 - /**  
115 - * Database root username  
116 - *  
117 - * @author KnowledgeTree Team  
118 - * @access private  
119 - * @var string  
120 - */  
121 - private $duname = '';  
122 -  
123 - /**  
124 - * Database root password  
125 - *  
126 - * @author KnowledgeTree Team  
127 - * @access private  
128 - * @var string  
129 - */  
130 - private $dpassword = '';  
131 -  
132 - /**  
133 - * Database dms username  
134 - *  
135 - * @author KnowledgeTree Team  
136 - * @access private  
137 - * @var string  
138 - */  
139 - private $dmsname = '';  
140 -  
141 - /**  
142 - * Database dms password  
143 - *  
144 - * @author KnowledgeTree Team  
145 - * @access private  
146 - * @var string  
147 - */  
148 - private $dmspassword = '';  
149 -  
150 - /**  
151 - * Default dms user username  
152 - *  
153 - * @author KnowledgeTree Team  
154 - * @access private  
155 - * @var boolean  
156 - */  
157 - private $dmsusername = '';  
158 -  
159 - /**  
160 - * Default dms user password  
161 - *  
162 - * @author KnowledgeTree Team  
163 - * @access private  
164 - * @var boolean  
165 - */  
166 - private $dmsuserpassword = '';  
167 -  
168 - /**  
169 * Location of database binaries. 69 * Location of database binaries.
170 * 70 *
171 * @author KnowledgeTree Team 71 * @author KnowledgeTree Team
@@ -181,25 +81,7 @@ class upgradeDatabase extends Step @@ -181,25 +81,7 @@ class upgradeDatabase extends Step
181 * @access private 81 * @access private
182 * @var string 82 * @var string
183 */ 83 */
184 - private $dbbinary = ''; // TODO:multiple databases  
185 -  
186 - /**  
187 - * Database table prefix  
188 - *  
189 - * @author KnowledgeTree Team  
190 - * @access private  
191 - * @var string  
192 - */  
193 - private $tprefix = '';  
194 -  
195 - /**  
196 - * Flag to drop database  
197 - *  
198 - * @author KnowledgeTree Team  
199 - * @access private  
200 - * @var boolean  
201 - */  
202 - private $ddrop = false; 84 + private $dbBinary = ''; // TODO:multiple databases
203 85
204 /** 86 /**
205 * List of errors encountered 87 * List of errors encountered
@@ -228,26 +110,11 @@ class upgradeDatabase extends Step @@ -228,26 +110,11 @@ class upgradeDatabase extends Step
228 */ 110 */
229 public $storeInSession = true; 111 public $storeInSession = true;
230 112
231 - /**  
232 - * Flag if step needs to be upgraded  
233 - *  
234 - * @author KnowledgeTree Team  
235 - * @access public  
236 - * @var array  
237 - */  
238 - protected $runUpgrade = true;  
239 -  
240 - /**  
241 - * Flag if step needs to run silently  
242 - *  
243 - * @author KnowledgeTree Team  
244 - * @access public  
245 - * @var array  
246 - */  
247 - protected $silent = true; 113 + protected $silent = false;
  114 + protected $temp_variables = array();
248 115
249 /** 116 /**
250 - * Constructs database object 117 + * Constructs database upgrade object
251 * 118 *
252 * @author KnowledgeTree Team 119 * @author KnowledgeTree Team
253 * @access public 120 * @access public
@@ -272,12 +139,12 @@ class upgradeDatabase extends Step @@ -272,12 +139,12 @@ class upgradeDatabase extends Step
272 public function doStep() { 139 public function doStep() {
273 parent::doStep(); 140 parent::doStep();
274 $this->initErrors(); 141 $this->initErrors();
275 - $this->setDetails(); // Set any posted variables  
276 -// if(!$this->inStep("database")) {  
277 -// $this->doRun();  
278 -// return 'landing';  
279 -// } 142 + if(!$this->inStep("database")) {
  143 + $this->doRun();
  144 + return 'landing';
  145 + }
280 if($this->next()) { 146 if($this->next()) {
  147 + $this->doRun('preview');
281 return 'next'; 148 return 'next';
282 } else if($this->previous()) { 149 } else if($this->previous()) {
283 return 'previous'; 150 return 'previous';
@@ -297,15 +164,15 @@ class upgradeDatabase extends Step @@ -297,15 +164,15 @@ class upgradeDatabase extends Step
297 return 'landing'; 164 return 'landing';
298 } 165 }
299 166
300 - function confirmUpgrade() { 167 + private function confirmUpgrade() {
301 return isset($_POST['ConfirmUpgrade']); 168 return isset($_POST['ConfirmUpgrade']);
302 } 169 }
303 170
304 - function upgrading() { 171 + private function upgrading() {
305 return isset($_POST['RunUpgrade']); 172 return isset($_POST['RunUpgrade']);
306 } 173 }
307 174
308 - function doRun($action = null) { 175 + private function doRun($action = null) {
309 $this->readConfig(KTConfig::getConfigFilename()); 176 $this->readConfig(KTConfig::getConfigFilename());
310 177
311 if($this->dbSettings['dbPort'] == '') { 178 if($this->dbSettings['dbPort'] == '') {
@@ -327,8 +194,7 @@ class upgradeDatabase extends Step @@ -327,8 +194,7 @@ class upgradeDatabase extends Step
327 } 194 }
328 else if ($action == 'runUpgrade') { 195 else if ($action == 'runUpgrade') {
329 $this->temp_variables['title'] = 'Upgrade In Progress'; 196 $this->temp_variables['title'] = 'Upgrade In Progress';
330 - if (!$this->upgrade()) {  
331 -// $this->temp_variables['upgradeTable'] = '';//$this->upgradeErrors(); 197 + if (!$this->upgradeDatabase()) {
332 return false; 198 return false;
333 } 199 }
334 } 200 }
@@ -336,7 +202,7 @@ class upgradeDatabase extends Step @@ -336,7 +202,7 @@ class upgradeDatabase extends Step
336 return true; 202 return true;
337 } 203 }
338 204
339 - public function generateUpgradeTable() { 205 + private function generateUpgradeTable() {
340 global $default; 206 global $default;
341 207
342 $this->temp_variables['systemVersion'] = $default->systemVersion; 208 $this->temp_variables['systemVersion'] = $default->systemVersion;
@@ -359,7 +225,7 @@ class upgradeDatabase extends Step @@ -359,7 +225,7 @@ class upgradeDatabase extends Step
359 $ret .= sprintf("<tr bgcolor='$color'><td>%s</td><td>%s</td><td>%s</td></tr>\n", 225 $ret .= sprintf("<tr bgcolor='$color'><td>%s</td><td>%s</td><td>%s</td></tr>\n",
360 htmlspecialchars($upgrade->getDescriptor()), 226 htmlspecialchars($upgrade->getDescriptor()),
361 htmlspecialchars($upgrade->getDescription()), 227 htmlspecialchars($upgrade->getDescription()),
362 - $upgrade->isAlreadyApplied() ? "Yes" : "No" 228 + $upgrade->isAlreadyApplied() ? "Yes" : "No"
363 ); 229 );
364 } 230 }
365 $ret .= '</table>'; 231 $ret .= '</table>';
@@ -367,42 +233,6 @@ class upgradeDatabase extends Step @@ -367,42 +233,6 @@ class upgradeDatabase extends Step
367 } 233 }
368 234
369 /** 235 /**
370 - * Store options  
371 - *  
372 - * @author KnowledgeTree Team  
373 - * @params object SimpleXmlObject  
374 - * @access private  
375 - * @return void  
376 - */  
377 - private function setDetails() {  
378 - // create lock file to indicate Upgrade mode  
379 - $this->createUpgradeFile();  
380 - }  
381 -  
382 - /**  
383 - * Creates miUpgradeock file so that system knows it is supposed to run an upgrade installation  
384 - *  
385 - * @author KnowledgeTree Team  
386 - * @access private  
387 - * @return void  
388 - */  
389 - private function createUpgradeFile() {  
390 - @touch($this->wizardLocation . DIRECTORY_SEPARATOR . "upgrade.lock");  
391 - }  
392 -  
393 - /**  
394 - * Safer way to return post data  
395 - *  
396 - * @author KnowledgeTree Team  
397 - * @params SimpleXmlObject $simplexml  
398 - * @access public  
399 - * @return void  
400 - */  
401 - public function getPostSafe($key) {  
402 - return isset($_POST[$key]) ? $_POST[$key] : "";  
403 - }  
404 -  
405 - /**  
406 * Stores varibles used by template 236 * Stores varibles used by template
407 * 237 *
408 * @author KnowledgeTree Team 238 * @author KnowledgeTree Team
@@ -455,7 +285,7 @@ class upgradeDatabase extends Step @@ -455,7 +285,7 @@ class upgradeDatabase extends Step
455 $this->temp_variables['dbSettings'] = $this->dbSettings; 285 $this->temp_variables['dbSettings'] = $this->dbSettings;
456 } 286 }
457 287
458 - function upgradeConfirm() 288 + private function upgradeConfirm()
459 { 289 {
460 if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) { 290 if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) {
461 $this->temp_variables['backupStatus'] = false; 291 $this->temp_variables['backupStatus'] = false;
@@ -465,158 +295,148 @@ class upgradeDatabase extends Step @@ -465,158 +295,148 @@ class upgradeDatabase extends Step
465 } 295 }
466 } 296 }
467 297
468 -  
469 -function upgrade()  
470 -{  
471 - global $default; 298 + private function upgradeDatabase()
  299 + {
  300 + global $default;
  301 +
  302 + $this->temp_variables['detail'] = '<p>The table below describes the upgrades that have occurred to
  303 + upgrade your KnowledgeTree installation to <strong>' . $default->systemVersion . '</strong>';
  304 +
  305 + $pre_res = $this->performPreUpgradeActions();
  306 + if (PEAR::isError($pre_res)) {
  307 + $this->temp_variables['preUpgrade'] = '<font color="red">Pre-Upgrade actions failed.</font>';
  308 + }
  309 + else {
  310 + $this->temp_variables['preUpgrade'] = '<font color="green">Pre-Upgrade actions succeeded.</font>';
472 311
473 - $this->temp_variables['detail'] = '<p>The table below describes the upgrades that have occurred to  
474 - upgrade your KnowledgeTree installation to <strong>' . $default->systemVersion . '</strong>';  
475 -?>  
476 - <p>  
477 -  
478 -<?php  
479 -  
480 - $pre_res = $this->performPreUpgradeActions();  
481 - if (PEAR::isError($pre_res)) {  
482 - $this->temp_variables['preUpgrade'] = '<font color="red">Pre-Upgrade actions failed.</font>';  
483 - }  
484 - else {  
485 - $this->temp_variables['preUpgrade'] = '<font color="green">Pre-Upgrade actions succeeded.</font>';  
486 - 312 + }
  313 +
  314 + $res = $this->performAllUpgrades();
  315 + if (PEAR::isError($res) || PEAR::isError($pres)) {
  316 + // TODO instantiate error details hideable section
  317 + $this->temp_variables['upgradeStatus'] = '<font color="red">Database upgrade failed</font><!--:
  318 + click here for error details-->
  319 + <br/><br/>
  320 + Please restore from your backup and ensure that the database does not contain
  321 + any unsupported modifications and try the upgrade process again.
  322 + <br/><br/>
  323 + If the problem persists, contact KnowledgeTree Support.';
  324 + }
  325 + else {
  326 + $this->temp_variables['upgradeStatus'] = '<font color="green">Upgrade succeeded.</font>';
  327 + }
  328 +
  329 + $post_pres = $this->performPostUpgradeActions();
  330 + if (PEAR::isError($post_res)) {
  331 + $this->temp_variables['postUpgrade'] = '<font color="red">Post-Upgrade actions failed.</font>';
  332 + }
  333 + else {
  334 + $this->temp_variables['postUpgrade'] = '<font color="green">Post-Upgrade actions succeeded.</font>';
  335 + }
487 } 336 }
488 - ?>  
489 - <br/>  
490 337
491 -<p>  
492 - <?php  
493 -?>  
494 -<p>  
495 -<?php  
496 - $res = $this->performAllUpgrades();  
497 - if (PEAR::isError($res) || PEAR::isError($pres)) {  
498 - $this->temp_variables['upgradeStatus'] = '<font color="red">Upgrade failed.</font>';  
499 - }  
500 - else {  
501 - $this->temp_variables['upgradeStatus'] = '<font color="green">Upgrade succeeded.</font>';  
502 - }  
503 -?>  
504 -<p>  
505 -  
506 -<p>  
507 - <?php  
508 - $post_pres = $this->performPostUpgradeActions();  
509 - if (PEAR::isError($post_res)) {  
510 - $this->temp_variables['postUpgrade'] = '<font color="red">Post-Upgrade actions failed.</font>';  
511 - }  
512 - else {  
513 - $this->temp_variables['postUpgrade'] = '<font color="green">Post-Upgrade actions succeeded.</font>'; 338 + private function performPreUpgradeActions() {
  339 +
  340 + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
  341 + // It should idealy work the same as the upgrades.
  342 +
  343 + global $default;
  344 +
  345 + // Lock the scheduler
  346 + $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
  347 + touch($lockFile);
  348 + return true;
  349 +
514 } 350 }
515 -}  
516 -  
517 -function performPreUpgradeActions() {  
518 -  
519 - // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.  
520 - // It should idealy work the same as the upgrades.  
521 -  
522 - global $default;  
523 -  
524 - // Lock the scheduler  
525 - $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';  
526 - touch($lockFile);  
527 - return true;  
528 -  
529 -}  
530 -  
531 -function performPostUpgradeActions() {  
532 -  
533 - // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.  
534 - // It should idealy work the same as the upgrades.  
535 -  
536 - global $default;  
537 -  
538 - // Ensure all plugins are re-registered.  
539 - $sql = "TRUNCATE plugin_helper";  
540 - $res = DBUtil::runQuery($sql);  
541 -  
542 - // Clear out all caches and proxies - they need to be regenerated with the new code  
543 - $proxyDir = $default->proxyCacheDirectory;  
544 - KTUtil::deleteDirectory($proxyDir);  
545 -  
546 - $oKTCache = new KTCache();  
547 - $oKTCache->deleteAllCaches();  
548 -  
549 - // Clear the configuration cache, it'll regenerate on next load  
550 - $oKTConfig = new KTConfig();  
551 - $oKTConfig->clearCache();  
552 -  
553 - // Unlock the scheduler  
554 - $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';  
555 - if(file_exists($lockFile)){  
556 - @unlink($lockFile); 351 +
  352 + private function performPostUpgradeActions() {
  353 +
  354 + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
  355 + // It should idealy work the same as the upgrades.
  356 +
  357 + global $default;
  358 +
  359 + // Ensure all plugins are re-registered.
  360 + $sql = "TRUNCATE plugin_helper";
  361 + $res = DBUtil::runQuery($sql);
  362 +
  363 + // Clear out all caches and proxies - they need to be regenerated with the new code
  364 + $proxyDir = $default->proxyCacheDirectory;
  365 + KTUtil::deleteDirectory($proxyDir);
  366 +
  367 + $oKTCache = new KTCache();
  368 + $oKTCache->deleteAllCaches();
  369 +
  370 + // Clear the configuration cache, it'll regenerate on next load
  371 + $oKTConfig = new KTConfig();
  372 + $oKTConfig->clearCache();
  373 +
  374 + // Unlock the scheduler
  375 + $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
  376 + if(file_exists($lockFile)){
  377 + @unlink($lockFile);
  378 + }
  379 +
  380 + return true;
  381 +
557 } 382 }
558 383
559 - return true;  
560 -  
561 -}  
562 -  
563 -function performAllUpgrades () {  
564 - global $default;  
565 - $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);  
566 - $lastVersion = DBUtil::getOneResultKey($query, 'value');  
567 - $currentVersion = $default->systemVersion;  
568 -  
569 - $upgrades = describeUpgrade($lastVersion, $currentVersion); 384 + private function performAllUpgrades () {
  385 + global $default;
  386 +
  387 + $row = 1;
  388 +
  389 + $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
  390 + $lastVersion = DBUtil::getOneResultKey($query, 'value');
  391 + $currentVersion = $default->systemVersion;
570 392
571 - $this->temp_variables['upgradeTable'] = '';  
572 -  
573 - foreach ($upgrades as $upgrade) {  
574 - if (($GLOBALS['row'] % 2) == 1) {  
575 - $class = "odd";  
576 - } else {  
577 - $class = "even"; 393 + $upgrades = describeUpgrade($lastVersion, $currentVersion);
  394 +
  395 + $this->temp_variables['upgradeTable'] = '';
  396 +
  397 + foreach ($upgrades as $upgrade) {
  398 + if (($row % 2) == 1) {
  399 + $class = "odd";
  400 + } else {
  401 + $class = "even";
  402 + }
  403 + $this->temp_variables['upgradeTable'] .= sprintf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, htmlspecialchars($upgrade->getDescription()));
  404 + ++$row;
  405 + $res = $upgrade->performUpgrade();
  406 + $this->temp_variables['upgradeTable'] .= sprintf('<div class="bar">%s</div>', $this->showResult($res));
  407 + $this->temp_variables['upgradeTable'] .= '<br style="clear: both">' . "\n";
  408 + $this->temp_variables['upgradeTable'] .= "</div>\n";
  409 + if (PEAR::isError($res)) {
  410 + if (!is_a($res, 'Upgrade_Already_Applied')) {
  411 + break;
  412 + } else {
  413 + $res = true;
  414 + }
  415 + }
  416 + if ($res === false) {
  417 + $res = PEAR::raiseError("Upgrade returned false");
  418 + break;
  419 + }
578 } 420 }
579 - $this->temp_variables['upgradeTable'] .= sprintf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, htmlspecialchars($upgrade->getDescription()));  
580 - $GLOBALS['row']++;  
581 - ob_flush();  
582 - flush();  
583 - $res = $upgrade->performUpgrade();  
584 - $this->temp_variables['upgradeTable'] .= sprintf('<div class="bar">%s</div>', $this->showResult($res));  
585 - $this->temp_variables['upgradeTable'] .= '<br style="clear: both">' . "\n";  
586 - ob_flush();  
587 - flush();  
588 - $this->temp_variables['upgradeTable'] .= "</div>\n"; 421 +
  422 + return $res;
  423 + }
  424 +
  425 + private function showResult($res) {
589 if (PEAR::isError($res)) { 426 if (PEAR::isError($res)) {
590 - if (!is_a($res, 'Upgrade_Already_Applied')) {  
591 - break;  
592 - } else {  
593 - $res = true; 427 + if (is_a($res, 'Upgrade_Already_Applied')) {
  428 + return '<span style="color: orange">Already applied</span>';
594 } 429 }
  430 + return sprintf('<span style="color: red">%s</span>', htmlspecialchars($res->toString()));
595 } 431 }
596 - if ($res === false) {  
597 - $res = PEAR::raiseError("Upgrade returned false");  
598 - break; 432 + if ($res === true) {
  433 + return '<span style="color: green">Success</span>';
599 } 434 }
600 - }  
601 -  
602 - return $res;  
603 -}  
604 -  
605 -function showResult($res) {  
606 - if (PEAR::isError($res)) {  
607 - if (is_a($res, 'Upgrade_Already_Applied')) {  
608 - return '<span style="color: orange">Already applied</span>'; 435 + if ($res === false) {
  436 + return '<span style="color: red">Failure</span>';
609 } 437 }
610 - return sprintf('<span style="color: red">%s</span>', htmlspecialchars($res->toString())); 438 + return $res;
611 } 439 }
612 - if ($res === true) {  
613 - return '<span style="color: green">Success</span>';  
614 - }  
615 - if ($res === false) {  
616 - return '<span style="color: red">Failure</span>';  
617 - }  
618 - return $res;  
619 -}  
620 440
621 } 441 }
622 ?> 442 ?>
623 \ No newline at end of file 443 \ No newline at end of file
setup/upgrade/steps/upgradeInstallation.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Upgrade Step Controller. 3 +* Notification Controller.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
@@ -50,12 +50,13 @@ class UpgradeInstallation extends step @@ -50,12 +50,13 @@ class UpgradeInstallation extends step
50 * @var array 50 * @var array
51 */ 51 */
52 protected $silent = false; 52 protected $silent = false;
  53 + protected $temp_variables = array();
53 54
54 - function __construct() { 55 + public function __construct() {
55 $this->temp_variables = array("step_name"=>"installation"); 56 $this->temp_variables = array("step_name"=>"installation");
56 } 57 }
57 58
58 - function doStep() { 59 + public function doStep() {
59 parent::doStep(); 60 parent::doStep();
60 if($this->next()) { 61 if($this->next()) {
61 return 'next'; 62 return 'next';
@@ -72,13 +73,5 @@ class UpgradeInstallation extends step @@ -72,13 +73,5 @@ class UpgradeInstallation extends step
72 return 'landing'; 73 return 'landing';
73 } 74 }
74 75
75 - function backup() {  
76 - return isset($_POST['Backup']);  
77 - }  
78 -  
79 - function restore() {  
80 - return isset($_POST['Restore']);  
81 - }  
82 -  
83 } 76 }
84 ?> 77 ?>
85 \ No newline at end of file 78 \ No newline at end of file
setup/upgrade/steps/upgradeRestore.php
1 <?php 1 <?php
2 /** 2 /**
3 -* Complete Step Controller. 3 +* Restore Step Controller.
4 * 4 *
5 * KnowledgeTree Community Edition 5 * KnowledgeTree Community Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
@@ -53,10 +53,8 @@ class upgradeRestore extends Step { @@ -53,10 +53,8 @@ class upgradeRestore extends Step {
53 */ 53 */
54 private $_dbhandler = null; 54 private $_dbhandler = null;
55 55
56 - private $privileges_check = 'tick';  
57 - private $database_check = 'tick';  
58 - protected $silent = true;  
59 - 56 + protected $silent = false;
  57 + protected $temp_variables = array();
60 protected $util = null; 58 protected $util = null;
61 59
62 public function __construct() { 60 public function __construct() {
@@ -65,8 +63,10 @@ class upgradeRestore extends Step { @@ -65,8 +63,10 @@ class upgradeRestore extends Step {
65 $this->util = new UpgradeUtil(); 63 $this->util = new UpgradeUtil();
66 } 64 }
67 65
68 - function doStep() { 66 + public function doStep() {
69 parent::doStep(); 67 parent::doStep();
  68 + $this->temp_variables['restore'] = false;
  69 +
70 if(!$this->inStep("restore")) { 70 if(!$this->inStep("restore")) {
71 $this->doRun(); 71 $this->doRun();
72 return 'landing'; 72 return 'landing';
@@ -78,24 +78,40 @@ class upgradeRestore extends Step { @@ -78,24 +78,40 @@ class upgradeRestore extends Step {
78 } else if($this->previous()) { 78 } else if($this->previous()) {
79 return 'previous'; 79 return 'previous';
80 } 80 }
  81 + else if ($this->restoreNow()) {
  82 + $this->temp_variables['restoreSuccessful'] = false;
  83 + $this->doRun(true);
  84 + return 'next';
  85 + }
81 86
82 $this->doRun(); 87 $this->doRun();
83 return 'landing'; 88 return 'landing';
84 } 89 }
85 90
86 - function doRun() {  
87 - $this->temp_variables['selected'] = false;  
88 - if ($this->select()) {  
89 - $this->restoreSelected();  
90 - $this->temp_variables['selected'] = true; 91 + private function restoreNow() {
  92 + return isset($_POST['RunRestore']);
  93 + }
  94 +
  95 + private function doRun($restore = false) {
  96 + if (!$restore) {
  97 + $this->temp_variables['selected'] = false;
  98 + if ($this->select()) {
  99 + $this->restoreSelected();
  100 + $this->temp_variables['selected'] = true;
  101 + $this->temp_variables['availableBackups'] = true;
  102 + }
  103 + $this->restoreConfirm();
  104 + } // end not running a restore, just setting up
  105 + else {
  106 + $this->restoreDatabase();
91 } 107 }
92 - $this->restoreConfirm(); 108 +
93 $this->storeSilent();// Set silent mode variables 109 $this->storeSilent();// Set silent mode variables
94 110
95 return true; 111 return true;
96 } 112 }
97 113
98 - function select() { 114 + private function select() {
99 return isset($_POST['RestoreSelect']); 115 return isset($_POST['RestoreSelect']);
100 } 116 }
101 117
@@ -105,183 +121,126 @@ class upgradeRestore extends Step { @@ -105,183 +121,126 @@ class upgradeRestore extends Step {
105 */ 121 */
106 private function storeSilent() { 122 private function storeSilent() {
107 } 123 }
108 - /*  
109 - // these belong in a shared lib  
110 - function set_state($value)  
111 -{  
112 - $_SESSION['state'] = $value;  
113 -}  
114 -function check_state($value, $state='Home')  
115 -{  
116 - if ($_SESSION['state'] != $value)  
117 - {  
118 - ?>  
119 - <script type="text/javascript">  
120 - document.location="?go=<?php echo $state;?>";  
121 - </script>  
122 - <?php  
123 - exit;  
124 - }  
125 -}  
126 -*/  
127 - function restore()  
128 -{  
129 -// check_state(1);  
130 -// set_state(5);  
131 -// title('Restore In Progress');  
132 - $status = $_SESSION['backupStatus'];  
133 - $filename = $_SESSION['backupFile'];  
134 - $stmt = $this->util->create_restore_stmt($filename);  
135 - $dir = $stmt['dir'];  
136 124
137 - if (is_file($dir . '/mysql') || is_file($dir . '/mysql.exe')) 125 + private function restoreDatabase()
138 { 126 {
139 -  
140 -?>  
141 - The restore is now underway. Please wait till it completes.  
142 -<?php  
143 - print "\n";  
144 -  
145 -  
146 - $curdir=getcwd();  
147 - chdir($dir);  
148 -  
149 -  
150 - $ok=true;  
151 - $stmts=explode("\n",$stmt['cmd']);  
152 - foreach($stmts as $stmt) 127 + $this->temp_variables['restore'] = true;
  128 + $status = $_SESSION['backupStatus'];
  129 + $filename = $_SESSION['backupFile'];
  130 + $stmt = $this->util->create_restore_stmt($filename);
  131 + $dir = $stmt['dir'];
  132 +
  133 + if (is_file($dir . '/mysql') || is_file($dir . '/mysql.exe'))
153 { 134 {
154 -  
155 - $handle = popen($stmt, 'r');  
156 - if ($handle=='false') 135 + $curdir=getcwd();
  136 + chdir($dir);
  137 +
  138 + $ok=true;
  139 + $stmts=explode("\n",$stmt['cmd']);
  140 + foreach($stmts as $stmt)
157 { 141 {
158 - $ok=false;  
159 - break; 142 +
  143 + $handle = popen($stmt, 'r');
  144 + if ($handle=='false')
  145 + {
  146 + $ok=false;
  147 + break;
  148 + }
  149 + $read = fread($handle, 10240);
  150 + pclose($handle);
  151 + $_SESSION['restoreOutput']=$read;
160 } 152 }
161 - $read = fread($handle, 10240);  
162 - pclose($handle);  
163 - $_SESSION['restoreOutput']=$read;  
164 - }  
165 - 153 +
166 $_SESSION['restoreStatus'] = $ok; 154 $_SESSION['restoreStatus'] = $ok;
167 -  
168 - }  
169 - else  
170 - {  
171 -?>  
172 -<P>  
173 - The <i>mysql</i> utility was not found in the <?php echo $dir;?> subdirectory.  
174 -  
175 -&nbsp;&nbsp; &nbsp; &nbsp; <input type=button value="back" onclick="javascript:do_start('welcome')">  
176 -<?php 155 + // should be some sort of error checking, really
  156 + $this->restoreDone();
  157 + }
177 } 158 }
178 159
179 -}  
180 -  
181 -  
182 -function restoreDone()  
183 -{  
184 -// check_state(5);  
185 -// set_state(6);  
186 -// title('Restore Status');  
187 - $status = $_SESSION['restoreStatus'];  
188 - $filename = $_SESSION['backupFile'];  
189 -  
190 - if ($status)  
191 - {  
192 -  
193 -?>  
194 - The restore of <nobr><i>"<?php echo $filename;?>"</i></nobr> has been completed.  
195 - <P>  
196 - It appears as though the <font color=green>restore has been successful</font>.  
197 - <P>  
198 -  
199 -  
200 -  
201 -<?php  
202 - }  
203 - else 160 + private function restoreDone()
204 { 161 {
205 -?>  
206 -It appears as though <font color=red>the restore process has failed</font>. <P>  
207 -Unfortunately, it is difficult to diagnose these problems automatically  
208 -and would recommend that you try to do the backup process manually.  
209 -<P>  
210 -We appologise for the inconvenience.  
211 -<P>  
212 -<table bgcolor="lightgrey">  
213 -<tr>  
214 -<td>  
215 -<?php echo $_SESSION['restoreOutput'];?>  
216 -</table>  
217 -<?php  
218 - 162 + $status = $_SESSION['restoreStatus'];
  163 + $filename = $_SESSION['backupFile'];
  164 +
  165 + if ($status)
  166 + {
  167 + $this->temp_variables['display'] = 'The restore of <nobr><i>"' . $filename . '"</i></nobr> has been completed.
  168 + <P>
  169 + It appears as though the <font color=green>restore has been successful</font>.
  170 + <P>';
  171 +
  172 + $this->temp_variables['title'] = 'Restore Complete';
  173 + $this->temp_variables['restoreSuccessful'] = true;
  174 + }
  175 + else
  176 + {
  177 + $this->temp_variables['display'] = 'It appears as though <font color=red>the restore process has failed</font>. <P>
  178 + Unfortunately, it is difficult to diagnose these problems automatically
  179 + and would recommend that you try to do the backup process manually.
  180 + <P>
  181 + We appologise for the inconvenience.
  182 + <P>
  183 + <table bgcolor="lightgrey">
  184 + <tr>
  185 + <td>' . $_SESSION['restoreOutput'] . '
  186 + </table>';
  187 + $this->temp_variables['title'] = 'Restore Failed';
  188 + $this->temp_variables['restoreSuccessful'] = false;
  189 + }
219 } 190 }
220 -?>  
221 -  
222 -<br/>  
223 -  
224 -&nbsp;&nbsp; &nbsp; &nbsp; <input type=button value="back" onclick="javascript:do_start('welcome')">  
225 -  
226 -<?php  
227 -  
228 -}  
229 -  
230 -function restoreSelect()  
231 -{  
232 - $this->temp_variables['availableBackups'] = false;  
233 -// title('Select Backup to Restore');  
234 - $dir = $this->util->resolveTempDir();  
235 -  
236 - $files = array();  
237 - if ($dh = opendir($dir)) 191 +
  192 + private function restoreSelect()
238 { 193 {
239 - while (($file = readdir($dh)) !== false) 194 + $this->temp_variables['availableBackups'] = false;
  195 + $dir = $this->util->resolveTempDir();
  196 +
  197 + $files = array();
  198 + if ($dh = opendir($dir))
240 { 199 {
241 - if (!preg_match('/kt-backup.+\.sql/',$file)) {  
242 - continue; 200 + while (($file = readdir($dh)) !== false)
  201 + {
  202 + if (!preg_match('/kt-backup.+\.sql/',$file)) {
  203 + continue;
  204 + }
  205 + $files[] = $file;
243 } 206 }
244 - $files[] = $file; 207 + closedir($dh);
  208 + }
  209 +
  210 + $this->temp_variables['title'] = 'Select Backup to Restore';
  211 + $this->temp_variables['dir'] = $dir;
  212 + if (count($files) != 0) {
  213 + $this->temp_variables['availableBackups'] = true;
  214 + $this->temp_variables['files'] = $files;
245 } 215 }
246 - closedir($dh);  
247 } 216 }
248 217
249 - $this->temp_variables['dir'] = $dir;  
250 - if (count($files) != 0) {  
251 - $this->temp_variables['availableBackups'] = true;  
252 - $this->temp_variables['files'] = $files; 218 + private function restoreSelected()
  219 + {
  220 + $file=$_REQUEST['file'];
  221 +
  222 + $dir = $this->util->resolveTempDir();
  223 + $_SESSION['backupFile'] = $dir . '/' . $file;
253 } 224 }
254 -}  
255 -  
256 -function restoreSelected()  
257 -{  
258 - $file=$_REQUEST['file'];  
259 -  
260 - $dir = $this->util->resolveTempDir();  
261 - $_SESSION['backupFile'] = $dir . '/' . $file;  
262 -?>  
263 -<?php  
264 -  
265 -}  
266 -  
267 -function restoreConfirm()  
268 -{  
269 - if (!isset($_SESSION['backupFile']) || !is_file($_SESSION['backupFile']) || filesize($_SESSION['backupFile']) == 0) 225 +
  226 + private function restoreConfirm()
270 { 227 {
271 - $this->restoreSelect();  
272 - return; 228 + if (!isset($_SESSION['backupFile']) || !is_file($_SESSION['backupFile']) || filesize($_SESSION['backupFile']) == 0)
  229 + {
  230 + $this->restoreSelect();
  231 + return;
  232 + }
  233 +
  234 + $status = $_SESSION['backupStatus'];
  235 + $filename = $_SESSION['backupFile'];
  236 + $stmt = $this->util->create_restore_stmt($filename);
  237 +
  238 + $this->temp_variables['title'] = 'Confirm Restore';
  239 + $this->temp_variables['dir'] = $stmt['dir'];
  240 + $this->temp_variables['display'] = $stmt['display'];
  241 + $this->temp_variables['availableBackups'] = true;
  242 + $this->temp_variables['selected'] = true;
273 } 243 }
274 244
275 - $status = $_SESSION['backupStatus'];  
276 - $filename = $_SESSION['backupFile'];  
277 - $stmt = $this->util->create_restore_stmt($filename);  
278 -  
279 - $this->temp_variables['dir'] = $stmt['dir'];  
280 - $this->temp_variables['display'] = $stmt['display'];  
281 -}  
282 -  
283 -  
284 -  
285 -  
286 } 245 }
287 ?> 246 ?>
288 \ No newline at end of file 247 \ No newline at end of file
setup/upgrade/steps/upgradeWelcome.php
@@ -40,14 +40,13 @@ @@ -40,14 +40,13 @@
40 * @version Version 0.1 40 * @version Version 0.1
41 */ 41 */
42 42
43 -global $default;  
44 -// include defaults  
45 include '../../config/dmsDefaults.php'; 43 include '../../config/dmsDefaults.php';
46 require_once KT_LIB_DIR . '/authentication/authenticationutil.inc.php'; 44 require_once KT_LIB_DIR . '/authentication/authenticationutil.inc.php';
47 45
48 class upgradeWelcome extends step { 46 class upgradeWelcome extends step {
49 47
50 - protected $silent = true; 48 + protected $silent = false;
  49 + protected $temp_variables = array();
51 50
52 public function __construct() { 51 public function __construct() {
53 $this->temp_variables = array("step_name"=>"welcome"); 52 $this->temp_variables = array("step_name"=>"welcome");
@@ -76,7 +75,6 @@ class upgradeWelcome extends step { @@ -76,7 +75,6 @@ class upgradeWelcome extends step {
76 if (!$authenticated) 75 if (!$authenticated)
77 { 76 {
78 session_unset(); 77 session_unset();
79 -// loginFailed(_kt('Could not authenticate administrative user'));  
80 return false; 78 return false;
81 } 79 }
82 80
setup/upgrade/templates/backup.tpl
@@ -44,18 +44,17 @@ You can continue to do the backup manually using the following process: @@ -44,18 +44,17 @@ You can continue to do the backup manually using the following process:
44 ?><nobr><?php echo $display; ?></nobr> 44 ?><nobr><?php echo $display; ?></nobr>
45 </table> 45 </table>
46 <P> 46 <P>
47 - <?php if($silent) { ?>  
48 - </div>  
49 - <?php } ?>  
50 </div> 47 </div>
51 - <?php 48 + </div>
  49 + <?php
52 if ($dir != '') 50 if ($dir != '')
53 { 51 {
54 if (($action == '') || ($action == 'confirm')) { 52 if (($action == '') || ($action == 'confirm')) {
55 ?><input type="submit" name="BackupNow" value="Next" class="button_next"><?php 53 ?><input type="submit" name="BackupNow" value="Next" class="button_next"><?php
56 } 54 }
57 else if ($backupStatus) { 55 else if ($backupStatus) {
58 - ?><input type="submit" name="Next" value="Next" class="button_next"><?php 56 + ?><input type="submit" name="Next" value="Restore" class="button_next">
  57 + <input type="submit" name="Upgrade" value="Upgrade" class="button_next"><?php
59 } 58 }
60 else { 59 else {
61 ?><input type="submit" name="Next" value="Next" class="button_next"><?php 60 ?><input type="submit" name="Next" value="Next" class="button_next"><?php
@@ -64,5 +63,4 @@ if ($dir != &#39;&#39;) @@ -64,5 +63,4 @@ if ($dir != &#39;&#39;)
64 63
65 ?> 64 ?>
66 <input type="submit" name="Previous" value="Back" class="button_previous"> 65 <input type="submit" name="Previous" value="Back" class="button_previous">
67 - </div>  
68 </form> 66 </form>
69 \ No newline at end of file 67 \ No newline at end of file
setup/upgrade/templates/installation.tpl
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 <p class="title">Current Installation</p> 2 <p class="title">Current Installation</p>
3 <div id="step_content" class="step"> 3 <div id="step_content" class="step">
4 <p class="empty_space"> 4 <p class="empty_space">
5 - <?php // set_state(1); ?>  
6 <p class="empty_space"> If you have just updated 5 <p class="empty_space"> If you have just updated
7 your KnowledgeTree code base, you will need to complete the upgrade process in order to ensure your system is fully operational with the new version. 6 your KnowledgeTree code base, you will need to complete the upgrade process in order to ensure your system is fully operational with the new version.
8 <p class="empty_space"> 7 <p class="empty_space">
setup/upgrade/templates/restore.tpl
1 <form action="index.php?step_name=restore" method="post"> 1 <form action="index.php?step_name=restore" method="post">
2 - <p class="title">Confirm Restore</p> 2 + <p class="title"><?php echo $title; ?></p>
3 3
4 <?php 4 <?php
5 if($errors || $warnings){ 5 if($errors || $warnings){
@@ -12,63 +12,65 @@ @@ -12,63 +12,65 @@
12 <br/><br/> 12 <br/><br/>
13 <div> 13 <div>
14 <?php 14 <?php
15 - if (!$availableBackups) {  
16 - ?>There don't seem to be any backups to restore from the <i>"<?php echo $dir;?>"</i> directory.<?php  
17 - }  
18 - else if (!$selected) { 15 + if (!$restore) {
  16 + if (!$availableBackups) {
  17 + ?>There don't seem to be any backups to restore from the <i>"<?php echo $dir;?>"</i> directory.<?php
  18 + }
  19 + else if (!$selected) {
  20 + ?>
  21 + <P>
  22 + Select a backup to restore from the list below:
  23 + <P>
  24 + <form action="index.php?step_name=restore" method="post">
  25 +
  26 + <table border=1 cellpadding=1 cellspacing=1>
  27 + <tr bgcolor="darkgrey">
  28 + <td>Filename
  29 + <td>File Size
  30 + <td>Action
  31 + <?php
  32 + $i=0;
  33 + foreach($files as $file)
  34 + {
  35 + $color=((($i++)%2)==0)?'white':'lightgrey';
  36 + ?>
  37 + <tr bgcolor="<?php echo $color;?>">
  38 + <td><?php echo $file;?>
  39 + <td><?php echo filesize($dir . '/'.$file);?>
  40 + <td><input type="submit" name="RestoreSelect" value="restore">
  41 + <?php
  42 + }
  43 + ?>
  44 + </table>
  45 + <input type="hidden" name="file" value="<?php echo $file; ?>" />
  46 + </form>
  47 + <?php
  48 + }
  49 + else if ($dir != '') {
19 ?> 50 ?>
20 <P> 51 <P>
21 - Select a backup to restore from the list below:  
22 <P> 52 <P>
23 - <form action="index.php?step_name=restore" method="post">  
24 -  
25 - <table border=1 cellpadding=1 cellspacing=1>  
26 - <tr bgcolor="darkgrey">  
27 - <td>Filename  
28 - <td>File Size  
29 - <td>Action  
30 -<?php  
31 - $i=0;  
32 - foreach($files as $file)  
33 - {  
34 - $color=((($i++)%2)==0)?'white':'lightgrey';  
35 -?>  
36 - <tr bgcolor="<?php echo $color;?>">  
37 - <td><?php echo $file;?>  
38 - <td><?php echo filesize($dir . '/'.$file);?>  
39 - <td><input type="submit" name="RestoreSelect" value="restore">  
40 -<?php  
41 - }  
42 -?>  
43 - </table>  
44 - <input type="hidden" name="file" value="<?php echo $file; ?>" />  
45 - </form> 53 + Manually, you would do the following to restore the backup:
  54 + <P>
  55 + <table bgcolor="lightgrey">
  56 + <tr>
  57 + <td>
  58 + <nobr>cd "<?php echo $dir;?>"</nobr>
  59 + <br/>
46 <?php 60 <?php
47 - }  
48 -else if ($dir != '') {  
49 -?>  
50 -<P>  
51 -<P>  
52 -Manually, you would do the following to restore the backup:  
53 -<P>  
54 -<table bgcolor="lightgrey">  
55 -<tr>  
56 -<td>  
57 -<nobr>cd "<?php echo $dir;?>"</nobr>  
58 -<br/>  
59 -<?php  
60 - }  
61 - else  
62 - {  
63 - ?>  
64 - The mysql backup utility could not be found automatically. Either do a manual restore, or edit the config.ini and update the backup/mysql Directory entry.  
65 -<P>  
66 -You can continue to do the restore manually using the following command(s):  
67 -<P>  
68 -<table bgcolor="lightgrey">  
69 -<tr>  
70 -<td><?php  
71 - } 61 + }
  62 + else
  63 + {
  64 + ?>
  65 + The mysql backup utility could not be found automatically. Either do a manual restore, or edit the config.ini and update the backup/mysql Directory entry.
  66 + <P>
  67 + You can continue to do the restore manually using the following command(s):
  68 + <P>
  69 + <table bgcolor="lightgrey">
  70 + <tr>
  71 + <td><?php
  72 + }
  73 + } // end not doing a restore, just preliminary steps
72 ?> 74 ?>
73 <nobr><?php echo $display;?></nobr> 75 <nobr><?php echo $display;?></nobr>
74 </td> 76 </td>
@@ -89,11 +91,12 @@ Press &lt;i&gt;Next&lt;/i&gt; to attempt the command(s) above. @@ -89,11 +91,12 @@ Press &lt;i&gt;Next&lt;/i&gt; to attempt the command(s) above.
89 } 91 }
90 ?> 92 ?>
91 </div> 93 </div>
92 -  
93 - 94 + </div>
94 <input type="submit" name="Previous" value="Back" class="button_previous"> 95 <input type="submit" name="Previous" value="Back" class="button_previous">
95 <?php if (($dir != '') && ($selected)) { ?> 96 <?php if (($dir != '') && ($selected)) { ?>
  97 + <input type="submit" name="RunRestore" value="Next" class="button_next">
  98 + <?php }
  99 + else { ?>
96 <input type="submit" name="Next" value="Next" class="button_next"> 100 <input type="submit" name="Next" value="Next" class="button_next">
97 <?php } ?> 101 <?php } ?>
98 - </div>  
99 </form> 102 </form>
100 \ No newline at end of file 103 \ No newline at end of file
setup/upgrade/upgradeUtil.php
@@ -666,115 +666,106 @@ class UpgradeUtil { @@ -666,115 +666,106 @@ class UpgradeUtil {
666 return join(" ", $aSafeArgs); 666 return join(" ", $aSafeArgs);
667 } 667 }
668 668
669 - function create_restore_stmt($targetfile)  
670 -{  
671 - $oKTConfig =& KTConfig::getSingleton();  
672 -  
673 - $adminUser = $oKTConfig->get('db/dbAdminUser');  
674 - $adminPwd = $oKTConfig->get('db/dbAdminPass');  
675 - $dbHost = $oKTConfig->get('db/dbHost');  
676 - $dbName = $oKTConfig->get('db/dbName');  
677 - $dbPort = trim($oKTConfig->get('db/dbPort'));  
678 - if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port');  
679 - if (empty($dbPort)) $dbPort='3306';  
680 - $dbSocket = trim($oKTConfig->get('db/dbSocket'));  
681 - if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket');  
682 - if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock';  
683 -  
684 - $dir = $this->resolveMysqlDir();  
685 -  
686 - $info['dir']=$dir;  
687 -  
688 - $prefix='';  
689 - if (OS_UNIX)  
690 - {  
691 - $prefix .= "./";  
692 - }  
693 -  
694 - if (@stat($dbSocket) !== false)  
695 - {  
696 - $mechanism="--socket=\"$dbSocket\"";  
697 - }  
698 - else 669 + public function create_restore_stmt($targetfile)
699 { 670 {
700 - $mechanism="--port=\"$dbPort\"";  
701 - }  
702 -  
703 - $tmpdir = $this->resolveTempDir();  
704 -  
705 - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"<br/>";  
706 - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"<br/>";  
707 -  
708 -  
709 - $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n";  
710 - $info['display']=$stmt;  
711 -  
712 -  
713 - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n";  
714 - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n";  
715 -  
716 - $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\"";  
717 - $info['cmd']=$stmt;  
718 - return $info;  
719 -}  
720 -  
721 -function resolveMysqlDir()  
722 -{  
723 - // possibly detect existing installations:  
724 -  
725 - if (OS_UNIX)  
726 - {  
727 - $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin');  
728 - $mysqlname ='mysql';  
729 - }  
730 - else  
731 - {  
732 - $dirs = explode(';', $_SERVER['PATH']);  
733 - $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin';  
734 - $dirs[] = 'c:/program files/ktdms/mysql/bin';  
735 - $mysqlname ='mysql.exe';  
736 - }  
737 -  
738 - $oKTConfig =& KTConfig::getSingleton();  
739 - $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir);  
740 - $dirs[] = $mysqldir;  
741 -  
742 - if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false)  
743 - {  
744 - $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); 671 + $oKTConfig =& KTConfig::getSingleton();
  672 +
  673 + $adminUser = $oKTConfig->get('db/dbAdminUser');
  674 + $adminPwd = $oKTConfig->get('db/dbAdminPass');
  675 + $dbHost = $oKTConfig->get('db/dbHost');
  676 + $dbName = $oKTConfig->get('db/dbName');
  677 + $dbPort = trim($oKTConfig->get('db/dbPort'));
  678 + if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port');
  679 + if (empty($dbPort)) $dbPort='3306';
  680 + $dbSocket = trim($oKTConfig->get('db/dbSocket'));
  681 + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket');
  682 + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock';
  683 +
  684 + $dir = $this->resolveMysqlDir();
  685 +
  686 + $info['dir']=$dir;
  687 +
  688 + $prefix='';
  689 + if (OS_UNIX) {
  690 + $prefix .= "./";
  691 + }
  692 +
  693 + if (@stat($dbSocket) !== false) {
  694 + $mechanism="--socket=\"$dbSocket\"";
  695 + }
  696 + else {
  697 + $mechanism="--port=\"$dbPort\"";
  698 + }
  699 +
  700 + $tmpdir = $this->resolveTempDir();
  701 +
  702 + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"<br/>";
  703 + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"<br/>";
  704 +
  705 +
  706 + $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n";
  707 + $info['display']=$stmt;
  708 +
  709 +
  710 + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n";
  711 + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n";
  712 +
  713 + $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\"";
  714 + $info['cmd']=$stmt;
  715 + return $info;
745 } 716 }
746 -  
747 - foreach($dirs as $dir) 717 +
  718 + public function resolveMysqlDir()
748 { 719 {
749 - if (is_file($dir . '/' . $mysqlname)) 720 + // possibly detect existing installations:
  721 +
  722 + if (OS_UNIX) {
  723 + $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin');
  724 + $mysqlname ='mysql';
  725 + }
  726 + else
750 { 727 {
751 - return $dir; 728 + $dirs = explode(';', $_SERVER['PATH']);
  729 + $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin';
  730 + $dirs[] = 'c:/program files/ktdms/mysql/bin';
  731 + $mysqlname ='mysql.exe';
752 } 732 }
  733 +
  734 + $oKTConfig =& KTConfig::getSingleton();
  735 + $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir);
  736 + $dirs[] = $mysqldir;
  737 +
  738 + if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) {
  739 + $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin');
  740 + }
  741 +
  742 + foreach($dirs as $dir)
  743 + {
  744 + if (is_file($dir . '/' . $mysqlname))
  745 + {
  746 + return $dir;
  747 + }
  748 + }
  749 +
  750 + return '';
753 } 751 }
754 -  
755 - return '';  
756 -}  
757 -  
758 -function resolveTempDir()  
759 -{  
760 -  
761 - if (OS_UNIX)  
762 - {  
763 - $dir='/tmp/kt-db-backup';  
764 - }  
765 - else  
766 - {  
767 - $dir='c:/kt-db-backup';  
768 - }  
769 - $oKTConfig =& KTConfig::getSingleton();  
770 - $dir = $oKTConfig->get('backup/backupDirectory',$dir);  
771 -  
772 - if (!is_dir($dir)) 752 +
  753 + public function resolveTempDir()
773 { 754 {
774 - mkdir($dir); 755 + if (OS_UNIX) {
  756 + $dir='/tmp/kt-db-backup';
  757 + }
  758 + else {
  759 + $dir='c:/kt-db-backup';
  760 + }
  761 + $oKTConfig =& KTConfig::getSingleton();
  762 + $dir = $oKTConfig->get('backup/backupDirectory',$dir);
  763 +
  764 + if (!is_dir($dir)) {
  765 + mkdir($dir);
  766 + }
  767 + return $dir;
775 } 768 }
776 - return $dir;  
777 -}  
778 769
779 } 770 }
780 ?> 771 ?>
781 \ No newline at end of file 772 \ No newline at end of file
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 }