| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS Product developed. (27.03.19)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\BackupJob\Providers;
- use MGProvision\Proxmox\v2\models\BackupSchedule;
- use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
- use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
- use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\ConfigurableOption;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- class BackupJobProvider extends BaseDataProvider implements ClientArea
- {
- use ApiService;
- use ProductService;
- public function read()
- {
- if ($this->actionElementId)
- {
- $this->data = json_decode(base64_decode($this->actionElementId), true);
- //down
- $dow = $this->data['dow'];
- $this->data['dow'] = explode(",", $dow);
- //mailto
- $mailto = $this->data['mailto'];
- $this->data['mailto'] = $mailto ? "on" : "off";
- }
- }
- public function create()
- {
- $this->acl()->backupJob();
- $this->resourceGuard()->backupJobLimit();
- $storage = $this->configuration()->getBackupStorage();
- $routing = $this->configuration()->isBackupRouting() ? 1 : 0;
- $maxFiles = $this->configuration()->getBackupMaxFiles();
- if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
- $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
- }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
- $maxFiles = null;
- }
- $backupSchedule = new BackupSchedule();
- $backupSchedule->setApi($this->api());
- $vmid = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->vmid;
- $backupSchedule->setAttributes([
- "vmid" => $vmid,
- "storage" => $storage,
- "remove" => $routing,
- "maxfiles" => $maxFiles,
- "starttime" => $this->formData['starttime'],
- "dow" => implode(",", $this->formData['dow']),
- "mode" => $this->formData['mode'],
- "compress" => $this->formData['compress'],
- "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
- ]);
- $backupSchedule->create();
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The backup job has been created successfully')
- ->setRefreshTargetIds(['backupJobDataTable'])
- ->addData('createButtonStatus', $this->resourceGuard()->hasBackupJobLimit())
- ->setCallBackFunction('pmToggleBackupButton');
- }
- public function update()
- {
- $this->acl()->backupJob();
- $storage = $this->configuration()->getBackupStorage();
- $routing = $this->configuration()->isBackupRouting() ? 1 : 0;
- $maxFiles = $this->configuration()->getBackupMaxFiles();
- if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
- $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
- }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
- $maxFiles = null;
- }
- $backupSchedule = new BackupSchedule();
- $backupSchedule->setApi($this->api());
- $vmid = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->vmid;
- $backupSchedule->setAttributes([
- "id" => $this->formData['backupScheduleId'],
- "vmid" => $vmid,
- "storage" => $storage,
- "remove" => $routing,
- "maxfiles" => $maxFiles,
- "starttime" => $this->formData['starttime'],
- "dow" => implode(",", $this->formData['dow']),
- "mode" => $this->formData['mode'],
- "compress" => $this->formData['compress'],
- "mailto" => $this->formData['mailto'] == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
- ]);
- $backupSchedule->update();
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The backup job has been updated successfully');
- }
- public function delete()
- {
- $this->acl()->backupJob();
- $backupSchedule = new BackupSchedule();
- $backupSchedule->setApi($this->api());
- $backupSchedule->setId($this->formData['backupScheduleId']);
- $backupSchedule->delete();
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The backup job has been deleted successfully')
- ->setRefreshTargetIds(['backupJobDataTable'])
- ->addData('createButtonStatus', 1)
- ->setCallBackFunction('pmToggleBackupButton');
- }
- }
|