BackupJobProvider.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\ProxmoxVps\App\UI\BackupJob\Providers;
  20. use MGProvision\Proxmox\v2\models\BackupSchedule;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  23. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  26. use ModulesGarden\Servers\ProxmoxVps\App\Enum\ConfigurableOption;
  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. $backupSchedule->setAttributes([
  59. "vmid" => $this->vm()->getVmid(),
  60. "storage" => $storage,
  61. "remove" => $routing,
  62. "maxfiles" => $maxFiles,
  63. "starttime" => $this->formData['starttime'],
  64. "dow" => implode(",", $this->formData['dow']),
  65. "mode" => $this->formData['mode'],
  66. "compress" => $this->formData['compress'],
  67. "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
  68. ]);
  69. $backupSchedule->create();
  70. return (new HtmlDataJsonResponse())
  71. ->setStatusSuccess()
  72. ->setMessageAndTranslate('The backup job has been created successfully')
  73. ->setRefreshTargetIds(['dackupJobDataTable'])
  74. ->addData('createButtonStatus', $this->resourceGuard()->hasBackupJobLimit())
  75. ->setCallBackFunction('toggleBackupButton');
  76. }
  77. public function update()
  78. {
  79. $this->acl()->backupJob();
  80. $storage = $this->configuration()->getBackupStorage();
  81. $routing = $this->configuration()->isBackupRouting() ? 1 : 0;
  82. $maxFiles = $this->configuration()->getBackupMaxFiles();
  83. if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
  84. $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
  85. }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
  86. $maxFiles = null;
  87. }
  88. $backupSchedule = new BackupSchedule();
  89. $backupSchedule->setApi($this->api());
  90. $backupSchedule->setAttributes([
  91. "id" => $this->formData['backupScheduleId'],
  92. "vmid" => $this->vm()->getVmid(),
  93. "storage" => $storage,
  94. "remove" => $routing,
  95. "maxfiles" => $maxFiles,
  96. "starttime" => $this->formData['starttime'],
  97. "dow" => implode(",", $this->formData['dow']),
  98. "mode" => $this->formData['mode'],
  99. "compress" => $this->formData['compress'],
  100. "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
  101. ]);
  102. $backupSchedule->update();
  103. return (new HtmlDataJsonResponse())
  104. ->setStatusSuccess()
  105. ->setMessageAndTranslate('The backup job has been updated successfully');
  106. }
  107. public function delete()
  108. {
  109. $this->acl()->backupJob();
  110. $backupSchedule = new BackupSchedule();
  111. $backupSchedule->setApi($this->api());
  112. $backupSchedule->setId($this->formData['backupScheduleId']);
  113. $backupSchedule->delete();
  114. return (new HtmlDataJsonResponse())
  115. ->setStatusSuccess()
  116. ->setMessageAndTranslate('The backup job has been deleted successfully')
  117. ->setRefreshTargetIds(['dackupJobDataTable'])
  118. ->addData('createButtonStatus', 1)
  119. ->setCallBackFunction('toggleBackupButton');
  120. }
  121. }