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;
}
}