diff --git a/system/CLI/CommandRunner.php b/system/CLI/CommandRunner.php index 917843d3e8..e34ff9dfb2 100644 --- a/system/CLI/CommandRunner.php +++ b/system/CLI/CommandRunner.php @@ -95,7 +95,7 @@ class CommandRunner extends Controller { $className = service('locator')->findQualifiedNameFromPath($file); - if (empty($className)) + if (empty($className) || ! class_exists($className)) { continue; } diff --git a/system/Commands/Sessions/CreateMigration.php b/system/Commands/Sessions/CreateMigration.php new file mode 100644 index 0000000000..80f4981c09 --- /dev/null +++ b/system/Commands/Sessions/CreateMigration.php @@ -0,0 +1,54 @@ + $config->sessionMatchIP ?? false, + 'tableName' => $config->sessionSavePath ?? 'ci_sessions', + ]; + + $template = view('\CodeIgniter\Commands\Sessions\Views\migration.tpl', $data); + $template = str_replace('@php', 'forge->addField([ + 'id' => ['type' => 'INT', 'constraint' => 9, 'unsigned' => true, 'auto_increment' => true], + 'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false], + 'timestamp' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => false, 'default' => 0], + 'data' => ['type' => 'text', 'null' => false, 'default' => ''], + ]); + + + $this->forge->addKey(['id', 'ip_address'], true); + + $this->forge->addKey('id', true); + + $this->forge->addKey('timestamp'); + $this->forge->createTable('', true); + } + + //-------------------------------------------------------------------- + + public function down() + { + $this->forge->dropTable('', true); + } +} diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index c9ec0aed21..7a51a6860f 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -609,6 +609,15 @@ You can choose the Database group to use by adding a new line to the public $sessionDBGroup = 'groupName'; +If you'd rather not do all of this by hand, you can use the ``session:migration`` command +from the cli to generate a migration file for you:: + + > php ci.php session:migration + > php ci.php migrate + +This command will take the **sessionSavePath** and **sessionMatchIP** settings into account +when it generates the code. + .. important:: Only MySQL and PostgreSQL databases are officially supported, due to lack of advisory locking mechanisms on other platforms. Using sessions without locks can cause all sorts of