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

Sync: add a new method, do_only_first_initial_sync #21676

Merged
merged 12 commits into from
Nov 12, 2021
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: patch
Type: changed

Actions: add the do_only_first_initial_sync method which starts an initial sync only when one hasn't already been done
16 changes: 15 additions & 1 deletion projects/packages/sync/src/class-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public static function send_data( $data, $codec_name, $sent_timestamp, $queue_id
* @return bool|null False if sync is not allowed.
*/
public static function do_initial_sync() {
// Lets not sync if we are not suppose to.
// Let's not sync if we are not supposed to.
if ( ! self::sync_allowed() ) {
return false;
}
Expand All @@ -507,6 +507,20 @@ public static function do_initial_sync() {
self::do_full_sync( $initial_sync_config );
}

/**
* Do an initial full sync only if one has not already been started.
*
* @return bool|null False if the initial full sync was already started, otherwise null.
*/
public static function do_only_first_initial_sync() {
$full_sync_module = Modules::get_module( 'full-sync' );
if ( $full_sync_module && $full_sync_module->is_started() ) {
return false;
}

static::do_initial_sync();
}

/**
* Kicks off a full sync.
*
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/sync/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '1.27.2';
const PACKAGE_VERSION = '1.27.3-alpha';

const PACKAGE_SLUG = 'sync';

Expand Down
46 changes: 46 additions & 0 deletions projects/packages/sync/tests/php/test-actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
kbrown9 marked this conversation as resolved.
Show resolved Hide resolved

namespace Automattic\Jetpack\Sync;

use Automattic\Jetpack\Constants;
use WorDBless\BaseTestCase;

/**
* Unit tests for the Actions class.
*
* @package automattic/jetpack-sync
*/
class Test_Actions extends BaseTestCase {

/**
* Set up before each test.
*
* @before
*/
public function set_up() {
// Don't try to get options directly from the database.
Constants::set_constant( 'JETPACK_DISABLE_RAW_OPTIONS', true );
}

/**
* Tests the do_only_first_intitial_sync method when an initial sync has not been performed yet.
*/
public function test_do_only_first_intitial_sync_successful() {
$this->assertNull( Actions::do_only_first_initial_sync() );
}

/**
* Tests the do_only_first_intitial_sync method when an initial sync has already been performed.
*/
public function test_do_only_first_intitial_sync_already_started() {
$full_sync_option = array(
'started' => time(),
'finished' => false,
'progress' => array(),
'config' => array(),
);
update_option( Modules\Full_Sync_Immediately::STATUS_OPTION, $full_sync_option );

$this->assertFalse( Actions::do_only_first_initial_sync() );
}
}