mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Force migrations to take into account the namespaces defined in composer
This commit is contained in:
parent
0047e81446
commit
e79560a09f
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user