2023-02-01 19:33:36 +00:00
|
|
|
<?php
|
|
|
|
|
2024-04-12 12:04:26 +00:00
|
|
|
use App\Classes\LegacySettingsMigration;
|
2023-02-01 19:33:36 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2024-04-12 12:04:26 +00:00
|
|
|
class CreateLocaleSettings extends LegacySettingsMigration
|
2023-02-01 19:33:36 +00:00
|
|
|
{
|
|
|
|
public function up(): void
|
|
|
|
{
|
2023-02-02 16:36:19 +00:00
|
|
|
$table_exists = DB::table('settings_old')->exists();
|
|
|
|
|
2023-02-01 19:33:36 +00:00
|
|
|
// Get the user-set configuration values from the old table.
|
2023-02-18 23:34:26 +00:00
|
|
|
$this->migrator->add('locale.available', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:AVAILABLE') : '');
|
2024-04-12 12:04:26 +00:00
|
|
|
$this->migrator->add('locale.clients_can_change', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE', true) : true);
|
2023-02-18 23:34:26 +00:00
|
|
|
$this->migrator->add('locale.datatables', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DATATABLES') : 'en-gb');
|
2024-04-12 12:04:26 +00:00
|
|
|
$this->migrator->add('locale.default', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DEFAULT', 'en') : 'en');
|
|
|
|
$this->migrator->add('locale.dynamic', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DYNAMIC', false) : false);
|
2023-02-18 23:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(): void
|
|
|
|
{
|
|
|
|
DB::table('settings_old')->insert([
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::LOCALE:AVAILABLE',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('available', 'locale'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The available locales.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::LOCALE:CLIENTS_CAN_CHANGE',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('clients_can_change', 'locale'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'boolean',
|
|
|
|
'description' => 'If clients can change their locale.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::LOCALE:DATATABLES',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('datatables', 'locale'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The locale for datatables.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::LOCALE:DEFAULT',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('default', 'locale'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The default locale.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::LOCALE:DYNAMIC',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('dynamic', 'locale'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'boolean',
|
|
|
|
'description' => 'If the locale should be dynamic.',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-04-12 19:01:49 +00:00
|
|
|
try {
|
|
|
|
$this->migrator->delete('locale.available');
|
|
|
|
$this->migrator->delete('locale.clients_can_change');
|
|
|
|
$this->migrator->delete('locale.datatables');
|
|
|
|
$this->migrator->delete('locale.default');
|
|
|
|
$this->migrator->delete('locale.dynamic');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2023-02-18 23:34:26 +00:00
|
|
|
}
|
|
|
|
}
|