Skip to content

Commit

Permalink
Backup: Add next daily backup schedule time (#39914)
Browse files Browse the repository at this point in the history
* Set up react-query, moment and typescript

* changelog

* Add endpoint to fetch site backup schedule time

* Setup react-query (queryClientProvider)

* Add useScheduledTimeQuery hook to fetch schedule time

* Add hook to parse and return the next backup schedule time

* Add component to render the next scheduled backup message

* Fix record Tracks event

* Removing changelog for migration and core plugin

* Bump `Automattic\Jetpack\Backup` namespace to V0005

* changelog

* Bump `Automattic\Jetpack\Transport_Helper` to V0005

* Remove `between` to make `Modify` fit in the same line

* Fix pnpm lock
  • Loading branch information
Initsogar authored Nov 12, 2024
1 parent 62d88f4 commit a512d13
Show file tree
Hide file tree
Showing 36 changed files with 420 additions and 34 deletions.
118 changes: 116 additions & 2 deletions pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Backup: added next daily backup schedule time on admin page
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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

/**
* 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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use Exception;
use Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use Exception;
use WorDBless\BaseTestCase;
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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use Exception;
use PHPUnit\Framework\TestCase;
Expand Down
4 changes: 2 additions & 2 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\\V0004\\Helper_Script_Manager', 'cleanup_expired_helper_scripts' ) );
$add_action( 'jetpack_backup_cleanup_helper_scripts', array( 'Automattic\\Jetpack\\Backup\\V0005\\Helper_Script_Manager', 'cleanup_expired_helper_scripts' ) );

// Register REST routes.
$add_action( 'rest_api_init', array( 'Automattic\\Jetpack\\Backup\\V0004\\REST_Controller', 'register_rest_routes' ) );
$add_action( 'rest_api_init', array( 'Automattic\\Jetpack\\Backup\\V0005\\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' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Backup: added next daily backup schedule time on admin page
4 changes: 4 additions & 0 deletions projects/packages/backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
"@automattic/jetpack-api": "workspace:*",
"@automattic/jetpack-components": "workspace:*",
"@automattic/jetpack-connection": "workspace:*",
"@tanstack/react-query": "5.20.5",
"@wordpress/api-fetch": "7.11.0",
"@wordpress/components": "28.11.0",
"@wordpress/data": "10.11.0",
"@wordpress/date": "5.11.0",
"@wordpress/element": "6.11.0",
"@wordpress/i18n": "5.11.0",
"moment": "2.29.4",
"prop-types": "^15.8.1",
"react": "18.3.1",
"react-dom": "18.3.1"
Expand All @@ -51,12 +53,14 @@
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.0.1",
"@testing-library/user-event": "14.5.2",
"@types/react": "18.3.3",
"@wordpress/browserslist-config": "6.11.0",
"concurrently": "7.6.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"sass": "1.64.1",
"sass-loader": "12.4.0",
"typescript": "5.0.4",
"webpack": "5.94.0",
"webpack-cli": "4.9.1"
}
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-initial-state.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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use Automattic\Jetpack\Connection\Plugin_Storage as Connection_Plugin_Storage;
use Automattic\Jetpack\Status;
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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use function get_option;
use function update_option;
Expand Down
40 changes: 38 additions & 2 deletions projects/packages/backup/src/class-jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
// 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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Backup\V0004\Initial_State as Backup_Initial_State;
use Automattic\Jetpack\Backup\V0005\Initial_State as Backup_Initial_State;
use Automattic\Jetpack\Config;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
Expand Down Expand Up @@ -341,6 +341,17 @@ public static function register_rest_routes() {
)
);

// Get backup schedule time
register_rest_route(
'jetpack/v4',
'/site/backup/schedule',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => __CLASS__ . '::get_site_backup_schedule_time',
'permission_callback' => __CLASS__ . '::backups_permissions_callback',
)
);

// Get site policies
register_rest_route(
'jetpack/v4',
Expand Down Expand Up @@ -785,6 +796,31 @@ public static function enqueue_backup() {
);
}

/**
* Get site backup schedule time
*
* @return string|WP_Error A JSON object with the backup schedule time if the request was successful, or a WP_Error otherwise.
*/
public static function get_site_backup_schedule_time() {
$blog_id = Jetpack_Options::get_option( 'id' );

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

if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return null;
}

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

/**
* Removes plugin from the connection manager
* If it's the last plugin using the connection, the site will be disconnected.
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\V0004;
namespace Automattic\Jetpack\Backup\V0005;

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Rest_Authentication;
Expand Down
Loading

0 comments on commit a512d13

Please sign in to comment.