Commit 3516c618b112eb8e48bed9e40cef83ff2e94d706
1 parent
8ff5cc59
Intermediate commit of new upgrade wizard. Still incomplete but this version doe…
…s upgrades properly and does a backup (no restore yet) Story ID:1244695. 3.7 Database Upgrade Script In Progress Committed by: Paul Barrett
Showing
5 changed files
with
251 additions
and
182 deletions
setup/upgrade/steps/upgradeBackup.php
| @@ -110,8 +110,10 @@ class upgradeBackup extends Step { | @@ -110,8 +110,10 @@ class upgradeBackup extends Step { | ||
| 110 | $this->backupConfirm(); | 110 | $this->backupConfirm(); |
| 111 | } | 111 | } |
| 112 | else { | 112 | else { |
| 113 | - $this->temp_variables['title'] = 'Backup In Progress'; | 113 | + $this->temp_variables['title'] = 'Backup Created'; |
| 114 | $this->backup(); | 114 | $this->backup(); |
| 115 | + // TODO error checking (done in backupDone at the moment) | ||
| 116 | + $this->backupDone(); | ||
| 115 | } | 117 | } |
| 116 | $this->storeSilent();// Set silent mode variables | 118 | $this->storeSilent();// Set silent mode variables |
| 117 | 119 | ||
| @@ -125,6 +127,7 @@ class upgradeBackup extends Step { | @@ -125,6 +127,7 @@ class upgradeBackup extends Step { | ||
| 125 | private function storeSilent() { | 127 | private function storeSilent() { |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 130 | + /* | ||
| 128 | // these belong in a shared lib | 131 | // these belong in a shared lib |
| 129 | function set_state($value) | 132 | function set_state($value) |
| 130 | { | 133 | { |
| @@ -142,34 +145,25 @@ function check_state($value, $state='Home') | @@ -142,34 +145,25 @@ function check_state($value, $state='Home') | ||
| 142 | exit; | 145 | exit; |
| 143 | } | 146 | } |
| 144 | } | 147 | } |
| 148 | +*/ | ||
| 145 | 149 | ||
| 146 | private function backup() { | 150 | private function backup() { |
| 147 | // $this->check_state(1); | 151 | // $this->check_state(1); |
| 148 | // $this->set_state(2); | 152 | // $this->set_state(2); |
| 149 | - $targetfile=$_SESSION['backupFile']; | 153 | + $targetfile = $_SESSION['backupFile']; |
| 150 | $stmt = $this->create_backup_stmt($targetfile); | 154 | $stmt = $this->create_backup_stmt($targetfile); |
| 151 | $dir = $stmt['dir']; | 155 | $dir = $stmt['dir']; |
| 152 | 156 | ||
| 153 | if (is_file($dir . '/mysqladmin') || is_file($dir . '/mysqladmin.exe')) | 157 | if (is_file($dir . '/mysqladmin') || is_file($dir . '/mysqladmin.exe')) |
| 154 | { | 158 | { |
| 155 | - ob_flush(); | ||
| 156 | - flush(); | ||
| 157 | - ?> | ||
| 158 | - The backup is now underway. Please wait till it completes. | ||
| 159 | - <?php | ||
| 160 | - | ||
| 161 | - ob_flush(); | ||
| 162 | - flush(); | ||
| 163 | $curdir=getcwd(); | 159 | $curdir=getcwd(); |
| 164 | chdir($dir); | 160 | chdir($dir); |
| 165 | - ob_flush(); | ||
| 166 | - flush(); | ||
| 167 | - | 161 | + |
| 168 | $handle = popen($stmt['cmd'], 'r'); | 162 | $handle = popen($stmt['cmd'], 'r'); |
| 169 | $read = fread($handle, 10240); | 163 | $read = fread($handle, 10240); |
| 170 | pclose($handle); | 164 | pclose($handle); |
| 171 | $_SESSION['backupOutput']=$read; | 165 | $_SESSION['backupOutput']=$read; |
| 172 | - $dir=$this->resolveTempDir(); | 166 | + $dir = $this->resolveTempDir(); |
| 173 | $_SESSION['backupFile'] = $stmt['target']; | 167 | $_SESSION['backupFile'] = $stmt['target']; |
| 174 | 168 | ||
| 175 | if (OS_UNIX) { | 169 | if (OS_UNIX) { |
| @@ -197,75 +191,52 @@ function check_state($value, $state='Home') | @@ -197,75 +191,52 @@ function check_state($value, $state='Home') | ||
| 197 | private function backupDone() { | 191 | private function backupDone() { |
| 198 | // $this->check_state(2); | 192 | // $this->check_state(2); |
| 199 | // $this->set_state(3); | 193 | // $this->set_state(3); |
| 200 | - title('Backup Status'); | 194 | +// title('Backup Status'); |
| 201 | $status = $_SESSION['backupStatus']; | 195 | $status = $_SESSION['backupStatus']; |
| 202 | - $filename=$_SESSION['backupFile']; | 196 | + $filename = $_SESSION['backupFile']; |
| 197 | + | ||
| 198 | + $this->temp_variables['backupStatus'] = $status; | ||
| 203 | 199 | ||
| 204 | if ($status) | 200 | if ($status) |
| 205 | { | 201 | { |
| 206 | - $stmt=create_restore_stmt($filename); | ||
| 207 | - ?> | ||
| 208 | - The backup file <nobr><i>"<?php echo $filename;?>"</i></nobr> has been created. | 202 | + $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. | ||
| 209 | <P> It appears as though the <font color=green>backup has been successful</font>. | 204 | <P> It appears as though the <font color=green>backup has been successful</font>. |
| 210 | - <P> | ||
| 211 | - <?php | 205 | + <P>'; |
| 212 | if ($stmt['dir'] != '') | 206 | if ($stmt['dir'] != '') |
| 213 | { | 207 | { |
| 214 | - ?> | ||
| 215 | - Manually, you would do the following to restore the backup: | 208 | + $this->temp_variables['dir'] = $stmt['dir']; |
| 209 | + $this->temp_variables['display'] .= 'Manually, you would do the following to restore the backup: | ||
| 216 | <P> | 210 | <P> |
| 217 | <table bgcolor="lightgrey"> | 211 | <table bgcolor="lightgrey"> |
| 218 | <tr> | 212 | <tr> |
| 219 | <td> | 213 | <td> |
| 220 | - <nobr>cd <?php echo $stmt['dir'];?></nobr> | ||
| 221 | - <br/> | ||
| 222 | - <?php | 214 | + <nobr>cd ' . $stmt['dir'] . '</nobr> |
| 215 | + <br/>'; | ||
| 223 | } | 216 | } |
| 224 | else | 217 | else |
| 225 | { | 218 | { |
| 226 | - ?> | ||
| 227 | - The mysql backup utility could not be found automatically. Please edit the config.ini and update the backup/mysql Directory entry. | 219 | + $this->temp_variables['display'] .= 'The mysql backup utility could not be found automatically. Please edit the config.ini and update the backup/mysql Directory entry. |
| 228 | <P> | 220 | <P> |
| 229 | If you need to restore from this backup, you should be able to use the following statements: | 221 | If you need to restore from this backup, you should be able to use the following statements: |
| 230 | <P> | 222 | <P> |
| 231 | <table bgcolor="lightgrey"> | 223 | <table bgcolor="lightgrey"> |
| 232 | <tr> | 224 | <tr> |
| 233 | - <td> | ||
| 234 | - <?php | 225 | + <td>'; |
| 235 | } | 226 | } |
| 236 | - ?> | ||
| 237 | - <nobr><?php echo $stmt['display'];?></nobr> | ||
| 238 | - </table> | ||
| 239 | - | ||
| 240 | - <?php | 227 | + $this->temp_variables['display'] .= '<nobr>' . $stmt['display'] . '</nobr> |
| 228 | + </table>'; | ||
| 241 | } | 229 | } |
| 242 | else | 230 | else |
| 243 | { | 231 | { |
| 244 | - ?> | ||
| 245 | - It appears as though <font color=red>the backup process has failed</font>.<P></P> Unfortunately, it is difficult to diagnose these problems automatically | 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 |
| 246 | and would recommend that you try to do the backup process manually. | 233 | and would recommend that you try to do the backup process manually. |
| 247 | <P> | 234 | <P> |
| 248 | We appologise for the inconvenience. | 235 | We appologise for the inconvenience. |
| 249 | <P> | 236 | <P> |
| 250 | <table bgcolor="lightgrey"> | 237 | <table bgcolor="lightgrey"> |
| 251 | <tr> | 238 | <tr> |
| 252 | - <td> | ||
| 253 | - <?php echo $_SESSION['backupOutput'];?> | ||
| 254 | - </table> | ||
| 255 | - <?php | ||
| 256 | - | ||
| 257 | - } | ||
| 258 | - ?> | ||
| 259 | - <br/> | ||
| 260 | - | ||
| 261 | - <input type=button value="back" onclick="javascript:do_start('welcome')"> | ||
| 262 | - <?php | ||
| 263 | - if ($status) | ||
| 264 | - { | ||
| 265 | - ?> | ||
| 266 | - <input type=button value="next" onclick="javascript:do_start('UpgradeConfirm')"> | ||
| 267 | - | ||
| 268 | - <?php | 239 | + <td>' . $_SESSION['backupOutput'] . '</table>'; |
| 269 | } | 240 | } |
| 270 | } | 241 | } |
| 271 | 242 |
setup/upgrade/steps/upgradeRestore.php
| @@ -244,117 +244,6 @@ We appologise for the inconvenience. | @@ -244,117 +244,6 @@ We appologise for the inconvenience. | ||
| 244 | 244 | ||
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | -function create_restore_stmt($targetfile) | ||
| 248 | -{ | ||
| 249 | - $oKTConfig =& KTConfig::getSingleton(); | ||
| 250 | - | ||
| 251 | - $adminUser = $oKTConfig->get('db/dbAdminUser'); | ||
| 252 | - $adminPwd = $oKTConfig->get('db/dbAdminPass'); | ||
| 253 | - $dbHost = $oKTConfig->get('db/dbHost'); | ||
| 254 | - $dbName = $oKTConfig->get('db/dbName'); | ||
| 255 | - $dbPort = trim($oKTConfig->get('db/dbPort')); | ||
| 256 | - if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); | ||
| 257 | - if (empty($dbPort)) $dbPort='3306'; | ||
| 258 | - $dbSocket = trim($oKTConfig->get('db/dbSocket')); | ||
| 259 | - if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); | ||
| 260 | - if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; | ||
| 261 | - | ||
| 262 | - $dir = $this->resolveMysqlDir(); | ||
| 263 | - | ||
| 264 | - $info['dir']=$dir; | ||
| 265 | - | ||
| 266 | - $prefix=''; | ||
| 267 | - if (OS_UNIX) | ||
| 268 | - { | ||
| 269 | - $prefix .= "./"; | ||
| 270 | - } | ||
| 271 | - | ||
| 272 | - if (@stat($dbSocket) !== false) | ||
| 273 | - { | ||
| 274 | - $mechanism="--socket=\"$dbSocket\""; | ||
| 275 | - } | ||
| 276 | - else | ||
| 277 | - { | ||
| 278 | - $mechanism="--port=\"$dbPort\""; | ||
| 279 | - } | ||
| 280 | - | ||
| 281 | - $tmpdir = $this->resolveTempDir(); | ||
| 282 | - | ||
| 283 | - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"<br/>"; | ||
| 284 | - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"<br/>"; | ||
| 285 | - | ||
| 286 | - | ||
| 287 | - $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n"; | ||
| 288 | - $info['display']=$stmt; | ||
| 289 | - | ||
| 290 | - | ||
| 291 | - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n"; | ||
| 292 | - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n"; | ||
| 293 | - | ||
| 294 | - $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\""; | ||
| 295 | - $info['cmd']=$stmt; | ||
| 296 | - return $info; | ||
| 297 | -} | ||
| 298 | - | ||
| 299 | -function resolveMysqlDir() | ||
| 300 | -{ | ||
| 301 | - // possibly detect existing installations: | ||
| 302 | - | ||
| 303 | - if (OS_UNIX) | ||
| 304 | - { | ||
| 305 | - $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); | ||
| 306 | - $mysqlname ='mysql'; | ||
| 307 | - } | ||
| 308 | - else | ||
| 309 | - { | ||
| 310 | - $dirs = explode(';', $_SERVER['PATH']); | ||
| 311 | - $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; | ||
| 312 | - $dirs[] = 'c:/program files/ktdms/mysql/bin'; | ||
| 313 | - $mysqlname ='mysql.exe'; | ||
| 314 | - } | ||
| 315 | - | ||
| 316 | - $oKTConfig =& KTConfig::getSingleton(); | ||
| 317 | - $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); | ||
| 318 | - $dirs[] = $mysqldir; | ||
| 319 | - | ||
| 320 | - if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) | ||
| 321 | - { | ||
| 322 | - $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); | ||
| 323 | - } | ||
| 324 | - | ||
| 325 | - foreach($dirs as $dir) | ||
| 326 | - { | ||
| 327 | - if (is_file($dir . '/' . $mysqlname)) | ||
| 328 | - { | ||
| 329 | - return $dir; | ||
| 330 | - } | ||
| 331 | - } | ||
| 332 | - | ||
| 333 | - return ''; | ||
| 334 | -} | ||
| 335 | - | ||
| 336 | -function resolveTempDir() | ||
| 337 | -{ | ||
| 338 | - | ||
| 339 | - if (OS_UNIX) | ||
| 340 | - { | ||
| 341 | - $dir='/tmp/kt-db-backup'; | ||
| 342 | - } | ||
| 343 | - else | ||
| 344 | - { | ||
| 345 | - $dir='c:/kt-db-backup'; | ||
| 346 | - } | ||
| 347 | - $oKTConfig =& KTConfig::getSingleton(); | ||
| 348 | - $dir = $oKTConfig->get('backup/backupDirectory',$dir); | ||
| 349 | - | ||
| 350 | - if (!is_dir($dir)) | ||
| 351 | - { | ||
| 352 | - mkdir($dir); | ||
| 353 | - } | ||
| 354 | - return $dir; | ||
| 355 | -} | ||
| 356 | - | ||
| 357 | - | ||
| 358 | function restoreSelect() | 247 | function restoreSelect() |
| 359 | { | 248 | { |
| 360 | // title('Select Backup to Restore'); | 249 | // title('Select Backup to Restore'); |
setup/upgrade/templates/backup.tpl
| 1 | -<?php echo $action; ?><form action="index.php?step_name=backup" method="post"> | 1 | +<form action="index.php?step_name=backup" method="post"> |
| 2 | <p class="title"><?php echo $title; ?></p> | 2 | <p class="title"><?php echo $title; ?></p> |
| 3 | 3 | ||
| 4 | <?php | 4 | <?php |
| @@ -12,20 +12,22 @@ | @@ -12,20 +12,22 @@ | ||
| 12 | <br/><br/> | 12 | <br/><br/> |
| 13 | <div> | 13 | <div> |
| 14 | <?php | 14 | <?php |
| 15 | -if ($dir != '') { | ||
| 16 | -?> | ||
| 17 | - Are you sure you want to perform the backup? | ||
| 18 | - | ||
| 19 | -<p> | ||
| 20 | -Your mysql installation has been resolved. Manually, you would do the following: | ||
| 21 | - </p> | ||
| 22 | -<p> | ||
| 23 | -<table bgcolor="lightgrey"> | ||
| 24 | -<tr> | ||
| 25 | -<td> | ||
| 26 | -<nobr>cd "<?php echo $dir; ?>"</nobr> | ||
| 27 | -<br/> | ||
| 28 | -</p><?php | 15 | + if ($dir != '') { |
| 16 | + if (!$backupStatus) { | ||
| 17 | + ?> | ||
| 18 | + Are you sure you want to perform the backup? | ||
| 19 | + | ||
| 20 | + <p> | ||
| 21 | + Your mysql installation has been resolved. Manually, you would do the following: | ||
| 22 | + </p> | ||
| 23 | + <p> | ||
| 24 | + <table bgcolor="lightgrey"> | ||
| 25 | + <tr> | ||
| 26 | + <td> | ||
| 27 | + <nobr>cd "<?php echo $dir; ?>"</nobr> | ||
| 28 | + <br/> | ||
| 29 | + </p><?php | ||
| 30 | + } | ||
| 29 | } | 31 | } |
| 30 | else | 32 | else |
| 31 | { | 33 | { |
| @@ -50,10 +52,13 @@ You can continue to do the backup manually using the following process: | @@ -50,10 +52,13 @@ You can continue to do the backup manually using the following process: | ||
| 50 | if ($dir != '') | 52 | if ($dir != '') |
| 51 | { | 53 | { |
| 52 | if (($action == '') || ($action == 'confirm')) { | 54 | if (($action == '') || ($action == 'confirm')) { |
| 53 | - ?><input type="submit" name="BackupNow" value="Next" class="button_next"><?php | 55 | + ?><input type="submit" name="BackupNow" value="Next" class="button_next"><?php |
| 56 | + } | ||
| 57 | + else if ($backupStatus) { | ||
| 58 | + ?><input type="submit" name="Next" value="Next" class="button_next"><?php | ||
| 54 | } | 59 | } |
| 55 | else { | 60 | else { |
| 56 | - ?><input type="submit" name="Next" value="Next" class="button_next"><?php | 61 | + ?><input type="submit" name="Next" value="Next" class="button_next"><?php |
| 57 | } | 62 | } |
| 58 | } | 63 | } |
| 59 | 64 |
setup/upgrade/templates/progress.tpl
0 → 100644
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| 2 | +<html> | ||
| 3 | + <head> | ||
| 4 | + <title>KnowledgeTree Upgrade Wizard</title> | ||
| 5 | + <script type="text/javascript" src="resources/jquery.js"></script> | ||
| 6 | + <script type="text/javascript" src="resources/wizard.js" ></script> | ||
| 7 | + <link rel="stylesheet" type="text/css" href="resources/wizard.css" /> | ||
| 8 | + | ||
| 9 | + </head> | ||
| 10 | + | ||
| 11 | + <body onload=""> | ||
| 12 | + <div id="outer-wrapper"> | ||
| 13 | + <div id="header"> | ||
| 14 | + <div id="logo"><img src="resources/graphics/dame/upgrader-header_logo.png"/></div> | ||
| 15 | + <div id="install_details"> | ||
| 16 | + <span style="font-size:120%;"> 3.7 </span> | ||
| 17 | + <span style="font-size:80%;">Commercial Edition</span> | ||
| 18 | + </div> | ||
| 19 | + </div> | ||
| 20 | + <div id="wrapper"> | ||
| 21 | + <div id="container"> | ||
| 22 | + <div id="sidebar"> | ||
| 23 | + <?php echo $left; ?> | ||
| 24 | + </div> | ||
| 25 | + <div id="content"> | ||
| 26 | + <div id="content_container"> | ||
| 27 | + <p class="title"><?php echo $title; ?></p> | ||
| 28 | + <form action="index.php?step_name=welcome" method="post"> | ||
| 29 | + <div id="step_content" class="step"> | ||
| 30 | + <?php if(isset($error)) { | ||
| 31 | + echo "<span class='error'>".$error."</span>"; | ||
| 32 | + ?> | ||
| 33 | + <?php | ||
| 34 | + } | ||
| 35 | + ?> | ||
| 36 | + <?php | ||
| 37 | + if(isset($errors)) { | ||
| 38 | + if($errors){ | ||
| 39 | + echo '<div class="error">'; | ||
| 40 | + foreach ($errors as $msg){ | ||
| 41 | + echo $msg . "<br />"; | ||
| 42 | + ?> | ||
| 43 | + <a href="javascript:this.location.reload();" class="refresh">Refresh</a> | ||
| 44 | + <?php | ||
| 45 | + } | ||
| 46 | + echo '</div>'; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + ?> | ||
| 50 | + <br/><br/> | ||
| 51 | + <?php echo $content; ?> | ||
| 52 | + </div> | ||
| 53 | + </form> | ||
| 54 | + </div> | ||
| 55 | + </div> | ||
| 56 | + </div> | ||
| 57 | + <div class="clearing"> </div> | ||
| 58 | + </div> | ||
| 59 | + | ||
| 60 | + <div id="footer"> | ||
| 61 | + | ||
| 62 | + <img width="105" height="23" align="right" src="resources/graphics/dame/powered-by-kt.png" style="padding: 5px;"/> | ||
| 63 | + </div> | ||
| 64 | + </div> | ||
| 65 | + </body> | ||
| 66 | +</html> | ||
| 67 | +<script> | ||
| 68 | + var w = new wizard(); | ||
| 69 | +</script> | ||
| 0 | \ No newline at end of file | 70 | \ No newline at end of file |
setup/upgrade/upgradeUtil.php
| @@ -79,6 +79,31 @@ class UpgradeUtil { | @@ -79,6 +79,31 @@ class UpgradeUtil { | ||
| 79 | ob_end_clean(); | 79 | ob_end_clean(); |
| 80 | echo $contents; | 80 | echo $contents; |
| 81 | } | 81 | } |
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * Function to send output to the browser prior to normal dynamic loading of a template after code execution | ||
| 85 | + * | ||
| 86 | + * @param string $template The name of the template to use | ||
| 87 | + * @param array $output [optional] Optional array containing output text to be inserted into the template | ||
| 88 | + * @return | ||
| 89 | + */ | ||
| 90 | + public function flushOutput($template, $output = null) { | ||
| 91 | + if (is_array($output)) { | ||
| 92 | + foreach ($output as $key => $value) { | ||
| 93 | + $template_vars[$key] = $value; | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + $file = "templates/" . $template; | ||
| 97 | + if (!file_exists($file)) { | ||
| 98 | + return false; | ||
| 99 | + } | ||
| 100 | + extract($template_vars); // Extract the vars to local namespace | ||
| 101 | + ob_start(); | ||
| 102 | + include($file); | ||
| 103 | + $contents = ob_get_contents(); | ||
| 104 | + ob_end_clean(); | ||
| 105 | + echo $contents; | ||
| 106 | + } | ||
| 82 | 107 | ||
| 83 | /** | 108 | /** |
| 84 | * Check if system needs to be upgraded | 109 | * Check if system needs to be upgraded |
| @@ -637,6 +662,116 @@ class UpgradeUtil { | @@ -637,6 +662,116 @@ class UpgradeUtil { | ||
| 637 | } | 662 | } |
| 638 | return join(" ", $aSafeArgs); | 663 | return join(" ", $aSafeArgs); |
| 639 | } | 664 | } |
| 665 | + | ||
| 666 | + function create_restore_stmt($targetfile) | ||
| 667 | +{ | ||
| 668 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 669 | + | ||
| 670 | + $adminUser = $oKTConfig->get('db/dbAdminUser'); | ||
| 671 | + $adminPwd = $oKTConfig->get('db/dbAdminPass'); | ||
| 672 | + $dbHost = $oKTConfig->get('db/dbHost'); | ||
| 673 | + $dbName = $oKTConfig->get('db/dbName'); | ||
| 674 | + $dbPort = trim($oKTConfig->get('db/dbPort')); | ||
| 675 | + if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); | ||
| 676 | + if (empty($dbPort)) $dbPort='3306'; | ||
| 677 | + $dbSocket = trim($oKTConfig->get('db/dbSocket')); | ||
| 678 | + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); | ||
| 679 | + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; | ||
| 680 | + | ||
| 681 | + $dir = $this->resolveMysqlDir(); | ||
| 682 | + | ||
| 683 | + $info['dir']=$dir; | ||
| 684 | + | ||
| 685 | + $prefix=''; | ||
| 686 | + if (OS_UNIX) | ||
| 687 | + { | ||
| 688 | + $prefix .= "./"; | ||
| 689 | + } | ||
| 690 | + | ||
| 691 | + if (@stat($dbSocket) !== false) | ||
| 692 | + { | ||
| 693 | + $mechanism="--socket=\"$dbSocket\""; | ||
| 694 | + } | ||
| 695 | + else | ||
| 696 | + { | ||
| 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; | ||
| 716 | +} | ||
| 717 | + | ||
| 718 | +function resolveMysqlDir() | ||
| 719 | +{ | ||
| 720 | + // possibly detect existing installations: | ||
| 721 | + | ||
| 722 | + if (OS_UNIX) | ||
| 723 | + { | ||
| 724 | + $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); | ||
| 725 | + $mysqlname ='mysql'; | ||
| 726 | + } | ||
| 727 | + else | ||
| 728 | + { | ||
| 729 | + $dirs = explode(';', $_SERVER['PATH']); | ||
| 730 | + $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; | ||
| 731 | + $dirs[] = 'c:/program files/ktdms/mysql/bin'; | ||
| 732 | + $mysqlname ='mysql.exe'; | ||
| 733 | + } | ||
| 734 | + | ||
| 735 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 736 | + $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); | ||
| 737 | + $dirs[] = $mysqldir; | ||
| 738 | + | ||
| 739 | + if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) | ||
| 740 | + { | ||
| 741 | + $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); | ||
| 742 | + } | ||
| 743 | + | ||
| 744 | + foreach($dirs as $dir) | ||
| 745 | + { | ||
| 746 | + if (is_file($dir . '/' . $mysqlname)) | ||
| 747 | + { | ||
| 748 | + return $dir; | ||
| 749 | + } | ||
| 750 | + } | ||
| 751 | + | ||
| 752 | + return ''; | ||
| 753 | +} | ||
| 754 | + | ||
| 755 | +function resolveTempDir() | ||
| 756 | +{ | ||
| 757 | + | ||
| 758 | + if (OS_UNIX) | ||
| 759 | + { | ||
| 760 | + $dir='/tmp/kt-db-backup'; | ||
| 761 | + } | ||
| 762 | + else | ||
| 763 | + { | ||
| 764 | + $dir='c:/kt-db-backup'; | ||
| 765 | + } | ||
| 766 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 767 | + $dir = $oKTConfig->get('backup/backupDirectory',$dir); | ||
| 768 | + | ||
| 769 | + if (!is_dir($dir)) | ||
| 770 | + { | ||
| 771 | + mkdir($dir); | ||
| 772 | + } | ||
| 773 | + return $dir; | ||
| 774 | +} | ||
| 640 | 775 | ||
| 641 | } | 776 | } |
| 642 | ?> | 777 | ?> |
| 643 | \ No newline at end of file | 778 | \ No newline at end of file |