Files
portal-api/app/Console/Commands/TestFullVMProcess.php
T
2025-07-24 16:18:27 +07:00

91 lines
2.9 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Invoice;
use App\Jobs\VirtualMachine\Create\CreateVirtualMachineJob;
use Illuminate\Support\Facades\Log;
class TestFullVMProcess extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:full-vm-process {order_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Test full VM creation process and VM ID saving';
/**
* Execute the console command.
*/
public function handle()
{
$orderId = $this->argument('order_id');
$this->info("Testing full VM process for Order #{$orderId}");
try {
// Tìm order
$order = Order::with(['orderItems.addons', 'customer'])->find($orderId);
if (!$order) {
$this->error("Order #{$orderId} not found!");
return 1;
}
$this->info("Found order: {$order->order_num}");
$this->info("Customer: {$order->customer->email}");
$this->info("Order items count: " . $order->orderItems->count());
// Tìm invoice
$invoice = Invoice::where('order_id', $orderId)->first();
if (!$invoice) {
$this->error("Invoice for Order #{$orderId} not found!");
return 1;
}
$this->info("Found invoice: #{$invoice->id}");
$this->info("Current VM ID: " . ($invoice->vm_id ?? 'NULL'));
// Test từng order item
foreach ($order->orderItems as $item) {
$this->info("\n--- Testing Order Item #{$item->id} ---");
$this->info("Product Type: {$item->product_type}");
$this->info("Server Name: {$item->server_name}");
$this->info("Addons count: " . $item->addons->count());
if ($item->addons->count() > 0) {
$this->info("Addons:");
foreach ($item->addons as $addon) {
$this->info(" - {$addon->addonItems->name}: {$addon->qty} {$addon->addonItems->prefix}");
}
}
// Dispatch job để test
$this->info("Dispatching CreateVirtualMachineJob...");
CreateVirtualMachineJob::dispatch($item);
$this->info("Job dispatched successfully!");
}
$this->info("\n✅ Full VM process test completed!");
$this->info("Check logs for detailed information about the process.");
return 0;
} catch (\Exception $e) {
$this->error("Error: " . $e->getMessage());
Log::error('TestFullVMProcess error: ' . $e->getMessage());
return 1;
}
}
}