fix: "migration:rollback -b" does not work due to TypeError

This commit is contained in:
kenjis 2024-06-12 09:46:56 +09:00
parent d2e50affec
commit 3cfb940551
No known key found for this signature in database
GPG Key ID: BD254878922AF198

View File

@ -15,6 +15,7 @@ namespace CodeIgniter\Commands\Database;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Database\MigrationRunner;
use Throwable;
/**
@ -78,10 +79,23 @@ class MigrateRollback extends BaseCommand
// @codeCoverageIgnoreEnd
}
/** @var MigrationRunner $runner */
$runner = service('migrations');
try {
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
if (is_string($batch)) {
if (! ctype_digit($batch)) {
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
CLI::newLine();
return EXIT_ERROR;
}
$batch = (int) $batch;
}
CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');
if (! $runner->regress($batch)) {