.htaccess
1 year ago
AbortQueueItem.php
1 year ago
AddToQueue.php
3 months ago
ClearAlerts.php
1 year ago
ClearCompletedQueueItems.php
1 year ago
CreateSupportUser.php
1 year ago
DeleteBackupJob.php
1 year ago
DeleteDestination.php
1 year ago
DeleteDownload.php
1 year ago
DeleteSchedule.php
1 year ago
DeleteSnapshot.php
1 year ago
DestinationSetExportConfig.php
1 year ago
DuplicateBackupJob.php
1 year ago
EditBackupNotes.php
1 year ago
EnableBackupJob.php
1 year ago
EnableDestination.php
1 year ago
ExecuteCron.php
1 year ago
FileManager.php
10 months ago
GetBackup.php
1 year ago
GetBackupJob.php
1 year ago
GetDashboard.php
1 year ago
GetDatabaseTables.php
1 year ago
GetDestination.php
1 year ago
GetLog.php
1 year ago
GetQRCode.php
1 year ago
GetQueueItem.php
1 year ago
GetSchedule.php
1 year ago
GetSettingsAutomation.php
1 year ago
GetSettingsGeneral.php
1 year ago
GetSettingsIntegrations.php
1 year ago
GetSettingsLogging.php
1 year ago
GetSettingsMaintenance.php
1 year ago
GetSettingsNotifications.php
1 year ago
GetSettingsPerformance.php
1 year ago
GetSettingsRestore.php
1 year ago
GetSettingsSecurity.php
1 year ago
GetSettingsUpdates.php
1 year ago
GetSystemInfo.php
11 months ago
ListAlerts.php
1 year ago
ListBackupJobs.php
1 year ago
ListBackups.php
1 year ago
ListDatabaseTables.php
1 year ago
ListDestinations.php
1 year ago
ListDownloads.php
1 year ago
ListQueueItems.php
4 months ago
ListSchedules.php
1 year ago
LockSnapshot.php
1 year ago
ManageBackupJob.php
1 year ago
ManageDestination.php
1 year ago
ManageSchedule.php
3 months ago
ManageSettingsAutomation.php
10 months ago
ManageSettingsGeneral.php
4 months ago
ManageSettingsIntegrations.php
1 year ago
ManageSettingsLogging.php
1 year ago
ManageSettingsMaintenance.php
1 year ago
ManageSettingsNotifications.php
1 year ago
ManageSettingsPerformance.php
1 year ago
ManageSettingsRestore.php
1 year ago
ManageSettingsSecurity.php
1 week ago
ManageSettingsUpdates.php
1 year ago
ManageShowcase.php
1 year ago
PanelPreload.php
1 year ago
SendTestEmail.php
1 year ago
StartOverQueueItem.php
1 year ago
ValidateDestination.php
1 year ago
ValidateMFA.php
1 year ago
index.html
1 year ago
web.config
1 year ago
ManageBackupJob.php
156 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Ajax\Calls; |
| 4 | |
| 5 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 6 | |
| 7 | use JetBackup\Ajax\aAjax; |
| 8 | use JetBackup\BackupJob\BackupJob; |
| 9 | use JetBackup\Exception\AjaxException; |
| 10 | use JetBackup\Exception\DBException; |
| 11 | use JetBackup\Exception\FieldsValidationException; |
| 12 | use JetBackup\Exception\JBException; |
| 13 | use JetBackup\Exception\ScheduleException; |
| 14 | use JetBackup\JetBackup; |
| 15 | use JetBackup\UserInput\UserInput; |
| 16 | use SleekDB\Exceptions\InvalidArgumentException; |
| 17 | use SleekDB\Exceptions\IOException; |
| 18 | |
| 19 | class ManageBackupJob extends aAjax { |
| 20 | |
| 21 | /** |
| 22 | * @return int |
| 23 | * @throws AjaxException |
| 24 | */ |
| 25 | private function _getId():int { return $this->getUserInput(JetBackup::ID_FIELD, 0, UserInput::UINT); } |
| 26 | |
| 27 | /** |
| 28 | * @return string |
| 29 | * @throws AjaxException |
| 30 | */ |
| 31 | private function _getName():string { return ($this->getUserInput(BackupJob::NAME, '', UserInput::STRING)); } |
| 32 | |
| 33 | /** |
| 34 | * @return int |
| 35 | * @throws AjaxException |
| 36 | */ |
| 37 | private function _getType():int { return $this->getUserInput(BackupJob::TYPE, 0, UserInput::UINT); } |
| 38 | |
| 39 | /** |
| 40 | * @return array |
| 41 | * @throws AjaxException |
| 42 | */ |
| 43 | private function _getDestinations():array { return $this->getUserInput(BackupJob::DESTINATIONS, [], UserInput::ARRAY, UserInput::UINT); } |
| 44 | |
| 45 | /** |
| 46 | * @return array |
| 47 | * @throws AjaxException |
| 48 | */ |
| 49 | private function _getExcludes():array { return $this->getUserInput(BackupJob::EXCLUDES, [], UserInput::ARRAY, UserInput::STRING); } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * @return array |
| 54 | * @throws AjaxException |
| 55 | */ |
| 56 | private function _getExcludeDatabases():array { return $this->getUserInput(BackupJob::EXCLUDE_DATABASES, [], UserInput::ARRAY, UserInput::STRING); } |
| 57 | |
| 58 | /** |
| 59 | * @return int |
| 60 | * @throws AjaxException |
| 61 | */ |
| 62 | private function _getContains():int { return $this->getUserInput(BackupJob::CONTAINS, 0, UserInput::UINT); } |
| 63 | |
| 64 | /** |
| 65 | * @return int |
| 66 | * @throws AjaxException |
| 67 | */ |
| 68 | private function _getMonitor():int { return $this->getUserInput(BackupJob::JOB_MONITOR, 0, UserInput::UINT); } |
| 69 | |
| 70 | /** |
| 71 | * @return string |
| 72 | * @throws AjaxException |
| 73 | */ |
| 74 | private function _getScheduleTime():string { return $this->getUserInput(BackupJob::SCHEDULE_TIME, '', UserInput::STRING); } |
| 75 | |
| 76 | /** |
| 77 | * @return bool |
| 78 | * @throws AjaxException |
| 79 | */ |
| 80 | private function _getDefault():bool { return $this->getUserInput(BackupJob::DEFAULT, false, UserInput::BOOL); } |
| 81 | |
| 82 | /** |
| 83 | * @return bool |
| 84 | * @throws AjaxException |
| 85 | */ |
| 86 | private function _isFilesExcluded():bool { return $this->getUserInput(BackupJob::IS_FILES_EXCLUDED, false, UserInput::BOOL); } |
| 87 | |
| 88 | /** |
| 89 | * @return bool |
| 90 | * @throws AjaxException |
| 91 | */ |
| 92 | private function _isTablesExcluded():bool { return $this->getUserInput(BackupJob::IS_TABLES_EXCLUDED, false, UserInput::BOOL); } |
| 93 | |
| 94 | /** |
| 95 | * @return bool |
| 96 | * @throws AjaxException |
| 97 | */ |
| 98 | private function _isEnabled():bool { return $this->getUserInput(BackupJob::ENABLED, false, UserInput::BOOL); } |
| 99 | |
| 100 | /** |
| 101 | * @return array |
| 102 | * @throws AjaxException |
| 103 | */ |
| 104 | private function _getSchedules():array { return $this->getUserInput(BackupJob::SCHEDULES, [], UserInput::ARRAY, UserInput::MIXED); } |
| 105 | |
| 106 | /** |
| 107 | * @return void |
| 108 | * @throws AjaxException |
| 109 | * @throws DBException |
| 110 | * @throws FieldsValidationException |
| 111 | * @throws IOException |
| 112 | * @throws InvalidArgumentException |
| 113 | * @throws ScheduleException |
| 114 | */ |
| 115 | public function execute(): void { |
| 116 | |
| 117 | if($this->_getId()) { |
| 118 | $job = new BackupJob($this->_getId()); |
| 119 | if(!$job->getId() || $job->isHidden()) throw new AjaxException("Invalid job id \"%s\" provided", [$this->_getId()]); |
| 120 | } else { |
| 121 | $job = new BackupJob(); |
| 122 | } |
| 123 | |
| 124 | $schedulesUpdate = []; |
| 125 | |
| 126 | if($this->isset(BackupJob::NAME)) $job->setName($this->_getName()); |
| 127 | if($this->isset(BackupJob::TYPE)) $job->setType($this->_getType()); |
| 128 | if($this->isset(BackupJob::DESTINATIONS)) $job->setDestinations($this->_getDestinations()); |
| 129 | |
| 130 | if($this->isset(BackupJob::EXCLUDES)) $job->setExcludes($this->_getExcludes()); |
| 131 | |
| 132 | if($this->isset(BackupJob::EXCLUDE_DATABASES)) $job->setExcludeDatabases($this->_getExcludeDatabases()); |
| 133 | |
| 134 | if($this->isset(BackupJob::JOB_MONITOR)) $job->setMonitor($this->_getMonitor()); |
| 135 | if($this->isset(BackupJob::ENABLED)) $job->setEnabled($this->_isEnabled()); |
| 136 | if($this->isset(BackupJob::CONTAINS)) $job->setContains($this->_getContains()); |
| 137 | // setScheduleTime Must be executed BEFORE updateMultiSchedules |
| 138 | if($this->isset(BackupJob::SCHEDULE_TIME)) $job->setScheduleTime($this->_getScheduleTime()); |
| 139 | $job->setDefault($job->isDefault()); |
| 140 | $job->validateFields(); |
| 141 | try { |
| 142 | if($this->isset(BackupJob::SCHEDULES)) $schedulesUpdate = $job->updateMultiSchedules($this->_getSchedules()); |
| 143 | } catch(\JetBackup\Exception\IOException $e) { |
| 144 | throw new AjaxException($e->getMessage()); |
| 145 | } |
| 146 | |
| 147 | $job->setHidden(false); |
| 148 | $job->save(); |
| 149 | |
| 150 | // Update schedules only after we save the job |
| 151 | if(sizeof($schedulesUpdate)) foreach($schedulesUpdate as $schedule) $schedule->save(); |
| 152 | |
| 153 | $this->setResponseMessage('Backup job ' . ($this->_getId() ? 'modified' : 'created') . ' successfully'); |
| 154 | $this->setResponseData($this->isCLI() ? $job->getDisplayCLI() : $job->getDisplay()); |
| 155 | } |
| 156 | } |