Skip to content

Commit

Permalink
Fix issue when the application database isn't available yet
Browse files Browse the repository at this point in the history
This fixes "SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `winter_translate_locales` where `is_default` = 1 order by `sort_order` asc limit 1)" that occurs when Locale::getDefault() is called in the boot() method of the plugin registration file before the necessary tables exist.
  • Loading branch information
LukeTowers committed Jul 13, 2023
1 parent e870a52 commit 206ee11
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion models/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ public static function getDefault()
return self::$defaultLocale;
}

if ($forceDefault = Config::get('winter.translate::forceDefaultLocale')) {
$forceDefault = Config::get('winter.translate::forceDefaultLocale');
if (!$forceDefault && !App::hasDatabase()) {
// If a database is not available, the default locale is always the app locale
$forceDefault = Config::get('app.locale');
}

if ($forceDefault) {
$locale = new self;
$locale->name = $locale->code = $forceDefault;
$locale->is_default = $locale->is_enabled = true;
Expand Down

0 comments on commit 206ee11

Please sign in to comment.