VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Mailbox;
|
|
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 ProvisionMailboxJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 3;
|
|
|
|
public int $backoff = 60;
|
|
|
|
public function __construct(
|
|
public int $mailboxId,
|
|
public ?string $encryptedPassword = null,
|
|
) {
|
|
}
|
|
|
|
public function handle(MailServerProvisioner $provisioner): void
|
|
{
|
|
$mailbox = Mailbox::query()
|
|
->with(['domain', 'emailDomain'])
|
|
->find($this->mailboxId);
|
|
|
|
if (! $mailbox || (string) $mailbox->status === 'deleting') {
|
|
return;
|
|
}
|
|
|
|
if (! $provisioner->isConfigured()) {
|
|
Log::info('ProvisionMailboxJob: Skipped — mail server DB not configured', [
|
|
'mailbox_id' => $mailbox->id,
|
|
]);
|
|
$mailbox->update(['status' => 'active']);
|
|
|
|
return;
|
|
}
|
|
|
|
$password = $this->encryptedPassword !== null
|
|
? decrypt($this->encryptedPassword)
|
|
: null;
|
|
|
|
try {
|
|
if ($mailbox->email_domain_id !== null) {
|
|
$provisioner->provisionStandaloneMailbox($mailbox, $password);
|
|
} else {
|
|
$provisioner->provisionMailbox($mailbox, $password);
|
|
}
|
|
|
|
$mailbox->update(['status' => 'active']);
|
|
} catch (\Throwable $exception) {
|
|
$mailbox->update(['status' => 'failed']);
|
|
Log::error('ProvisionMailboxJob: Failed', [
|
|
'mailbox_id' => $mailbox->id,
|
|
'address' => $mailbox->address,
|
|
'error' => $exception->getMessage(),
|
|
]);
|
|
|
|
throw $exception;
|
|
}
|
|
}
|
|
}
|