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 CreateDiscordSettings 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.
|
2024-04-12 12:04:26 +00:00
|
|
|
$this->migrator->add('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN') : null);
|
|
|
|
$this->migrator->add('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID') : null);
|
|
|
|
$this->migrator->add('discord.client_secret', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_SECRET') : null);
|
|
|
|
$this->migrator->add('discord.guild_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:GUILD_ID') : null);
|
|
|
|
$this->migrator->add('discord.invite_url', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:INVITE_URL') : null);
|
|
|
|
$this->migrator->add('discord.role_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:ROLE_ID') : null);
|
2023-02-18 23:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(): void
|
|
|
|
{
|
|
|
|
DB::table('settings_old')->insert([
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:BOT_TOKEN',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('bot_token', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The bot token for the Discord bot.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:CLIENT_ID',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('client_id', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The client ID for the Discord bot.',
|
|
|
|
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:CLIENT_SECRET',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('client_secret', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The client secret for the Discord bot.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:GUILD_ID',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('guild_id', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The guild ID for the Discord bot.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:INVITE_URL',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('invite_url', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The invite URL for the Discord bot.',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'SETTINGS::DISCORD:ROLE_ID',
|
2024-04-12 19:01:49 +00:00
|
|
|
'value' => $this->getNewValue('role_id', 'discord'),
|
2023-02-18 23:34:26 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'description' => 'The role ID for the Discord bot.',
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2024-04-12 19:01:49 +00:00
|
|
|
try {
|
|
|
|
$this->migrator->delete('discord.bot_token');
|
|
|
|
$this->migrator->delete('discord.client_id');
|
|
|
|
$this->migrator->delete('discord.client_secret');
|
|
|
|
$this->migrator->delete('discord.guild_id');
|
|
|
|
$this->migrator->delete('discord.invite_url');
|
|
|
|
$this->migrator->delete('discord.role_id');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
2023-02-18 23:34:26 +00:00
|
|
|
}
|
|
|
|
}
|