Files
portal-api/app/Jobs/VirtualMachine/Provision/ResendVmCredentialsEmailJob.php
T
baodev0 c917e3bf5e feat: Add IT Support catalog and related migrations, seeders, and email templates
- Created migration to add 'group_label' to 'product_type_fields' table.
- Implemented ItSupportCatalogSeeder to populate IT Support features and tiers.
- Added ProductCategorySeeder for initial product categories.
- Developed ProductMockupSeeder for mockup products in various categories.
- Introduced ProductTypeFieldSeeder to define fields for different product types.
- Created email templates for VPS service information and service renewal reminders.
2026-08-26 16:19:38 +07:00

80 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Jobs\VirtualMachine\Provision;
use App\Http\Services\Telegram;
use App\Jobs\Mail\SendInformationVirtualMachine;
use App\Models\Invoice;
use App\Models\ModuleVmware;
use App\Services\VirtualMachine\VmCredentialsEmailDataBuilder;
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;
/**
* Admin-triggered resend of the VPS credentials email — same email as
* SendVmCredentialsEmailJob, but without re-running service/VM activation
* or the admin "new order" notification.
*/
class ResendVmCredentialsEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $timeout = 60;
public function __construct(
public readonly int $moduleVmwareId,
) {}
public function handle(Telegram $telegram): void
{
$vm = ModuleVmware::with([
'customer',
'os.osGroup',
'order.orderItems.service',
])->find($this->moduleVmwareId);
if (!$vm) {
$msg = "ResendVmCredentialsEmailJob: ModuleVmware #{$this->moduleVmwareId} not found";
Log::error($msg);
$telegram->SendErrorMessage($msg);
return;
}
$customer = $vm->customer;
if (!$customer?->email) {
$msg = "ResendVmCredentialsEmailJob: customer or email missing for ModuleVmware #{$this->moduleVmwareId}";
Log::error($msg, ['module_vmware_id' => $this->moduleVmwareId]);
$telegram->SendErrorMessage($msg);
return;
}
$orderItem = $vm->order?->orderItems?->first();
$emailData = app(VmCredentialsEmailDataBuilder::class)->build($vm, $orderItem);
$invoice = Invoice::where('order_id', $vm->order_id)->first();
SendInformationVirtualMachine::dispatch($emailData, $customer, $invoice?->id);
Log::info('ResendVmCredentialsEmailJob: email dispatched', [
'module_vmware_id' => $this->moduleVmwareId,
'customer_email' => $customer->email,
]);
}
public function failed(\Throwable $e): void
{
Log::error('ResendVmCredentialsEmailJob: failed', [
'module_vmware_id' => $this->moduleVmwareId,
'error' => $e->getMessage(),
]);
}
}