.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
ManageSchedule.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Ajax\Calls; |
| 4 | |
| 5 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 6 | |
| 7 | |
| 8 | use JetBackup\Ajax\aAjax; |
| 9 | use JetBackup\BackupJob\BackupJob; |
| 10 | use JetBackup\Exception\AjaxException; |
| 11 | use JetBackup\Exception\DBException; |
| 12 | use JetBackup\Exception\FieldsValidationException; |
| 13 | use JetBackup\JetBackup; |
| 14 | use JetBackup\Schedule\Schedule; |
| 15 | use JetBackup\UserInput\UserInput; |
| 16 | use SleekDB\Exceptions\InvalidArgumentException; |
| 17 | use SleekDB\Exceptions\IOException; |
| 18 | |
| 19 | class ManageSchedule 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(Schedule::NAME, '', UserInput::STRING)); } |
| 32 | |
| 33 | /** |
| 34 | * @return int |
| 35 | * @throws AjaxException |
| 36 | */ |
| 37 | private function _getType():int { return($this->getUserInput(Schedule::TYPE, 0, UserInput::UINT)); } |
| 38 | |
| 39 | /** |
| 40 | * @return array|bool|float|int|mixed|object |
| 41 | * @throws AjaxException |
| 42 | */ |
| 43 | private function _getIntervals() { return($this->getUserInput(Schedule::INTERVALS, 0, UserInput::UINT|UserInput::ARRAY, UserInput::UINT)); } |
| 44 | |
| 45 | /** |
| 46 | * @return int |
| 47 | * @throws AjaxException |
| 48 | */ |
| 49 | private function _getBackupId():int { return($this->getUserInput(Schedule::BACKUP_ID, 0, UserInput::UINT)); } |
| 50 | |
| 51 | /** |
| 52 | * @return void |
| 53 | * @throws AjaxException |
| 54 | * @throws DBException |
| 55 | * @throws IOException |
| 56 | * @throws InvalidArgumentException |
| 57 | * @throws FieldsValidationException |
| 58 | */ |
| 59 | public function execute(): void { |
| 60 | |
| 61 | if($this->_getId()) { |
| 62 | $schedule = new Schedule($this->_getId()); |
| 63 | if(!$schedule->getId() || $schedule->isHidden()) throw new AjaxException("Invalid schedule id \"%s\" provided", [$this->_getId()]); |
| 64 | } else { |
| 65 | $schedule = new Schedule(); |
| 66 | $schedule->setHidden(false); |
| 67 | $schedule->setDefault(false); |
| 68 | } |
| 69 | |
| 70 | if($this->isset(Schedule::NAME)) $schedule->setName($this->_getName()); |
| 71 | if($this->isset(Schedule::TYPE)) $schedule->setType($this->_getType()); |
| 72 | if($this->isset(Schedule::INTERVALS)) $schedule->setIntervals($this->_getIntervals()); |
| 73 | if($this->isset(Schedule::BACKUP_ID)) $schedule->setBackupId($this->_getBackupId()); |
| 74 | |
| 75 | $schedule->validateFields(); |
| 76 | $schedule->save(); |
| 77 | |
| 78 | $jobs = BackupJob::query() |
| 79 | ->select([JetBackup::ID_FIELD]) |
| 80 | ->getQuery() |
| 81 | ->fetch(); |
| 82 | |
| 83 | foreach ($jobs as $jobData) { |
| 84 | $job = new BackupJob($jobData[JetBackup::ID_FIELD]); |
| 85 | |
| 86 | foreach ($job->getSchedules() as $scheduleItem) { |
| 87 | if ($scheduleItem->getId() == $schedule->getId()) { |
| 88 | // update next_run on backup job |
| 89 | $job->calculateNextRun(); |
| 90 | $job->save(); |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $this->setResponseMessage('Success'); |
| 97 | $this->setResponseData($this->isCLI() ? $schedule->getDisplayCLI() : $schedule->getDisplay()); |
| 98 | |
| 99 | } |
| 100 | } |