Example #1
0
         } else {
             putenv('BACKUP_VERBOSE=true');
             $backup_dao = DAOFactory::getDAO('BackupDAO');
             print "\nExporting data to: {$filename}\n\n";
             $backup_dao->export($filename);
             print "\nBackup completed.\n\n";
         }
     }
 }
 // run updates...
 // get migrations we need to run...
 print "\nUpgrading Thinkup to version {$thinkup_db_version}...\n\n";
 $upgrade_start_time = microtime(true);
 putenv('CLI_BACKUP=true');
 $upgrade_ctl = new UpgradeController();
 $migrations = $upgrade_ctl->getMigrationList($db_version);
 $install_dao = DAOFactory::getDAO('InstallerDAO');
 foreach ($migrations as $migration) {
     print "  Running migration " . $migration['version'] . "\n";
     $install_dao->runMigrationSQL($migration['sql']);
 }
 $option_dao = DAOFactory::getDAO('OptionDAO');
 $option = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'database_version');
 if ($option) {
     $option_dao->updateOptionByName(OptionDAO::APP_OPTIONS, 'database_version', $thinkup_db_version);
 } else {
     $option_dao->insertOption(OptionDAO::APP_OPTIONS, 'database_version', $thinkup_db_version);
 }
 // release global mutex
 BackupController::mutexLock();
 // delete upgrade token if it exists
 public function testRunNewMigrationUpdateCompletedTable()
 {
     $this->simulateLogin('*****@*****.**', true);
     $controller = new UpgradeController(true);
     $this->newMigrationFiles('some_stuff');
     $this->newMigrationFiles('some_stuff', $old = true);
     // older already ran?
     $db_version = UpgradeController::getCurrentDBVersion($cached = false);
     $list = $controller->getMigrationList($db_version);
     $this->assertEqual(count($list), 1);
     $this->assertTrue($list[0]['new_migration']);
     $this->assertPattern("/^2011-09-21_some_stuff_v\\d+\\.\\d+\\.sql\$/", $list[0]['filename']);
     // create completion table
     $com_sql_file = THINKUP_ROOT_PATH . 'webapp/install/sql/completed_migrations.sql';
     //echo $com_sql_file;
     $com_sql = file_get_contents($com_sql_file);
     $this->pdo->query($com_sql);
     $this->pdo->query("alter table " . $this->table_prefix . "completed_migrations DROP column sql_ran");
     $_GET['migration_index'] = 1;
     $results = $controller->go();
     $obj = json_decode($results);
     $this->assertTrue($obj->processed);
     $sql = file_get_contents($this->test_migrations[0]);
     $sql = preg_replace('/\\-\\-.*/', '', $sql);
     $this->assertEqual($obj->sql, $sql);
     $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
     $data2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->assertEqual(count($data2), 3);
     $this->assertPattern('/CREATE TABLE `.*test1`/', $data2[0]['sql_ran']);
 }