From d7a0794bd995b703df90bbc370a547a8f8abb0d0 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:15:46 +0100 Subject: [PATCH] fix: instance settings migration --- ...ncrypt_instance_settings_email_columns.php | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php index 5602e0ae9..b17e53ddf 100644 --- a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php +++ b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php @@ -13,28 +13,26 @@ return new class extends Migration */ public function up(): void { - if (DB::table('instance_settings')->exists()) { - Schema::table('instance_settings', function (Blueprint $table) { - $table->text('smtp_from_address')->nullable()->change(); - $table->text('smtp_from_name')->nullable()->change(); - $table->text('smtp_recipients')->nullable()->change(); - $table->text('smtp_host')->nullable()->change(); - $table->text('smtp_username')->nullable()->change(); - }); + Schema::table('instance_settings', function (Blueprint $table) { + $table->text('smtp_from_address')->nullable()->change(); + $table->text('smtp_from_name')->nullable()->change(); + $table->text('smtp_recipients')->nullable()->change(); + $table->text('smtp_host')->nullable()->change(); + $table->text('smtp_username')->nullable()->change(); + }); - $settings = DB::table('instance_settings')->get(); - foreach ($settings as $setting) { - try { - 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_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null, - 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null, - 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null, - 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null, - ]); - } catch (Exception $e) { - \Log::error('Error encrypting instance settings email columns: '.$e->getMessage()); - } + $settings = DB::table('instance_settings')->get(); + foreach ($settings as $setting) { + try { + 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_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null, + 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null, + 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null, + 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null, + ]); + } catch (Exception $e) { + \Log::error('Error encrypting instance settings email columns: '.$e->getMessage()); } } }