summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2020-01-06 14:32:30 -0500
committerAnthony G. Basile <blueness@gentoo.org>2020-01-06 14:32:30 -0500
commit10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch)
treeb4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/json-endpoints/jetpack
parentUpdating script for Update (diff)
downloadblogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz
blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2
blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/json-endpoints/jetpack')
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-delete-backup-helper-script-endpoint.php76
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-install-backup-helper-script-endpoint.php85
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php12
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php12
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php5
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php141
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php4
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php4
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php4
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php5
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php147
11 files changed, 402 insertions, 93 deletions
diff --git a/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-delete-backup-helper-script-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-delete-backup-helper-script-endpoint.php
new file mode 100644
index 00000000..2729dc58
--- /dev/null
+++ b/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-delete-backup-helper-script-endpoint.php
@@ -0,0 +1,76 @@
+<?php
+/**
+ * API endpoint /sites/%s/delete-backup-helper-script
+ * This API endpoint deletes a Jetpack Backup Helper Script
+ *
+ * @package Jetpack
+ */
+
+use Automattic\Jetpack\Backup\Helper_Script_Manager;
+
+class Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * This endpoint is only accessible from Jetpack Backup; it requires no further capabilities.
+ *
+ * @var array
+ */
+ protected $needed_capabilities = array();
+
+ /**
+ * Method to call when running this endpoint (delete)
+ *
+ * @var string
+ */
+ protected $action = 'delete';
+
+ /**
+ * Local path to the Helper Script to delete.
+ *
+ * @var string|null
+ */
+ protected $script_path = null;
+
+ /**
+ * True if the specified file has been successfully deleted.
+ *
+ * @var boolean
+ */
+ protected $result = false;
+
+ /**
+ * Checks that the input args look like a valid Helper Script path.
+ *
+ * @param null $object Unused.
+ * @return bool|WP_Error a WP_Error object or true if the input seems ok.
+ */
+ protected function validate_input( $object ) {
+ $args = $this->input();
+
+ if ( ! isset( $args['path'] ) ) {
+ return new WP_Error( 'invalid_args', __( 'You must specify a helper script path', 'jetpack' ), 400 );
+ }
+
+ $this->script_path = $args['path'];
+ return true;
+ }
+
+ /**
+ * Deletes the specified Helper Script.
+ */
+ protected function delete() {
+ $this->result = Helper_Script_Manager::delete_helper_script( $this->script_path );
+ Helper_Script_Manager::cleanup_expired_helper_scripts();
+ }
+
+ /**
+ * Returns the success or failure of the deletion operation
+ *
+ * @return array An array containing one key; 'success', which specifies whether the operation was successful.
+ */
+ protected function result() {
+ return array(
+ 'success' => $this->result,
+ );
+ }
+
+}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-install-backup-helper-script-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-install-backup-helper-script-endpoint.php
new file mode 100644
index 00000000..a5c2bdeb
--- /dev/null
+++ b/plugins/jetpack/json-endpoints/jetpack/class-jetpack-json-api-install-backup-helper-script-endpoint.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * API endpoint /sites/%s/install-backup-helper-script
+ * This API endpoint installs a Helper Script to assist Jetpack Backup fetch data
+ *
+ * @package Jetpack
+ */
+
+use Automattic\Jetpack\Backup\Helper_Script_Manager;
+
+class Jetpack_JSON_API_Install_Backup_Helper_Script_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * This endpoint is only accessible from Jetpack Backup; it requires no further capabilities.
+ *
+ * @var array
+ */
+ protected $needed_capabilities = array();
+
+ /**
+ * Method to call when running this endpoint (install)
+ *
+ * @var string
+ */
+ protected $action = 'install';
+
+ /**
+ * Contents of the Helper Script to install
+ *
+ * @var string|null
+ */
+ protected $helper_script = null;
+
+ /**
+ * Contains the result of installing the Helper Script.
+ *
+ * @var null|WP_Error|array
+ */
+ protected $result = null;
+
+ /**
+ * Checks that the input args look like a valid Helper Script.
+ *
+ * @param null $object Unused.
+ * @return bool|WP_Error a WP_Error object or true if the input seems ok.
+ */
+ protected function validate_input( $object ) {
+ $args = $this->input();
+
+ if ( ! isset( $args['helper'] ) ) {
+ return new WP_Error( 'invalid_args', __( 'You must specify a helper script body', 'jetpack' ), 400 );
+ }
+
+ $this->helper_script = base64_decode( $args['helper'] );
+ if ( ! $this->helper_script ) {
+ return new WP_Error( 'invalid_args', __( 'Helper script body must be base64 encoded', 'jetpack' ), 400 );
+ }
+
+ return true;
+ }
+
+ /**
+ * Installs the uploaded Helper Script.
+ */
+ protected function install() {
+ $this->result = Helper_Script_Manager::install_helper_script( $this->helper_script );
+ Helper_Script_Manager::cleanup_expired_helper_scripts();
+ }
+
+ /**
+ * Returns the result of Helper Script installation. Returns one of:
+ * - WP_Error on failure, or
+ * - An array containing the access url ('url') and installation path ('path') on success.
+ *
+ * @return array|WP_Error Success or failure information.
+ */
+ protected function result() {
+ // Include ABSPATH with successful result.
+ if ( ! is_wp_error( $this->result ) ) {
+ $this->result['abspath'] = ABSPATH;
+ }
+
+ return $this->result;
+ }
+
+}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
index 903a16ac..7e7ff2a7 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
@@ -17,14 +17,22 @@ class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoin
}
protected function result() {
+ global $wpdb;
+
$post = get_post( $this->post_id );
if ( empty( $post ) ) {
return new WP_Error( 'post_not_found', __( 'Post not found', 'jetpack' ), 404 );
}
+ // Fetch terms associated with this post object
+ $terms = $wpdb->get_results( $wpdb->prepare(
+ "SELECT term_taxonomy_id, term_order FROM {$wpdb->term_relationships} WHERE object_id = %d;", $post->ID
+ ) );
+
return array(
- 'post' => (array)$post,
- 'meta' => get_post_meta( $post->ID ),
+ 'post' => (array)$post,
+ 'meta' => get_post_meta( $post->ID ),
+ 'terms' => (array)$terms,
);
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
index 1df4fe66..6c3b4d0a 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
@@ -1,5 +1,8 @@
<?php
+use Automattic\Jetpack\Constants;
+use Automattic\Jetpack\Sync\Functions;
+
/**
* Base class for working with plugins.
*/
@@ -200,17 +203,17 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$reasons_can_not_autoupdate = array();
$reasons_can_not_modify_files = array();
- $has_file_system_write_access = Jetpack_Sync_Functions::file_system_write_access();
+ $has_file_system_write_access = Functions::file_system_write_access();
if ( ! $has_file_system_write_access ) {
$reasons_can_not_modify_files['has_no_file_system_write_access'] = __( 'The file permissions on this host prevent editing files.', 'jetpack' );
}
- $disallow_file_mods = Jetpack_Constants::get_constant('DISALLOW_FILE_MODS' );
+ $disallow_file_mods = Constants::get_constant('DISALLOW_FILE_MODS' );
if ( $disallow_file_mods ) {
$reasons_can_not_modify_files['disallow_file_mods'] = __( 'File modifications are explicitly disabled by a site administrator.', 'jetpack' );
}
- $automatic_updater_disabled = Jetpack_Constants::get_constant( 'AUTOMATIC_UPDATER_DISABLED' );
+ $automatic_updater_disabled = Constants::get_constant( 'AUTOMATIC_UPDATER_DISABLED' );
if ( $automatic_updater_disabled ) {
$reasons_can_not_autoupdate['automatic_updater_disabled'] = __( 'Any autoupdates are explicitly disabled by a site administrator.', 'jetpack' );
}
@@ -315,7 +318,6 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
}
protected function get_plugin_action_links( $plugin_file ) {
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
- return Jetpack_Sync_Functions::get_plugins_action_links( $plugin_file );
+ return Functions::get_plugins_action_links( $plugin_file );
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
index 49cf43dc..232cc2c5 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
@@ -1,4 +1,7 @@
<?php
+
+use Automattic\Jetpack\Constants;
+
new Jetpack_JSON_API_Plugins_Modify_Endpoint(
array(
'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates',
@@ -291,7 +294,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
protected function update() {
$query_args = $this->query_args();
if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] ) {
- Jetpack_Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true );
+ Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true );
}
wp_clean_plugins_cache();
ob_start();
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
index 72dcd52c..03e6a4d4 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
@@ -1,5 +1,13 @@
<?php
+use Automattic\Jetpack\Sync\Actions;
+use Automattic\Jetpack\Sync\Modules;
+use Automattic\Jetpack\Sync\Queue;
+use Automattic\Jetpack\Sync\Queue_Buffer;
+use Automattic\Jetpack\Sync\Replicastore;
+use Automattic\Jetpack\Sync\Sender;
+use Automattic\Jetpack\Sync\Settings;
+
// POST /sites/%s/sync
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
protected $needed_capabilities = 'manage_options';
@@ -32,7 +40,7 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
if ( empty( $modules ) ) {
$modules = null;
}
- return array( 'scheduled' => Jetpack_Sync_Actions::do_full_sync( $modules ) );
+ return array( 'scheduled' => Actions::do_full_sync( $modules ) );
}
protected function validate_queue( $query ) {
@@ -50,15 +58,16 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
// GET /sites/%s/sync/status
class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
protected function result() {
- return Jetpack_Sync_Actions::get_sync_status();
+ $args = $this->query_args();
+ $fields = isset( $args['fields'] ) ? $args['fields'] : array();
+ return Actions::get_sync_status( $fields );
}
}
// GET /sites/%s/data-check
class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
protected function result() {
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php';
- $store = new Jetpack_Sync_WP_Replicastore();
+ $store = new Replicastore();
return $store->checksum_all();
}
}
@@ -74,8 +83,7 @@ class Jetpack_JSON_API_Sync_Histogram_Endpoint extends Jetpack_JSON_API_Sync_End
$columns = null; // go with defaults
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php';
- $store = new Jetpack_Sync_WP_Replicastore();
+ $store = new Replicastore();
if ( ! isset( $args['strip_non_ascii'] ) ) {
$args['strip_non_ascii'] = true;
@@ -91,16 +99,14 @@ class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sy
protected function result() {
$args = $this->input();
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-settings.php';
-
- $sync_settings = Jetpack_Sync_Settings::get_settings();
+ $sync_settings = Settings::get_settings();
foreach ( $args as $key => $value ) {
if ( $value !== false ) {
if ( is_numeric( $value ) ) {
$value = (int) $value;
}
-
+
// special case for sending empty arrays - a string with value 'empty'
if ( $value === 'empty' ) {
$value = array();
@@ -110,19 +116,18 @@ class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sy
}
}
- Jetpack_Sync_Settings::update_settings( $sync_settings );
+ Settings::update_settings( $sync_settings );
// re-fetch so we see what's really being stored
- return Jetpack_Sync_Settings::get_settings();
+ return Settings::get_settings();
}
}
// GET /sites/%s/sync/settings
class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
protected function result() {
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-settings.php';
- return Jetpack_Sync_Settings::get_settings();
+ return Settings::get_settings();
}
}
@@ -133,21 +138,18 @@ class Jetpack_JSON_API_Sync_Object extends Jetpack_JSON_API_Sync_Endpoint {
$module_name = $args['module_name'];
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
-
- if ( ! $sync_module = Jetpack_Sync_Modules::get_module( $module_name ) ) {
+ if ( ! $sync_module = Modules::get_module( $module_name ) ) {
return new WP_Error( 'invalid_module', 'You specified an invalid sync module' );
}
$object_type = $args['object_type'];
$object_ids = $args['object_ids'];
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
- $codec = Jetpack_Sync_Sender::get_instance()->get_codec();
+ $codec = Sender::get_instance()->get_codec();
- Jetpack_Sync_Settings::set_is_syncing( true );
+ Settings::set_is_syncing( true );
$objects = $codec->encode( $sync_module->get_objects_by_id( $object_type, $object_ids ) );
- Jetpack_Sync_Settings::set_is_syncing( false );
+ Settings::set_is_syncing( false );
return array(
'objects' => $objects,
@@ -165,10 +167,8 @@ class Jetpack_JSON_API_Sync_Now_Endpoint extends Jetpack_JSON_API_Sync_Endpoint
return $queue_name;
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
-
- $sender = Jetpack_Sync_Sender::get_instance();
- $response = $sender->do_sync_for_queue( new Jetpack_Sync_Queue( $args['queue'] ) );
+ $sender = Sender::get_instance();
+ $response = $sender->do_sync_for_queue( new Queue( $args['queue'] ) );
return array(
'response' => $response
@@ -178,49 +178,51 @@ class Jetpack_JSON_API_Sync_Now_Endpoint extends Jetpack_JSON_API_Sync_Endpoint
class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
protected function result() {
- $args = $this->input();
+ $args = $this->input();
$queue_name = $this->validate_queue( $args['queue'] );
- if ( is_wp_error( $queue_name ) ){
+ if ( is_wp_error( $queue_name ) ) {
return $queue_name;
}
- if ( $args[ 'number_of_items' ] < 1 || $args[ 'number_of_items' ] > 100 ) {
+ if ( $args['number_of_items'] < 1 || $args['number_of_items'] > 100 ) {
return new WP_Error( 'invalid_number_of_items', 'Number of items needs to be an integer that is larger than 0 and less then 100', 400 );
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php';
- $queue = new Jetpack_Sync_Queue( $queue_name );
+ $number_of_items = absint( $args['number_of_items'] );
+
+ $queue = new Queue( $queue_name );
if ( 0 === $queue->size() ) {
return new WP_Error( 'queue_size', 'The queue is empty and there is nothing to send', 400 );
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
- $sender = Jetpack_Sync_Sender::get_instance();
+ $sender = Sender::get_instance();
- // try to give ourselves as much time as possible
+ // try to give ourselves as much time as possible.
set_time_limit( 0 );
- // let's delete the checkin state
- if ( $args['force'] ) {
- $queue->unlock();
+ if ( $args['pop'] ) {
+ $buffer = new Queue_Buffer( 'pop', $queue->pop( $number_of_items ) );
+ } else {
+ // let's delete the checkin state.
+ if ( $args['force'] ) {
+ $queue->unlock();
+ }
+ $buffer = $this->get_buffer( $queue, $number_of_items );
}
-
- $buffer = $this->get_buffer( $queue, $args[ 'number_of_items' ] );
-
- // Check that the $buffer is not checkout out already
+ // Check that the $buffer is not checkout out already.
if ( is_wp_error( $buffer ) ) {
return new WP_Error( 'buffer_open', "We couldn't get the buffer it is currently checked out", 400 );
}
-
+
if ( ! is_object( $buffer ) ) {
return new WP_Error( 'buffer_non-object', 'Buffer is not an object', 400 );
}
- Jetpack_Sync_Settings::set_is_syncing( true );
- list( $items_to_send, $skipped_items_ids, $items ) = $sender->get_items_to_send( $buffer, $args['encode'] );
- Jetpack_Sync_Settings::set_is_syncing( false );
+ Settings::set_is_syncing( true );
+ list( $items_to_send, $skipped_items_ids ) = $sender->get_items_to_send( $buffer, $args['encode'] );
+ Settings::set_is_syncing( false );
return array(
'buffer_id' => $buffer->id,
@@ -260,7 +262,6 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
if ( is_wp_error( $queue_name ) ) {
return $queue_name;
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php';
if ( ! isset( $request_body['buffer_id'] ) ) {
return new WP_Error( 'missing_buffer_id', 'Please provide a buffer id', 400 );
@@ -274,9 +275,16 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
$request_body ['buffer_id'] = preg_replace( '/[^A-Za-z0-9]/', '', $request_body['buffer_id'] );
$request_body['item_ids'] = array_filter( array_map( array( 'Jetpack_JSON_API_Sync_Close_Endpoint', 'sanitize_item_ids' ), $request_body['item_ids'] ) );
- $buffer = new Jetpack_Sync_Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] );
- $queue = new Jetpack_Sync_Queue( $queue_name );
+ $queue = new Queue( $queue_name );
+
+ $items = $queue->peek_by_id( $request_body['item_ids'] );
+
+ /** This action is documented in packages/sync/src/modules/Full_Sync.php */
+ $full_sync_module = Modules::get_module( 'full-sync' );
+
+ $full_sync_module->update_sent_progress_action( $items );
+ $buffer = new Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] );
$response = $queue->close( $buffer, $request_body['item_ids'] );
if ( is_wp_error( $response ) ) {
@@ -284,7 +292,8 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
}
return array(
- 'success' => $response
+ 'success' => $response,
+ 'status' => Actions::get_sync_status(),
);
}
@@ -310,8 +319,7 @@ class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoi
return new WP_Error( 'invalid_queue', 'Queue name should be sync or full_sync', 400 );
}
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php';
- $queue = new Jetpack_Sync_Queue( $args['queue'] );
+ $queue = new Queue( $args['queue'] );
// False means that there was no lock to delete.
$response = $queue->unlock();
@@ -320,3 +328,36 @@ class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoi
);
}
}
+
+class Jetpack_JSON_API_Sync_Object_Id_Range extends Jetpack_JSON_API_Sync_Endpoint {
+ protected function result() {
+ $args = $this->query_args();
+
+ $module_name = $args['sync_module'];
+ $batch_size = $args['batch_size'];
+
+ if ( ! $this->is_valid_sync_module( $module_name ) ) {
+ return new WP_Error( 'invalid_module', 'This sync module cannot be used to calculate a range.', 400 );
+ }
+
+ $module = Modules::get_module( $module_name );
+
+ return array(
+ 'ranges' => $module->get_min_max_object_ids_for_batches( $batch_size ),
+ );
+ }
+
+ protected function is_valid_sync_module( $module_name ) {
+ return in_array(
+ $module_name,
+ array(
+ 'comments',
+ 'posts',
+ 'terms',
+ 'term_relationships',
+ 'users',
+ ),
+ true
+ );
+ }
+}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
index c3cec3d3..5c69b4dd 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
@@ -3,6 +3,8 @@
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/file.php';
+use Automattic\Jetpack\Connection\Client;
+
class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
// POST /sites/%s/themes/%s/install
@@ -160,7 +162,7 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
$url = "themes/download/$theme.zip";
$args = array( 'stream' => true, 'filename' => $file );
- $result = Jetpack_Client::wpcom_json_api_request_as_blog( $url, '1.1', $args );
+ $result = Client::wpcom_json_api_request_as_blog( $url, '1.1', $args );
$response = $result[ 'response' ];
if ( $response[ 'code' ] !== 200 ) {
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
index b30597de..366f5ff7 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Connection\Utils as Connection_Utils;
+
class Jetpack_JSON_API_User_Connect_Endpoint extends Jetpack_JSON_API_Endpoint {
protected $needed_capabilities = 'create_users';
@@ -8,7 +10,7 @@ class Jetpack_JSON_API_User_Connect_Endpoint extends Jetpack_JSON_API_Endpoint {
private $user_token;
function result() {
- Jetpack::update_user_token( $this->user_id, sprintf( '%s.%d', $this->user_token, $this->user_id ), false );
+ Connection_Utils::update_user_token( $this->user_id, sprintf( '%s.%d', $this->user_token, $this->user_id ), false );
return array( 'success' => Jetpack::is_user_connected( $this->user_id ) );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
index bd71249b..1a45b317 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Constants;
+
class Jetpack_JSON_API_User_Create_Endpoint extends Jetpack_JSON_API_Endpoint {
protected $needed_capabilities = 'create_users';
@@ -34,7 +36,7 @@ class Jetpack_JSON_API_User_Create_Endpoint extends Jetpack_JSON_API_Endpoint {
$query_args = $this->query_args();
if ( isset( $query_args['invite_accepted'] ) && $query_args['invite_accepted'] ) {
- Jetpack_Constants::set_constant( 'JETPACK_INVITE_ACCEPTED', true );
+ Constants::set_constant( 'JETPACK_INVITE_ACCEPTED', true );
}
if ( ! $user ) {
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
index 3a76256f..b261f202 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Sync\Defaults;
+
class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
protected $needed_capabilities = 'manage_options';
@@ -22,7 +24,6 @@ class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
}
$this->site_option = isset( $query_args['site_option'] ) ? $query_args['site_option'] : false;
- require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-defaults.php';
/**
* Filter the list of options that are manageable via the JSON API.
*
@@ -33,7 +34,7 @@ class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
* @param array The default list of site options.
* @param bool Is the option a site option.
*/
- if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Jetpack_Sync_Defaults::$default_options_whitelist, $this->site_option ) ) ) {
+ if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ) ) ) {
return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
}
return true;
diff --git a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
index a7fd2acd..7c7c76f1 100644
--- a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
+++ b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
@@ -455,34 +455,43 @@ new Jetpack_JSON_API_Sync_Endpoint( array(
) );
// GET /sites/%s/sync/status
-new Jetpack_JSON_API_Sync_Status_Endpoint( array(
- 'description' => 'Status of the current full sync or the previous full sync',
- 'method' => 'GET',
- 'path' => '/sites/%s/sync/status',
- 'stat' => 'sync-status',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'started' => '(int|null) The unix timestamp when the last sync started',
- 'queue_finished' => '(int|null) The unix timestamp when the enqueuing was done for the last sync',
- 'send_started' => '(int|null) The unix timestamp when the last sent process started',
- 'finished' => '(int|null) The unix timestamp when the last sync finished',
- 'total' => '(array) Count of actions that could be sent',
- 'queue' => '(array) Count of actions that have been added to the queue',
- 'sent' => '(array) Count of actions that have been sent',
- 'config' => '(array) Configuration of the last full sync',
- 'queue_size' => '(int) Number of items in the sync queue',
- 'queue_lag' => '(float) Time delay of the oldest item in the sync queue',
- 'queue_next_sync' => '(float) Time in seconds before trying to sync again',
- 'full_queue_size' => '(int) Number of items in the full sync queue',
- 'full_queue_lag' => '(float) Time delay of the oldest item in the full sync queue',
- 'full_queue_next_sync' => '(float) Time in seconds before trying to sync the full sync queue again',
- 'cron_size' => '(int) Size of the current cron array',
- 'next_cron' => '(int) The number of seconds till the next item in cron.',
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/status'
-) );
+new Jetpack_JSON_API_Sync_Status_Endpoint(
+ array(
+ 'description' => 'Status of the current full sync or the previous full sync',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/sync/status',
+ 'stat' => 'sync-status',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'query_parameters' => array(
+ 'fields' => '(string|null) List of comma-separated fields to return (see `response_format`).',
+ ),
+ 'response_format' => array(
+ 'posts_checksum' => '(string|null) Posts checksum. Needs to be requested using the filter parameter.',
+ 'comments_checksum' => '(string|null) Comments checksum. Needs to be requested using the filter parameter.',
+ 'post_meta_checksum' => '(string|null) Post Meta checksum. Needs to be requested using the filter parameter.',
+ 'comment_meta_checksum' => '(string|null) Comment Meta checksum. Needs to be requested using the filter parameter.',
+ 'started' => '(int|null) The unix timestamp when the last sync started',
+ 'queue_finished' => '(int|null) The unix timestamp when the enqueuing was done for the last sync',
+ 'send_started' => '(int|null) The unix timestamp when the last send process started',
+ 'finished' => '(int|null) The unix timestamp when the last sync finished',
+ 'total' => '(array) Count of actions that could be sent',
+ 'queue' => '(array) Count of actions that have been added to the queue',
+ 'sent' => '(array) Count of actions that have been sent',
+ 'config' => '(array) Configuration of the last full sync',
+ 'queue_size' => '(int) Number of items in the sync queue',
+ 'queue_lag' => '(float) Time delay of the oldest item in the sync queue',
+ 'queue_next_sync' => '(float) Time in seconds before trying to sync again',
+ 'full_queue_size' => '(int) Number of items in the full sync queue',
+ 'full_queue_lag' => '(float) Time delay of the oldest item in the full sync queue',
+ 'full_queue_next_sync' => '(float) Time in seconds before trying to sync the full sync queue again',
+ 'cron_size' => '(int) Size of the current cron array',
+ 'next_cron' => '(int) The number of seconds till the next item in cron.',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/status',
+ )
+);
// GET /sites/%s/data-checksums
@@ -547,6 +556,8 @@ $sync_settings_response = array(
'sync_via_cron' => '(int|bool=false) Set to 1 or true to avoid using cron for sync.',
'cron_sync_time_limit' => '(int|bool=false) Limit cron jobs to number of seconds',
'enqueue_wait_time' => '(int|bool=false) Wait time in seconds between attempting to continue a full sync, via requests',
+ 'sync_sender_enabled' => '(int|bool=false) Set to 1 or true to enable the default sender for the incremental queue.',
+ 'full_sync_sender_enabled' => '(int|bool=false) Set to 1 or true to enable the default sender for the "full sync" queue.',
);
// GET /sites/%s/sync/settings
@@ -638,6 +649,26 @@ new Jetpack_JSON_API_Sync_Unlock_Endpoint( array(
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/unlock'
) );
+// GET /sites/%s/sync/object-id-range
+new Jetpack_JSON_API_Sync_Object_Id_Range( array(
+ 'description' => 'Gets minimum and maximum object ids for each batch of given batch size.',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/sync/object-id-range',
+ 'group' => '__do_not_document',
+ 'stat' => 'sync-object-id-range',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain'
+ ),
+ 'query_parameters' => array(
+ 'batch_size' => '(int=1000) The amount of objects per batch.',
+ 'sync_module' => '(string=posts) The sync module used to enumerate the ranges.',
+ ),
+ 'response_format' => array(
+ 'ranges' => '(array) An array of range objects with min and max properties for each batch.',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/object-id-range?batch_size=100&sync_module=comments'
+) );
+
// POST /sites/%s/sync/checkout
new Jetpack_JSON_API_Sync_Checkout_Endpoint( array(
'description' => 'Locks the queue and returns items and the buffer ID.',
@@ -653,6 +684,7 @@ new Jetpack_JSON_API_Sync_Checkout_Endpoint( array(
'number_of_items' => '(int=10) Maximum number of items from the queue to be returned',
'encode' => '(bool=true) Use the default encode method',
'force' => '(bool=false) Force unlock the queue',
+ 'pop' => '(bool=false) Pop from the queue without checkout, use carefully 😱',
),
'response_format' => array(
'buffer_id' => '(string) Buffer ID that we are using',
@@ -1052,8 +1084,9 @@ new Jetpack_JSON_API_Get_Post_Backup_Endpoint( array(
'$post' => '(int) The post ID',
),
'response_format' => array(
- 'post' => '(array) Post table row',
- 'meta' => '(array) Associative array of key/value postmeta data',
+ 'post' => '(array) Post table row',
+ 'meta' => '(array) Associative array of key/value postmeta data',
+ 'terms' => '(array) List of terms attached to the post object',
),
'example_request_data' => array(
'headers' => array(
@@ -1232,3 +1265,57 @@ new Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint( array(
'example_response' => '{ "success": true }',
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jps/woo-connect'
) );
+
+// POST /sites/%s/install-backup-helper-script
+require_once( $json_jetpack_endpoints_dir . 'class-jetpack-json-api-install-backup-helper-script-endpoint.php' );
+new Jetpack_JSON_API_Install_Backup_Helper_Script_Endpoint( array(
+ 'description' => 'Setup a Helper Script, to allow Jetpack Backup to connect to this site',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'stat' => 'install-backup-helper-script',
+ 'path' => '/sites/%s/install-backup-helper-script',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'helper' => '(string) Base64-encoded Helper Script contents',
+ ),
+ 'response_format' => array(
+ 'abspath' => '(string) WordPress install path',
+ 'path' => '(string) Path of the helper script',
+ 'url' => '(string) URL to access the helper script',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/install-backup-helper-script'
+) );
+
+// POST /sites/%s/delete-backup-helper-script
+require_once( $json_jetpack_endpoints_dir . 'class-jetpack-json-api-delete-backup-helper-script-endpoint.php' );
+new Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint( array(
+ 'description' => 'Delete a Helper Script',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'stat' => 'delete-backup-helper-script',
+ 'path' => '/sites/%s/delete-backup-helper-script',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Deleted the Helper Script successfully?'
+ ),
+ 'request_format' => array(
+ 'path' => '(string) Path to Helper Script to delete',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/delete-backup-helper-script'
+) );