.htaccess
5 months ago
AbortQueueItem.php
5 months ago
AddToQueue.php
5 months ago
ClearAlerts.php
5 months ago
ClearCompletedQueueItems.php
5 months ago
CreateSupportUser.php
5 months ago
DeleteBackupJob.php
5 months ago
DeleteDestination.php
5 months ago
DeleteDownload.php
5 months ago
DeleteSchedule.php
5 months ago
DeleteSnapshot.php
5 months ago
DestinationSetExportConfig.php
5 months ago
DuplicateBackupJob.php
5 months ago
EditBackupNotes.php
5 months ago
EnableBackupJob.php
5 months ago
EnableDestination.php
5 months ago
ExecuteCron.php
5 months ago
FileManager.php
5 months ago
GetBackup.php
5 months ago
GetBackupJob.php
5 months ago
GetDashboard.php
5 months ago
GetDatabaseTables.php
5 months ago
GetDestination.php
5 months ago
GetLog.php
5 months ago
GetQRCode.php
5 months ago
GetQueueItem.php
5 months ago
GetSchedule.php
5 months ago
GetSettingsAutomation.php
5 months ago
GetSettingsGeneral.php
5 months ago
GetSettingsIntegrations.php
5 months ago
GetSettingsLogging.php
5 months ago
GetSettingsMaintenance.php
5 months ago
GetSettingsNotifications.php
5 months ago
GetSettingsPerformance.php
5 months ago
GetSettingsRestore.php
5 months ago
GetSettingsSecurity.php
5 months ago
GetSettingsUpdates.php
5 months ago
GetSystemInfo.php
5 months ago
ListAlerts.php
5 months ago
ListBackupJobs.php
5 months ago
ListBackups.php
5 months ago
ListDatabaseTables.php
5 months ago
ListDestinations.php
5 months ago
ListDownloads.php
5 months ago
ListQueueItems.php
5 months ago
ListSchedules.php
5 months ago
LockSnapshot.php
5 months ago
ManageBackupJob.php
5 months ago
ManageDestination.php
5 months ago
ManageSchedule.php
5 months ago
ManageSettingsAutomation.php
5 months ago
ManageSettingsGeneral.php
5 months ago
ManageSettingsIntegrations.php
5 months ago
ManageSettingsLogging.php
5 months ago
ManageSettingsMaintenance.php
5 months ago
ManageSettingsNotifications.php
5 months ago
ManageSettingsPerformance.php
5 months ago
ManageSettingsRestore.php
5 months ago
ManageSettingsSecurity.php
5 months ago
ManageSettingsUpdates.php
5 months ago
ManageShowcase.php
5 months ago
PanelPreload.php
5 months ago
SendTestEmail.php
5 months ago
StartOverQueueItem.php
5 months ago
ValidateDestination.php
5 months ago
ValidateMFA.php
5 months ago
index.html
5 months ago
web.config
5 months ago
ManageSettingsNotifications.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Ajax\Calls; |
| 4 | |
| 5 | use JetBackup\Ajax\aAjax; |
| 6 | use JetBackup\Exception\AjaxException; |
| 7 | use JetBackup\Exception\FieldsValidationException; |
| 8 | use JetBackup\Factory; |
| 9 | use JetBackup\Settings\Notifications; |
| 10 | use JetBackup\UserInput\UserInput; |
| 11 | use JetBackup\Wordpress\Wordpress; |
| 12 | use SleekDB\Exceptions\InvalidArgumentException; |
| 13 | use SleekDB\Exceptions\IOException; |
| 14 | |
| 15 | class ManageSettingsNotifications extends aAjax { |
| 16 | |
| 17 | /** |
| 18 | * @return bool |
| 19 | * @throws AjaxException |
| 20 | */ |
| 21 | private function _getEmails(): bool { return $this->getUserInput(Notifications::EMAILS, false, UserInput::BOOL); } |
| 22 | |
| 23 | /** |
| 24 | * @return string |
| 25 | * @throws AjaxException |
| 26 | */ |
| 27 | private function _getAlternateEmail(): string { return Wordpress::sanitizeEmail($this->getUserInput(Notifications::ALTERNATE_EMAIL, '', UserInput::STRING)); } |
| 28 | |
| 29 | /** |
| 30 | * @return array |
| 31 | * @throws AjaxException |
| 32 | */ |
| 33 | private function _getAlertLevelsFrequency(): array { return $this->getUserInput(Notifications::NOTIFICATION_LEVELS_FREQUENCY, Notifications::NOTIFICATION_FREQUENCY_DEFAULTS, UserInput::ARRAY, UserInput::UINT); } |
| 34 | |
| 35 | /** |
| 36 | * @return void |
| 37 | * @throws AjaxException |
| 38 | * @throws FieldsValidationException |
| 39 | * @throws IOException |
| 40 | * @throws InvalidArgumentException |
| 41 | */ |
| 42 | public function execute(): void { |
| 43 | |
| 44 | $settings = Factory::getSettingsNotifications(); |
| 45 | |
| 46 | if($this->isset(Notifications::EMAILS)) $settings->setEmailsEnabled($this->_getEmails()); |
| 47 | if($this->isset(Notifications::ALTERNATE_EMAIL)) $settings->setAlternateEmail($this->_getAlternateEmail()); |
| 48 | if($this->isset(Notifications::NOTIFICATION_LEVELS_FREQUENCY)) $settings->setAlertLevelFrequency($this->_getAlertLevelsFrequency()); |
| 49 | |
| 50 | $settings->validateFields(); |
| 51 | $settings->save(); |
| 52 | |
| 53 | $this->setResponseMessage('Saved Successfully'); |
| 54 | $this->setResponseData($this->isCLI() ? $settings->getDisplayCLI() : $settings->getDisplay()); |
| 55 | } |
| 56 | } |