RestoreVm.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Vps;
  3. use ModulesGarden\ProxmoxAddon\App\Events\Vps\QemuUpdateEvent;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  5. use function ModulesGarden\ProxmoxAddon\Core\Helper\fire;
  6. class RestoreVm extends BaseJob
  7. {
  8. use ProductService;
  9. public function handle($text = null)
  10. {
  11. $this->initParams();
  12. $this->initServices();
  13. $this->setHostingId($this->getWhmcsParamByKey("serviceid"));
  14. if ($this->isDone())
  15. {
  16. if ($this->configuration()->isQemu())
  17. {
  18. fire(new QemuUpdateEvent($this->vm()));
  19. }
  20. if (!$this->vm()->isRunning())
  21. {
  22. $this->vm()->start();
  23. }
  24. return true;
  25. }
  26. elseif ($this->isTaskRunning())
  27. {
  28. //sleep
  29. $this->sleep(5);
  30. return false;
  31. }
  32. $taskId = $this->vm()->restore($this->getModelData()['volid']);
  33. //save task id
  34. $this->putModelDataAndSave(["taskId" => $taskId, "node" => $this->vm()->getNode()]);
  35. //sleep
  36. $this->sleep(5);
  37. return false;
  38. }
  39. }