RestoreVm.php 1.3 KB

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