update change port

This commit is contained in:
pbao9
2026-01-17 11:27:54 +07:00
parent a79f0041f4
commit 4f2fdbaaa5
14 changed files with 70 additions and 147 deletions
@@ -49,22 +49,17 @@ class ServiceController extends Controller
return redirect()->route('service.index')->with('error', 'Không tìm thấy dịch vụ.');
}
// Kiểm tra quyền truy cập - chỉ cho phép customer sở hữu
if ($invoice->customer_id !== customer()->id) {
return redirect()->route('service.index')->with('error', 'Bạn không có quyền truy cập dịch vụ này.');
}
// Lấy thông tin VM nếu có - WITH CACHING AND BACKGROUND UPDATE
$vmInfo = null;
if ($invoice->vm_id) {
$vmInfo = $this->getVMInfoFromVCenter($invoice, $vCenterService);
// Dispatch background job to update VM info if cache is stale
$this->dispatchVMInfoUpdateJob($invoice);
}
$title = "Chi tiết dịch vụ #" . $invoice->id;
dd($vmInfo);
return view('frontend.service.show', [
'title' => $title,
'invoice' => $invoice,
@@ -82,11 +77,9 @@ class ServiceController extends Controller
*/
private function getVMInfoFromVCenter($invoice, $vCenterService)
{
// Cache key for this VM info
$cacheKey = "vm_info_{$invoice->vm_id}";
$cacheDuration = 300; // 5 minutes
// Try to get from cache first
if (Cache::has($cacheKey)) {
return Cache::get($cacheKey);
}
@@ -118,7 +111,6 @@ class ServiceController extends Controller
return $defaultInfo;
}
// Login vào vCenter - with timeout
$loginSuccess = false;
try {
$loginSuccess = $vCenterService->loginServer($vcenter);
@@ -132,7 +124,6 @@ class ServiceController extends Controller
return $defaultInfo;
}
// Lấy thông tin VM từ vCenter API - with timeout handling
$vmDetail = null;
$ipInfo = null;
@@ -180,7 +171,7 @@ class ServiceController extends Controller
'cpu' => $cpuCount . ' cores',
'ram' => $memoryGB . ' GB',
'disk' => $diskSizeGB . ' GB',
'uptime' => 'N/A', // Có thể lấy từ guest info nếu cần
'uptime' => 'N/A',
'last_updated' => now()->format('Y-m-d H:i:s'),
'vm_name' => $vmData['name'] ?? 'Unknown',
'vm_folder' => $vmData['folder'] ?? 'Unknown',
@@ -611,7 +602,7 @@ class ServiceController extends Controller
$validated = Validator::make($request->all(), [
'product_id' => 'required|string|max:255',
'new_port' => 'required|string|min:4|max:128',
'password' => 'required|string|min:8|max:128',
'password' => 'required|string|min:4|max:128',
]);
if ($validated->fails()) {
return response()->json(['error' => true, 'message' => __('Dữ liệu không hợp lệ'), 'errors' => $validated->errors()], 422);