| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | use Elementor\Core\Admin\Admin_Notices; |
| 6 | 6 | use Elementor\Plugin; |
| 7 | 7 | |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | - exit; // Exit if accessed directly. | |
| 9 | + exit; // Exit if accessed directly | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | abstract class DB_Upgrades_Manager extends Background_Task_Manager { |
| 13 | 13 | protected $current_version = null; |
| @@ -52,11 +52,9 @@ | ||
| 52 | 52 | |
| 53 | 53 | public function on_runner_start() { |
| 54 | 54 | parent::on_runner_start(); |
| 55 | 55 | |
| 56 | - if ( ! defined( 'IS_ELEMENTOR_UPGRADE' ) ) { | |
| 57 | - define( 'IS_ELEMENTOR_UPGRADE', true ); | |
| 58 | - } | |
| 56 | + define( 'IS_ELEMENTOR_UPGRADE', true ); | |
| 59 | 57 | } |
| 60 | 58 | |
| 61 | 59 | public function on_runner_complete( $did_tasks = false ) { |
| 62 | 60 | $logger = Plugin::$instance->logger->get_logger(); |
| @@ -68,9 +66,9 @@ | ||
| 68 | 66 | 'to' => $this->get_new_version(), |
| 69 | 67 | ], |
| 70 | 68 | ] ); |
| 71 | 69 | |
| 72 | - $this->clear_cache(); | |
| 70 | + Plugin::$instance->files_manager->clear_cache(); | |
| 73 | 71 | |
| 74 | 72 | $this->update_db_version(); |
| 75 | 73 | |
| 76 | 74 | if ( $did_tasks ) { |
| @@ -77,12 +75,8 @@ | ||
| 77 | 75 | $this->add_flag( 'completed' ); |
| 78 | 76 | } |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | - protected function clear_cache() { | |
| 82 | - Plugin::$instance->files_manager->clear_cache(); | |
| 83 | - } | |
| 84 | - | |
| 85 | 79 | public function admin_notice_start_upgrade() { |
| 86 | 80 | /** |
| 87 | 81 | * @var Admin_Notices $admin_notices |
| 88 | 82 | */ |
| @@ -89,13 +83,13 @@ | ||
| 89 | 83 | $admin_notices = Plugin::$instance->admin->get_component( 'admin-notices' ); |
| 90 | 84 | |
| 91 | 85 | $options = [ |
| 92 | 86 | 'title' => $this->get_updater_label(), |
| 93 | - 'description' => esc_html__( 'Your site database needs to be updated to the latest version.', 'elementor' ), | |
| 87 | + 'description' => __( 'Your site database needs to be updated to the latest version.', 'elementor' ), | |
| 94 | 88 | 'type' => 'error', |
| 95 | 89 | 'icon' => false, |
| 96 | 90 | 'button' => [ |
| 97 | - 'text' => esc_html__( 'Update Now', 'elementor' ), | |
| 91 | + 'text' => __( 'Update Now', 'elementor' ), | |
| 98 | 92 | 'url' => $this->get_start_action_url(), |
| 99 | 93 | 'class' => 'e-button e-button--cta', |
| 100 | 94 | ], |
| 101 | 95 | ]; |
| @@ -110,13 +104,13 @@ | ||
| 110 | 104 | $admin_notices = Plugin::$instance->admin->get_component( 'admin-notices' ); |
| 111 | 105 | |
| 112 | 106 | $options = [ |
| 113 | 107 | 'title' => $this->get_updater_label(), |
| 114 | - 'description' => esc_html__( 'Database update process is running in the background. Taking a while?', 'elementor' ), | |
| 108 | + 'description' => __( 'Database update process is running in the background. Taking a while?', 'elementor' ), | |
| 115 | 109 | 'type' => 'warning', |
| 116 | 110 | 'icon' => false, |
| 117 | 111 | 'button' => [ |
| 118 | - 'text' => esc_html__( 'Click here to run it now', 'elementor' ), | |
| 112 | + 'text' => __( 'Click here to run it now', 'elementor' ), | |
| 119 | 113 | 'url' => $this->get_continue_action_url(), |
| 120 | 114 | 'class' => 'e-button e-button--primary', |
| 121 | 115 | ], |
| 122 | 116 | ]; |
| @@ -126,9 +120,9 @@ | ||
| 126 | 120 | |
| 127 | 121 | public function admin_notice_upgrade_is_completed() { |
| 128 | 122 | $this->delete_flag( 'completed' ); |
| 129 | 123 | |
| 130 | - $message = esc_html__( 'The database update process is now complete. Thank you for updating to the latest version!', 'elementor' ); | |
| 124 | + $message = __( 'The database update process is now complete. Thank you for updating to the latest version!', 'elementor' ); | |
| 131 | 125 | |
| 132 | 126 | /** |
| 133 | 127 | * @var Admin_Notices $admin_notices |
| 134 | 128 | */ |
| @@ -148,12 +142,9 @@ | ||
| 148 | 142 | */ |
| 149 | 143 | protected function start_run() { |
| 150 | 144 | $updater = $this->get_task_runner(); |
| 151 | 145 | |
| 152 | - // Skip if process is actively running (has lock) or queue already has items. | |
| 153 | - // Stuck queues (items exist but no lock) are handled by the shutdown fallback | |
| 154 | - // registered in the constructor, so we don't need to re-push callbacks here. | |
| 155 | - if ( $updater->is_process_locked() || $updater->is_running() ) { | |
| 146 | + if ( $updater->is_running() ) { | |
| 156 | 147 | return; |
| 157 | 148 | } |
| 158 | 149 | |
| 159 | 150 | $upgrade_callbacks = $this->get_upgrade_callbacks(); |
| @@ -162,10 +153,8 @@ | ||
| 162 | 153 | $this->on_runner_complete(); |
| 163 | 154 | return; |
| 164 | 155 | } |
| 165 | 156 | |
| 166 | - $this->clear_cache(); | |
| 167 | - | |
| 168 | 157 | foreach ( $upgrade_callbacks as $callback ) { |
| 169 | 158 | $updater->push_to_queue( [ |
| 170 | 159 | 'callback' => $callback, |
| 171 | 160 | ] ); |
| @@ -194,14 +183,8 @@ | ||
| 194 | 183 | $callbacks = []; |
| 195 | 184 | |
| 196 | 185 | foreach ( $upgrades_reflection->getMethods() as $method ) { |
| 197 | 186 | $method_name = $method->getName(); |
| 198 | - | |
| 199 | - if ( '_on_each_version' === $method_name ) { | |
| 200 | - $callbacks[] = [ $upgrades_class, $method_name ]; | |
| 201 | - continue; | |
| 202 | - } | |
| 203 | - | |
| 204 | 187 | if ( false === strpos( $method_name, $prefix ) ) { |
| 205 | 188 | continue; |
| 206 | 189 | } |
| 207 | 190 | |
| @@ -227,17 +210,8 @@ | ||
| 227 | 210 | if ( is_admin() && current_user_can( 'update_plugins' ) && $this->get_flag( 'completed' ) ) { |
| 228 | 211 | add_action( 'admin_notices', [ $this, 'admin_notice_upgrade_is_completed' ] ); |
| 229 | 212 | } |
| 230 | 213 | |
| 231 | - // Don't run upgrade logic during background process AJAX requests. | |
| 232 | - // The AJAX handler (maybe_handle) will process the queue. | |
| 233 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 234 | - $ajax_action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : ''; | |
| 235 | - | |
| 236 | - if ( wp_doing_ajax() && $ajax_action && false !== strpos( $ajax_action, 'updater' ) ) { | |
| 237 | - return; | |
| 238 | - } | |
| 239 | - | |
| 240 | 214 | if ( ! $this->should_upgrade() ) { |
| 241 | 215 | return; |
| 242 | 216 | } |
| 243 | 217 | |
| @@ -243,15 +217,8 @@ | ||
| 243 | 217 | |
| 244 | 218 | $updater = $this->get_task_runner(); |
| 245 | 219 | |
| 246 | 220 | $this->start_run(); |
| 247 | - | |
| 248 | - // If queue has items but process is not locked, it's stuck - try to process on shutdown. | |
| 249 | - if ( $updater->is_running() && ! $updater->is_process_locked() ) { | |
| 250 | - if ( is_admin() && ! wp_doing_ajax() && ! wp_doing_cron() ) { | |
| 251 | - add_action( 'shutdown', [ $updater, 'maybe_handle_on_shutdown' ], 0 ); | |
| 252 | - } | |
| 253 | - } | |
| 254 | 221 | |
| 255 | 222 | if ( $updater->is_running() && current_user_can( 'update_plugins' ) ) { |
| 256 | 223 | add_action( 'admin_notices', [ $this, 'admin_notice_upgrade_is_running' ] ); |
| 257 | 224 | } |