diff --git a/system/Commands/Database/MigrateRollback.php b/system/Commands/Database/MigrateRollback.php index f206d7fc5162..e1c788e7702e 100644 --- a/system/Commands/Database/MigrateRollback.php +++ b/system/Commands/Database/MigrateRollback.php @@ -15,6 +15,7 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use CodeIgniter\Database\MigrationRunner; use Throwable; /** @@ -78,10 +79,23 @@ public function run(array $params) // @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)) {