Skip to content

Commit 5f09806

Browse files
gititondereksmart
authored andcommitted
Jetpack DNA: Move Jetpack Sync Settings from Legacy to psr-4 (#12789)
* Move sync settings from legacy to psr-4 * fixing missed occurrences * fix * dna-sync-settings
1 parent eaf929e commit 5f09806

23 files changed

+163
-140
lines changed

class.jetpack-cli.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Automattic\Jetpack\Sync\Actions;
77
use Automattic\Jetpack\Sync\Listener;
88
use Automattic\Jetpack\Sync\Queue;
9+
use Automattic\Jetpack\Sync\Settings;
910

1011
/**
1112
* Control your local Jetpack installation.
@@ -832,7 +833,7 @@ public function sync( $args, $assoc_args ) {
832833
break;
833834
case 'settings':
834835
WP_CLI::log( __( 'Sync Settings:', 'jetpack' ) );
835-
foreach( Jetpack_Sync_Settings::get_settings() as $setting => $item ) {
836+
foreach( Settings::get_settings() as $setting => $item ) {
836837
$settings[] = array(
837838
'setting' => $setting,
838839
'value' => is_scalar( $item ) ? $item : json_encode( $item )
@@ -841,18 +842,18 @@ public function sync( $args, $assoc_args ) {
841842
WP_CLI\Utils\format_items( 'table', $settings, array( 'setting', 'value' ) );
842843

843844
case 'disable':
844-
// Don't set it via the Jetpack_Sync_Settings since that also resets the queues.
845+
// Don't set it via the Settings since that also resets the queues.
845846
update_option( 'jetpack_sync_settings_disable', 1 );
846847
/* translators: %s is the site URL */
847848
WP_CLI::log( sprintf( __( 'Sync Disabled on %s', 'jetpack' ), get_site_url() ) );
848849
break;
849850
case 'enable':
850-
Jetpack_Sync_Settings::update_settings( array( 'disable' => 0 ) );
851+
Settings::update_settings( array( 'disable' => 0 ) );
851852
/* translators: %s is the site URL */
852853
WP_CLI::log( sprintf( __( 'Sync Enabled on %s', 'jetpack' ), get_site_url() ) );
853854
break;
854855
case 'reset':
855-
// Don't set it via the Jetpack_Sync_Settings since that also resets the queues.
856+
// Don't set it via the Settings since that also resets the queues.
856857
update_option( 'jetpack_sync_settings_disable', 1 );
857858

858859
/* translators: %s is the site URL */
@@ -887,7 +888,7 @@ public function sync( $args, $assoc_args ) {
887888
break;
888889
case 'start':
889890
if ( ! Actions::sync_allowed() ) {
890-
if( ! Jetpack_Sync_Settings::get_setting( 'disable' ) ) {
891+
if( ! Settings::get_setting( 'disable' ) ) {
891892
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' ) );
892893
return;
893894
}
@@ -906,19 +907,19 @@ public function sync( $args, $assoc_args ) {
906907

907908
}
908909
// Get the original settings so that we can restore them later
909-
$original_settings = Jetpack_Sync_Settings::get_settings();
910+
$original_settings = Settings::get_settings();
910911

911912
// Initialize sync settigns so we can sync as quickly as possible
912913
$sync_settings = wp_parse_args(
913-
array_intersect_key( $assoc_args, Jetpack_Sync_Settings::$valid_settings ),
914+
array_intersect_key( $assoc_args, Settings::$valid_settings ),
914915
array(
915916
'sync_wait_time' => 0,
916917
'enqueue_wait_time' => 0,
917918
'queue_max_writes_sec' => 10000,
918919
'max_queue_size_full_sync' => 100000
919920
)
920921
);
921-
Jetpack_Sync_Settings::update_settings( $sync_settings );
922+
Settings::update_settings( $sync_settings );
922923

923924
// Convert comma-delimited string of modules to an array
924925
if ( ! empty( $assoc_args['modules'] ) ) {
@@ -959,7 +960,7 @@ public function sync( $args, $assoc_args ) {
959960
} else {
960961

961962
// Reset sync settings to original.
962-
Jetpack_Sync_Settings::update_settings( $original_settings );
963+
Settings::update_settings( $original_settings );
963964

964965
if ( $modules ) {
965966
/* translators: %s is a comma separated list of Jetpack modules */
@@ -990,7 +991,7 @@ public function sync( $args, $assoc_args ) {
990991
} while ( $result && ! is_wp_error( $result ) );
991992

992993
// Reset sync settings to original.
993-
Jetpack_Sync_Settings::update_settings( $original_settings );
994+
Settings::update_settings( $original_settings );
994995

995996
WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) );
996997
break;

json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Automattic\Jetpack\Sync\Queue_Buffer;
77
use Automattic\Jetpack\Sync\Replicastore;
88
use Automattic\Jetpack\Sync\Sender;
9+
use Automattic\Jetpack\Sync\Settings;
910

1011
// POST /sites/%s/sync
1112
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
@@ -98,7 +99,7 @@ class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sy
9899
protected function result() {
99100
$args = $this->input();
100101

101-
$sync_settings = Jetpack_Sync_Settings::get_settings();
102+
$sync_settings = Settings::get_settings();
102103

103104
foreach ( $args as $key => $value ) {
104105
if ( $value !== false ) {
@@ -115,18 +116,18 @@ protected function result() {
115116
}
116117
}
117118

118-
Jetpack_Sync_Settings::update_settings( $sync_settings );
119+
Settings::update_settings( $sync_settings );
119120

120121
// re-fetch so we see what's really being stored
121-
return Jetpack_Sync_Settings::get_settings();
122+
return Settings::get_settings();
122123
}
123124
}
124125

125126
// GET /sites/%s/sync/settings
126127
class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
127128
protected function result() {
128129

129-
return Jetpack_Sync_Settings::get_settings();
130+
return Settings::get_settings();
130131
}
131132
}
132133

@@ -146,9 +147,9 @@ protected function result() {
146147

147148
$codec = Sender::get_instance()->get_codec();
148149

149-
Jetpack_Sync_Settings::set_is_syncing( true );
150+
Settings::set_is_syncing( true );
150151
$objects = $codec->encode( $sync_module->get_objects_by_id( $object_type, $object_ids ) );
151-
Jetpack_Sync_Settings::set_is_syncing( false );
152+
Settings::set_is_syncing( false );
152153

153154
return array(
154155
'objects' => $objects,
@@ -215,9 +216,9 @@ protected function result() {
215216
return new WP_Error( 'buffer_non-object', 'Buffer is not an object', 400 );
216217
}
217218

218-
Jetpack_Sync_Settings::set_is_syncing( true );
219+
Settings::set_is_syncing( true );
219220
list( $items_to_send, $skipped_items_ids, $items ) = $sender->get_items_to_send( $buffer, $args['encode'] );
220-
Jetpack_Sync_Settings::set_is_syncing( false );
221+
Settings::set_is_syncing( false );
221222

222223
return array(
223224
'buffer_id' => $buffer->id,

modules/contact-form/grunion-contact-form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
License: GPLv2 or later
1111
*/
1212

13+
use Automattic\Jetpack\Sync\Settings;
14+
1315
define( 'GRUNION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
1416
define( 'GRUNION_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
1517

@@ -1935,7 +1937,7 @@ static function _style_on() {
19351937
* @return string HTML for the concat form.
19361938
*/
19371939
static function parse( $attributes, $content ) {
1938-
if ( Jetpack_Sync_Settings::is_syncing() ) {
1940+
if ( Settings::is_syncing() ) {
19391941
return '';
19401942
}
19411943
// Create a new Grunion_Contact_Form object (this class)

modules/likes/jetpack-likes-settings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Automattic\Jetpack\Sync\Settings;
4+
35
class Jetpack_Likes_Settings {
46
function __construct() {
57
$this->in_jetpack = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM );
@@ -269,7 +271,7 @@ function is_post_likeable( $post_id = 0 ) {
269271
* similar logic and filters apply here, too.
270272
*/
271273
function is_likes_visible() {
272-
if ( Jetpack_Sync_Settings::is_syncing() ) {
274+
if ( Settings::is_syncing() ) {
273275
return false;
274276
}
275277

modules/related-posts/jetpack-related-posts.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use Automattic\Jetpack\Sync\Settings;
4+
25
class Jetpack_RelatedPosts {
36
const VERSION = '20190204';
47
const SHORTCODE = 'jetpack-related-posts';
@@ -197,7 +200,7 @@ public function test_for_shortcode( $content ) {
197200
* @returns string
198201
*/
199202
public function get_target_html() {
200-
if ( Jetpack_Sync_Settings::is_syncing() ) {
203+
if ( Settings::is_syncing() ) {
201204
return '';
202205
}
203206

@@ -231,7 +234,7 @@ public function get_target_html() {
231234
* @returns string
232235
*/
233236
public function get_target_html_unsupported() {
234-
if ( Jetpack_Sync_Settings::is_syncing() ) {
237+
if ( Settings::is_syncing() ) {
235238
return '';
236239
}
237240
return "\n\n<!-- Jetpack Related Posts is not supported in this context. -->\n\n";

modules/sharedaddy/sharing-service.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Automattic\Jetpack\Sync\Settings;
4+
35
include_once dirname( __FILE__ ) . '/sharing-sources.php';
46

57
define( 'WP_SHARING_PLUGIN_VERSION', JETPACK__VERSION );
@@ -669,7 +671,7 @@ function sharing_process_requests() {
669671
function sharing_display( $text = '', $echo = false ) {
670672
global $post, $wp_current_filter;
671673

672-
if ( Jetpack_Sync_Settings::is_syncing() ) {
674+
if ( Settings::is_syncing() ) {
673675
return $text;
674676
}
675677

packages/sync/src/Actions.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static function sync_allowed() {
106106
if ( defined( 'PHPUNIT_JETPACK_TESTSUITE' ) ) {
107107
return true;
108108
}
109-
if ( ! \Jetpack_Sync_Settings::is_sync_enabled() ) {
109+
110+
if ( ! Settings::is_sync_enabled() ) {
110111
return false;
111112
}
112113
if ( \Jetpack::is_development_mode() ) {
@@ -125,19 +126,19 @@ static function sync_allowed() {
125126
}
126127

127128
static function sync_via_cron_allowed() {
128-
return ( \Jetpack_Sync_Settings::get_setting( 'sync_via_cron' ) );
129+
return ( Settings::get_setting( 'sync_via_cron' ) );
129130
}
130131

131132
static function prevent_publicize_blacklisted_posts( $should_publicize, $post ) {
132-
if ( in_array( $post->post_type, \Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ) ) {
133+
if ( in_array( $post->post_type, Settings::get_setting( 'post_types_blacklist' ) ) ) {
133134
return false;
134135
}
135136

136137
return $should_publicize;
137138
}
138139

139140
static function set_is_importing_true() {
140-
\Jetpack_Sync_Settings::set_importing( true );
141+
Settings::set_importing( true );
141142
}
142143

143144
static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $checkout_duration, $preprocess_duration ) {
@@ -163,7 +164,7 @@ static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $chec
163164
$query_args['migrate_for_idc'] = true;
164165
}
165166

166-
$query_args['timeout'] = \Jetpack_Sync_Settings::is_doing_cron() ? 30 : 15;
167+
$query_args['timeout'] = Settings::is_doing_cron() ? 30 : 15;
167168

168169
/**
169170
* Filters query parameters appended to the Sync request URL sent to WordPress.com.
@@ -290,7 +291,7 @@ static function do_cron_sync_by_type( $type ) {
290291

291292
self::initialize_sender();
292293

293-
$time_limit = \Jetpack_Sync_Settings::get_setting( 'cron_sync_time_limit' );
294+
$time_limit = Settings::get_setting( 'cron_sync_time_limit' );
294295
$start_time = time();
295296

296297
do {
@@ -438,7 +439,7 @@ static function cleanup_on_upgrade( $new_version = null, $old_version = null ) {
438439
$is_new_sync_upgrade = version_compare( $old_version, '4.2', '>=' );
439440
if ( ! empty( $old_version ) && $is_new_sync_upgrade && version_compare( $old_version, '4.5', '<' ) ) {
440441
self::clear_sync_cron_jobs();
441-
\Jetpack_Sync_Settings::update_settings(
442+
Settings::update_settings(
442443
array(
443444
'render_filtered_content' => Defaults::$default_render_filtered_content,
444445
)

packages/sync/src/Listener.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function force_recheck_queue_limit() {
8484
// prevent adding items to the queue if it hasn't sent an item for 15 mins
8585
// AND the queue is over 1000 items long (by default)
8686
function can_add_to_queue( $queue ) {
87-
if ( ! \Jetpack_Sync_Settings::is_sync_enabled() ) {
87+
if ( ! Settings::is_sync_enabled() ) {
8888
return false;
8989
}
9090

@@ -140,7 +140,7 @@ function bulk_enqueue_full_sync_actions( $action_name, $args_array ) {
140140
$data_to_enqueue = array();
141141
$user_id = get_current_user_id();
142142
$currtime = microtime( true );
143-
$is_importing = \Jetpack_Sync_Settings::is_importing();
143+
$is_importing = Settings::is_importing();
144144

145145
foreach ( $args_array as $args ) {
146146
$previous_end = isset( $args['previous_end'] ) ? $args['previous_end'] : null;
@@ -179,7 +179,7 @@ function bulk_enqueue_full_sync_actions( $action_name, $args_array ) {
179179

180180
function enqueue_action( $current_filter, $args, $queue ) {
181181
// don't enqueue an action during the outbound http request - this prevents recursion
182-
if ( \Jetpack_Sync_Settings::is_sending() ) {
182+
if ( Settings::is_sending() ) {
183183
return;
184184
}
185185

@@ -235,7 +235,7 @@ function enqueue_action( $current_filter, $args, $queue ) {
235235
$args,
236236
get_current_user_id(),
237237
microtime( true ),
238-
\Jetpack_Sync_Settings::is_importing(),
238+
Settings::is_importing(),
239239
$this->get_actor( $current_filter, $args ),
240240
)
241241
);
@@ -246,7 +246,7 @@ function enqueue_action( $current_filter, $args, $queue ) {
246246
$args,
247247
get_current_user_id(),
248248
microtime( true ),
249-
\Jetpack_Sync_Settings::is_importing(),
249+
Settings::is_importing(),
250250
)
251251
);
252252
}
@@ -313,8 +313,8 @@ function should_send_user_data_with_actor( $current_filter ) {
313313
function set_defaults() {
314314
$this->sync_queue = new Queue( 'sync' );
315315
$this->full_sync_queue = new Queue( 'full_sync' );
316-
$this->set_queue_size_limit( \Jetpack_Sync_Settings::get_setting( 'max_queue_size' ) );
317-
$this->set_queue_lag_limit( \Jetpack_Sync_Settings::get_setting( 'max_queue_lag' ) );
316+
$this->set_queue_size_limit( Settings::get_setting( 'max_queue_size' ) );
317+
$this->set_queue_lag_limit( Settings::get_setting( 'max_queue_lag' ) );
318318
}
319319

320320
function get_request_url() {

0 commit comments

Comments
 (0)