Merge branch 'main' into next

This commit is contained in:
Andras Bacsai
2024-12-27 11:09:29 +01:00
14 changed files with 169 additions and 39 deletions

View File

@@ -13,15 +13,15 @@ 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();
});
if (DB::table('instance_settings')->exists()) {
$settings = DB::table('instance_settings')->get();
foreach ($settings as $setting) {
try {
@@ -45,11 +45,11 @@ return new class extends Migration
public function down(): void
{
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();
$table->string('smtp_from_address')->nullable()->change();
$table->string('smtp_from_name')->nullable()->change();
$table->string('smtp_recipients')->nullable()->change();
$table->string('smtp_host')->nullable()->change();
$table->string('smtp_username')->nullable()->change();
});
if (DB::table('instance_settings')->exists()) {

View File

@@ -0,0 +1,114 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
class UpdateEmailEncryptionValues extends Migration
{
/**
* Encryption mappings.
*/
private array $encryptionMappings = [
'tls' => 'starttls',
'ssl' => 'tls',
'' => 'none',
];
/**
* Run the migrations.
*/
public function up(): void
{
try {
DB::beginTransaction();
$instanceSettings = DB::table('instance_settings')->get();
foreach ($instanceSettings as $setting) {
try {
if (array_key_exists($setting->smtp_encryption, $this->encryptionMappings)) {
DB::table('instance_settings')
->where('id', $setting->id)
->update([
'smtp_encryption' => $this->encryptionMappings[$setting->smtp_encryption],
]);
}
} catch (\Exception $e) {
\Log::error('Failed to update instance settings: '.$e->getMessage());
}
}
$emailSettings = DB::table('email_notification_settings')->get();
foreach ($emailSettings as $setting) {
try {
if (array_key_exists($setting->smtp_encryption, $this->encryptionMappings)) {
DB::table('email_notification_settings')
->where('id', $setting->id)
->update([
'smtp_encryption' => $this->encryptionMappings[$setting->smtp_encryption],
]);
}
} catch (\Exception $e) {
\Log::error('Failed to update email settings: '.$e->getMessage());
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
\Log::error('Failed to update email encryption: '.$e->getMessage());
throw $e;
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
try {
DB::beginTransaction();
$reverseMapping = [
'starttls' => 'tls',
'tls' => 'ssl',
'none' => '',
];
$instanceSettings = DB::table('instance_settings')->get();
foreach ($instanceSettings as $setting) {
try {
if (array_key_exists($setting->smtp_encryption, $reverseMapping)) {
DB::table('instance_settings')
->where('id', $setting->id)
->update([
'smtp_encryption' => $reverseMapping[$setting->smtp_encryption],
]);
}
} catch (\Exception $e) {
\Log::error('Failed to reverse instance settings: '.$e->getMessage());
}
}
$emailSettings = DB::table('email_notification_settings')->get();
foreach ($emailSettings as $setting) {
try {
if (array_key_exists($setting->smtp_encryption, $reverseMapping)) {
DB::table('email_notification_settings')
->where('id', $setting->id)
->update([
'smtp_encryption' => $reverseMapping[$setting->smtp_encryption],
]);
}
} catch (\Exception $e) {
\Log::error('Failed to reverse email settings: '.$e->getMessage());
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
\Log::error('Failed to reverse email encryption: '.$e->getMessage());
throw $e;
}
}
}