Skip to content
Draft
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
Comment: Follow the Backup namespace version bump from V0005 to V0006; no user-facing change.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use Exception;
use WP_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

/**
* Manage installation, deletion and cleanup of Helper Scripts to assist with backing up Jetpack Sites.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use Exception;
use Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use Exception;
use WorDBless\BaseTestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use Exception;
use PHPUnit\Framework\TestCase;
Expand Down
2 changes: 0 additions & 2 deletions projects/packages/backup/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
return [
// # Issue statistics:
// PhanTypeMismatchReturnProbablyReal : 7 occurrences
// PhanTypeMismatchReturn : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-jetpack-backup.php' => ['PhanTypeMismatchReturn'],
'src/class-rest-controller.php' => ['PhanTypeMismatchReturnProbablyReal'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
8 changes: 4 additions & 4 deletions projects/packages/backup/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
}

// Clean up expired Helper Scripts from a scheduled event.
$add_action( 'jetpack_backup_cleanup_helper_scripts', array( 'Automattic\\Jetpack\\Backup\\V0005\\Helper_Script_Manager', 'cleanup_expired_helper_scripts' ) );
$add_action( 'jetpack_backup_cleanup_helper_scripts', array( 'Automattic\\Jetpack\\Backup\\V0006\\Helper_Script_Manager', 'cleanup_expired_helper_scripts' ) );

// Register REST routes.
$add_action( 'rest_api_init', array( 'Automattic\\Jetpack\\Backup\\V0005\\REST_Controller', 'register_rest_routes' ) );
$add_action( 'rest_api_init', array( 'Automattic\\Jetpack\\Backup\\V0006\\REST_Controller', 'register_rest_routes' ) );

// Set up package version hook.
$add_filter( 'jetpack_package_versions', 'Automattic\\Jetpack\\Backup\\Package_Version::send_package_version_to_tracker' );
Expand All @@ -42,10 +42,10 @@ static function () {
if ( ! apply_filters( 'jetpack_wp_abilities_enabled', false ) ) {
return;
}
if ( ! class_exists( \Automattic\Jetpack\Backup\V0005\Abilities\Backup_Abilities::class ) ) {
if ( ! class_exists( \Automattic\Jetpack\Backup\V0006\Abilities\Backup_Abilities::class ) ) {
return;
}
\Automattic\Jetpack\Backup\V0005\Abilities\Backup_Abilities::init();
\Automattic\Jetpack\Backup\V0006\Abilities\Backup_Abilities::init();
},
20
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: removed

Remove the `backup-capabilities`, `has-backup-plan`, `site/current-purchases` and `site/dismissed-review-request` REST routes. Only the legacy dashboard called them.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @package automattic/jetpack-backup
*/

namespace Automattic\Jetpack\Backup\V0005\Abilities;
namespace Automattic\Jetpack\Backup\V0006\Abilities;

use Automattic\Jetpack\Backup\V0005\Jetpack_Backup;
use Automattic\Jetpack\Backup\V0006\Jetpack_Backup;
use Automattic\Jetpack\My_Jetpack\Products\Backup as My_Jetpack_Backup;
use Automattic\Jetpack\WP_Abilities\Registrar;
use WP_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use function get_option;
use function update_option;
Expand Down
146 changes: 3 additions & 143 deletions projects/packages/backup/src/class-jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
Expand Down Expand Up @@ -173,7 +173,7 @@ public static function initialize( array $options = array() ) {
$options = array_merge( self::DEFAULT_INIT_OPTIONS, $options );

add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ) );
add_action( 'rest_api_init', array( \Automattic\Jetpack\Backup\V0005\REST\Rest_Controller::class, 'register_routes' ) );
add_action( 'rest_api_init', array( \Automattic\Jetpack\Backup\V0006\REST\Rest_Controller::class, 'register_routes' ) );
add_filter( 'jetpack_activity_log_restore_url_template', array( __CLASS__, 'activity_log_restore_url_template' ) );
add_filter( 'jetpack_activity_log_backup_url_template', array( __CLASS__, 'activity_log_backup_url_template' ) );

Expand Down Expand Up @@ -401,28 +401,6 @@ public static function register_rest_routes() {
)
);

// Get site backup/scan/anti-spam capabilities.
register_rest_route(
'jetpack/v4',
'/backup-capabilities',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => __CLASS__ . '::get_backup_capabilities',
'permission_callback' => __CLASS__ . '::backups_permissions_callback',
)
);

// Get whether the site has a backup plan
register_rest_route(
'jetpack/v4',
'/has-backup-plan',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => __CLASS__ . '::get_backup_plan_state',
'permission_callback' => __CLASS__ . '::backups_permissions_callback',
)
);

// Get site rewind data.
register_rest_route(
'jetpack/v4',
Expand All @@ -434,19 +412,6 @@ public static function register_rest_routes() {
)
);

// Get information on site products.
// Backup plugin version of /site/purchases from JP plugin.
// Revert once this route and MyPlan component are extracted to a common package.
register_rest_route(
'jetpack/v4',
'/site/current-purchases',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => __CLASS__ . '::get_site_current_purchases',
'permission_callback' => __CLASS__ . '::backups_permissions_callback',
)
);

// Get currently promoted product from the product's endpoint.
register_rest_route(
'jetpack/v4',
Expand All @@ -458,34 +423,6 @@ public static function register_rest_routes() {
)
);

