* @copyright 2007-2022 Apollotheme * @license http://apollotheme.com - prestashop template provider */ namespace LeoElements\Core\Base; use LeoElements\Plugin; use LeoElements\Leo_Helper; if ( ! defined( '_PS_VERSION_' ) ) { exit; // Exit if accessed directly } abstract class DB_Upgrades_Manager extends Background_Task_Manager { protected $current_version = null; abstract public function get_new_version(); abstract public function get_version_option_name(); abstract public function get_upgrades_class(); abstract public function get_updater_label(); public function get_task_runner_class() { return 'LeoElements\Core\Upgrade\Updater'; } public function get_query_limit() { return 100; } public function get_current_version() { if ( null === $this->current_version ) { $this->current_version = Leo_Helper::get_option( $this->get_version_option_name() ); } return $this->current_version; } public function should_upgrade() { $current_version = $this->get_current_version(); // It's a new install. if ( ! $current_version ) { $this->update_db_version(); return false; } return version_compare( $this->get_new_version(), $current_version, '>' ); } public function on_runner_start() { parent::on_runner_start(); define( 'IS_LEOELEMENTS_UPGRADE', true ); } public function on_runner_complete( $did_tasks = false ) { $logger = Plugin::$instance->logger->get_logger(); $logger->info( 'Elementor data updater process has been completed.', [ 'meta' => [ 'plugin' => $this->get_plugin_label(), 'from' => $this->current_version, 'to' => $this->get_new_version(), ], ] ); Plugin::$instance->files_manager->clear_cache(); $this->update_db_version(); if ( $did_tasks ) { $this->add_flag( 'completed' ); } } public function admin_notice_start_upgrade() { $upgrade_link = $this->get_start_action_url(); $message = '
' . sprintf( Leo_Helper::__( '%s Your site database needs to be updated to the latest version.', 'elementor' ), $this->get_updater_label() ) . '
'; $message .= '' . sprintf( '%s', $upgrade_link, Leo_Helper::__( 'Update Now', 'elementor' ) ) . '
'; echo '' . sprintf( Leo_Helper::__( '%s Database update process is running in the background.', 'elementor' ), $this->get_updater_label() ) . '
'; $message .= '' . sprintf( 'Taking a while? Click here to run it now', $upgrade_link ) . '
'; echo '' . sprintf( Leo_Helper::__( '%s The database update process is now complete. Thank you for updating to the latest version!', 'elementor' ), $this->get_updater_label() ) . '
'; echo '