yii\console\controllers\BaseMigrateController::beforeAction PHP Method

beforeAction() public method

This method is invoked right before an action is to be executed (after all possible filters.) It checks the existence of the [[migrationPath]].
public beforeAction ( Action $action ) : boolean
$action yii\base\Action the action to be executed.
return boolean whether the action should continue to be executed.
    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) {
            if (empty($this->migrationNamespaces) && empty($this->migrationPath)) {
                throw new InvalidConfigException('At least one of `migrationPath` or `migrationNamespaces` should be specified.');
            }
            foreach ($this->migrationNamespaces as $key => $value) {
                $this->migrationNamespaces[$key] = trim($value, '\\');
            }
            if ($this->migrationPath !== null) {
                $path = Yii::getAlias($this->migrationPath);
                if (!is_dir($path)) {
                    if ($action->id !== 'create') {
                        throw new InvalidConfigException("Migration failed. Directory specified in migrationPath doesn't exist: {$this->migrationPath}");
                    }
                    FileHelper::createDirectory($path);
                }
                $this->migrationPath = $path;
            }
            $version = Yii::getVersion();
            $this->stdout("Yii Migration Tool (based on Yii v{$version})\n\n");
            return true;
        } else {
            return false;
        }
    }

Usage Example

コード例 #1
0
ファイル: MigrateController.php プロジェクト: ajnok/yii2mis
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             $this->db = Instance::ensure($this->db, Connection::className());
         }
         return true;
     } else {
         return false;
     }
 }
All Usage Examples Of yii\console\controllers\BaseMigrateController::beforeAction