// Get and set value of dismissed_backup_review_request option
register_rest_route(
'jetpack/v4',
'/site/dismissed-review-request',
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => __CLASS__ . '::manage_dismissed_backup_review_request',
'permission_callback' => __CLASS__ . '::backups_permissions_callback',
'args' => array(
'option_name' => array(
'required' => true,
'type' => 'string',
// The two names `Jetpack_Options` recognises. Anything else
// falls through its allowlist to a `trigger_error()` and is
// stored nowhere, so an unlisted reason would dismiss
// nothing while answering as though it had — and on a site
// with `display_errors` on, the warning is printed ahead of
// the JSON and the response no longer parses.
'enum' => array( 'restore', 'backups' ),
),
'should_dismiss' => array(
'required' => true,
'type' => 'boolean',
),
),
)
);

// Get site size
register_rest_route(
'jetpack/v4',
Expand Down Expand Up @@ -718,36 +655,6 @@ public static function has_backup_plan() {
return ! is_wp_error( $state ) && $state;
}

/**
* Get an array of backup/scan/anti-spam site capabilities
*
* @access public
* @static
*
* @return \WP_REST_Response|WP_Error The site capabilities, or a WP_Error if WordPress.com could not be reached.
*/
public static function get_backup_capabilities() {
$blog_id = Jetpack_Options::get_option( 'id' );

$response = Client::wpcom_json_api_request_as_user(
'/sites/' . $blog_id . '/rewind/capabilities',
'v2',
array(),
null,
'wpcom'
);

$response_code = (int) wp_remote_retrieve_response_code( $response );

if ( 200 !== $response_code ) {
return self::get_failed_fetch_error( $response );
}

return rest_ensure_response(
json_decode( $response['body'], true )
);
}

/**
* Get information about recent restores
*
Expand Down Expand Up @@ -936,53 +843,6 @@ public static function jetpack_check_user_licenses( $has_license, $licenses, $pl
return $license_found && ! static::has_backup_plan();
}

/**
* Returns the result of `/upgrades` endpoint call.
*
* @return \WP_REST_Response|WP_Error The site purchases, or a WP_Error if WordPress.com could not be reached.
*/
public static function get_site_current_purchases() {

$request = sprintf( '/upgrades?site=%d', Jetpack_Options::get_option( 'id' ) );
$response = Client::wpcom_json_api_request_as_blog( $request, '1.2' );

// Bail if there was an error or malformed response.
if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
return self::get_failed_fetch_error( $response );
}

$response_code = (int) wp_remote_retrieve_response_code( $response );

if ( 200 !== $response_code ) {
return self::get_failed_fetch_error( $response );
}

return rest_ensure_response(
json_decode( $response['body'], true )
);
}

/**
* Set value of the dismissed_backup_review_request Jetack option.
* Get value if should_dismiss is false
*
* @access public
* @static
* @param array $request arguments should_dismiss and option_name.
* @return bool value of option if value is requested | updated or not if value is updated.
*/
public static function manage_dismissed_backup_review_request( $request ) {

if ( ! $request['should_dismiss'] ) {

return rest_ensure_response(
Jetpack_Options::get_option( 'dismissed_backup_review_' . $request['option_name'] )
);
}

return Jetpack_Options::update_option( 'dismissed_backup_review_' . $request['option_name'], true );
}

/**
* Get site storage size
*
Expand Down Expand Up @@ -1222,7 +1082,7 @@ public static function render_connection_initial_state() {
. wp_json_encode(
array(
'activityLogUrl' => self::get_activity_log_url(),
'knownThreatsAvailable' => \Automattic\Jetpack\Backup\V0005\REST\Restore_Bridge::known_threats_available(),
'knownThreatsAvailable' => \Automattic\Jetpack\Backup\V0006\REST\Restore_Bridge::known_threats_available(),
),
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_json_encode() with JSON_HEX_* flags is safe in a script tag.
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// order to ensure that the specific version of this file always get loaded. Otherwise, Jetpack autoloader might decide
// to load an older/newer version of the class (if, for example, both the standalone and bundled versions of the plugin
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0005;
namespace Automattic\Jetpack\Backup\V0006;

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Rest_Authentication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Connection\Client;
use WP_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Connection\Client;
use WP_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Connection\Client;
use WP_Error;
Expand Down Expand Up @@ -41,8 +41,7 @@ public static function register_routes() {
* Proxy `/sites/{id}/rewind/capabilities` (v2, as_user) and project
* the response into the shape the React layer expects.
*
* This is the same endpoint the legacy `/jetpack/v4/backup-capabilities`
* route hits — it returns a flat `{ capabilities: [...] }` envelope.
* This endpoint returns a flat `{ capabilities: [...] }` envelope.
* The earlier `/rewind?force=wpcom` variant returns site *state*, not
* a capabilities list, and on some plan shapes (e.g. Jetpack Complete)
* the `capabilities` key is missing entirely, which produced a false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Connection\Client;
use WP_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Connection\Client;
use WP_Error;
Expand Down
4 changes: 2 additions & 2 deletions projects/packages/backup/src/rest/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* @package automattic/jetpack-backup-plugin
*/

namespace Automattic\Jetpack\Backup\V0005\REST;
namespace Automattic\Jetpack\Backup\V0006\REST;

use Automattic\Jetpack\Backup\V0005\Jetpack_Backup;
use Automattic\Jetpack\Backup\V0006\Jetpack_Backup;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Jetpack_Options;
use WP_Error;
Expand Down
Loading
Loading