RestoreVm.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Vps\Reinstall;
  3. use MGProvision\Proxmox\v2\repository\FileRepository;
  4. use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\BaseJob;
  5. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  6. class RestoreVm extends BaseJob
  7. {
  8. use ProductService;
  9. public function handle($text = null)
  10. {
  11. $this->initParams();
  12. $this->initServices();
  13. if ($this->isTaskRunning())
  14. {
  15. $this->sleep(20);
  16. return false;
  17. }
  18. //get backup
  19. $storage = $this->configuration()->getBackupStorage() ? $this->configuration()->getBackupStorage() : 'local';
  20. $fileRepository = new FileRepository();
  21. $fileRepository->findBackup($this->vm())
  22. ->findByStorages([$storage]);
  23. $backup = $fileRepository->fetchLast();
  24. //done process is finished
  25. if ($this->isDone())
  26. {
  27. $backup->delete();
  28. return true;
  29. }
  30. //restore
  31. $taskId = $this->vm()->restore($backup->getVolid());
  32. //save task id
  33. $this->putModelDataAndSave(["taskId" => $taskId, "node" => $this->vm()->getNode()]);
  34. $this->sleep(20);
  35. return false;
  36. }
  37. }