diff --git a/setup/migrate/steps/migrateDatabase.php b/setup/migrate/steps/migrateDatabase.php index 21d0197..99c300c 100644 --- a/setup/migrate/steps/migrateDatabase.php +++ b/setup/migrate/steps/migrateDatabase.php @@ -253,6 +253,7 @@ class migrateDatabase extends Step $this->_util = new MigrateUtil(); if(WINDOWS_OS) $this->mysqlDir = MYSQL_BIN; + $this->wizardLocation = '../wizard'; } /** @@ -292,6 +293,19 @@ class migrateDatabase extends Step $this->temp_variables['duname'] = $this->getPostSafe('duname'); $this->temp_variables['dpassword'] = $this->getPostSafe('dpassword'); $this->temp_variables['dbbinary'] = $this->getPostSafe('dbbinary'); + // create lock file to indicate migration mode + $this->createMigrateFile(); + } + + /** + * Creates migration lock file so that system knows it is supposed to run an upgrade installation + * + * @author KnowledgeTree Team + * @access private + * @return void + */ + private function createMigrateFile() { + @touch($this->wizardLocation . DIRECTORY_SEPARATOR . "migrate.lock"); } /** diff --git a/setup/wizard/installer.php b/setup/wizard/installer.php index 66bae75..44152ca 100644 --- a/setup/wizard/installer.php +++ b/setup/wizard/installer.php @@ -414,6 +414,7 @@ class Installer { */ private function _completeInstall() { @touch("install.lock"); + @unlink("migrate.lock"); } /** diff --git a/setup/wizard/path.php b/setup/wizard/path.php index 4a27496..12080c0 100644 --- a/setup/wizard/path.php +++ b/setup/wizard/path.php @@ -94,6 +94,7 @@ define('SYSTEM_ROOT', $asys); define('SQL_DIR', SYSTEM_DIR."sql".DS); define('SQL_INSTALL_DIR', SQL_DIR."mysql".DS."install".DS); + define('SQL_MIGRATE_DIR', SQL_DIR."mysql".DS."migrate".DS); // Install Type preg_match('/Zend/', $sys, $matches); // TODO: Dirty if($matches) { diff --git a/setup/wizard/steps/database.php b/setup/wizard/steps/database.php index 9a6855a..5e03da3 100644 --- a/setup/wizard/steps/database.php +++ b/setup/wizard/steps/database.php @@ -579,9 +579,18 @@ class database extends Step private function mysql() { $con = $this->connectMysql(); if($con) { - if(!$this->createDB($con)) { - $this->error['con'] = "Could not Create Database: "; - return false; + // check for migrate.lock file which indicates this is a migration and not a clean install + if (file_exists('migrate.lock')) { + if(!$this->migrateDB($con)) { + $this->error['con'] = "Could not Create Database: "; + return false; + } + } + else { + if(!$this->createDB($con)) { + $this->error['con'] = "Could not Create Database: "; + return false; + } } $this->closeMysql($con); } @@ -605,6 +614,47 @@ class database extends Step return $con; } + + /** + * Helper + * + * @author KnowledgeTree Team + * @params object mysql connection object $con + * @access private + * @return object mysql connection + */ + private function migrateDB($con) { + if($this->usedb($con)) { // attempt to use the db + if($this->dropdb($con)) { // attempt to drop the db + if(!$this->create($con)) { // attempt to create the db + $this->error['con'] = "Could not create database: "; + return false;// cannot overwrite database + } + } else { + $this->error['con'] = "Could not drop database: "; + return false;// cannot overwrite database + } + } else { + if(!$this->create($con)) { // attempt to create the db + $this->error['con'] = "Could not create database: "; + return false;// cannot overwrite database + } + } + + if(!$this->createDmsUser($con)) { // Create dms users + + } + + if(!$this->loadUpgraded($con)) { + $this->error['con'] = "Could not load upgraded database"; + } + + if(!$this->applyUpgrades($con)) { + $this->error['con'] = "Could not apply updates "; + } + + return true; + } /** * Helper @@ -634,11 +684,7 @@ class database extends Step if(!$this->createDmsUser($con)) { // Create dms users } -/* - if(!$this->loadUpgraded($con)) { - $this->error['con'] = "Could not load upgraded database"; - } -*/ + if(!$this->createSchema($con)) { $this->error['con'] = "Could not create schema "; } @@ -741,9 +787,9 @@ class database extends Step private function loadUpgraded($con) { if($this->dpassword == '') { - $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} {$this->dname} < \"".SQL_INSTALL_DIR."dms.sql\""; + $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} {$this->dname} < \"".SQL_MIGRATE_DIR."dms.sql\""; } else { - $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} -p{$this->dpassword} {$this->dname} < \"".SQL_INSTALL_DIR."dms.sql\""; + $command = "\"".$this->mysqlDir."{$this->dbbinary}\" -u{$this->duname} -p{$this->dpassword} {$this->dname} < \"".SQL_MIGRATE_DIR."dms.sql\""; } $response = $this->_util->pexec($command); return $response; diff --git a/setup/wizard/steps/installtype.php b/setup/wizard/steps/installtype.php index f9df553..38b13e5 100644 --- a/setup/wizard/steps/installtype.php +++ b/setup/wizard/steps/installtype.php @@ -54,6 +54,7 @@ class installType extends step if($this->migrate()) { return 'migrate'; } if($this->next()) { + $this->deleteMigrateFile(); return 'next'; } else if($this->previous()) { return 'previous'; @@ -70,5 +71,17 @@ class installType extends step public function getErrors() { return $this->error; } + + /** + * Deletes migration lock file if a clean install is chosen + * This is in case someone changes their mind after choosing upgrade/migrate and clicks back up to this step + * + * @author KnowledgeTree Team + * @access private + * @return void + */ + private function deleteMigrateFile() { + @unlink("migrate.lock"); + } } ?> \ No newline at end of file