diff --git a/app/Abstracts/Http/SettingController.php b/app/Abstracts/Http/SettingController.php index 8a0175749..e206a564b 100644 --- a/app/Abstracts/Http/SettingController.php +++ b/app/Abstracts/Http/SettingController.php @@ -99,7 +99,7 @@ abstract class SettingController extends Controller } if ($real_key == 'default.locale') { - if (!in_array($value, config('language.allowed'))) { + if (! in_array($value, config('language.allowed'))) { continue; } @@ -109,7 +109,7 @@ abstract class SettingController extends Controller if ($real_key == 'default.currency') { $currencies = Currency::enabled()->pluck('code')->toArray(); - if (!in_array($value, $currencies)) { + if (! in_array($value, $currencies)) { continue; } @@ -149,39 +149,25 @@ abstract class SettingController extends Controller return response()->json($response); } - protected function oneCompany($real_key, $value) + protected function oneCompany($real_key, $value): void { - switch ($real_key) { - case 'company.name': - Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']); - break; - case 'company.email': - Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']); - break; - case 'default.locale': - Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']); - break; - case 'schedule.time': - Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']); - break; - case 'email.protocol': - Installer::updateEnv(['MAIL_MAILER' => '"' . $value . '"']); - break; - case 'email.smtp_host': - Installer::updateEnv(['MAIL_HOST' => '"' . $value . '"']); - break; - case 'email.smtp_port': - Installer::updateEnv(['MAIL_PORT' => '"' . $value . '"']); - break; - case 'email.smtp_username': - Installer::updateEnv(['MAIL_USERNAME' => '"' . $value . '"']); - break; - case 'email.smtp_password': - Installer::updateEnv(['MAIL_PASSWORD' => '"' . $value . '"']); - break; - case 'email.smtp_encryption': - Installer::updateEnv(['MAIL_ENCRYPTION' => '"' . $value . '"']); - break; + $key = match($real_key) { + 'default.locale' => 'APP_LOCALE', + 'schedule.time' => 'APP_SCHEDULE_TIME', + 'company.name' => 'MAIL_FROM_NAME', + 'company.email' => 'MAIL_FROM_ADDRESS', + 'email.protocol' => 'MAIL_MAILER', + 'email.smtp_host' => 'MAIL_HOST', + 'email.smtp_port' => 'MAIL_PORT', + 'email.smtp_username' => 'MAIL_USERNAME', + 'email.smtp_password' => 'MAIL_PASSWORD', + 'email.smtp_encryption' => 'MAIL_ENCRYPTION', + }; + + if (empty($key)) { + return; } + + Installer::updateEnv([$key => '"' . $value . '"']); } } diff --git a/app/Http/Controllers/Wizard/Companies.php b/app/Http/Controllers/Wizard/Companies.php index e4c234731..acff64709 100644 --- a/app/Http/Controllers/Wizard/Companies.php +++ b/app/Http/Controllers/Wizard/Companies.php @@ -76,19 +76,12 @@ class Companies extends Controller continue; } - switch ($key) { - case 'api_key': - $real_key = 'apps.' . $key; - break; - case 'financial_start': - $real_key = 'localisation.' . $key; - break; - case 'country': - $real_key = 'company.' . $key; - break; - default: - $real_key = 'company.' . $key; - } + $real_key = match($key) { + 'api_key' => 'apps.api_key', + 'financial_start' => 'localisation.financial_start', + 'locale' => 'default.locale', + default => 'company.' . $key, + }; // change dropzone middleware already uploaded file if (in_array($real_key, $uploaded_file_keys)) { @@ -112,6 +105,14 @@ class Companies extends Controller } } + if ($real_key == 'default.locale') { + if (! in_array($value, config('language.allowed'))) { + continue; + } + + user()->setAttribute('locale', $value)->save(); + } + setting()->set($real_key, $value); } diff --git a/app/Jobs/Install/DisableModule.php b/app/Jobs/Install/DisableModule.php index 7cbb2abe7..ab1d91b75 100644 --- a/app/Jobs/Install/DisableModule.php +++ b/app/Jobs/Install/DisableModule.php @@ -26,7 +26,7 @@ class DisableModule extends Job public function __construct($alias, $company_id, $locale = null) { $this->alias = $alias; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; $this->locale = $locale ?: company($company_id)->locale; } @@ -58,5 +58,9 @@ class DisableModule extends Job if (! $this->moduleExists($this->alias)) { throw new \Exception("Module [{$this->alias}] not found."); } + + if (! in_array($this->locale, config('language.allowed'))) { + throw new \Exception("Unknown locale: {$this->locale}"); + } } } diff --git a/app/Jobs/Install/DownloadModule.php b/app/Jobs/Install/DownloadModule.php index 3e7ab89b4..a8a2dcffd 100644 --- a/app/Jobs/Install/DownloadModule.php +++ b/app/Jobs/Install/DownloadModule.php @@ -20,7 +20,7 @@ class DownloadModule extends Job public function __construct($alias, $company_id) { $this->alias = $alias; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; } /** diff --git a/app/Jobs/Install/EnableModule.php b/app/Jobs/Install/EnableModule.php index 416719a57..d3fa288da 100644 --- a/app/Jobs/Install/EnableModule.php +++ b/app/Jobs/Install/EnableModule.php @@ -26,7 +26,7 @@ class EnableModule extends Job public function __construct($alias, $company_id, $locale = null) { $this->alias = $alias; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; $this->locale = $locale ?: company($company_id)->locale; } @@ -56,5 +56,9 @@ class EnableModule extends Job if (! $this->moduleExists($this->alias)) { throw new \Exception("Module [{$this->alias}] not found."); } + + if (! in_array($this->locale, config('language.allowed'))) { + throw new \Exception("Unknown locale: {$this->locale}"); + } } } diff --git a/app/Jobs/Install/FinishUpdate.php b/app/Jobs/Install/FinishUpdate.php index dfde982e9..eca42755e 100644 --- a/app/Jobs/Install/FinishUpdate.php +++ b/app/Jobs/Install/FinishUpdate.php @@ -37,7 +37,7 @@ class FinishUpdate extends Job $this->alias = $alias; $this->new = $new; $this->old = $old; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; } public function handle(): void diff --git a/app/Jobs/Install/InstallModule.php b/app/Jobs/Install/InstallModule.php index d316f2dfe..70a74338b 100644 --- a/app/Jobs/Install/InstallModule.php +++ b/app/Jobs/Install/InstallModule.php @@ -26,7 +26,7 @@ class InstallModule extends Job public function __construct($alias, $company_id, $locale = null) { $this->alias = $alias; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; $this->locale = $locale ?: company($company_id)->locale; } @@ -58,5 +58,9 @@ class InstallModule extends Job if (! $this->moduleExists($this->alias)) { throw new \Exception("Module [{$this->alias}] not found."); } + + if (! in_array($this->locale, config('language.allowed'))) { + throw new \Exception("Unknown locale: {$this->locale}"); + } } } diff --git a/app/Jobs/Install/UninstallModule.php b/app/Jobs/Install/UninstallModule.php index 4056a94ce..dc2ba1358 100644 --- a/app/Jobs/Install/UninstallModule.php +++ b/app/Jobs/Install/UninstallModule.php @@ -26,7 +26,7 @@ class UninstallModule extends Job public function __construct($alias, $company_id, $locale = null) { $this->alias = $alias; - $this->company_id = $company_id; + $this->company_id = (int) $company_id; $this->locale = $locale ?: company($company_id)->locale; } @@ -58,5 +58,9 @@ class UninstallModule extends Job if (! $this->moduleExists($this->alias)) { throw new \Exception("Module [{$this->alias}] not found."); } + + if (! in_array($this->locale, config('language.allowed'))) { + throw new \Exception("Unknown locale: {$this->locale}"); + } } }