Commit 76d7a32e8286821a88c1637d40f34338ba44abb4

Authored by unknown
1 parent 537aa2a4

Added migrate.lock file to indicate migration mode. Modified database install c…

…ode to use exported database (assumed name dms.sql, location sql/mysql/migrate

Story ID:1244695. 3.7 Database Upgrade Script

Committed by: Paul Barrett

Reviewed by: Jarrett Jordaan
setup/migrate/steps/migrateDatabase.php
... ... @@ -253,6 +253,7 @@ class migrateDatabase extends Step
253 253 $this->_util = new MigrateUtil();
254 254 if(WINDOWS_OS)
255 255 $this->mysqlDir = MYSQL_BIN;
  256 + $this->wizardLocation = '../wizard';
256 257 }
257 258  
258 259 /**
... ... @@ -292,6 +293,19 @@ class migrateDatabase extends Step
292 293 $this->temp_variables['duname'] = $this->getPostSafe('duname');
293 294 $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword');
294 295 $this->temp_variables['dbbinary'] = $this->getPostSafe('dbbinary');
  296 + // create lock file to indicate migration mode
  297 + $this->createMigrateFile();
  298 + }
  299 +
  300 + /**
  301 + * Creates migration lock file so that system knows it is supposed to run an upgrade installation
  302 + *
  303 + * @author KnowledgeTree Team
  304 + * @access private
  305 + * @return void
  306 + */
  307 + private function createMigrateFile() {
  308 + @touch($this->wizardLocation . DIRECTORY_SEPARATOR . "migrate.lock");
295 309 }
296 310  
297 311 /**
... ...
setup/wizard/installer.php
... ... @@ -414,6 +414,7 @@ class Installer {
414 414 */
415 415 private function _completeInstall() {
416 416 @touch("install.lock");
  417 + @unlink("migrate.lock");
417 418 }
418 419  
419 420 /**
... ...
setup/wizard/path.php
... ... @@ -94,6 +94,7 @@
94 94 define('SYSTEM_ROOT', $asys);
95 95 define('SQL_DIR', SYSTEM_DIR."sql".DS);
96 96 define('SQL_INSTALL_DIR', SQL_DIR."mysql".DS."install".DS);
  97 + define('SQL_MIGRATE_DIR', SQL_DIR."mysql".DS."migrate".DS);
97 98 // Install Type
98 99 preg_match('/Zend/', $sys, $matches); // TODO: Dirty
99 100 if($matches) {
... ...
setup/wizard/steps/database.php
... ... @@ -579,9 +579,18 @@ class database extends Step
579 579 private function mysql() {
580 580 $con = $this->connectMysql();
581 581 if($con) {
582   - if(!$this->createDB($con)) {
583   - $this->error['con'] = "Could not Create Database: ";
584   - return false;
  582 + // check for migrate.lock file which indicates this is a migration and not a clean install
  583 + if (file_exists('migrate.lock')) {
  584 + if(!$this->migrateDB($con)) {
  585 + $this->error['con'] = "Could not Create Database: ";
  586 + return false;
  587 + }
  588 + }
  589 + else {
  590 + if(!$this->createDB($con)) {
  591 + $this->error['con'] = "Could not Create Database: ";
  592 + return false;
  593 + }
585 594 }
586 595 $this->closeMysql($con);
587 596 }
... ... @@ -605,6 +614,47 @@ class database extends Step
605 614  
606 615 return $con;
607 616 }
  617 +
  618 + /**
  619 + * Helper
  620 + *
  621 + * @author KnowledgeTree Team
  622 + * @params object mysql connection object $con
  623 + * @access private
  624 + * @return object mysql connection
  625 + */
  626 + private function migrateDB($con) {
  627 + if($this->usedb($con)) { // attempt to use the db
  628 + if($this->dropdb($con)) { // attempt to drop the db
  629 + if(!$this->create($con)) { // attempt to create the db
  630 + $this->error['con'] = "Could not create database: ";
  631 + return false;// cannot overwrite database
  632 + }
  633 + } else {
  634 + $this->error['con'] = "Could not drop database: ";
  635 + return false;// cannot overwrite database
  636 + }
  637 + } else {
  638 + if(!$this->create($con)) { // attempt to create the db
  639 + $this->error['con'] = "Could not create database: ";
  640 + return false;// cannot overwrite database
  641 + }
  642 + }
  643 +
  644 + if(!$this->createDmsUser($con)) { // Create dms users
  645 +
  646 + }
  647 +
  648 + if(!$this->loadUpgraded($con)) {
  649 + $this->error['con'] = "Could not load upgraded database";
  650 + }
  651 +
  652 + if(!$this->applyUpgrades($con)) {
  653 + $this->error['con'] = "Could not apply updates ";
  654 + }
  655 +
  656 + return true;
  657 + }
608 658  
609 659 /**
610 660 * Helper
... ... @@ -634,11 +684,7 @@ class database extends Step
634 684 if(!$this->createDmsUser($con)) { // Create dms users
635 685  
636 686 }
637   -/*
638   - if(!$this->loadUpgraded($con)) {
639   - $this->error['con'] = "Could not load upgraded database";
640   - }
641   -*/
  687 +
642 688 if(!$this->createSchema($con)) {
643 689 $this->error['con'] = "Could not create schema ";
644 690 }
... ... @@ -741,9 +787,9 @@ class database extends Step
741 787  
742 788 private function loadUpgraded($con) {
743 789 if($this->dpassword == '') {
744   - $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} {$this->dname} < \"".SQL_INSTALL_DIR."dms.sql\"";
  790 + $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} {$this->dname} < \"".SQL_MIGRATE_DIR."dms.sql\"";
745 791 } else {
746   - $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} -p{$this->dpassword} {$this->dname} < \"".SQL_INSTALL_DIR."dms.sql\"";
  792 + $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} -p{$this->dpassword} {$this->dname} < \"".SQL_MIGRATE_DIR."dms.sql\"";
747 793 }
748 794 $response = $this->_util->pexec($command);
749 795 return $response;
... ...
setup/wizard/steps/installtype.php
... ... @@ -54,6 +54,7 @@ class installType extends step
54 54 if($this->migrate()) {
55 55 return 'migrate';
56 56 } if($this->next()) {
  57 + $this->deleteMigrateFile();
57 58 return 'next';
58 59 } else if($this->previous()) {
59 60 return 'previous';
... ... @@ -70,5 +71,17 @@ class installType extends step
70 71 public function getErrors() {
71 72 return $this->error;
72 73 }
  74 +
  75 + /**
  76 + * Deletes migration lock file if a clean install is chosen
  77 + * This is in case someone changes their mind after choosing upgrade/migrate and clicks back up to this step
  78 + *
  79 + * @author KnowledgeTree Team
  80 + * @access private
  81 + * @return void
  82 + */
  83 + private function deleteMigrateFile() {
  84 + @unlink("migrate.lock");
  85 + }
73 86 }
74 87 ?>
75 88 \ No newline at end of file
... ...