Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Argument;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\Config\Factories;
Expand Down Expand Up @@ -53,7 +52,7 @@ protected function configure(): void
protected function interact(array &$arguments, array &$options): void
{
if ($arguments === []) {
$arguments[] = CLI::prompt('Database name', null, 'required');
$arguments[] = $this->getPrompt()->ask('Database name', null, 'required');
}

$ext = $this->getUnboundOption('ext', $options);
Expand All @@ -71,6 +70,8 @@ protected function execute(array $arguments, array $options): int
$name = $arguments['db_name'];
assert(is_string($name));

$output = $this->getOutput();

try {
$config = config(Database::class);

Expand All @@ -86,7 +87,7 @@ protected function execute(array $arguments, array $options): int
assert(is_string($ext));

if (! in_array($ext, self::VALID_EXTENSIONS, true)) {
CLI::error(sprintf('Invalid file extension "%s". Use either `db` or `sqlite`.', $ext), 'light_gray', 'red');
$output->error(sprintf('Invalid file extension "%s". Use either `db` or `sqlite`.', $ext), 'light_gray', 'red');

return EXIT_ERROR;
}
Expand All @@ -102,7 +103,7 @@ protected function execute(array $arguments, array $options): int
$dbName = str_contains($name, DIRECTORY_SEPARATOR) ? $name : WRITEPATH . $name;

if (is_file($dbName)) {
CLI::error("Database \"{$dbName}\" already exists.", 'light_gray', 'red');
$output->error("Database \"{$dbName}\" already exists.", 'light_gray', 'red');

return EXIT_ERROR;
}
Expand All @@ -116,18 +117,18 @@ protected function execute(array $arguments, array $options): int

if (! is_file($db->getDatabase()) && $name !== ':memory:') {
// @codeCoverageIgnoreStart
CLI::error('Database creation failed.', 'light_gray', 'red');
$output->error('Database creation failed.', 'light_gray', 'red');

return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}
} elseif (! Database::forge()->createDatabase($name)) {
CLI::error('Database creation failed.', 'light_gray', 'red');
$output->error('Database creation failed.', 'light_gray', 'red');

return EXIT_ERROR;
}

CLI::write("Database \"{$name}\" successfully created.", 'green');
$output->write("Database \"{$name}\" successfully created.", 'green');

return EXIT_SUCCESS;
} catch (Throwable $e) {
Expand Down
13 changes: 7 additions & 6 deletions system/Commands/Database/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\CLI\SignalTrait;
use CodeIgniter\Database\MigrationRunner;
Expand Down Expand Up @@ -62,7 +61,9 @@ protected function execute(array $arguments, array $options): int
$runner = service('migrations');
$runner->clearCliMessages();

CLI::write(lang('Migrations.latest'), 'yellow');
$output = $this->getOutput();

$output->write(lang('Migrations.latest'), 'yellow');

$namespace = $options['namespace'];
assert(is_string($namespace));
Expand All @@ -79,19 +80,19 @@ protected function execute(array $arguments, array $options): int
$runner->setNamespace($namespace);
}

$this->withSignalsBlocked(static function () use ($runner, $group): void {
$this->withSignalsBlocked(static function () use ($runner, $group, $output): void {
if (! $runner->latest($group)) {
CLI::error(lang('Migrations.generalFault'), 'light_gray', 'red');
$output->error(lang('Migrations.generalFault'), 'light_gray', 'red');
}
});

$messages = $runner->getCliMessages();

foreach ($messages as $message) {
CLI::write($message);
$output->write($message);
}

CLI::write(lang('Migrations.migrated'), 'green');
$output->write(lang('Migrations.migrated'), 'green');

return EXIT_SUCCESS;
} catch (Throwable $e) {
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Database/MigrateRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\CLI\SignalTrait;

Expand Down Expand Up @@ -69,7 +68,7 @@ protected function interact(array &$arguments, array &$options): void
return;
}

if (CLI::prompt(lang('Migrations.refreshConfirm'), ['y', 'n']) === 'y') {
if ($this->getPrompt()->ask(lang('Migrations.refreshConfirm'), ['y', 'n']) === 'y') {
$options['force'] = null; // simulate the presence of the --force option
}
}
Expand Down
16 changes: 8 additions & 8 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\CLI\SignalTrait;
use CodeIgniter\Database\MigrationRunner;
Expand Down Expand Up @@ -60,7 +59,7 @@ protected function interact(array &$arguments, array &$options): void
return;
}

