PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.11.1
JetBackup – Backup, Restore & Migrate v3.1.11.1
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 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 / Automation.php
backup / src / JetBackup / Settings Last commit date
.htaccess 1 year ago Automation.php 1 year ago General.php 1 year ago Integrations.php 1 year ago Logging.php 1 year ago Maintenance.php 1 year ago Notifications.php 1 year ago Performance.php 1 year ago Restore.php 1 year ago Security.php 1 year ago Settings.php 1 year ago Updates.php 1 year ago index.html 1 year ago web.config 1 year ago
Automation.php
162 lines
1 <?php
2
3 namespace JetBackup\Settings;
4
5 use JetBackup\Crontab\Crontab;
6 use JetBackup\Exception\AjaxException;
7 use JetBackup\Exception\DBException;
8 use JetBackup\Exception\IOException;
9 use JetBackup\Wordpress\Wordpress;
10 use ReflectionException;
11 use SleekDB\Exceptions\InvalidArgumentException;
12
13 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
14
15 class Automation extends Settings {
16
17 const SECTION = 'automation';
18
19 const CRON_PUBLIC = 'AUTOMATION_CRON_PUBLIC';
20 const CRON_COMMAND = 'AUTOMATION_CRON_COMMAND';
21 const CRON_CONTENT = 'AUTOMATION_CRON_CONTENT';
22
23 const WP_CRON = 'WP_CRON';
24
25 const HEARTBEAT = 'HEARTBEAT';
26 const HEARTBEAT_TTL = 'HEARTBEAT_TTL';
27 const HEARTBEAT_TTL_VALUES = 'HEARTBEAT_TTL_VALUES';
28 const CRONS = 'CRONS';
29 const ENABLE_REST_API_SCHEDULER = 'ENABLE_REST_API_SCHEDULER';
30 const CRON_STATUS = 'CRON_STATUS';
31
32 /**
33 * @throws DBException
34 * @throws \SleekDB\Exceptions\IOException
35 * @throws InvalidArgumentException
36 */
37 public function __construct() {
38 parent::__construct(self::SECTION);
39 }
40
41 public function isWPCronEnabled():bool { return (bool) $this->get(self::WP_CRON, true); }
42 public function setWPCron(bool $value):void { $this->set(self::WP_CRON, $value); }
43
44 /**
45 * @return bool
46 */
47 public function isHeartbeatEnabled():bool { return (bool) $this->get(self::HEARTBEAT, true); }
48
49 /**
50 * @param bool $value
51 *
52 * @return void
53 */
54 public function setHeartbeatEnabled(bool $value):void { $this->set(self::HEARTBEAT, $value); }
55
56 /**
57 * @return int
58 */
59 public function getHeartbeatTTL():int { return (int) $this->get(self::HEARTBEAT_TTL, 10000); }
60
61 /**
62 * @param int $value
63 *
64 * @return void
65 */
66 public function setHeartbeatTTL(int $value):void { $this->set(self::HEARTBEAT_TTL, $value); }
67
68 /**
69 * @return bool
70 */
71 public function isCronsEnabled():bool { return (bool) $this->get(self::CRONS, true); }
72
73 /**
74 * @param bool $value
75 *
76 * @return void
77 */
78 public function setCronsEnabled(bool $value):void { $this->set(self::CRONS, $value); }
79
80 /**
81 * @return bool
82 */
83 public function isRestAPISchedulerEnabled():bool { return (bool) $this->get(self::ENABLE_REST_API_SCHEDULER, false); }
84
85 /**
86 * @param bool $value
87 *
88 * @return void
89 */
90 public function setRestAPISchedulerEnabled(bool $value):void { $this->set(self::ENABLE_REST_API_SCHEDULER, $value); }
91
92 /**
93 * @return bool
94 */
95 public function isCronStatusEnabled():bool { return (bool) $this->get(self::CRON_STATUS, false); }
96
97 /**
98 * @param bool $value
99 *
100 * @return void
101 */
102 public function setCronStatusEnabled(bool $value):void { $this->set(self::CRON_STATUS, $value); }
103
104 /**
105 * @return array
106 */
107 public function getDisplay():array {
108
109 $cron = new Crontab();
110
111 return [
112 self::CRON_PUBLIC => Crontab::getPublicCron(),
113 self::CRON_COMMAND => Crontab::getCommand(),
114 self::CRON_CONTENT => implode(PHP_EOL, $cron->getCrontab()),
115 self::WP_CRON => $this->isWPCronEnabled() ? 1 : 0,
116 self::HEARTBEAT => $this->isHeartbeatEnabled() ? 1 : 0,
117 self::CRONS => $this->isCronsEnabled() ? 1 : 0,
118 self::ENABLE_REST_API_SCHEDULER => $this->isRestAPISchedulerEnabled() ? 1 : 0,
119 self::CRON_STATUS => $this->isCronStatusEnabled() ? 1 : 0,
120 self::HEARTBEAT_TTL => $this->getHeartbeatTTL(),
121 self::HEARTBEAT_TTL_VALUES => [
122 5 => 5000,
123 10 => 10000,
124 20 => 20000,
125 30 => 30000,
126 40 => 40000,
127 50 => 50000,
128 60 => 60000,
129 ]
130 ];
131 }
132
133 /**
134 * @return array
135 */
136 public function getDisplayCLI():array {
137
138 return [
139 'Wordpress Cron' => $this->isWPCronEnabled() ? "Yes" : "No",
140 'Heartbeat' => $this->isHeartbeatEnabled() ? "Yes" : "No",
141 'Cron Jobs' => $this->isCronsEnabled() ? "Yes" : "No",
142 'FrontEnd REST API Enabled' => $this->isRestAPISchedulerEnabled() ? "Yes" : "No",
143 'Cron Job Status' => $this->isCronStatusEnabled() ? "Yes" : "No",
144 ];
145 }
146
147 /**
148 * @return void
149 */
150 public function validateFields():void {}
151
152 public function save(): void {
153
154 if ($this->isRestAPISchedulerEnabled()) {
155 if (!Wordpress::getOption('permalink_structure')) throw new AjaxException('Permalink structure cannot be "Plain" for REST-API (WordPress -> Settings -> Permalinks)');
156 }
157
158 parent::save();
159
160 }
161
162 }