From 069dfa4c9e04c5bba99020adab0d42ee74670776 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 28 Apr 2023 09:30:49 -0700 Subject: [PATCH 1/2] setup/message-tables command --- src/console/controllers/SetupController.php | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/console/controllers/SetupController.php b/src/console/controllers/SetupController.php index 2d11e1313cd..5a2b9c03ad5 100644 --- a/src/console/controllers/SetupController.php +++ b/src/console/controllers/SetupController.php @@ -21,6 +21,7 @@ use craft\helpers\StringHelper; use craft\migrations\CreateDbCacheTable; use craft\migrations\CreatePhpSessionTable; +use m150207_210500_i18n_init; use PDOException; use Seld\CliPrompt\CliPrompt; use Throwable; @@ -523,6 +524,37 @@ public function actionPhpSessionTable(): int return ExitCode::OK; } + /** + * Creates database tables for storing message translations. (EXPERIMENTAL!) + * + * @return int + * @since 4.5.0 + */ + public function actionMessageTables(): int + { + $db = Craft::$app->getDb(); + if ($db->tableExists('{{%source_message}}')) { + $this->stdout("The `source_message` table already exists.\n", Console::FG_YELLOW); + return ExitCode::OK; + } + if ($db->tableExists('{{%message}}')) { + $this->stdout("The `message` table already exists.\n", Console::FG_YELLOW); + return ExitCode::OK; + } + + require Craft::getAlias('@vendor/yiisoft/yii2/i18n/migrations/m150207_210500_i18n_init.php'); + /** @phpstan-ignore-next-line */ + $migration = new m150207_210500_i18n_init(); + /** @phpstan-ignore-next-line */ + if ($migration->up() === false) { + $this->stderr("An error occurred while creating the `source_message` and `message` tables.\n", Console::FG_RED); + return ExitCode::UNSPECIFIED_ERROR; + } + + $this->stdout("The `source_message` and `message` tables were created successfully.\n", Console::FG_GREEN); + return ExitCode::OK; + } + /** * Creates a database table for storing DB caches. * From 13764a812b58622a3d37f0cd917186047652c83a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 9 Aug 2023 21:42:12 -0700 Subject: [PATCH 2/2] Release note [ci skip] --- CHANGELOG-WIP.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 7988430d976..07c959ed5a2 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -31,6 +31,7 @@ ### Administration - Added the “Slug Translation Method” setting to entry types. ([#8962](https://github.com/craftcms/cms/discussions/8962), [#13291](https://github.com/craftcms/cms/pull/13291)) - Added the “Show the Status field” setting to entry types. ([#12837](https://github.com/craftcms/cms/discussions/12837), [#13265](https://github.com/craftcms/cms/pull/13265)) +- Added the `setup/message-tables` command, which can be run to set the project up for database-stored static translations via [DbMessageSource](https://www.yiiframework.com/doc/api/2.0/yii-i18n-dbmessagesource). ([#13542](https://github.com/craftcms/cms/pull/13542)) - Entry types created via the `entrify/global-set` command now have “Show the Status field” disabled by default. ([#12837](https://github.com/craftcms/cms/discussions/12837)) - Added the `defaultCountryCode` config setting. ([#13478](https://github.com/craftcms/cms/discussions/13478)) - Custom element sources can now be configured to only appear for certain sites. ([#13344](https://github.com/craftcms/cms/discussions/13344))