Fix database migrations for mailgateways

This commit is contained in:
philipp lang 2024-12-23 03:07:05 +01:00
parent d68b166e15
commit 4644f3832b
2 changed files with 34 additions and 0 deletions

View File

@ -39,6 +39,8 @@ class MailgatewayServiceProvider extends ServiceProvider
MailmanType::class,
]));
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
View::addNamespace('mailgateway', __DIR__ . '/Components');
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Mailgateway\Types\MailmanType;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
foreach (DB::table('mailgateways')->get() as $gateway) {
$type = json_decode($gateway->type);
$newType = ['type' => $type->cls, 'data' => $type->params];
if (str_contains($type->cls, 'MailmanType')) {
$newType['type'] = MailmanType::class;
}
DB::table('mailgateways')->where('id', $gateway->id)->update(['type' => json_encode($newType)]);
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
}
};