Skip to content
Open
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
24 changes: 17 additions & 7 deletions controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
class MigrateController extends \yii\console\controllers\MigrateController
{
/**
* @var bool
* @var bool TRUE if migrations should be found in "migrationPaths"
*/
public $autoDiscover = false;

/**
* @var array
* @var array List of paths for migrations lookup. Aliases can be used.
*/
public $migrationPaths = [];

/**
* @var bool TRUE if the migrations lookup should be recursive
*/
public $recursiveDiscover = true;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -97,12 +102,17 @@ private function getMigrationPaths()

$migrations = [];

// Recursively iterate through each path
// Iterate through each path
foreach ($paths as $path) {
$recursiveDirectory = new \RecursiveDirectoryIterator(Yii::getAlias($path));
$recursiveIterator = new \RecursiveIteratorIterator($recursiveDirectory);
$recursiveRegex = new \RegexIterator($recursiveIterator, '/^.*[\\\\\\/]migrations[\\\\\\/]m(\d{6}_\d{6})_.*?\.php$/i',
\RecursiveRegexIterator::GET_MATCH);
$migrationCandidateIterator = $this->recursiveDiscover
? new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Yii::getAlias($path)))
: new \FilesystemIterator(Yii::getAlias($path));

$recursiveRegex = new \RegexIterator(
$migrationCandidateIterator,
'~^.*[\/]m(\d{6}_\d{6})_.*?\.php$~i',
\RecursiveRegexIterator::GET_MATCH
);

// Add to array which will be sortable by filename
foreach ($recursiveRegex as $file) {
Expand Down