if (CLI::prompt(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'y') {
if ($this->getPrompt()->ask(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'y') {
$options['force'] = null; // simulate the presence of the --force option
}
}
Expand All @@ -73,6 +72,7 @@ protected function execute(array $arguments, array $options): int

/** @var MigrationRunner $runner */
$runner = service('migrations');
$output = $this->getOutput();

try {
$batch = $options['batch'];
Expand All @@ -81,18 +81,18 @@ protected function execute(array $arguments, array $options): int
if ($batch === '') {
$batch = $runner->getLastBatch() - 1;
} elseif (! ctype_digit($batch)) {
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
$output->error('Invalid batch number: ' . $batch, 'light_gray', 'red');

return EXIT_ERROR;
} else {
$batch = (int) $batch;
}

CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');
$output->write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

$exit = $this->withSignalsBlocked(static function () use ($runner, $batch): int {
$exit = $this->withSignalsBlocked(static function () use ($runner, $batch, $output): int {
if (! $runner->regress($batch)) {
CLI::error(lang('Migrations.generalFault'), 'light_gray', 'red');
$output->error(lang('Migrations.generalFault'), 'light_gray', 'red');

return EXIT_ERROR;
}
Expand All @@ -107,10 +107,10 @@ protected function execute(array $arguments, array $options): int
$messages = $runner->getCliMessages();

foreach ($messages as $message) {
CLI::write($message);
$output->write($message);
}

CLI::write('Done rolling back migrations.', 'green');
$output->write('Done rolling back migrations.', 'green');

return EXIT_SUCCESS;
} catch (Throwable $e) {
Expand Down
20 changes: 11 additions & 9 deletions system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\CLI\Table;
use CodeIgniter\Database\MigrationRunner;

/**
Expand Down Expand Up @@ -118,22 +118,24 @@ protected function execute(array $arguments, array $options): int
}
}

$output = $this->getOutput();

if ($status === []) {
CLI::error(lang('Migrations.noneFound'), 'light_gray', 'red');
$output->error(lang('Migrations.noneFound'), 'light_gray', 'red');

return EXIT_ERROR;
}

$headers = [
CLI::color(lang('Migrations.namespace'), 'yellow'),
CLI::color(lang('Migrations.version'), 'yellow'),
CLI::color(lang('Migrations.filename'), 'yellow'),
CLI::color(lang('Migrations.group'), 'yellow'),
CLI::color(str_replace(': ', '', lang('Migrations.on')), 'yellow'),
CLI::color(lang('Migrations.batch'), 'yellow'),
$output->color(lang('Migrations.namespace'), 'yellow'),
$output->color(lang('Migrations.version'), 'yellow'),
$output->color(lang('Migrations.filename'), 'yellow'),
$output->color(lang('Migrations.group'), 'yellow'),
$output->color(str_replace(': ', '', lang('Migrations.on')), 'yellow'),
$output->color(lang('Migrations.batch'), 'yellow'),
];

CLI::table($status, $headers);
$output->write((new Table($status, $headers))->render());

return EXIT_SUCCESS;
}
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Database/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Argument;
use CodeIgniter\Database\Seeder;
use Config\Database;
Expand Down Expand Up @@ -43,7 +42,7 @@ protected function configure(): void
protected function interact(array &$arguments, array &$options): void
{
if ($arguments === []) {
$arguments[] = CLI::prompt(lang('Migrations.migSeeder'), null, 'required');
$arguments[] = $this->getPrompt()->ask(lang('Migrations.migSeeder'), null, 'required');
}
}

Expand Down
Loading
Loading