Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for DbMessageSource #13542

Merged
merged 3 commits into from
Aug 10, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 32 additions & 0 deletions src/console/controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down