initParams(); $this->initServices(); $this->setHostingId($this->getWhmcsParamByKey("serviceid")); if ($this->isDone()) { $this->qemuUpdate(); if ($this->agentUpdate()) { fire(new VmCreatedEvent($this->vm())); return true; } return false; }elseif ($this->isTaskRunning()) { //sleep $this->sleep(5); return false; } try { Api::beginTransaction(); DB::beginTransaction(); if($this->isWhmcsConfigOption(ConfigurableOption::ARCHIVE) && $this->getWhmcsConfigOption(ConfigurableOption::ARCHIVE) !="0"){ $archive = $this->getWhmcsConfigOption(ConfigurableOption::ARCHIVE); }else{ $archive = $this->configuration()->archive; } list($backupNode, $volid) = explode(":", $archive, 2); //vmid $vmid = $this->nextVmid(); $this->customFieldUpdate("vmid", $vmid); $vm = new Kvm($backupNode,$vmid); $vm->setApi($this->api()); $container = [ 'vmid' => $vmid, 'archive' => $volid ]; $this->setVm($vm); $taskId = $vm->create($container); $this->customFieldUpdate("node", $backupNode); DB::commit(); }catch (\Exception $ex) { echo $ex->getMessage(); DB::rollBack(); Api::commit(); throw $ex; } //task history $this->createTaskHistory($taskId, "Create"); //save task id $this->putModelDataAndSave(["taskId" => $taskId, "node" => $backupNode]); //sleep $this->sleep(); return false; } }