yupe\components\Migrator::getMigrationHistory PHP Method

getMigrationHistory() public method

Check each modules for new migrations
public getMigrationHistory ( string $module, integer $limit = 20 ) : mixed
$module string - required module
$limit integer - limit of array
return mixed version and apply time
    public function getMigrationHistory($module, $limit = 20)
    {
        $db = $this->getDbConnection();
        $allData = Yii::app()->getCache()->get('getMigrationHistory');
        if ($allData === false || !isset($allData[$module])) {
            Yii::app()->getCache()->clear('getMigrationHistory');
            $data = $db->cache(3600, new CDbCacheDependency('select count(id) from {{migrations}}'))->createCommand()->select('version, apply_time')->from('{{migrations}}')->order('id DESC')->where('module = :module', [':module' => $module])->limit($limit)->queryAll();
            $allData[$module] = $data;
            Yii::app()->getCache()->set('getMigrationHistory', $allData, 3600, new TagsCache('yupe', 'installedModules', 'getModulesDisabled', 'getMigrationHistory', $module));
        } else {
            $data = $allData[$module];
        }
        return CHtml::listData($data, 'version', 'apply_time');
    }

Usage Example

 /**
  * Check, if NestedSets Migration exists in DB.
  * @param  Migrator $migrator
  * @return bool
  */
 public function NsMigrationExists(Migrator $migrator)
 {
     $history = $migrator->getMigrationHistory('comment');
     if (array_key_exists(self::NS_MIGRATION_NAME, $history)) {
         return true;
     }
     return false;
 }