Пример #1
0
 /**
  * Fetches a list of migrations which have already been run.
  *
  * @uses MpmDbHelper::doSingleRowSelect()
  * @uses MpmDbHelper::doMultiRowSelect()
  *
  * @param string $latestTimestamp the current timestamp of the migration run last
  * @param string $direction the way we are migrating; should either be up or down
  *
  * @return array
  */
 public static function getListFromDb($latestTimestamp, $direction = 'up')
 {
     $db_config = $GLOBALS['db_config'];
     $migrations_table = $db_config->migrations_table;
     if ($direction == 'down') {
         $sql = "SELECT * FROM `{$migrations_table}` WHERE `timestamp` <= '{$latestTimestamp}' AND `active` = 1";
         $countSql = "SELECT COUNT(*) as total FROM `{$migrations_table}` WHERE `timestamp` <= '{$latestTimestamp}' AND `active` = 1";
     } else {
         $sql = "SELECT * FROM `{$migrations_table}` WHERE `timestamp` >= '{$latestTimestamp}' AND `active` = 1";
         $countSql = "SELECT COUNT(*) as total FROM `{$migrations_table}` WHERE `timestamp` >= '{$latestTimestamp}' AND `active` = 1";
     }
     $list = array();
     $countObj = MpmDbHelper::doSingleRowSelect($countSql);
     if ($countObj->total > 0) {
         $results = MpmDbHelper::doMultiRowSelect($sql);
         foreach ($results as $obj) {
             $list[] = $obj->timestamp;
         }
     }
     return $list;
 }
Пример #2
0
 /**
  * Clears the migrations table and then rebuilds it.
  *
  * @uses MpmListHelper::mergeFilesWithDb()
  * @uses MpmDbHelper::doSingleRowSelect()
  *
  * @return void
  */
 public function reloadMigrations()
 {
     $db_config = $GLOBALS['db_config'];
     $migrations_table = $db_config->migrations_table;
     echo 'Clearing out existing migration data... ';
     $this->dbObj->exec('TRUNCATE TABLE `' . $migrations_table . '`');
     echo 'done.', "\n\n", 'Rebuilding migration data... ';
     MpmListHelper::mergeFilesWithDb();
     echo 'done.', "\n";
     if ($this->initialMigrationTimestamp != null) {
         echo "\n", 'Updating initial migration timestamp to ', $this->initialMigrationTimestamp, '... ';
         $result = MpmDbHelper::doSingleRowSelect('SELECT COUNT(*) AS total FROM `' . $migrations_table . '` WHERE `timestamp` = "' . $this->initialMigrationTimestamp . '"', $this->dbObj);
         if ($result->total == 1) {
             $this->dbObj->exec('UPDATE `' . $migrations_table . '` SET `is_current` = 0');
             $this->dbObj->exec('UPDATE `' . $migrations_table . '` SET `is_current` = 1 WHERE `timestamp` = "' . $this->initialMigrationTimestamp . '"');
             $this->dbObj->exec('UPDATE `' . $migrations_table . '` SET `active` = 1 WHERE `timestamp` <= "' . $this->initialMigrationTimestamp . '"');
         }
         echo 'done.', "\n";
     }
 }