Commit 3f416054fe85cc22db86ef2873e7402038bda73a

Authored by unknown
1 parent 0c0833f3

Working version of Database Upgrade/Backup/Restore tool in new wizArd format

Story ID:1244695. 3.7 Database Upgrade Script

Committed by: Paul Barrett

Reviewed by: Jarrett Jordaan
setup/upgrade/index.php
1 1 <?php
2 2 /**
3   -* Upgrader Index.
  3 +* Database Upgrader Index.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ...
setup/upgrade/step.php
1 1 <?php
2 2 /**
3   -* Step .
  3 +* Step Controller.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -119,10 +119,10 @@ class Step
119 119 {
120 120 // if not authenticated, return to step 1
121 121 if (!isset($_SESSION['setup_user'])) {
122   - header('index.php?step=welcome');
  122 + header('Location: index.php?step=welcome');
123 123 exit;
124 124 }
125   -
  125 +
126 126 return '';
127 127 }
128 128  
... ... @@ -254,38 +254,31 @@ class Step
254 254  
255 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 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 283 * Checks if we are currently in this class step
291 284 *
... ...
setup/upgrade/steps/upgradeBackup.php
1 1 <?php
2 2 /**
3   -* Complete Step Controller.
  3 +* Backup Step Controller.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -52,12 +52,9 @@ class upgradeBackup extends Step {
52 52 * @var object
53 53 */
54 54 private $_dbhandler = null;
55   -
56   - private $privileges_check = 'tick';
57   - private $database_check = 'tick';
58   - protected $silent = true;
59   -
60 55 protected $util = null;
  56 + protected $silent = false;
  57 + protected $temp_variables = array();
