.htaccess
9 months ago
Blog.php
9 months ago
Helper.php
9 months ago
Init.php
9 months ago
Installer.php
9 months ago
MySQL.php
9 months ago
UI.php
9 months ago
Update.php
9 months ago
Wordpress.php
9 months ago
index.html
9 months ago
web.config
9 months ago
Installer.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Wordpress; |
| 4 | |
| 5 | use JetBackup\Alert\Alert; |
| 6 | use JetBackup\Crontab\Crontab; |
| 7 | use JetBackup\Destination\Destination; |
| 8 | use JetBackup\Exception\DBException; |
| 9 | use JetBackup\Exception\QueueException; |
| 10 | use JetBackup\Factory; |
| 11 | use JetBackup\JetBackup; |
| 12 | use Plugin_Upgrader; |
| 13 | use SleekDB\Exceptions\InvalidArgumentException; |
| 14 | use SleekDB\Exceptions\IOException; |
| 15 | |
| 16 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 17 | |
| 18 | class Installer { |
| 19 | |
| 20 | private function __construct() {} // only static method |
| 21 | |
| 22 | public static function install():void { |
| 23 | |
| 24 | try { |
| 25 | |
| 26 | if (version_compare(PHP_VERSION, JetBackup::MINIMUM_PHP_VERSION, '<')) |
| 27 | throw new \Exception('Error: PHP version ' . JetBackup::MINIMUM_PHP_VERSION . ' or higher is required, Current version: ' . PHP_VERSION); |
| 28 | |
| 29 | if (version_compare(Wordpress::getVersion(), JetBackup::MINIMUM_WP_VERSION, '<')) |
| 30 | throw new \Exception('WordPress version ' . JetBackup::MINIMUM_WP_VERSION . ' or higher is required. Current version: ' . Wordpress::getVersion()); |
| 31 | |
| 32 | $plugins = Wordpress::getPlugins(); |
| 33 | |
| 34 | foreach (JetBackup::PLUGIN_CONFLICTS as $plugin) { |
| 35 | if(!isset($plugins[$plugin]) || !Wordpress::isPluginActive($plugin)) continue; |
| 36 | throw new \Exception('Conflicting plugin found: Using the ' . $plugins[$plugin]['Name'] . ' plugin alongside with JetBackup might interfere with our plugin functionality and is likely to cause errors, Please disable this plugin before using JetBackup.'); |
| 37 | } |
| 38 | |
| 39 | } catch (\Exception $e) { |
| 40 | wp_die(__('This plugin cannot be activated, Error : ' . $e->getMessage(), 'text-domain'), __('Plugin Activation Error', 'text-domain'), array( |
| 41 | 'back_link' => true, |
| 42 | )); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public static function uninstall():void { |
| 47 | $cron = new Crontab(); |
| 48 | $cron->removeCrontab(); |
| 49 | } |
| 50 | |
| 51 | public static function deactivate():void { |
| 52 | $cron = new Crontab(); |
| 53 | $cron->removeCrontab(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @throws \JetBackup\Exception\IOException |
| 58 | */ |
| 59 | public static function update($upgrader):void { |
| 60 | |
| 61 | if ( |
| 62 | !isset($upgrader->new_plugin_data) || |
| 63 | !is_array($upgrader->new_plugin_data) || |
| 64 | !isset($upgrader->new_plugin_data['Name']) || |
| 65 | $upgrader->new_plugin_data['Name'] != JetBackup::PLUGIN_EXT_NAME |
| 66 | ) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | $config = Factory::getConfig(); |
| 72 | $current_version = $config->getCurrentVersion(); |
| 73 | |
| 74 | if(!$current_version || version_compare($current_version, '3.1', '<')) { |
| 75 | |
| 76 | try { |
| 77 | |
| 78 | // Add all destinations to Queue |
| 79 | $list = Destination::query()->getQuery()->fetch(); |
| 80 | |
| 81 | foreach ($list as $destination_details) { |
| 82 | $destination = new Destination($destination_details[JetBackup::ID_FIELD]); |
| 83 | $destination->addToQueue(false); |
| 84 | } |
| 85 | Alert::add( |
| 86 | "JetBackup has been upgraded to version " . JetBackup::VERSION, |
| 87 | "As part of the upgrade to version " . JetBackup::VERSION . ", all remote destinations have been removed. Please re-add your remote destinations to continue using them.", |
| 88 | Alert::LEVEL_WARNING |
| 89 | ); |
| 90 | |
| 91 | } catch (\Exception $e) { |
| 92 | Alert::add( |
| 93 | "JetBackup encountered an error during the update process", |
| 94 | "Error: " . $e->getMessage(), |
| 95 | Alert::LEVEL_WARNING |
| 96 | ); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |
| 102 | $config->setCurrentVersion(JetBackup::VERSION); |
| 103 | $config->save(); |
| 104 | } |
| 105 | } |
| 106 |