Files
ladill-hosting/app/Jobs/DeactivateMailboxJob.php
T
isaaccladandCursor 1135915797
Deploy Ladill Hosting / deploy (push) Successful in 20s
Fix 500 when exiting hosting panel for existing accounts.
The account overview queried a local mailboxes table that the extracted hosting app does not have; guard those lookups and skip email-addon upsells when mailboxes are managed on Ladill Email.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 17:02:44 +00:00

62 lines
1.7 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\HostingAccount;
use App\Models\Mailbox;
use App\Services\Hosting\HostingMailboxService;
use App\Services\Mail\MailServerProvisioner;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class DeactivateMailboxJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $backoff = 60;
public function __construct(public int $mailboxId)
{
}
public function handle(MailServerProvisioner $provisioner, HostingMailboxService $hostingMailboxes): void
{
$mailbox = Mailbox::query()->find($this->mailboxId);
if (! $mailbox) {
return;
}
$hostingAccountId = $mailbox->hosting_account_id;
try {
if ($provisioner->isConfigured()) {
$provisioner->deactivateMailbox($mailbox);
}
} catch (\Throwable $exception) {
$mailbox->update(['status' => 'failed']);
Log::error('DeactivateMailboxJob: Remote deactivation failed', [
'mailbox_id' => $mailbox->id,
'address' => $mailbox->address,
'error' => $exception->getMessage(),
]);
throw $exception;
}
$mailbox->delete();
if ($hostingAccountId) {
$account = HostingAccount::query()->with(['product'])->find($hostingAccountId);
if ($account) {
$hostingMailboxes->syncAddonInvoice($account);
}
}
}
}