BackupJobProvider.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\BackupJob\Providers;
  20. use MGProvision\Proxmox\v2\models\BackupSchedule;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  23. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\ConfigurableOption;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  27. class BackupJobProvider extends BaseDataProvider implements ClientArea
  28. {
  29. use ApiService;
  30. use ProductService;
  31. public function read()
  32. {
  33. if ($this->actionElementId)
  34. {
  35. $this->data = json_decode(base64_decode($this->actionElementId), true);
  36. //down
  37. $dow = $this->data['dow'];
  38. $this->data['dow'] = explode(",", $dow);
  39. //mailto
  40. $mailto = $this->data['mailto'];
  41. $this->data['mailto'] = $mailto ? "on" : "off";
  42. }
  43. }
  44. public function create()
  45. {
  46. $this->acl()->backupJob();
  47. $this->resourceGuard()->backupJobLimit();
  48. $storage = $this->configuration()->getBackupStorage();
  49. $routing = $this->configuration()->isBackupRouting() ? 1 : 0;
  50. $maxFiles = $this->configuration()->getBackupMaxFiles();
  51. if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
  52. $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
  53. }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
  54. $maxFiles = null;
  55. }
  56. $backupSchedule = new BackupSchedule();
  57. $backupSchedule->setApi($this->api());
  58. $vmid = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->vmid;
  59. $backupSchedule->setAttributes([
  60. "vmid" => $vmid,
  61. "storage" => $storage,
  62. "remove" => $routing,
  63. "maxfiles" => $maxFiles,
  64. "starttime" => $this->formData['starttime'],
  65. "dow" => implode(",", $this->formData['dow']),
  66. "mode" => $this->formData['mode'],
  67. "compress" => $this->formData['compress'],
  68. "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
  69. ]);
  70. $backupSchedule->create();
  71. return (new HtmlDataJsonResponse())
  72. ->setStatusSuccess()
  73. ->setMessageAndTranslate('The backup job has been created successfully')
  74. ->setRefreshTargetIds(['backupJobDataTable'])
  75. ->addData('createButtonStatus', $this->resourceGuard()->hasBackupJobLimit())
  76. ->setCallBackFunction('pmToggleBackupButton');
  77. }
  78. public function update()
  79. {
  80. $this->acl()->backupJob();
  81. $storage = $this->configuration()->getBackupStorage();
  82. $routing = $this->configuration()->isBackupRouting() ? 1 : 0;
  83. $maxFiles = $this->configuration()->getBackupMaxFiles();
  84. if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
  85. $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
  86. }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
  87. $maxFiles = null;
  88. }
  89. $backupSchedule = new BackupSchedule();
  90. $backupSchedule->setApi($this->api());
  91. $vmid = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->vmid;
  92. $backupSchedule->setAttributes([
  93. "id" => $this->formData['backupScheduleId'],
  94. "vmid" => $vmid,
  95. "storage" => $storage,
  96. "remove" => $routing,
  97. "maxfiles" => $maxFiles,
  98. "starttime" => $this->formData['starttime'],
  99. "dow" => implode(",", $this->formData['dow']),
  100. "mode" => $this->formData['mode'],
  101. "compress" => $this->formData['compress'],
  102. "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
  103. ]);
  104. $backupSchedule->update();
  105. return (new HtmlDataJsonResponse())
  106. ->setStatusSuccess()
  107. ->setMessageAndTranslate('The backup job has been updated successfully');
  108. }
  109. public function delete()
  110. {
  111. $this->acl()->backupJob();
  112. $backupSchedule = new BackupSchedule();
  113. $backupSchedule->setApi($this->api());
  114. $backupSchedule->setId($this->formData['backupScheduleId']);
  115. $backupSchedule->delete();
  116. return (new HtmlDataJsonResponse())
  117. ->setStatusSuccess()
  118. ->setMessageAndTranslate('The backup job has been deleted successfully')
  119. ->setRefreshTargetIds(['backupJobDataTable'])
  120. ->addData('createButtonStatus', 1)
  121. ->setCallBackFunction('pmToggleBackupButton');
  122. }
  123. }