AllTraits.php
1 year ago
Asset_Builder.php
9 months ago
Bootstrap.php
2 weeks ago
Compatibility_Support.php
2 months ago
Elements_Manager.php
7 months ago
Helper.php
1 month ago
Migration.php
5 months ago
Plugin_Usage_Tracker.php
5 months ago
WPDeveloper_Core_Installer.php
5 months ago
WPDeveloper_Notice.php
2 months ago
WPDeveloper_Plugin_Installer.php
5 months ago
WPDeveloper_Setup_Wizard.php
2 months ago
index.php
3 years ago
Migration.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Essential_Addons_Elementor\Classes; |
| 4 | |
| 5 | if (!defined('ABSPATH')) { |
| 6 | exit; |
| 7 | } // Exit if accessed directly |
| 8 | |
| 9 | class Migration |
| 10 | { |
| 11 | use \Essential_Addons_Elementor\Traits\Core; |
| 12 | use \Essential_Addons_Elementor\Traits\Library; |
| 13 | |
| 14 | /** |
| 15 | * Plugin activation hook |
| 16 | * |
| 17 | * @since 3.0.0 |
| 18 | */ |
| 19 | public function plugin_activation_hook() |
| 20 | { |
| 21 | // remove old cache files |
| 22 | $this->empty_dir(EAEL_ASSET_PATH); |
| 23 | |
| 24 | //check setup wizard condition |
| 25 | $this->enable_setup_wizard(); |
| 26 | |
| 27 | // save default values |
| 28 | $this->set_default_values(); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Plugin deactivation hook |
| 34 | * |
| 35 | * @since 3.0.0 |
| 36 | */ |
| 37 | public function plugin_deactivation_hook() |
| 38 | { |
| 39 | $this->empty_dir(EAEL_ASSET_PATH); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Plugin upgrade hook |
| 44 | * |
| 45 | * @since 3.0.0 |
| 46 | */ |
| 47 | public function plugin_upgrade_hook( $upgrader_object, $options ) { |
| 48 | if ( isset( $options['action'], $options['type'] ) && $options['action'] === 'update' && $options['type'] === 'plugin' ) { |
| 49 | if ( ( isset( $options['plugins'] ) && |
| 50 | ( in_array( EAEL_PLUGIN_BASENAME, $options['plugins'] ) || |
| 51 | in_array( 'essential-addons-elementor/essential_adons_elementor.php', $options['plugins'] ) |
| 52 | ) |
| 53 | ) || ( isset( $options['plugin'] ) && |
| 54 | in_array( $options['plugin'], [ EAEL_PLUGIN_BASENAME, 'essential-addons-elementor/essential_adons_elementor.php' ] ) |
| 55 | ) |
| 56 | ) { |
| 57 | // remove old cache files |
| 58 | $this->empty_dir( EAEL_ASSET_PATH ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Plugin migrator |
| 65 | * |
| 66 | * @since 3.0.0 |
| 67 | */ |
| 68 | public function migrator() { |
| 69 | // set current version to db |
| 70 | if ( get_option( 'eael_version' ) != EAEL_PLUGIN_VERSION ) { |
| 71 | // update plugin version |
| 72 | update_option( 'eael_version', EAEL_PLUGIN_VERSION ); |
| 73 | } |
| 74 | |
| 75 | add_action( 'eael_after_clear_cache_files', [ $this, 'reduce_options_data' ] ); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | public function reduce_options_data() { |
| 80 | $status = get_transient( 'eael_reduce_op_table_data' ); |
| 81 | if ( $status ) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | global $wpdb; |
| 86 | $sql = "from {$wpdb->options} as options_tb |
| 87 | inner join (SELECT option_id FROM {$wpdb->options} |
| 88 | WHERE ((option_name like '%\_eael_elements' and LENGTH(option_name) = 23 ) |
| 89 | or (option_name like '%\_eael_custom_js' and LENGTH(option_name) = 24) |
| 90 | or (option_name like '%\_eael_updated_at' and LENGTH(option_name) = 25) |
| 91 | or (option_name = 'eael_reduce_op_table_data') |
| 92 | or (option_name = 'eael_remove_old_cache') |
| 93 | or (option_name = 'eael_editor_updated_at') |
| 94 | or (option_name = 'eael_gb_eb_popup_hide') |
| 95 | or (option_name like 'eael_login_error_%')) |
| 96 | ) AS options_tb2 |
| 97 | ON options_tb2.option_id = options_tb.option_id"; |
| 98 | $selection_sql = "select count(options_tb.option_id) as total " . $sql; |
| 99 | |
| 100 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 101 | $results = $wpdb->get_var( $selection_sql ); |
| 102 | if ( $results > 0 ) { |
| 103 | $deletiation_sql = "delete options_tb " . $sql; |
| 104 | |
| 105 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 106 | $wpdb->query( $deletiation_sql ); |
| 107 | } |
| 108 | |
| 109 | set_transient( 'eael_reduce_op_table_data', 1, DAY_IN_SECONDS ); |
| 110 | wp_clear_scheduled_hook( 'eael_remove_unused_options_data' ); |
| 111 | } |
| 112 | } |