← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/modules/class-full-sync.php
+15
-5
12.8.3
→
16.3-a.7
View file →
| @@ -12,8 +12,12 @@ | ||
| 12 | 12 | use Automattic\Jetpack\Sync\Modules; |
| 13 | 13 | use Automattic\Jetpack\Sync\Queue; |
| 14 | 14 | use Automattic\Jetpack\Sync\Settings; |
| 15 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 16 | 20 | /** |
| 17 | 21 | * This class does a full resync of the database by |
| 18 | 22 | * enqueuing an outbound action for every single object |
| 19 | 23 | * that we care about. |
| @@ -79,11 +83,12 @@ | ||
| 79 | 83 | * |
| 80 | 84 | * @access public |
| 81 | 85 | * |
| 82 | 86 | * @param array $module_configs Full sync configuration for all sync modules. |
| 87 | + * @param mixed $context Context for the full sync. | |
| 83 | 88 | * @return bool Always returns true at success. |
| 84 | 89 | */ |
| 85 | - public function start( $module_configs = null ) { | |
| 90 | + public function start( $module_configs = null, $context = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 86 | 91 | $was_already_running = $this->is_started() && ! $this->is_finished(); |
| 87 | 92 | |
| 88 | 93 | // Remove all evidence of previous full sync items and status. |
| 89 | 94 | $this->reset_data(); |
| @@ -117,9 +122,9 @@ | ||
| 117 | 122 | |
| 118 | 123 | // Set default configuration, calculate totals, and save configuration if totals > 0. |
| 119 | 124 | foreach ( Modules::get_modules() as $module ) { |
| 120 | 125 | $module_name = $module->name(); |
| 121 | - $module_config = isset( $module_configs[ $module_name ] ) ? $module_configs[ $module_name ] : false; | |
| 126 | + $module_config = $module_configs[ $module_name ] ?? false; | |
| 122 | 127 | |
| 123 | 128 | if ( ! $module_config ) { |
| 124 | 129 | continue; |
| 125 | 130 | } |
| @@ -124,8 +129,9 @@ | ||
| 124 | 129 | continue; |
| 125 | 130 | } |
| 126 | 131 | |
| 127 | 132 | if ( 'users' === $module_name && 'initial' === $module_config ) { |
| 133 | + '@phan-var Users $module'; | |
| 128 | 134 | $module_config = $module->get_initial_sync_user_config(); |
| 129 | 135 | } |
| 130 | 136 | |
| 131 | 137 | $enqueue_status[ $module_name ] = false; |
| @@ -211,9 +217,9 @@ | ||
| 211 | 217 | Modules::get_modules(), |
| 212 | 218 | /** |
| 213 | 219 | * Select configured and not finished modules. |
| 214 | 220 | * |
| 215 | - * @var $module Module | |
| 221 | + * @param Module $module | |
| 216 | 222 | * @return bool |
| 217 | 223 | */ |
| 218 | 224 | function ( $module ) use ( $configs, $enqueue_status ) { |
| 219 | 225 | // Skip module if not configured for this sync or module is done. |
| @@ -333,8 +339,12 @@ | ||
| 333 | 339 | $table = $wpdb->comments; |
| 334 | 340 | $id = 'comment_ID'; |
| 335 | 341 | $where_sql = Settings::get_comments_filter_sql(); |
| 336 | 342 | break; |
| 343 | + default: | |
| 344 | + // This should never be reached due to the guard condition above, | |
| 345 | + // but Phan complains so let's make it happy. | |
| 346 | + return array(); | |
| 337 | 347 | } |
| 338 | 348 | |
| 339 | 349 | // TODO: Call $wpdb->prepare on the following query. |
| 340 | 350 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| @@ -356,13 +366,13 @@ | ||
| 356 | 366 | */ |
| 357 | 367 | private function get_content_range( $config ) { |
| 358 | 368 | $range = array(); |
| 359 | 369 | // Only when we are sending the whole range do we want to send also the range. |
| 360 | - if ( true === isset( $config['posts'] ) && $config['posts'] ) { | |
| 370 | + if ( ! empty( $config['posts'] ) ) { | |
| 361 | 371 | $range['posts'] = $this->get_range( 'posts' ); |
| 362 | 372 | } |
| 363 | 373 | |
| 364 | - if ( true === isset( $config['comments'] ) && $config['comments'] ) { | |
| 374 | + if ( ! empty( $config['comments'] ) ) { | |
| 365 | 375 | $range['comments'] = $this->get_range( 'comments' ); |
| 366 | 376 | } |
| 367 | 377 | return $range; |
| 368 | 378 | } |