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
10 changes: 5 additions & 5 deletions system/CLI/InputOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function input(?string $prefix = null): string
// @codeCoverageIgnoreStart
$prompt = $this->readlinePrompt($prefix, readline_info('library_version'));

if ($prompt !== null) {
return readline($prompt);
if ($prompt === null) {
// The library cannot render the prompt, so write it ourselves and let readline() only read the line.
self::fwrite(STDOUT, $prefix ?? '');
}

// The library cannot render the prompt, so write it ourselves and let readline() only read the line.
self::fwrite(STDOUT, $prefix ?? '');
$input = readline($prompt);

return readline();
return $input === false ? '' : $input;
// @codeCoverageIgnoreEnd
}

Expand Down
18 changes: 18 additions & 0 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,28 @@ public function run(array $params)
if (array_key_exists('session', $params) || CLI::getOption('session')) {
$table = $params['table'] ?? CLI::getOption('table') ?? 'ci_sessions';
$params[0] = "_create_{$table}_table";

$group = $params['dbgroup'] ?? CLI::getOption('dbgroup');
$group = is_string($group) ? $group : 'default';
$driver = config(Database::class)->{$group}['DBDriver'] ?? null;

if ($driver === null) {
CLI::error(lang('CLI.generator.undefinedDatabaseGroup', [$group]));

return EXIT_ERROR;
}

if ($driver !== 'MySQLi' && $driver !== 'Postgre') {
CLI::error(lang('CLI.generator.unsupportedSessionDriver', [$group, $driver]));

return EXIT_ERROR;
}
}

$this->classNameLang = 'CLI.generator.className.migration';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
24 changes: 13 additions & 11 deletions system/Language/en/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@
'transformer' => 'Transformer class name',
'validation' => 'Validation class name',
],
'commandType' => 'Command type',
'databaseGroup' => 'Database group',
'fileCreate' => 'File created: {0}',
'fileError' => 'Error while creating file: "{0}"',
'fileExist' => 'File exists: "{0}"',
'fileOverwrite' => 'File overwritten: "{0}"',
'parentClass' => 'Parent class',
'returnType' => 'Return type',
'tableName' => 'Table name',
'usingCINamespace' => 'Warning: Using the "CodeIgniter" namespace will generate the file in the system directory.',
'viewName' => [
'commandType' => 'Command type',
'databaseGroup' => 'Database group',
'fileCreate' => 'File created: {0}',
'fileError' => 'Error while creating file: "{0}"',
'fileExist' => 'File exists: "{0}"',
'fileOverwrite' => 'File overwritten: "{0}"',
'parentClass' => 'Parent class',
'returnType' => 'Return type',
'tableName' => 'Table name',
'undefinedDatabaseGroup' => 'The "{0}" database group is not defined.',
'unsupportedSessionDriver' => 'Database sessions are only supported on MySQLi and Postgre. The "{0}" database group uses the "{1}" driver.',
'usingCINamespace' => 'Warning: Using the "CodeIgniter" namespace will generate the file in the system directory.',
'viewName' => [
'cell' => 'Cell view name',
],
],
Expand Down
27 changes: 27 additions & 0 deletions tests/system/Commands/Generators/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

namespace CodeIgniter\Commands\Generators;

use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use Config\Database;
use PHPUnit\Framework\Attributes\Group;

/**
Expand All @@ -27,6 +29,8 @@ final class MigrationGeneratorTest extends CIUnitTestCase

protected function tearDown(): void
{
Factories::reset('config');

$result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', $this->getStreamFilterBuffer());
$file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14)));
if (is_file($file)) {
Expand All @@ -52,6 +56,29 @@ public function testGenerateMigrationWithOptionTable(): void
$this->assertStringContainsString('_CreateLoggerTable.php', $this->getStreamFilterBuffer());
}

public function testSessionRejectsUnsupportedDriver(): void
{
$config = new Database();
$config->default['DBDriver'] = 'SQLite3';
Factories::injectMock('config', 'Database', $config);

command('make:migration -session');

$this->assertStringContainsString(
'Database sessions are only supported on MySQLi and Postgre. The "default" database group uses the "SQLite3" driver.',
$this->getStreamFilterBuffer(),
);
$this->assertSame([], glob(APPPATH . 'Database/Migrations/*_CreateCiSessionsTable.php'));
}

public function testSessionRejectsUndefinedGroup(): void
{
command('make:migration -session -dbgroup bogus');

$this->assertStringContainsString('The "bogus" database group is not defined.', $this->getStreamFilterBuffer());
$this->assertSame([], glob(APPPATH . 'Database/Migrations/*_CreateCiSessionsTable.php'));
}

public function testGenerateMigrationWithOptionSuffix(): void
{
command('make:migration database -suffix');
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/changelogs/v4.7.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BREAKING
Message Changes
***************

- Added the ``CLI.generator.undefinedDatabaseGroup`` and ``CLI.generator.unsupportedSessionDriver`` language strings.
- Added the ``Cookie.invalidCookieValue`` language string.
- Added the ``Cookie.invalidCookiePath`` language string.
- Added the ``Cookie.invalidCookieDomain`` language string.
Expand All @@ -41,8 +42,10 @@ Bugs Fixed
- **CLI:** Fixed a bug where pressing backspace in a ``CLI::prompt()`` erased the prompt text when the ``readline`` extension is enabled. The prompt is now passed to ``readline()`` so line redraws repaint it.
ANSI color codes in the prompt (e.g., option defaults) are wrapped in readline's non-printing markers under GNU readline so cursor positioning stays accurate.
On Windows, where the ``readline`` extension is built on WinEditLine, the prompt is written to STDOUT first because WinEditLine reports no library version and prints ANSI sequences literally.
- **CLI:** Fixed a bug where ``CLI::input()`` and ``CLI::prompt()`` threw a ``TypeError`` when STDIN reached end-of-file (e.g., Ctrl+D) with the ``readline`` extension enabled. An empty string is now returned, matching the behavior without ``readline``.
- **CLIRequest:** Fixed a bug where ``parseCommand()`` could throw a TypeError when ``argv`` is missing.
- **CodeIgniter:** Fixed a bug where ``gatherOutput()`` could be called twice when ``startController()`` returned a ``ResponseInterface`` (e.g., from filter attributes or closure routes).
- **Commands:** Fixed a bug where ``make:migration --session`` silently generated a broken migration when the database group's driver is neither ``MySQLi`` nor ``Postgre``. The command now reports an error and returns ``EXIT_ERROR``.
- **Content Security Policy:** Fixed a bug where empty ``Content-Security-Policy``, ``Content-Security-Policy-Report-Only``, and ``Reporting-Endpoints`` response headers were generated when no corresponding values existed.
- **Cookie:** Fixed a bug where ``Cookie`` instances created with ``raw: true`` allowed invalid characters in cookie values rejected by ``setrawcookie()``.
- **Cookie:** Fixed a bug where ``Cookie`` instances allowed invalid characters in path, domain, and prefix attributes rejected by ``setcookie()`` and ``setrawcookie()``.
Expand Down
Loading