.htaccess
1 year ago
Automation.php
10 months ago
General.php
3 months ago
Integrations.php
4 months ago
Logging.php
4 months ago
Maintenance.php
4 months ago
Notifications.php
4 months ago
Performance.php
3 months ago
Restore.php
1 year ago
Security.php
1 day ago
Settings.php
4 months ago
Updates.php
4 months ago
index.html
1 year ago
web.config
1 year ago
Automation.php
136 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 | const WP_CRON = 'WP_CRON'; |
| 23 | |
| 24 | const HEARTBEAT = 'HEARTBEAT'; |
| 25 | const HEARTBEAT_TTL = 'HEARTBEAT_TTL'; |
| 26 | const HEARTBEAT_TTL_VALUES = 'HEARTBEAT_TTL_VALUES'; |
| 27 | const CRONS = 'CRONS'; |
| 28 | const CRON_STATUS = 'CRON_STATUS'; |
| 29 | |
| 30 | /** |
| 31 | * @throws DBException |
| 32 | * @throws \SleekDB\Exceptions\IOException |
| 33 | * @throws InvalidArgumentException |
| 34 | */ |
| 35 | public function __construct() { |
| 36 | parent::__construct(self::SECTION); |
| 37 | } |
| 38 | |
| 39 | public function isWPCronEnabled():bool { return (bool) $this->get(self::WP_CRON, true); } |
| 40 | public function setWPCron(bool $value):void { $this->set(self::WP_CRON, $value); } |
| 41 | |
| 42 | /** |
| 43 | * @return bool |
| 44 | */ |
| 45 | public function isHeartbeatEnabled():bool { return (bool) $this->get(self::HEARTBEAT, true); } |
| 46 | |
| 47 | /** |
| 48 | * @param bool $value |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function setHeartbeatEnabled(bool $value):void { $this->set(self::HEARTBEAT, $value); } |
| 53 | |
| 54 | /** |
| 55 | * @return int |
| 56 | */ |
| 57 | public function getHeartbeatTTL():int { return (int) $this->get(self::HEARTBEAT_TTL, 10000); } |
| 58 | |
| 59 | /** |
| 60 | * @param int $value |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | public function setHeartbeatTTL(int $value):void { $this->set(self::HEARTBEAT_TTL, $value); } |
| 65 | |
| 66 | /** |
| 67 | * @return bool |
| 68 | */ |
| 69 | public function isCronsEnabled():bool { return (bool) $this->get(self::CRONS, true); } |
| 70 | |
| 71 | /** |
| 72 | * @param bool $value |
| 73 | * |
| 74 | * @return void |
| 75 | */ |
| 76 | public function setCronsEnabled(bool $value):void { $this->set(self::CRONS, $value); } |
| 77 | |
| 78 | /** |
| 79 | * @return bool |
| 80 | */ |
| 81 | public function isCronStatusEnabled():bool { return (bool) $this->get(self::CRON_STATUS, false); } |
| 82 | |
| 83 | /** |
| 84 | * @param bool $value |
| 85 | * |
| 86 | * @return void |
| 87 | */ |
| 88 | public function setCronStatusEnabled(bool $value):void { $this->set(self::CRON_STATUS, $value); } |
| 89 | |
| 90 | /** |
| 91 | * @return array |
| 92 | */ |
| 93 | public function getDisplay():array { |
| 94 | |
| 95 | $cron = new Crontab(); |
| 96 | |
| 97 | return [ |
| 98 | self::CRON_PUBLIC => Crontab::getPublicCron(), |
| 99 | self::CRON_COMMAND => Crontab::getCommand(), |
| 100 | self::CRON_CONTENT => implode(PHP_EOL, $cron->getCrontab()), |
| 101 | self::WP_CRON => $this->isWPCronEnabled() ? 1 : 0, |
| 102 | self::HEARTBEAT => $this->isHeartbeatEnabled() ? 1 : 0, |
| 103 | self::CRONS => $this->isCronsEnabled() ? 1 : 0, |
| 104 | self::CRON_STATUS => $this->isCronStatusEnabled() ? 1 : 0, |
| 105 | self::HEARTBEAT_TTL => $this->getHeartbeatTTL(), |
| 106 | self::HEARTBEAT_TTL_VALUES => [ |
| 107 | 5 => 5000, |
| 108 | 10 => 10000, |
| 109 | 20 => 20000, |
| 110 | 30 => 30000, |
| 111 | 40 => 40000, |
| 112 | 50 => 50000, |
| 113 | 60 => 60000, |
| 114 | ] |
| 115 | ]; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @return array |
| 120 | */ |
| 121 | public function getDisplayCLI():array { |
| 122 | |
| 123 | return [ |
| 124 | 'Wordpress Cron' => $this->isWPCronEnabled() ? "Yes" : "No", |
| 125 | 'Heartbeat' => $this->isHeartbeatEnabled() ? "Yes" : "No", |
| 126 | 'Cron Jobs' => $this->isCronsEnabled() ? "Yes" : "No", |
| 127 | 'Cron Job Status' => $this->isCronStatusEnabled() ? "Yes" : "No", |
| 128 | ]; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @return void |
| 133 | */ |
| 134 | public function validateFields():void {} |
| 135 | |
| 136 | } |