.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
Integrations.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Settings; |
| 4 | |
| 5 | use JetBackup\Exception\AjaxException; |
| 6 | use JetBackup\Exception\DBException; |
| 7 | use SleekDB\Exceptions\InvalidArgumentException; |
| 8 | use SleekDB\Exceptions\IOException; |
| 9 | |
| 10 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 11 | |
| 12 | class Integrations extends Settings { |
| 13 | |
| 14 | const SECTION = 'integrations'; |
| 15 | const ELEMENTOR = 'Elementor'; |
| 16 | const SUPERCACHE = 'Supercache'; |
| 17 | const WOOCOMMERCE = 'Woocommerce'; |
| 18 | const AUTOPTIMIZE = 'Autoptimize'; |
| 19 | const W3TOTALCACHE = 'W3TotalCache'; |
| 20 | |
| 21 | const INTEGRATIONS = 'integrations'; |
| 22 | const INTEGRATION_DEFAULTS = [ |
| 23 | self::ELEMENTOR, |
| 24 | self::SUPERCACHE, |
| 25 | self::WOOCOMMERCE, |
| 26 | self::W3TOTALCACHE, |
| 27 | self::AUTOPTIMIZE, |
| 28 | ]; |
| 29 | /** |
| 30 | * @throws DBException |
| 31 | * @throws IOException |
| 32 | * @throws InvalidArgumentException |
| 33 | */ |
| 34 | public function __construct() { |
| 35 | parent::__construct(self::SECTION); |
| 36 | } |
| 37 | |
| 38 | public function getInegrations(): array { |
| 39 | return $this->get(self::INTEGRATIONS, self::INTEGRATION_DEFAULTS); |
| 40 | } |
| 41 | |
| 42 | public function setIntegrations(array $values) : void { |
| 43 | $this->set(self::INTEGRATIONS, $values); |
| 44 | } |
| 45 | /** |
| 46 | * @return bool[] |
| 47 | */ |
| 48 | public function getDisplay():array { |
| 49 | return [self::INTEGRATIONS => $this->getInegrations()]; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return bool[] |
| 54 | */ |
| 55 | public function getDisplayCLI():array { |
| 56 | return [self::INTEGRATIONS => $this->getInegrations()]; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return void |
| 61 | * @throws AjaxException |
| 62 | */ |
| 63 | public function validateFields():void { |
| 64 | |
| 65 | $changedFields = self::getChangedFields($this->getData(), (new Integrations())->getData()); |
| 66 | |
| 67 | if(in_array(self::INTEGRATIONS, $changedFields)) { |
| 68 | $missing = array_diff($this->getInegrations(), self::INTEGRATION_DEFAULTS); |
| 69 | |
| 70 | if (!empty($missing)) { |
| 71 | throw new AjaxException("The following integrations are not supported: " . implode(', ', $missing)); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |