fix: instance settings migration

This commit is contained in:
peaklabs-dev
2024-12-23 17:15:46 +01:00
parent f26853b576
commit d7a0794bd9

View File

@@ -13,28 +13,26 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
if (DB::table('instance_settings')->exists()) { Schema::table('instance_settings', function (Blueprint $table) {
Schema::table('instance_settings', function (Blueprint $table) { $table->text('smtp_from_address')->nullable()->change();
$table->text('smtp_from_address')->nullable()->change(); $table->text('smtp_from_name')->nullable()->change();
$table->text('smtp_from_name')->nullable()->change(); $table->text('smtp_recipients')->nullable()->change();
$table->text('smtp_recipients')->nullable()->change(); $table->text('smtp_host')->nullable()->change();
$table->text('smtp_host')->nullable()->change(); $table->text('smtp_username')->nullable()->change();
$table->text('smtp_username')->nullable()->change(); });
});
$settings = DB::table('instance_settings')->get(); $settings = DB::table('instance_settings')->get();
foreach ($settings as $setting) { foreach ($settings as $setting) {
try { try {
DB::table('instance_settings')->where('id', $setting->id)->update([ DB::table('instance_settings')->where('id', $setting->id)->update([
'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null, 'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null,
'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null, 'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null,
'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null, 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null,
'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null, 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null,
'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null, 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null,
]); ]);
} catch (Exception $e) { } catch (Exception $e) {
\Log::error('Error encrypting instance settings email columns: '.$e->getMessage()); \Log::error('Error encrypting instance settings email columns: '.$e->getMessage());
}
} }
} }
} }