Skip to content
Closed
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
5 changes: 4 additions & 1 deletion 3rd-party/class.jetpack-amp-support.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName

use Automattic\Jetpack\Sync\Functions;

/**
* Manages compatibility with the amp-wp plugin
*
Expand Down Expand Up @@ -129,7 +132,7 @@ public static function amp_post_template_metadata( $metadata, $post ) {
*/
private static function add_site_icon_to_metadata( $metadata ) {
$size = 60;
$site_icon_url = class_exists( 'Jetpack_Sync_Functions' ) ? Jetpack_Sync_Functions::site_icon_url( $size ) : '';
$site_icon_url = class_exists( 'Functions' ) ? Functions::site_icon_url( $size ) : '';

if ( function_exists( 'blavatar_domain' ) ) {
$metadata['publisher']['logo'] = array(
Expand Down
8 changes: 5 additions & 3 deletions _inc/class.jetpack-provision.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php //phpcs:ignore

use Automattic\Jetpack\Sync\Actions;

class Jetpack_Provision { //phpcs:ignore

/**
Expand Down Expand Up @@ -35,9 +37,9 @@ public static function register_and_build_request_body( $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_active() && ! Jetpack::validate_sync_error_idc_option() && Jetpack_Sync_Actions::sync_allowed() ) {
Jetpack_Sync_Actions::do_full_sync( array( 'functions' => true ) );
Jetpack_Sync_Actions::$sender->do_full_sync();
if ( Jetpack::is_active() && ! Jetpack::validate_sync_error_idc_option() && Actions::sync_allowed() ) {
Actions::do_full_sync( array( 'functions' => true ) );
Actions::$sender->do_full_sync();
}

if ( Jetpack::validate_sync_error_idc_option() ) {
Expand Down
21 changes: 9 additions & 12 deletions _inc/lib/debugger/class-jetpack-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @package jetpack
*/

use Automattic\Jetpack\Sync\Functions;
use Automattic\Jetpack\Sync\Modules;
use Automattic\Jetpack\Sync\Sender;

/**
* Class Jetpack_Debug_Data
*
Expand Down Expand Up @@ -266,14 +270,7 @@ public static function debug_data() {
);

/** Sync Debug Information */
/** Load Sync modules */
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
/** Load Sync sender */
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
/** Load Sync functions */
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';

$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
$sync_module = Modules::get_module( 'full-sync' );
if ( $sync_module ) {
$sync_statuses = $sync_module->get_status();
$human_readable_sync_status = array();
Expand All @@ -289,7 +286,7 @@ public static function debug_data() {
);
}

$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
$queue = Sender::get_instance()->get_sync_queue();

$debug_info['sync_size'] = array(
'label' => 'Sync Queue Size',
Expand All @@ -302,7 +299,7 @@ public static function debug_data() {
'private' => false,
);

$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
$full_sync_queue = Sender::get_instance()->get_full_sync_queue();

$debug_info['full_sync_size'] = array(
'label' => 'Full Sync Queue Size',
Expand All @@ -321,8 +318,8 @@ public static function debug_data() {
* Must follow sync debug since it depends on sync functionality.
*/
$idc_urls = array(
'home' => Jetpack_Sync_Functions::home_url(),
'siteurl' => Jetpack_Sync_Functions::site_url(),
'home' => Functions::home_url(),
'siteurl' => Functions::site_url(),
'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '',
'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '',
);
Expand Down
41 changes: 22 additions & 19 deletions class.jetpack-cli.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use Automattic\Jetpack\Sync\Actions;
use Automattic\Jetpack\Sync\Listener;
use Automattic\Jetpack\Sync\Queue;
use Automattic\Jetpack\Sync\Settings;

WP_CLI::add_command( 'jetpack', 'Jetpack_CLI' );

/**
Expand Down Expand Up @@ -823,7 +828,7 @@ public function sync( $args, $assoc_args ) {

switch ( $action ) {
case 'status':
$status = Jetpack_Sync_Actions::get_sync_status();
$status = Actions::get_sync_status();
$collection = array();
foreach ( $status as $key => $item ) {
$collection[] = array(
Expand All @@ -836,7 +841,7 @@ public function sync( $args, $assoc_args ) {
break;
case 'settings':
WP_CLI::log( __( 'Sync Settings:', 'jetpack' ) );
foreach( Jetpack_Sync_Settings::get_settings() as $setting => $item ) {
foreach( Settings::get_settings() as $setting => $item ) {
$settings[] = array(
'setting' => $setting,
'value' => is_scalar( $item ) ? $item : json_encode( $item )
Expand All @@ -845,24 +850,23 @@ public function sync( $args, $assoc_args ) {
WP_CLI\Utils\format_items( 'table', $settings, array( 'setting', 'value' ) );

case 'disable':
// Don't set it via the Jetpack_Sync_Settings since that also resets the queues.
// Don't set it via the Settings since that also resets the queues.
update_option( 'jetpack_sync_settings_disable', 1 );
/* translators: %s is the site URL */
WP_CLI::log( sprintf( __( 'Sync Disabled on %s', 'jetpack' ), get_site_url() ) );
break;
case 'enable':
Jetpack_Sync_Settings::update_settings( array( 'disable' => 0 ) );
Settings::update_settings( array( 'disable' => 0 ) );
/* translators: %s is the site URL */
WP_CLI::log( sprintf( __( 'Sync Enabled on %s', 'jetpack' ), get_site_url() ) );
break;
case 'reset':
// Don't set it via the Jetpack_Sync_Settings since that also resets the queues.
// Don't set it via the Settings since that also resets the queues.
update_option( 'jetpack_sync_settings_disable', 1 );

/* translators: %s is the site URL */
WP_CLI::log( sprintf( __( 'Sync Disabled on %s. Use `wp jetpack sync enable` to enable syncing again.', 'jetpack' ), get_site_url() ) );
require_once dirname( __FILE__ ) . '/sync/class.jetpack-sync-listener.php';
$listener = Jetpack_Sync_Listener::get_instance();
$listener = Listener::get_instance();
if ( empty( $assoc_args['queue'] ) ) {
$listener->get_sync_queue()->reset();
$listener->get_full_sync_queue()->reset();
Expand Down Expand Up @@ -891,8 +895,8 @@ public function sync( $args, $assoc_args ) {

break;
case 'start':
if ( ! Jetpack_Sync_Actions::sync_allowed() ) {
if( ! Jetpack_Sync_Settings::get_setting( 'disable' ) ) {
if ( ! Actions::sync_allowed() ) {
if( ! Settings::get_setting( 'disable' ) ) {
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. It is currently disabled. Run `wp jetpack sync enable` to enable it.', 'jetpack' ) );
return;
}
Expand All @@ -911,19 +915,19 @@ public function sync( $args, $assoc_args ) {

}
// Get the original settings so that we can restore them later
$original_settings = Jetpack_Sync_Settings::get_settings();
$original_settings = Settings::get_settings();

// Initialize sync settigns so we can sync as quickly as possible
$sync_settings = wp_parse_args(
array_intersect_key( $assoc_args, Jetpack_Sync_Settings::$valid_settings ),
array_intersect_key( $assoc_args, Settings::$valid_settings ),
array(
'sync_wait_time' => 0,
'enqueue_wait_time' => 0,
'queue_max_writes_sec' => 10000,
'max_queue_size_full_sync' => 100000
)
);
Jetpack_Sync_Settings::update_settings( $sync_settings );
Settings::update_settings( $sync_settings );

// Convert comma-delimited string of modules to an array
if ( ! empty( $assoc_args['modules'] ) ) {
Expand Down Expand Up @@ -954,7 +958,7 @@ public function sync( $args, $assoc_args ) {
}

// Kick off a full sync
if ( Jetpack_Sync_Actions::do_full_sync( $modules ) ) {
if ( Actions::do_full_sync( $modules ) ) {
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' ), join( ', ', array_keys( $modules ) ) ) );
Expand All @@ -964,7 +968,7 @@ public function sync( $args, $assoc_args ) {
} else {

// Reset sync settings to original.
Jetpack_Sync_Settings::update_settings( $original_settings );
Settings::update_settings( $original_settings );

if ( $modules ) {
/* translators: %s is a comma separated list of Jetpack modules */
Expand All @@ -977,7 +981,7 @@ public function sync( $args, $assoc_args ) {
// Keep sending to WPCOM until there's nothing to send
$i = 1;
do {
$result = Jetpack_Sync_Actions::$sender->do_full_sync();
$result = Actions::$sender->do_full_sync();
if ( is_wp_error( $result ) ) {
$queue_empty_error = ( 'empty_queue_full_sync' == $result->get_error_code() );
if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 == $i ) ) ) {
Expand All @@ -995,7 +999,7 @@ public function sync( $args, $assoc_args ) {
} while ( $result && ! is_wp_error( $result ) );

// Reset sync settings to original.
Jetpack_Sync_Settings::update_settings( $original_settings );
Settings::update_settings( $original_settings );

WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) );
break;
Expand All @@ -1016,7 +1020,7 @@ public function sync( $args, $assoc_args ) {
* @synopsis <incremental|full_sync> <peek>
*/
public function sync_queue( $args, $assoc_args ) {
if ( ! Jetpack_Sync_Actions::sync_allowed() ) {
if ( ! Actions::sync_allowed() ) {
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) );
}

Expand All @@ -1033,8 +1037,7 @@ public function sync_queue( $args, $assoc_args ) {

switch( $action ) {
case 'peek':
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php';
$queue = new Jetpack_Sync_Queue( $mapped_queue_name );
$queue = new Queue( $mapped_queue_name );
$items = $queue->peek( 100 );

if ( empty( $items ) ) {
Expand Down
15 changes: 8 additions & 7 deletions class.jetpack-xmlrpc-server.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use Automattic\Jetpack\Sync\Functions;
use Automattic\Jetpack\Sync\Modules;
use Automattic\Jetpack\Sync\Sender;

/**
* Just a sack of functions. Not actually an IXR_Server
*/
Expand Down Expand Up @@ -634,11 +638,9 @@ function unlink_user() {
function sync_object( $args ) {
// e.g. posts, post, 5
list( $module_name, $object_type, $id ) = $args;
require_once dirname( __FILE__ ) . '/sync/class.jetpack-sync-modules.php';
require_once dirname( __FILE__ ) . '/sync/class.jetpack-sync-sender.php';

$sync_module = Jetpack_Sync_Modules::get_module( $module_name );
$codec = Jetpack_Sync_Sender::get_instance()->get_codec();
$sync_module = Modules::get_module( $module_name );
$codec = Sender::get_instance()->get_codec();

return $codec->encode( $sync_module->get_object_by_id( $object_type, $id ) );
}
Expand All @@ -651,10 +653,9 @@ function sync_object( $args ) {
* @return array
*/
function validate_urls_for_idc_mitigation() {
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
return array(
'home' => Jetpack_Sync_Functions::home_url(),
'siteurl' => Jetpack_Sync_Functions::site_url(),
'home' => Functions::home_url(),
'siteurl' => Functions::site_url(),
);
}

Expand Down
20 changes: 11 additions & 9 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
Flag for "activating" the plugin on sites where the activation hook never fired (auto-installs)
*/

use Automattic\Jetpack\Sync\Functions;
use Automattic\Jetpack\Sync\Sender;
use Automattic\Jetpack\Sync\Users;

require_once( JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php' );

class Jetpack {
Expand Down Expand Up @@ -1449,8 +1453,8 @@ public static function file_system_write_access() {
* @return string ( '1' | '0' )
**/
public static function is_version_controlled() {
_deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' );
return (string) (int) Jetpack_Sync_Functions::is_version_controlled();
_deprecated_function( __METHOD__, 'jetpack-4.2', 'Functions::is_version_controlled' );
return (string) (int) Functions::is_version_controlled();
}

/**
Expand Down Expand Up @@ -1804,8 +1808,8 @@ function extra_oembed_providers() {
* Synchronize connected user role changes
*/
function user_role_change( $user_id ) {
_deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' );
Jetpack_Sync_Users::user_role_change( $user_id );
_deprecated_function( __METHOD__, 'jetpack-4.2', 'Users::user_role_change()' );
Users::user_role_change( $user_id );
}

/**
Expand Down Expand Up @@ -3357,8 +3361,7 @@ public static function disconnect( $update_activated_state = true ) {
delete_transient( $transient_key );

// Delete all the sync related data. Since it could be taking up space.
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
Jetpack_Sync_Sender::get_instance()->uninstall();
Sender::get_instance()->uninstall();

// Disable the Heartbeat cron
Jetpack_Heartbeat::init()->deactivate();
Expand Down Expand Up @@ -6209,10 +6212,9 @@ public static function get_sync_error_idc_option( $response = array() ) {
// in a transient to allow for autoloading and caching on subsequent views.
$local_options = get_transient( 'jetpack_idc_local' );
if ( false === $local_options ) {
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
$local_options = array(
'home' => Jetpack_Sync_Functions::home_url(),
'siteurl' => Jetpack_Sync_Functions::site_url(),
'home' => Functions::home_url(),
'siteurl' => Functions::site_url(),
);
set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS );
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"require": {
"ext-openssl": "*",
"automattic/jetpack-logo": "@dev"
"automattic/jetpack-logo": "@dev",
"automattic/jetpack-sync": "@dev"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "0.5.0",
Expand Down
25 changes: 23 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function jetpack_admin_missing_autoloader() { ?>
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-data.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client-server.php' );
require_once( JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-actions.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-options.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-user-agent.php' );
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-post-images.php' );
Expand Down
Loading