← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/modules/class-updates.php
+35
-21
13.7.2
→
16.3-a.5
View file →
| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | namespace Automattic\Jetpack\Sync\Modules; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Constants as Jetpack_Constants; |
| 11 | 11 | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 12 | 16 | /** |
| 13 | 17 | * Class to handle sync for updates. |
| 14 | 18 | */ |
| 15 | 19 | class Updates extends Module { |
| @@ -102,10 +106,8 @@ | ||
| 102 | 106 | 10, |
| 103 | 107 | 2 |
| 104 | 108 | ); |
| 105 | 109 | |
| 106 | - add_action( 'automatic_updates_complete', $callable ); | |
| 107 | - | |
| 108 | 110 | if ( is_multisite() ) { |
| 109 | 111 | add_filter( 'pre_update_site_option_wpmu_upgrade_site', array( $this, 'update_core_network_event' ), 10, 2 ); |
| 110 | 112 | add_action( 'jetpack_sync_core_update_network', $callable, 10, 3 ); |
| 111 | 113 | } |
| @@ -231,11 +233,12 @@ | ||
| 231 | 233 | $no_updated = array(); |
| 232 | 234 | switch ( $transient ) { |
| 233 | 235 | case 'update_plugins': |
| 234 | 236 | if ( ! empty( $update->response ) && is_array( $update->response ) ) { |
| 235 | - foreach ( $update->response as $plugin_slug => $response ) { | |
| 236 | - if ( ! empty( $plugin_slug ) && isset( $response->new_version ) ) { | |
| 237 | - $updates[] = array( $plugin_slug => $response->new_version ); | |
| 237 | + foreach ( $update->response as $plugin_slug => $plugin_data ) { | |
| 238 | + $plugin_data = (array) $plugin_data; | |
| 239 | + if ( ! empty( $plugin_slug ) && isset( $plugin_data['new_version'] ) ) { | |
| 240 | + $updates[] = array( $plugin_slug => $plugin_data['new_version'] ); | |
| 238 | 241 | } |
| 239 | 242 | } |
| 240 | 243 | } |
| 241 | 244 | if ( ! empty( $update->no_update ) ) { |
| @@ -248,11 +251,12 @@ | ||
| 248 | 251 | |
| 249 | 252 | break; |
| 250 | 253 | case 'update_themes': |
| 251 | 254 | if ( ! empty( $update->response ) && is_array( $update->response ) ) { |
| 252 | - foreach ( $update->response as $theme_slug => $response ) { | |
| 253 | - if ( ! empty( $theme_slug ) && isset( $response['new_version'] ) ) { | |
| 254 | - $updates[] = array( $theme_slug => $response['new_version'] ); | |
| 255 | + foreach ( $update->response as $theme_slug => $theme_data ) { | |
| 256 | + $theme_data = (array) $theme_data; | |
| 257 | + if ( ! empty( $theme_slug ) && isset( $theme_data['new_version'] ) ) { | |
| 258 | + $updates[] = array( $theme_slug => $theme_data['new_version'] ); | |
| 255 | 259 | } |
| 256 | 260 | } |
| 257 | 261 | } |
| 258 | 262 | |
| @@ -262,14 +266,14 @@ | ||
| 262 | 266 | |
| 263 | 267 | break; |
| 264 | 268 | case 'update_core': |
| 265 | 269 | if ( ! empty( $update->updates ) && is_array( $update->updates ) ) { |
| 266 | - foreach ( $update->updates as $response ) { | |
| 267 | - if ( ! empty( $response->response ) && 'latest' === $response->response ) { | |
| 270 | + foreach ( $update->updates as $core_update ) { | |
| 271 | + if ( ! empty( $core_update->response ) && 'latest' === $core_update->response ) { | |
| 268 | 272 | continue; |
| 269 | 273 | } |
| 270 | - if ( ! empty( $response->response ) && isset( $response->packages->full ) ) { | |
| 271 | - $updates[] = array( $response->response => $response->packages->full ); | |
| 274 | + if ( ! empty( $core_update->response ) && isset( $core_update->packages->full ) ) { | |
| 275 | + $updates[] = array( $core_update->response => $core_update->packages->full ); | |
| 272 | 276 | } |
| 273 | 277 | } |
| 274 | 278 | } |
| 275 | 279 | |
| @@ -390,19 +394,25 @@ | ||
| 390 | 394 | * |
| 391 | 395 | * @access public |
| 392 | 396 | * |
| 393 | 397 | * @param array $config Full sync configuration for this sync module. |
| 398 | + * @param array $status This module Full Sync status. | |
| 394 | 399 | * @param int $send_until The timestamp until the current request can send. |
| 395 | - * @param array $state This module Full Sync status. | |
| 400 | + * @param int $started The timestamp when the full sync started. | |
| 396 | 401 | * |
| 397 | 402 | * @return array This module Full Sync status. |
| 398 | 403 | */ |
| 399 | - public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 404 | + public function send_full_sync_actions( $config, $status, $send_until, $started ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 400 | 405 | // we call this instead of do_action when sending immediately. |
| 401 | - $this->send_action( 'jetpack_full_sync_updates', array( true ) ); | |
| 406 | + $result = $this->send_action( 'jetpack_full_sync_updates', array( true ) ); | |
| 402 | 407 | |
| 403 | - // The number of actions enqueued, and next module state (true == done). | |
| 404 | - return array( 'finished' => true ); | |
| 408 | + if ( is_wp_error( $result ) ) { | |
| 409 | + $status['error'] = true; | |
| 410 | + return $status; | |
| 411 | + } | |
| 412 | + $status['finished'] = true; | |
| 413 | + $status['sent'] = $status['total']; | |
| 414 | + return $status; | |
| 405 | 415 | } |
| 406 | 416 | |
| 407 | 417 | /** |
| 408 | 418 | * Retrieve an estimated number of actions that will be enqueued. |
| @@ -409,9 +419,9 @@ | ||
| 409 | 419 | * |
| 410 | 420 | * @access public |
| 411 | 421 | * |
| 412 | 422 | * @param array $config Full sync configuration for this sync module. |
| 413 | - * @return array Number of items yet to be enqueued. | |
| 423 | + * @return int Number of items yet to be enqueued. | |
| 414 | 424 | */ |
| 415 | 425 | public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 416 | 426 | return 1; |
| 417 | 427 | } |
| @@ -503,14 +513,18 @@ | ||
| 503 | 513 | return $args; |
| 504 | 514 | } |
| 505 | 515 | if ( ! is_array( $args[0]->response ) ) { |
| 506 | 516 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
| 507 | - trigger_error( 'Warning: Not an Array as expected but -> ' . wp_json_encode( $args[0]->response ) . ' instead', E_USER_WARNING ); | |
| 517 | + trigger_error( 'Warning: Not an Array as expected but -> ' . wp_json_encode( $args[0]->response, JSON_UNESCAPED_SLASHES ) . ' instead', E_USER_WARNING ); | |
| 508 | 518 | return $args; |
| 509 | 519 | } |
| 510 | 520 | foreach ( $args[0]->response as $stylesheet => &$theme_data ) { |
| 511 | - $theme = wp_get_theme( $stylesheet ); | |
| 512 | - $theme_data['name'] = $theme->name; | |
| 521 | + $theme_data = (array) $theme_data; | |
| 522 | + // Make sure the theme data array is not empty and has data that would indicate it is in the correct format. | |
| 523 | + if ( isset( $theme_data['theme'] ) ) { | |
| 524 | + $theme = wp_get_theme( $stylesheet ); | |
| 525 | + $theme_data['name'] = $theme->name; | |
| 526 | + } | |
| 513 | 527 | } |
| 514 | 528 | return $args; |
| 515 | 529 | } |
| 516 | 530 | |