| 1 |
<?php |
| 2 |
namespace Elementor\Core\Upgrade; |
| 3 |
|
| 4 |
use Elementor\Core\Base\DB_Upgrades_Manager; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly |
| 8 |
} |
| 9 |
|
| 10 |
class Manager extends DB_Upgrades_Manager { |
| 11 |
|
| 12 |
const INSTALLS_HISTORY_META = 'elementor_install_history'; |
| 13 |
|
| 14 |
// todo: remove in future releases |
| 15 |
public function should_upgrade() { |
| 16 |
if ( ( 'elementor' === $this->get_plugin_name() ) && version_compare( get_option( $this->get_version_option_name() ), '2.4.2', '<' ) ) { |
| 17 |
delete_option( 'elementor_log' ); |
| 18 |
} |
| 19 |
|
| 20 |
return parent::should_upgrade(); |
| 21 |
} |
| 22 |
|
| 23 |
public function get_name() { |
| 24 |
return 'upgrade'; |
| 25 |
} |
| 26 |
|
| 27 |
public function get_action() { |
| 28 |
return 'elementor_updater'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_plugin_name() { |
| 32 |
return 'elementor'; |
| 33 |
} |
| 34 |
|
| 35 |
public function get_plugin_label() { |
| 36 |
return __( 'Elementor', 'elementor' ); |
| 37 |
} |
| 38 |
|
| 39 |
public function get_updater_label() { |
| 40 |
return __( 'Elementor Data Updater', 'elementor' ); |
| 41 |
} |
| 42 |
|
| 43 |
public function get_new_version() { |
| 44 |
return ELEMENTOR_VERSION; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_version_option_name() { |
| 48 |
return 'elementor_version'; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_upgrades_class() { |
| 52 |
return 'Elementor\Core\Upgrade\Upgrades'; |
| 53 |
} |
| 54 |
|
| 55 |
public static function get_installs_history() { |
| 56 |
return get_option( self::INSTALLS_HISTORY_META, [] ); |
| 57 |
} |
| 58 |
|
| 59 |
public static function install_compare( $version, $operator ) { |
| 60 |
$installs_history = self::get_installs_history(); |
| 61 |
|
| 62 |
return version_compare( key( $installs_history ), $version, $operator ); |
| 63 |
} |
| 64 |
|
| 65 |
protected function update_db_version() { |
| 66 |
parent::update_db_version(); |
| 67 |
|
| 68 |
$installs_history = self::get_installs_history(); |
| 69 |
|
| 70 |
$time = time(); |
| 71 |
|
| 72 |
$installs_history[ ELEMENTOR_VERSION ] = $time; |
| 73 |
|
| 74 |
$old_version = $this->get_current_version(); |
| 75 |
|
| 76 |
// If there was an old version of Elementor, and there's no record for that install yet |
| 77 |
if ( $old_version && empty( $installs_history[ $old_version ] ) ) { |
| 78 |
$installs_history[ $old_version ] = $installs_history[ ELEMENTOR_VERSION ] - 1; |
| 79 |
} |
| 80 |
|
| 81 |
uksort( $installs_history, 'version_compare' ); |
| 82 |
|
| 83 |
update_option( self::INSTALLS_HISTORY_META, $installs_history ); |
| 84 |
} |
| 85 |
} |
| 86 |
|