Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full sync: Send context for initial full sync action #40930

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Full Sync: Added context
7 changes: 4 additions & 3 deletions projects/packages/sync/src/class-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public static function do_initial_sync() {
'network_options' => true,
);

self::do_full_sync( $initial_sync_config );
self::do_full_sync( $initial_sync_config, 'initial_sync' );
}

/**
Expand All @@ -633,9 +633,10 @@ public static function do_only_first_initial_sync() {
* @static
*
* @param array $modules The sync modules should be included in this full sync. All will be included if null.
* @param mixed $context The context where the full sync was initiated from.
* @return bool True if full sync was successfully started.
*/
public static function do_full_sync( $modules = null ) {
public static function do_full_sync( $modules = null, $context = null ) {
if ( ! self::sync_allowed() ) {
return false;
}
Expand All @@ -649,7 +650,7 @@ public static function do_full_sync( $modules = null ) {

self::initialize_listener();

$full_sync_module->start( $modules );
$full_sync_module->start( $modules, $context );

return true;
}
Expand Down
9 changes: 8 additions & 1 deletion projects/packages/sync/src/class-rest-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static function initialize_rest_api() {
'type' => 'array',
'required' => false,
),
'context' => array(
'description' => __( 'Context for the Full Sync', 'jetpack-sync' ),
'type' => 'string',
'required' => false,
),
),
)
);
Expand Down Expand Up @@ -363,9 +368,11 @@ public static function full_sync_start( $request ) {
$modules = null;
}

$context = $request->get_param( 'context' );

return rest_ensure_response(
array(
'scheduled' => Actions::do_full_sync( $modules ),
'scheduled' => Actions::do_full_sync( $modules, $context ),
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public function init_full_sync_listeners( $callable ) { // phpcs:ignore Variable
* @access public
*
* @param array $full_sync_config Full sync configuration.
* @param mixed $context The context where the full sync was initiated from.
*
* @return bool Always returns true at success.
*/
public function start( $full_sync_config = null ) {
public function start( $full_sync_config = null, $context = null ) {
// There was a full sync in progress.
if ( $this->is_started() && ! $this->is_finished() ) {
/**
Expand Down Expand Up @@ -114,15 +115,15 @@ public function start( $full_sync_config = null ) {
*
* @param array $full_sync_config Sync configuration for all sync modules.
* @param array $range Range of the sync items, containing min and max IDs for some item types.
* @param array $empty The modules with no items to sync during a full sync.
* @param mixed $context The context where the full sync was initiated from.
*
* @since 1.6.3
* @since-jetpack 4.2.0
* @since-jetpack 7.3.0 Added $range arg.
* @since-jetpack 7.4.0 Added $empty arg.
* @since $$next-version$$ Added $context arg.
*/
do_action( 'jetpack_full_sync_start', $full_sync_config, $range );
$this->send_action( 'jetpack_full_sync_start', array( $full_sync_config, $range ) );
$this->send_action( 'jetpack_full_sync_start', array( $full_sync_config, $range, $context ) );

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/sync/src/modules/class-full-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public function init_before_send() {
* @access public
*
* @param array $module_configs Full sync configuration for all sync modules.
* @param mixed $context Context for the full sync.
* @return bool Always returns true at success.
*/
public function start( $module_configs = null ) {
public function start( $module_configs = null, $context = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$was_already_running = $this->is_started() && ! $this->is_finished();

// Remove all evidence of previous full sync items and status.
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/class.jetpack-provision.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function () use ( $url_arg, $named_args ) {
// If Jetpack is currently connected, and is not in Safe Mode already, kick off a sync of the current
// functions/callables so that we can test if this site is in IDC.
if ( Jetpack::is_connection_ready() && ! Identity_Crisis::validate_sync_error_idc_option() && Actions::sync_allowed() ) {
Actions::do_full_sync( array( 'functions' => true ) );
Actions::do_full_sync( array( 'functions' => true ), 'provision' );
Actions::$sender->do_full_sync();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Full Sync: Added context
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/class.jetpack-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ public function sync( $args, $assoc_args ) {
}

// Kick off a full sync.
if ( Actions::do_full_sync( $modules ) ) {
if ( Actions::do_full_sync( $modules, 'jetpack_cli' ) ) {
if ( $modules ) {
/* translators: %s is a comma separated list of Jetpack modules */
WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), implode( ', ', array_keys( $modules ) ) ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function result() {
if ( empty( $modules ) ) {
$modules = null;
}
return array( 'scheduled' => Actions::do_full_sync( $modules ) );
return array( 'scheduled' => Actions::do_full_sync( $modules, 'jetpack_json_api_sync_endpoint' ) );
}

/**
Expand Down
Loading