← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/modules/class-updates.php
+43
-23
12.4.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 { |
| @@ -76,8 +80,16 @@ | ||
| 76 | 80 | add_action( 'jetpack_update_themes_change', $callable ); |
| 77 | 81 | add_action( 'jetpack_update_core_change', $callable ); |
| 78 | 82 | |
| 79 | 83 | add_filter( |
| 84 | + 'jetpack_sync_before_enqueue_jetpack_update_themes_change', | |
| 85 | + array( | |
| 86 | + $this, | |
| 87 | + 'expand_themes', | |
| 88 | + ) | |
| 89 | + ); | |
| 90 | + | |
| 91 | + add_filter( | |
| 80 | 92 | 'jetpack_sync_before_enqueue_jetpack_update_plugins_change', |
| 81 | 93 | array( |
| 82 | 94 | $this, |
| 83 | 95 | 'filter_update_keys', |
| @@ -94,10 +106,8 @@ | ||
| 94 | 106 | 10, |
| 95 | 107 | 2 |
| 96 | 108 | ); |
| 97 | 109 | |
| 98 | - add_action( 'automatic_updates_complete', $callable ); | |
| 99 | - | |
| 100 | 110 | if ( is_multisite() ) { |
| 101 | 111 | add_filter( 'pre_update_site_option_wpmu_upgrade_site', array( $this, 'update_core_network_event' ), 10, 2 ); |
| 102 | 112 | add_action( 'jetpack_sync_core_update_network', $callable, 10, 3 ); |
| 103 | 113 | } |
| @@ -126,9 +136,8 @@ | ||
| 126 | 136 | * @access public |
| 127 | 137 | */ |
| 128 | 138 | public function init_before_send() { |
| 129 | 139 | add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) ); |
| 130 | - add_filter( 'jetpack_sync_before_send_jetpack_update_themes_change', array( $this, 'expand_themes' ) ); | |
| 131 | 140 | } |
| 132 | 141 | |
| 133 | 142 | /** |
| 134 | 143 | * Handle a core network update. |
| @@ -224,11 +233,12 @@ | ||
| 224 | 233 | $no_updated = array(); |
| 225 | 234 | switch ( $transient ) { |
| 226 | 235 | case 'update_plugins': |
| 227 | 236 | if ( ! empty( $update->response ) && is_array( $update->response ) ) { |
| 228 | - foreach ( $update->response as $plugin_slug => $response ) { | |
| 229 | - if ( ! empty( $plugin_slug ) && isset( $response->new_version ) ) { | |
| 230 | - $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'] ); | |
| 231 | 241 | } |
| 232 | 242 | } |
| 233 | 243 | } |
| 234 | 244 | if ( ! empty( $update->no_update ) ) { |
| @@ -241,11 +251,12 @@ | ||
| 241 | 251 | |
| 242 | 252 | break; |
| 243 | 253 | case 'update_themes': |
| 244 | 254 | if ( ! empty( $update->response ) && is_array( $update->response ) ) { |
| 245 | - foreach ( $update->response as $theme_slug => $response ) { | |
| 246 | - if ( ! empty( $theme_slug ) && isset( $response['new_version'] ) ) { | |
| 247 | - $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'] ); | |
| 248 | 259 | } |
| 249 | 260 | } |
| 250 | 261 | } |
| 251 | 262 | |
| @@ -255,14 +266,14 @@ | ||
| 255 | 266 | |
| 256 | 267 | break; |
| 257 | 268 | case 'update_core': |
| 258 | 269 | if ( ! empty( $update->updates ) && is_array( $update->updates ) ) { |
| 259 | - foreach ( $update->updates as $response ) { | |
| 260 | - if ( ! empty( $response->response ) && 'latest' === $response->response ) { | |
| 270 | + foreach ( $update->updates as $core_update ) { | |
| 271 | + if ( ! empty( $core_update->response ) && 'latest' === $core_update->response ) { | |
| 261 | 272 | continue; |
| 262 | 273 | } |
| 263 | - if ( ! empty( $response->response ) && isset( $response->packages->full ) ) { | |
| 264 | - $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 ); | |
| 265 | 276 | } |
| 266 | 277 | } |
| 267 | 278 | } |
| 268 | 279 | |
| @@ -383,19 +394,25 @@ | ||
| 383 | 394 | * |
| 384 | 395 | * @access public |
| 385 | 396 | * |
| 386 | 397 | * @param array $config Full sync configuration for this sync module. |
| 398 | + * @param array $status This module Full Sync status. | |
| 387 | 399 | * @param int $send_until The timestamp until the current request can send. |
| 388 | - * @param array $state This module Full Sync status. | |
| 400 | + * @param int $started The timestamp when the full sync started. | |
| 389 | 401 | * |
| 390 | 402 | * @return array This module Full Sync status. |
| 391 | 403 | */ |
| 392 | - 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 | |
| 393 | 405 | // we call this instead of do_action when sending immediately. |
| 394 | - $this->send_action( 'jetpack_full_sync_updates', array( true ) ); | |
| 406 | + $result = $this->send_action( 'jetpack_full_sync_updates', array( true ) ); | |
| 395 | 407 | |
| 396 | - // The number of actions enqueued, and next module state (true == done). | |
| 397 | - 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; | |
| 398 | 415 | } |
| 399 | 416 | |
| 400 | 417 | /** |
| 401 | 418 | * Retrieve an estimated number of actions that will be enqueued. |
| @@ -402,9 +419,9 @@ | ||
| 402 | 419 | * |
| 403 | 420 | * @access public |
| 404 | 421 | * |
| 405 | 422 | * @param array $config Full sync configuration for this sync module. |
| 406 | - * @return array Number of items yet to be enqueued. | |
| 423 | + * @return int Number of items yet to be enqueued. | |
| 407 | 424 | */ |
| 408 | 425 | public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 409 | 426 | return 1; |
| 410 | 427 | } |
| @@ -496,14 +513,18 @@ | ||
| 496 | 513 | return $args; |
| 497 | 514 | } |
| 498 | 515 | if ( ! is_array( $args[0]->response ) ) { |
| 499 | 516 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
| 500 | - 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 ); | |
| 501 | 518 | return $args; |
| 502 | 519 | } |
| 503 | 520 | foreach ( $args[0]->response as $stylesheet => &$theme_data ) { |
| 504 | - $theme = wp_get_theme( $stylesheet ); | |
| 505 | - $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 | + } | |
| 506 | 527 | } |
| 507 | 528 | return $args; |
| 508 | 529 | } |
| 509 | 530 | |
| @@ -578,6 +599,5 @@ | ||
| 578 | 599 | } |
| 579 | 600 | |
| 580 | 601 | return false; |
| 581 | 602 | } |
| 582 | - | |
| 583 | 603 | } |