| 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 |
/** |
| 13 |
* @deprecated 3.17.0 |
| 14 |
*/ |
| 15 |
const INSTALLS_HISTORY_META = 'elementor_install_history'; |
| 16 |
|
| 17 |
public static function get_install_history_meta() { |
| 18 |
return 'elementor_install_history'; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* TODO: Remove in future releases |
| 23 |
* |
| 24 |
* @deprecated 3.1.0 |
| 25 |
*/ |
| 26 |
public function should_upgrade() { |
| 27 |
if ( ( 'elementor' === $this->get_plugin_name() ) && version_compare( get_option( $this->get_version_option_name() ), '2.4.2', '<' ) ) { |
| 28 |
delete_option( 'elementor_log' ); |
| 29 |
} |
| 30 |
|
| 31 |
return parent::should_upgrade(); |
| 32 |
} |
| 33 |
|
| 34 |
public function get_name() { |
| 35 |
return 'upgrade'; |
| 36 |
} |
| 37 |
|
| 38 |
public function get_action() { |
| 39 |
return 'elementor_updater'; |
| 40 |
} |
| 41 |
|
| 42 |
public function get_plugin_name() { |
| 43 |
return 'elementor'; |
| 44 |
} |
| 45 |
|
| 46 |
public function get_plugin_label() { |
| 47 |
return esc_html__( 'Elementor', 'elementor' ); |
| 48 |
} |
| 49 |
|
| 50 |
public function get_updater_label() { |
| 51 |
return esc_html__( 'Elementor Data Updater', 'elementor' ); |
| 52 |
} |
| 53 |
|
| 54 |
public function get_new_version() { |
| 55 |
return ELEMENTOR_VERSION; |
| 56 |
} |
| 57 |
|
| 58 |
public function get_version_option_name() { |
| 59 |
return 'elementor_version'; |
| 60 |
} |
| 61 |
|
| 62 |
public function get_upgrades_class() { |
| 63 |
return 'Elementor\Core\Upgrade\Upgrades'; |
| 64 |
} |
| 65 |
|
| 66 |
public static function get_installs_history() { |
| 67 |
return get_option( static::get_install_history_meta(), [] ); |
| 68 |
} |
| 69 |
|
| 70 |
public static function install_compare( $version, $operator ) { |
| 71 |
$installs_history = self::get_installs_history(); |
| 72 |
|
| 73 |
return version_compare( |
| 74 |
key( $installs_history ), |
| 75 |
$version ? $version : '0.0.0', // when no version assigned |
| 76 |
$operator |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
protected function update_db_version() { |
| 81 |
parent::update_db_version(); |
| 82 |
|
| 83 |
$installs_history = self::get_installs_history(); |
| 84 |
|
| 85 |
$time = time(); |
| 86 |
|
| 87 |
$installs_history[ $this->get_new_version() ] = $time; |
| 88 |
|
| 89 |
$old_version = $this->get_current_version(); |
| 90 |
|
| 91 |
// If there was an old version of Elementor, and there's no record for that install yet |
| 92 |
if ( $old_version && empty( $installs_history[ $old_version ] ) ) { |
| 93 |
$installs_history[ $old_version ] = $installs_history[ $this->get_new_version() ] - 1; |
| 94 |
} |
| 95 |
|
| 96 |
uksort( $installs_history, 'version_compare' ); |
| 97 |
|
| 98 |
update_option( static::get_install_history_meta(), $installs_history ); |
| 99 |
} |
| 100 |
|
| 101 |
public static function is_new_installation(): bool { |
| 102 |
$installs_history = self::get_installs_history(); |
| 103 |
|
| 104 |
return empty( $installs_history ) || static::install_compare( ELEMENTOR_VERSION, '>=' ); |
| 105 |
} |
| 106 |
|
| 107 |
public static function had_install_prior_to( string $version ): bool { |
| 108 |
if ( ! $version ) { |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
$installs_history = self::get_installs_history(); |
| 113 |
|
| 114 |
if ( empty( $installs_history ) ) { |
| 115 |
return false; |
| 116 |
} |
| 117 |
|
| 118 |
uksort( $installs_history, 'version_compare' ); |
| 119 |
|
| 120 |
$first_version = array_key_first( $installs_history ); |
| 121 |
|
| 122 |
if ( ! $first_version ) { |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
return version_compare( $first_version, $version, '<' ); |
| 127 |
} |
| 128 |
} |
| 129 |
|