61 58  
62 59 public function __construct() {
63 60 $this->temp_variables = array("step_name"=>"backup", "silent"=>$this->silent);
... ... @@ -65,7 +62,7 @@ class upgradeBackup extends Step {
65 62 $this->util = new UpgradeUtil();
66 63 }
67 64  
68   - function doStep() {
  65 + public function doStep() {
69 66 parent::doStep();
70 67 if(!$this->inStep("backup")) {
71 68 $this->doRun();
... ... @@ -92,17 +89,21 @@ class upgradeBackup extends Step {
92 89 else if($this->previous()) {
93 90 return 'previous';
94 91 }
  92 + else if ($this->upgrade()) {
  93 + header('Location: index.php?step_name=database');
  94 + exit;
  95 + }
95 96  
96 97 $this->doRun();
97 98 return 'landing';
98 99 }
99 100  
100   - function backupNow()
  101 + private function backupNow()
101 102 {
102 103 return isset($_POST['BackupNow']);
103 104 }
104 105  
105   - function doRun($action = null) {
  106 + private function doRun($action = null) {
106 107 $this->temp_variables['action'] = $action;
107 108  
108 109 if (is_null($action) || ($action == 'confirm')) {
... ... @@ -127,29 +128,7 @@ class upgradeBackup extends Step {
127 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 131 private function backup() {
151   -// $this->check_state(1);
152   -// $this->set_state(2);
153 132 $targetfile = $_SESSION['backupFile'];
154 133 $stmt = $this->create_backup_stmt($targetfile);
155 134 $dir = $stmt['dir'];
... ... @@ -163,7 +142,7 @@ function check_state($value, $state=&#39;Home&#39;)
163 142 $read = fread($handle, 10240);
164 143 pclose($handle);
165 144 $_SESSION['backupOutput']=$read;
166   - $dir = $this->resolveTempDir();
  145 + $dir = $this->util->resolveTempDir();
167 146 $_SESSION['backupFile'] = $stmt['target'];
168 147  
169 148 if (OS_UNIX) {
... ... @@ -177,21 +156,9 @@ function check_state($value, $state=&#39;Home&#39;)
177 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 161 private function backupDone() {
192   -// $this->check_state(2);
193   -// $this->set_state(3);
194   -// title('Backup Status');
195 162 $status = $_SESSION['backupStatus'];
196 163 $filename = $_SESSION['backupFile'];
197 164  
... ... @@ -200,7 +167,7 @@ function check_state($value, $state=&#39;Home&#39;)
200 167 if ($status)
201 168 {
202 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 171 <P> It appears as though the <font color=green>backup has been successful</font>.
205 172 <P>';
206 173 if ($stmt['dir'] != '')
... ... @@ -230,136 +197,78 @@ function check_state($value, $state=&#39;Home&#39;)
230 197 else
231 198 {
232 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 275 \ No newline at end of file
... ...
setup/upgrade/steps/upgradeComplete.php
... ... @@ -44,20 +44,20 @@ require &#39;../../config/dmsDefaults.php&#39;;
44 44  
45 45 class upgradeComplete extends Step {
46 46  
47   - protected $silent = true;
48   -
49 47 protected $util = null;
  48 + protected $silent = false;
  49 + protected $temp_variables = array();
50 50  
51 51 public function __construct() {
52 52 $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent);
53 53 }
54 54  
55   - function doStep() {
  55 + public function doStep() {
56 56 $this->doRun();
57 57 return 'landing';
58 58 }
59 59  
60   - function doRun() {
  60 + private function doRun() {
61 61 $this->storeSilent();// Set silent mode variables
62 62 }
63 63  
... ...
setup/upgrade/steps/upgradeDatabase.php
1 1 <?php
2 2 /**
3   -* Database Step Controller.
  3 +* Upgrade Step Controller.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -40,7 +40,6 @@
40 40 * @version Version 0.1
41 41 */
42 42  
43   -// include defaults
44 43 require '../../config/dmsDefaults.php';
45 44 require_once KT_LIB_DIR . '/config/config.inc.php';
46 45 require_once KT_LIB_DIR . '/plugins/pluginutil.inc.php';
... ... @@ -67,105 +66,6 @@ class upgradeDatabase extends Step
67 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 69 * Location of database binaries.
170 70 *
171 71 * @author KnowledgeTree Team
... ... @@ -181,25 +81,7 @@ class upgradeDatabase extends Step
181 81 * @access private
182 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 87 * List of errors encountered
... ... @@ -228,26 +110,11 @@ class upgradeDatabase extends Step
228 110 */
229 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 119 * @author KnowledgeTree Team
253 120 * @access public
... ... @@ -272,12 +139,12 @@ class upgradeDatabase extends Step
272 139 public function doStep() {
273 140 parent::doStep();
274 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 146 if($this->next()) {
  147 + $this->doRun('preview');
281 148 return 'next';
282 149 } else if($this->previous()) {
283 150 return 'previous';
... ... @@ -297,15 +164,15 @@ class upgradeDatabase extends Step
297 164 return 'landing';
298 165 }
299 166  
300   - function confirmUpgrade() {
  167 + private function confirmUpgrade() {
301 168 return isset($_POST['ConfirmUpgrade']);
302 169 }
303 170  
304   - function upgrading() {
  171 + private function upgrading() {
305 172 return isset($_POST['RunUpgrade']);
306 173 }
307 174  
308   - function doRun($action = null) {
  175 + private function doRun($action = null) {
309 176 $this->readConfig(KTConfig::getConfigFilename());
310 177  
311 178 if($this->dbSettings['dbPort'] == '') {
... ... @@ -327,8 +194,7 @@ class upgradeDatabase extends Step
327 194 }
328 195 else if ($action == 'runUpgrade') {
329 196 $this->temp_variables['title'] = 'Upgrade In Progress';
330   - if (!$this->upgrade()) {
331   -// $this->temp_variables['upgradeTable'] = '';//$this->upgradeErrors();
  197 + if (!$this->upgradeDatabase()) {
332 198 return false;
333 199 }
334 200 }
... ... @@ -336,7 +202,7 @@ class upgradeDatabase extends Step
336 202 return true;
337 203 }
338 204  
339   - public function generateUpgradeTable() {
  205 + private function generateUpgradeTable() {
340 206 global $default;
341 207  
342 208 $this->temp_variables['systemVersion'] = $default->systemVersion;
... ... @@ -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 236 * Stores varibles used by template
407 237 *
408 238 * @author KnowledgeTree Team
... ... @@ -455,7 +285,7 @@ class upgradeDatabase extends Step
455 285 $this->temp_variables['dbSettings'] = $this->dbSettings;
456 286 }
457 287  
458   - function upgradeConfirm()
  288 + private function upgradeConfirm()
459 289 {
460 290 if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) {
461 291 $this->temp_variables['backupStatus'] = false;
... ... @@ -465,158 +295,141 @@ 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 + $this->temp_variables['upgradeStatus'] = '<font color="red">Upgrade failed.</font>';
  317 + }
  318 + else {
  319 + $this->temp_variables['upgradeStatus'] = '<font color="green">Upgrade succeeded.</font>';
  320 + }
  321 +
  322 + $post_pres = $this->performPostUpgradeActions();
  323 + if (PEAR::isError($post_res)) {
  324 + $this->temp_variables['postUpgrade'] = '<font color="red">Post-Upgrade actions failed.</font>';
  325 + }
  326 + else {
  327 + $this->temp_variables['postUpgrade'] = '<font color="green">Post-Upgrade actions succeeded.</font>';
  328 + }
487 329 }
488   - ?>
489   - <br/>
490 330  
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>';
  331 + private function performPreUpgradeActions() {
  332 +
  333 + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
  334 + // It should idealy work the same as the upgrades.
  335 +
  336 + global $default;
  337 +
  338 + // Lock the scheduler
  339 + $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
  340 + touch($lockFile);
  341 + return true;
  342 +
514 343 }
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);
  344 +
  345 + private function performPostUpgradeActions() {
  346 +
  347 + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
  348 + // It should idealy work the same as the upgrades.
  349 +
  350 + global $default;
  351 +
  352 + // Ensure all plugins are re-registered.
  353 + $sql = "TRUNCATE plugin_helper";
  354 + $res = DBUtil::runQuery($sql);
  355 +
  356 + // Clear out all caches and proxies - they need to be regenerated with the new code
  357 + $proxyDir = $default->proxyCacheDirectory;
  358 + KTUtil::deleteDirectory($proxyDir);
  359 +
  360 + $oKTCache = new KTCache();
  361 + $oKTCache->deleteAllCaches();
  362 +
  363 + // Clear the configuration cache, it'll regenerate on next load
  364 + $oKTConfig = new KTConfig();
  365 + $oKTConfig->clearCache();
  366 +
  367 + // Unlock the scheduler
  368 + $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
  369 + if(file_exists($lockFile)){
  370 + @unlink($lockFile);
  371 + }
  372 +
  373 + return true;
  374 +
557 375 }
558 376  
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);
  377 + private function performAllUpgrades () {
  378 + global $default;
  379 +
  380 + $row = 1;
  381 +
  382 + $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
  383 + $lastVersion = DBUtil::getOneResultKey($query, 'value');
  384 + $currentVersion = $default->systemVersion;
570 385  
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";
  386 + $upgrades = describeUpgrade($lastVersion, $currentVersion);
  387 +
  388 + $this->temp_variables['upgradeTable'] = '';
  389 +
  390 + foreach ($upgrades as $upgrade) {
  391 + if (($row % 2) == 1) {
  392 + $class = "odd";
  393 + } else {
  394 + $class = "even";
  395 + }
  396 + $this->temp_variables['upgradeTable'] .= sprintf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, htmlspecialchars($upgrade->getDescription()));
  397 + ++$row;
  398 + $res = $upgrade->performUpgrade();
  399 + $this->temp_variables['upgradeTable'] .= sprintf('<div class="bar">%s</div>', $this->showResult($res));
  400 + $this->temp_variables['upgradeTable'] .= '<br style="clear: both">' . "\n";
  401 + $this->temp_variables['upgradeTable'] .= "</div>\n";
  402 + if (PEAR::isError($res)) {
  403 + if (!is_a($res, 'Upgrade_Already_Applied')) {
  404 + break;
  405 + } else {
  406 + $res = true;
  407 + }
  408 + }
  409 + if ($res === false) {
  410 + $res = PEAR::raiseError("Upgrade returned false");
  411 + break;
  412 + }
578 413 }
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";
  414 +
  415 + return $res;
  416 + }
  417 +
  418 + private function showResult($res) {
589 419 if (PEAR::isError($res)) {
590   - if (!is_a($res, 'Upgrade_Already_Applied')) {
591   - break;
592   - } else {
593   - $res = true;
  420 + if (is_a($res, 'Upgrade_Already_Applied')) {
  421 + return '<span style="color: orange">Already applied</span>';
594 422 }
  423 + return sprintf('<span style="color: red">%s</span>', htmlspecialchars($res->toString()));
595 424 }
596   - if ($res === false) {
597   - $res = PEAR::raiseError("Upgrade returned false");
598   - break;
  425 + if ($res === true) {
  426 + return '<span style="color: green">Success</span>';
599 427 }
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>';
  428 + if ($res === false) {
  429 + return '<span style="color: red">Failure</span>';
609 430 }
610   - return sprintf('<span style="color: red">%s</span>', htmlspecialchars($res->toString()));
  431 + return $res;
611 432 }
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 433  
621 434 }
622 435 ?>
623 436 \ No newline at end of file
... ...
setup/upgrade/steps/upgradeInstallation.php
1 1 <?php
2 2 /**
3   -* Upgrade Step Controller.
  3 +* Notification Controller.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -50,12 +50,13 @@ class UpgradeInstallation extends step
50 50 * @var array
51 51 */
52 52 protected $silent = false;
  53 + protected $temp_variables = array();
53 54  
54   - function __construct() {
  55 + public function __construct() {
55 56 $this->temp_variables = array("step_name"=>"installation");
56 57 }
57 58  
58   - function doStep() {
  59 + public function doStep() {
59 60 parent::doStep();
60 61 if($this->next()) {
61 62 return 'next';
... ... @@ -72,13 +73,5 @@ class UpgradeInstallation extends step
72 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 78 \ No newline at end of file
... ...
setup/upgrade/steps/upgradeRestore.php
1 1 <?php
2 2 /**
3   -* Complete Step Controller.
  3 +* Restore Step Controller.
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -53,10 +53,8 @@ class upgradeRestore extends Step {
53 53 */
54 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 58 protected $util = null;
61 59  
62 60 public function __construct() {
... ... @@ -65,8 +63,10 @@ class upgradeRestore extends Step {
65 63 $this->util = new UpgradeUtil();
66 64 }
67 65  
68   - function doStep() {
  66 + public function doStep() {
69 67 parent::doStep();
  68 + $this->temp_variables['restore'] = false;
  69 +
70 70 if(!$this->inStep("restore")) {
71 71 $this->doRun();
72 72 return 'landing';
... ... @@ -78,24 +78,40 @@ class upgradeRestore extends Step {
78 78 } else if($this->previous()) {
79 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 87 $this->doRun();
83 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 109 $this->storeSilent();// Set silent mode variables
94 110  
95 111 return true;
96 112 }
97 113  
98   - function select() {
  114 + private function select() {
99 115 return isset($_POST['RestoreSelect']);
100 116 }
101 117  
... ... @@ -105,183 +121,126 @@ class upgradeRestore extends Step {
105 121 */
106 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 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 247 \ No newline at end of file
... ...
setup/upgrade/steps/upgradeWelcome.php
... ... @@ -40,14 +40,13 @@
40 40 * @version Version 0.1
41 41 */
42 42  
43   -global $default;
44   -// include defaults
45 43 include '../../config/dmsDefaults.php';
46 44 require_once KT_LIB_DIR . '/authentication/authenticationutil.inc.php';
47 45  
48 46 class upgradeWelcome extends step {
49 47  
50   - protected $silent = true;
  48 + protected $silent = false;
  49 + protected $temp_variables = array();
51 50  
52 51 public function __construct() {
53 52 $this->temp_variables = array("step_name"=>"welcome");
... ... @@ -76,7 +75,6 @@ class upgradeWelcome extends step {
76 75 if (!$authenticated)
77 76 {
78 77 session_unset();
79   -// loginFailed(_kt('Could not authenticate administrative user'));
80 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 44 ?><nobr><?php echo $display; ?></nobr>
45 45 </table>
46 46 <P>
47   - <?php if($silent) { ?>
48   - </div>
49   - <?php } ?>
50 47 </div>
51   - <?php
  48 + </div>
  49 + <?php
52 50 if ($dir != '')
53 51 {
54 52 if (($action == '') || ($action == 'confirm')) {
55 53 ?><input type="submit" name="BackupNow" value="Next" class="button_next"><?php
56 54 }
57 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 59 else {
61 60 ?><input type="submit" name="Next" value="Next" class="button_next"><?php
... ... @@ -64,5 +63,4 @@ if ($dir != &#39;&#39;)
64 63  
65 64 ?>
66 65 <input type="submit" name="Previous" value="Back" class="button_previous">
67   - </div>
68 66 </form>
69 67 \ No newline at end of file
... ...
setup/upgrade/templates/installation.tpl
... ... @@ -2,7 +2,6 @@
2 2 <p class="title">Current Installation</p>
3 3 <div id="step_content" class="step">
4 4 <p class="empty_space">
5   - <?php // set_state(1); ?>
6 5 <p class="empty_space"> If you have just updated
7 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 7 <p class="empty_space">
... ...
setup/upgrade/templates/restore.tpl
1 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 4 <?php
5 5 if($errors || $warnings){
... ... @@ -12,63 +12,65 @@
12 12 <br/><br/>
13 13 <div>
14 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 51 <P>
21   - Select a backup to restore from the list below:
22 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 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 75 <nobr><?php echo $display;?></nobr>
74 76 </td>
... ... @@ -89,11 +91,12 @@ Press &lt;i&gt;Next&lt;/i&gt; to attempt the command(s) above.
89 91 }
90 92 ?>
91 93 </div>
92   -
93   -
  94 + </div>
94 95 <input type="submit" name="Previous" value="Back" class="button_previous">
95 96 <?php if (($dir != '') && ($selected)) { ?>
  97 + <input type="submit" name="RunRestore" value="Next" class="button_next">
  98 + <?php }
  99 + else { ?>
96 100 <input type="submit" name="Next" value="Next" class="button_next">
97 101 <?php } ?>
98   - </div>
99 102 </form>
100 103 \ No newline at end of file
... ...
setup/upgrade/upgradeUtil.php
... ... @@ -666,115 +666,106 @@ class UpgradeUtil {
666 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 772 \ No newline at end of file
... ...