Skip to content

Commit

Permalink
Full sync: Send context for initial full sync action (#40930)
Browse files Browse the repository at this point in the history
* Add a new parameter to the  functions in the  class to specify the context in which the full sync was initiated

* changelog

* Versioning is for the package

* Fixed doc since empty is not used and added context

* Updated type for context in the endpoint definition

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12805468078

Upstream-Ref: Automattic/jetpack@0cb4b07
  • Loading branch information
darssen authored and matticbot committed Jan 16, 2025
1 parent 8bc4db0 commit 5528436
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 175 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This is an alpha version! The changes listed here are not final.
### Other changes <!-- Non-user-facing changes go here. This section will not be copied to readme.txt. -->
- Block nudges: ensure clicking on a banner button leads to Plans page in Safari.
- Embeds: fix the Descript block variation icon svg path.
- Full Sync: Added context
- Hide related posts options for block themes
- Moved WPCOM_REST_API_Proxy_Request trait to the connection package
- SIG: Changed description for togle
Expand Down
2 changes: 1 addition & 1 deletion _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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"automattic/jetpack-stats": "^0.15.0",
"automattic/jetpack-stats-admin": "^0.24.0",
"automattic/jetpack-status": "^5.0.1",
"automattic/jetpack-sync": "^4.3.0",
"automattic/jetpack-sync": "^4.4.0-alpha",
"automattic/jetpack-videopress": "^0.25.6",
"automattic/jetpack-waf": "^0.23.1",
"automattic/jetpack-wordads": "^0.4.5",
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/jetpack-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.4.0-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Full Sync: Added context

## [4.3.0] - 2025-01-09
### Added
- Instant Search: add taxonomies for a8c-support-theme kb_article cpt. [#38660]
Expand Down Expand Up @@ -1367,6 +1374,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Packages: Move sync to a classmapped package

[4.4.0-alpha]: https://github.com/Automattic/jetpack-sync/compare/v4.3.0...v4.4.0-alpha
[4.3.0]: https://github.com/Automattic/jetpack-sync/compare/v4.2.0...v4.3.0
[4.2.0]: https://github.com/Automattic/jetpack-sync/compare/v4.1.1...v4.2.0
[4.1.1]: https://github.com/Automattic/jetpack-sync/compare/v4.1.0...v4.1.1
Expand Down
7 changes: 4 additions & 3 deletions jetpack_vendor/automattic/jetpack-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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '4.3.0';
const PACKAGE_VERSION = '4.4.0-alpha';

const PACKAGE_SLUG = 'sync';

Expand Down
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 4.4.0-alpha 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
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 jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
),
'jetpack-sync' => array(
'path' => 'jetpack_vendor/automattic/jetpack-sync',
'ver' => '4.3.0',
'ver' => '4.4.0-alpha1737018235',
),
'jetpack-videopress-pkg' => array(
'path' => 'jetpack_vendor/automattic/jetpack-videopress',
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

0 comments on commit 5528436

Please sign in to comment.