| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Activator for the Robin image optimizer |
| 5 |
* |
| 6 |
* @author Webcraftic <wordpress.webraftic@gmail.com> |
| 7 |
* @copyright (c) 09.09.2017, Webcraftic |
| 8 |
* @see Factory458_Activator |
| 9 |
* @version 1.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
class WIO_Activation extends Wbcr_Factory458_Activator { |
| 18 |
|
| 19 |
/** |
| 20 |
* Runs activation actions. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* @throws \Exception |
| 24 |
*/ |
| 25 |
public function activate() { |
| 26 |
WRIO_Plugin::app()->logger->info( 'Parent plugin start installation!' ); |
| 27 |
|
| 28 |
WRIO_Plugin::app()->updatePopulateOption( 'image_optimization_server', 'server_1' ); |
| 29 |
WRIO_Plugin::app()->updatePopulateOption( 'backup_origin_images', 1 ); |
| 30 |
WRIO_Plugin::app()->updatePopulateOption( 'save_exif_data', 1 ); |
| 31 |
|
| 32 |
if ( function_exists( 'wrio_is_license_activate' ) && wrio_is_license_activate() ) { |
| 33 |
WRIO_Plugin::app()->logger->info( 'Premium plugin start installation!' ); |
| 34 |
require_once( WRIO_PLUGIN_DIR . '/libs/addons/robin-image-optimizer-premium.php' ); |
| 35 |
wrio_premium_activate(); |
| 36 |
WRIO_Plugin::app()->logger->info( 'Premium plugin installation complete!' ); |
| 37 |
} |
| 38 |
|
| 39 |
$db_version = RIO_Process_Queue::get_db_version(); |
| 40 |
$plugin_version_in_db = $this->get_plugin_version_in_db(); |
| 41 |
$current_plugin_version = $this->plugin->getPluginVersion(); |
| 42 |
|
| 43 |
$create_table_log_message = "Plugin installation: try create plugin tables.\r\n"; |
| 44 |
$create_table_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-DB Version: {$db_version}\r\n"; |
| 45 |
$create_table_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-Plugin Version in DB: {$plugin_version_in_db}\r\n"; |
| 46 |
$create_table_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-Current Plugin Version: {$current_plugin_version}"; |
| 47 |
|
| 48 |
WRIO_Plugin::app()->logger->info( $create_table_log_message ); |
| 49 |
|
| 50 |
RIO_Process_Queue::try_create_plugin_tables(); |
| 51 |
|
| 52 |
WBCR\Factory_Templates_110\Helpers::flushPageCache(); |
| 53 |
|
| 54 |
WRIO_Plugin::app()->logger->info( 'Parent plugin installation complete!' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get previous plugin version |
| 59 |
* |
| 60 |
* @author Alexander Kovalev <alex.kovalevv@gmail.com> |
| 61 |
* @since 1.3.8 |
| 62 |
* @return number |
| 63 |
*/ |
| 64 |
public function get_plugin_version_in_db() { |
| 65 |
if ( WRIO_Plugin::app()->isNetworkActive() ) { |
| 66 |
return get_site_option( WRIO_Plugin::app()->getOptionName( 'plugin_version' ), 0 ); |
| 67 |
} |
| 68 |
|
| 69 |
return get_option( WRIO_Plugin::app()->getOptionName( 'plugin_version' ), 0 ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Runs activation actions. |
| 74 |
* |
| 75 |
* @since 1.0.0 |
| 76 |
*/ |
| 77 |
public function deactivate() { |
| 78 |
WRIO_Plugin::app()->logger->info( 'Parent plugin start deactivation!' ); |
| 79 |
|
| 80 |
if ( class_exists( 'WRIO_Cron' ) ) { |
| 81 |
WRIO_Cron::stop(); |
| 82 |
} |
| 83 |
|
| 84 |
if ( function_exists( 'wrio_is_license_activate' ) && wrio_is_license_activate() ) { |
| 85 |
WRIO_Plugin::app()->logger->info( 'Premium plugin start deactivation!' ); |
| 86 |
require_once( WRIO_PLUGIN_DIR . '/libs/addons/robin-image-optimizer-premium.php' ); |
| 87 |
wrio_premium_deactivate(); |
| 88 |
WRIO_Plugin::app()->logger->info( 'Premium plugin deactivation complete!' ); |
| 89 |
} |
| 90 |
|
| 91 |
WRIO_Plugin::app()->logger->info( 'Parent plugin deactivation complete!' ); |
| 92 |
} |
| 93 |
} |
| 94 |
|