Force migrations to take into account the namespaces defined in composer

This commit is contained in:
michalsn 2020-03-07 08:40:40 +01:00
parent 0047e81446
commit e79560a09f
No known key found for this signature in database
GPG Key ID: 0E4DB53924E59366
2 changed files with 23 additions and 13 deletions

View File

@ -40,7 +40,7 @@ namespace CodeIgniter\Commands\Database;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Autoload;
use Config\Services;
use Config\Migrations;
/**
@ -124,15 +124,14 @@ class CreateMigration extends BaseCommand
if (! empty($ns))
{
// Get all namespaces from PSR4 paths.
$config = new Autoload();
$namespaces = $config->psr4;
// Get all namespaces
$namespaces = Services::autoloader()->getNamespace();
foreach ($namespaces as $namespace => $path)
{
if ($namespace === $ns)
{
$homepath = realpath($path);
$homepath = realpath(reset($path));
break;
}
}

View File

@ -42,7 +42,6 @@ namespace CodeIgniter\Commands\Database;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
use Config\Autoload;
/**
* Displays a list of all migrations and whether they've been run or not.
@ -106,6 +105,10 @@ class MigrateStatus extends BaseCommand
'CodeIgniter',
'Config',
'Tests\Support',
'Kint',
'Laminas\ZendFrameworkBridge',
'Laminas\Escaper',
'Psr\Log',
];
/**
@ -124,9 +127,11 @@ class MigrateStatus extends BaseCommand
$runner->setGroup($group);
}
// Get all namespaces from PSR4 paths.
$config = new Autoload();
$namespaces = $config->psr4;
// Get all namespaces
$namespaces = Services::autoloader()->getNamespace();
// Determines whether any migrations were found
$found = false;
// Loop for all $namespaces
foreach ($namespaces as $namespace => $path)
@ -138,16 +143,17 @@ class MigrateStatus extends BaseCommand
$runner->setNamespace($namespace);
$migrations = $runner->findMigrations();
$history = $runner->getHistory();
CLI::write($namespace);
if (empty($migrations))
{
CLI::error(lang('Migrations.noneFound'));
continue;
}
$found = true;
$history = $runner->getHistory();
CLI::write($namespace);
ksort($migrations);
$max = 0;
@ -176,6 +182,11 @@ class MigrateStatus extends BaseCommand
CLI::write(str_pad(' ' . $migration->name, $max + 6) . ($date ? $date : '---'));
}
}
if (! $found)
{
CLI::error(lang('Migrations.noneFound'));
}
}
}