public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$path = Yii::getAlias($this->migrationPath);
if ($action->id !== 'create') {
if (is_string($this->db)) {
$this->db = Yii::$app->get($this->db);
}
if (!$this->db instanceof Connection) {
throw new Exception("The 'db' option must refer to the application component ID of a DB connection.");
}
} else {
if (!is_dir($path)) {
echo "\n{$path} does not exist, creating...";
FileHelper::createDirectory($path);
}
}
$version = Yii::getVersion();
echo "Yii Migration Tool (based on Yii v{$version})\n\n";
if (isset($this->db->dsn)) {
echo "Database Connection: " . $this->db->dsn . "\n";
}
return true;
} else {
return false;
}
}