Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] added migration namespaces to options, added alias syntax support #13359

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework/console/controllers/BaseMigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function options($actionID)
{
return array_merge(
parent::options($actionID),
['migrationPath'], // global for all actions
['migrationPath', 'migrationNamespaces'], // global for all actions
$actionID === 'create' ? ['templateFile'] : [] // action create
);
}
Expand Down
7 changes: 7 additions & 0 deletions framework/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use yii\di\Instance;
use yii\helpers\ArrayHelper;
use yii\helpers\Console;
use yii\helpers\StringHelper;

/**
* Manages application migrations.
Expand Down Expand Up @@ -186,6 +187,12 @@ protected function createMigration($class)
if (strpos($class, '\\') === false) {
$file = $this->migrationPath . DIRECTORY_SEPARATOR . $class . '.php';
require_once($file);
} elseif (!class_exists($class, false)) {
// detect aliases migration in global namespace
require_once(Yii::getAlias('@'.str_replace('\\', '/', $class)).'.php');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this step is done by the Yii autoloader in case you enable second parameter in class_exists, so it is not needed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it would be

} elseif (!class_exists($class, true)) {
    $class = StringHelper::basename($class);
}

Copy link
Contributor Author

@schmunk42 schmunk42 Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update that if all concerns are sorted out.

if (!class_exists($class, false)) {
$class = StringHelper::basename($class);
}
}

return new $class(['db' => $this->db]);
Expand Down