PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.18.8
JetBackup – Backup, Restore & Migrate v3.1.18.8
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Settings / Maintenance.php
backup / src / JetBackup / Settings Last commit date
.htaccess 5 months ago Automation.php 5 months ago General.php 5 months ago Integrations.php 5 months ago Logging.php 5 months ago Maintenance.php 5 months ago Notifications.php 5 months ago Performance.php 5 months ago Restore.php 5 months ago Security.php 5 months ago Settings.php 5 months ago Updates.php 5 months ago index.html 5 months ago web.config 5 months ago
Maintenance.php
138 lines
1 <?php
2
3 namespace JetBackup\Settings;
4
5 use JetBackup\BackupJob\BackupJob;
6 use JetBackup\Exception\DBException;
7 use JetBackup\Exception\FieldsValidationException;
8 use JetBackup\Exception\IOException;
9 use JetBackup\Exception\JBException;
10 use SleekDB\Exceptions\InvalidArgumentException;
11
12 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
13
14 class Maintenance extends Settings {
15
16 const SECTION = 'maintenance';
17
18 const MAINTENANCE_QUEUE_HOURS_TTL = 'MAINTENANCE_QUEUE_HOURS_TTL';
19 const MAINTENANCE_QUEUE_ALERTS_TTL = 'MAINTENANCE_QUEUE_ALERTS_TTL';
20 const MAINTENANCE_DOWNLOAD_ITEMS_TTL = 'MAINTENANCE_DOWNLOAD_ITEMS_TTL';
21 const MAINTENANCE_DOWNLOAD_LIMIT = 'MAINTENANCE_DOWNLOAD_LIMIT';
22
23 const CONFIG_EXPORT_ROTATE = 'CONFIG_EXPORT_ROTATE';
24
25 private BackupJob $_backup;
26
27 /**
28 * @throws DBException
29 * @throws IOException
30 * @throws JBException
31 * @throws \SleekDB\Exceptions\IOException
32 * @throws InvalidArgumentException
33 */
34 public function __construct() {
35 parent::__construct(self::SECTION);
36 $this->_backup = BackupJob::getDefaultConfigJob();
37 }
38
39 /**
40 * @return int
41 */
42 public function getQueueItemsTTL():int { return (int) $this->get(self::MAINTENANCE_QUEUE_HOURS_TTL, 24); }
43 public function getDownloadItemsTTL():int { return (int) $this->get(self::MAINTENANCE_DOWNLOAD_ITEMS_TTL, 72); }
44 public function getDownloadLimit():int { return (int) $this->get(self::MAINTENANCE_DOWNLOAD_LIMIT, 5); }
45
46 /**
47 * @param int $value
48 *
49 * @return void
50 */
51 public function setQueueItemsTTL(int $value):void { $this->set(self::MAINTENANCE_QUEUE_HOURS_TTL, $value); }
52 public function setDownloadItemsTTL(int $value):void { $this->set(self::MAINTENANCE_DOWNLOAD_ITEMS_TTL, $value); }
53 public function setDownloadLimit(int $value):void { $this->set(self::MAINTENANCE_DOWNLOAD_LIMIT, $value); }
54
55 /**
56 * @return int
57 */
58 public function getAlertsTTL():int { return (int) $this->get(self::MAINTENANCE_QUEUE_ALERTS_TTL, 72); }
59
60 /**
61 * @param int $value
62 *
63 * @return void
64 */
65 public function setAlertsTTL(int $value):void { $this->set(self::MAINTENANCE_QUEUE_ALERTS_TTL, $value); }
66
67 /**
68 * @return int
69 */
70 public function getConfigExportRotate():int {
71 $schedules = $this->_backup->getSchedules();
72 return $schedules[0]->getRetain();
73 }
74
75 /**
76 * @param int $value
77 *
78 * @return void
79 */
80 public function setConfigExportRotate(int $value):void {
81 $schedules = $this->_backup->getSchedules();
82 $schedules[0]->setRetain($value);
83 $this->_backup->setSchedules($schedules);
84 }
85
86 /**
87 * @return array
88 */
89 public function getDisplay():array {
90
91 return [
92 self::MAINTENANCE_QUEUE_HOURS_TTL => $this->getQueueItemsTTL(),
93 self::MAINTENANCE_QUEUE_ALERTS_TTL => $this->getAlertsTTL(),
94 self::MAINTENANCE_DOWNLOAD_ITEMS_TTL => $this->getDownloadItemsTTL(),
95 self::MAINTENANCE_DOWNLOAD_LIMIT => $this->getDownloadLimit(),
96 self::CONFIG_EXPORT_ROTATE => $this->getConfigExportRotate(),
97 ];
98 }
99
100 /**
101 * @return array
102 */
103 public function getDisplayCLI():array {
104
105 return [
106 'Queue Items TTL' => $this->getQueueItemsTTL(),
107 'Alerts TTL' => $this->getAlertsTTL(),
108 'Download Items TTL' => $this->getDownloadItemsTTL(),
109 'Downloads Limits' => $this->getDownloadLimit(),
110 'Config Export Rotate' => $this->getConfigExportRotate(),
111 ];
112 }
113
114 /**
115 * @return void
116 * @throws FieldsValidationException
117 */
118 public function validateFields():void {
119 if($this->getQueueItemsTTL() < 0) throw new FieldsValidationException("Done Queue items TTL must be a positive integer or 0 to disable");
120 if($this->getDownloadItemsTTL() < 0) throw new FieldsValidationException("Download TTL must be a positive integer or 0 to disable");
121 if($this->getDownloadLimit() < 0) throw new FieldsValidationException("Download limit must be a positive integer or 0 to disable");
122 if($this->getAlertsTTL() < 0) throw new FieldsValidationException("System Alerts TTL must be a positive integer or 0 to disable");
123 if($this->getConfigExportRotate() < 1) throw new FieldsValidationException("Export Config Rotate Days must be grater then 0");
124 }
125
126 /**
127 * @return void
128 * @throws InvalidArgumentException
129 * @throws JBException
130 * @throws \SleekDB\Exceptions\IOException
131 */
132 public function save(): void {
133 parent::save();
134
135 $this->_backup->calculateNextRun();
136 $this->_backup->save();
137 }
138 }