.htaccess
5 months ago
Blog.php
5 months ago
Helper.php
5 months ago
Init.php
5 months ago
Installer.php
5 months ago
MySQL.php
5 months ago
UI.php
5 months ago
Update.php
5 months ago
Wordpress.php
5 months ago
index.html
5 months ago
web.config
5 months ago
Installer.php
126 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Wordpress; |
| 4 | |
| 5 | use JetBackup\Alert\Alert; |
| 6 | use JetBackup\Config\Config; |
| 7 | use JetBackup\Crontab\Crontab; |
| 8 | use JetBackup\Destination\Destination; |
| 9 | use JetBackup\Exception\DBException; |
| 10 | use JetBackup\Exception\QueueException; |
| 11 | use JetBackup\Factory; |
| 12 | use JetBackup\JetBackup; |
| 13 | use Plugin_Upgrader; |
| 14 | use SleekDB\Exceptions\InvalidArgumentException; |
| 15 | use SleekDB\Exceptions\IOException; |
| 16 | |
| 17 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 18 | |
| 19 | class Installer { |
| 20 | |
| 21 | private function __construct() {} // only static method |
| 22 | |
| 23 | public static function install(): void { |
| 24 | |
| 25 | try { |
| 26 | |
| 27 | if (!class_exists('PDO')) { |
| 28 | throw new \Exception( |
| 29 | __('The PHP PDO extension is not installed or enabled on your server. JetBackup requires PDO to communicate with databases. Please enable the PDO extension in your PHP configuration and try again.', 'text-domain') |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | if (version_compare(PHP_VERSION, JetBackup::MINIMUM_PHP_VERSION, '<')) { |
| 34 | throw new \Exception( |
| 35 | sprintf( |
| 36 | __('PHP version %s or higher is required. Current version: %s', 'text-domain'), |
| 37 | JetBackup::MINIMUM_PHP_VERSION, |
| 38 | PHP_VERSION |
| 39 | ) |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | if (version_compare(Wordpress::getVersion(), JetBackup::MINIMUM_WP_VERSION, '<')) { |
| 44 | throw new \Exception( |
| 45 | sprintf( |
| 46 | __('WordPress version %s or higher is required. Current version: %s', 'text-domain'), |
| 47 | JetBackup::MINIMUM_WP_VERSION, |
| 48 | Wordpress::getVersion() |
| 49 | ) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | $plugins = Wordpress::getPlugins(); |
| 54 | foreach (JetBackup::PLUGIN_CONFLICTS as $plugin) { |
| 55 | if (!isset($plugins[$plugin]) || !Wordpress::isPluginActive($plugin)) continue; |
| 56 | |
| 57 | throw new \Exception( |
| 58 | sprintf( |
| 59 | __('Conflicting plugin detected: %s. Using this plugin alongside JetBackup may cause unexpected behavior. Please disable it before activating JetBackup.', 'text-domain'), |
| 60 | $plugins[$plugin]['Name'] |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | } catch (\Exception $e) { |
| 66 | wp_die( |
| 67 | sprintf(__('This plugin cannot be activated. %s', 'text-domain'), $e->getMessage()), |
| 68 | __('Plugin Activation Error', 'text-domain'), |
| 69 | ['back_link' => true] |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | public static function uninstall():void { |
| 76 | Wordpress::deleteOption(Config::WP_DB_CONFIG_PREFIX); |
| 77 | $cron = new Crontab(); |
| 78 | $cron->removeCrontab(); |
| 79 | } |
| 80 | |
| 81 | public static function deactivate():void { |
| 82 | Wordpress::deleteOption(Config::WP_DB_CONFIG_PREFIX); |
| 83 | $cron = new Crontab(); |
| 84 | $cron->removeCrontab(); |
| 85 | } |
| 86 | |
| 87 | public static function update($upgrader):void { |
| 88 | |
| 89 | if ( |
| 90 | !isset($upgrader->new_plugin_data) || |
| 91 | !is_array($upgrader->new_plugin_data) || |
| 92 | !isset($upgrader->new_plugin_data['Name']) || |
| 93 | $upgrader->new_plugin_data['Name'] != JetBackup::PLUGIN_EXT_NAME |
| 94 | ) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | $config = Factory::getConfig(); |
| 100 | |
| 101 | /* |
| 102 | // PLACEHOLDER - in case we need changes between versions, this is an example |
| 103 | |
| 104 | $current_version = $config->getCurrentVersion(); |
| 105 | if(!$current_version || version_compare($current_version, '3.1', '<')) { |
| 106 | |
| 107 | try { |
| 108 | |
| 109 | |
| 110 | } catch (\Exception $e) { |
| 111 | Alert::add( |
| 112 | "JetBackup encountered an error during the update process", |
| 113 | "Error: " . $e->getMessage(), |
| 114 | Alert::LEVEL_WARNING |
| 115 | ); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | */ |
| 121 | |
| 122 | $config->setCurrentVersion(JetBackup::VERSION); |
| 123 | $config->save(); |
| 124 | } |
| 125 | } |
| 126 |