コード例 #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;
 }