← All changes
|
json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
+15
-6
13.3.3
→
16.3-a.5
View file →
| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | 3 | use Automattic\Jetpack\Constants; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit( 0 ); | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | new Jetpack_JSON_API_Plugins_Modify_Endpoint( |
| 6 | 10 | array( |
| 7 | 11 | 'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates', |
| 8 | 12 | 'min_version' => '1', |
| @@ -112,8 +116,10 @@ | ||
| 112 | 116 | * Plugins modify endpoint class. |
| 113 | 117 | * |
| 114 | 118 | * POST /sites/%s/plugins/%s |
| 115 | 119 | * POST /sites/%s/plugins |
| 120 | + * | |
| 121 | + * @phan-constructor-used-for-side-effects | |
| 116 | 122 | */ |
| 117 | 123 | class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { |
| 118 | 124 | |
| 119 | 125 | /** |
| @@ -382,11 +388,14 @@ | ||
| 382 | 388 | * @return bool|WP_Error |
| 383 | 389 | */ |
| 384 | 390 | protected function update() { |
| 385 | 391 | $query_args = $this->query_args(); |
| 392 | + | |
| 393 | + $is_automatic_update = false; | |
| 386 | 394 | if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] || $this->scheduled_update ) { |
| 387 | - Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); | |
| 395 | + $is_automatic_update = true; | |
| 388 | 396 | } |
| 397 | + | |
| 389 | 398 | if ( $this->scheduled_update ) { |
| 390 | 399 | Constants::set_constant( 'SCHEDULED_AUTOUPDATE', true ); |
| 391 | 400 | } |
| 392 | 401 | wp_clean_plugins_cache( false ); |
| @@ -415,9 +424,9 @@ | ||
| 415 | 424 | $lock_release_timeout = $this->scheduled_update ? 15 * MINUTE_IN_SECONDS : null; |
| 416 | 425 | |
| 417 | 426 | // Early return if unable to obtain auto_updater lock. |
| 418 | 427 | // @see https://github.com/WordPress/wordpress-develop/blob/66469efa99e7978c8824e287834135aa9842e84f/src/wp-admin/includes/class-wp-automatic-updater.php#L453. |
| 419 | - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) && ! WP_Upgrader::create_lock( 'auto_updater', $lock_release_timeout ) ) { | |
| 428 | + if ( $is_automatic_update && ! WP_Upgrader::create_lock( 'auto_updater', $lock_release_timeout ) ) { | |
| 420 | 429 | return new WP_Error( 'update_fail', __( 'Updates are already in progress.', 'jetpack' ), 400 ); |
| 421 | 430 | } |
| 422 | 431 | |
| 423 | 432 | $result = false; |
| @@ -429,9 +438,9 @@ | ||
| 429 | 438 | continue; |
| 430 | 439 | } |
| 431 | 440 | |
| 432 | 441 | // Rely on WP_Automatic_Updater class to check if a plugin item should be updated if it is a Jetpack autoupdate request. |
| 433 | - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) && ! ( new WP_Automatic_Updater() )->should_update( 'plugin', $update_plugins->response[ $plugin ], WP_PLUGIN_DIR ) ) { | |
| 442 | + if ( $is_automatic_update && ! ( new WP_Automatic_Updater() )->should_update( 'plugin', $update_plugins->response[ $plugin ], WP_PLUGIN_DIR ) ) { | |
| 434 | 443 | continue; |
| 435 | 444 | } |
| 436 | 445 | |
| 437 | 446 | // Establish per plugin lock. |
| @@ -460,10 +469,10 @@ | ||
| 460 | 469 | $upgrader->init(); |
| 461 | 470 | // This avoids the plugin to be deactivated. |
| 462 | 471 | // Using bulk upgrade puts the site into maintenance mode during the upgrades |
| 463 | 472 | $result = $upgrader->bulk_upgrade( array( $plugin ) ); |
| 464 | - $errors = $upgrader->skin->get_errors(); | |
| 465 | - $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages(); | |
| 473 | + $errors = $skin->get_errors(); | |
| 474 | + $this->log[ $plugin ] = $skin->get_upgrade_messages(); | |
| 466 | 475 | |
| 467 | 476 | // release individual plugin lock. |
| 468 | 477 | WP_Upgrader::release_lock( 'jetpack_' . $plugin_slug ); |
| 469 | 478 | |
| @@ -472,9 +481,9 @@ | ||
| 472 | 481 | } |
| 473 | 482 | } |
| 474 | 483 | |
| 475 | 484 | // release auto_udpate lock. |
| 476 | - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) ) { | |
| 485 | + if ( $is_automatic_update ) { | |
| 477 | 486 | WP_Upgrader::release_lock( 'auto_updater' ); |
| 478 | 487 | } |
| 479 | 488 | |
| 480 | 489 | if ( ! $this->bulk && ! $result && $update_attempted ) { |