Skip to content

Commit

Permalink
Site migration: change migration_status in sites endpoint to `site_…
Browse files Browse the repository at this point in the history
…migration` (#14716)

* Site migration: save migration meta option on target site, and return the data in sites endpoint

Summary:
In this patch, the migration manager saves a `site_migration_meta` option on the target site when a migration is failed or finished. This is an array containing the source blog ID, status and last modified timestamp of the migration.

The `/me/sites` endpoint returns this array in a `site_migration` element, replacing the `migration_status` value we've been returning up till now.

Test Plan:
* Apply the patch and sandbox the API.
* Sandbox the migration job by adding this to your `0-sandbox.php` file, and run the async job [[ https://fieldguide.automattic.com/asynchronous-jobs/testing-asynchronous-jobs-on-a-sandbox/ | watcher script ]].

```php
function sandbox_import_jobs( $sandboxed, $type ) {
	return in_array( $type, array(
		'wpcom_migrate_site_monitor',
	) );
}

add_filter( 'sandbox_async_job', 'sandbox_import_jobs', 10, 2 );
```

* Do a migration: run Calypso locally, go to `https://calypso.localhost:3000/migrate/[ TARGET SITE DOMAIN ]` and follow the steps.
* When the migration is complete, check the `site_migration_meta` option for the target site. It should contain the source blog ID, status and last modified timestamp for the migration.
* Go to the [[ https://[private link] | WordPress.com console ]] and make a request to `https://[private link].2/me/sites`.
* View the target site you've just migrated to. It should have a `site_migration` node with the same data.
* View a Simple site in the array. It should should have a `site_migration` node with a value of `false`.

Reviewers: #samus_team, biskobe

Reviewed By: #samus_team, biskobe

Subscribers: biskobe

Tags: #touches_jetpack_files

Differential Revision: D38929-code

This commit syncs r203001-wpcom.

* Update to site_migration in 1.2 endpoint

* Update e2e tests to match new value

Co-authored-by: Jeremy Herve <jeremy@tagada.hu>
  • Loading branch information
andfinally and jeherve authored Feb 18, 2020
1 parent 7a89807 commit 31e32f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions json-endpoints/class.wpcom-json-api-get-site-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
'meta' => '(object) Meta data',
'quota' => '(array) An array describing how much space a user has left for uploads',
'launch_status' => '(string) A string describing the launch status of a site',
'migration_status' => '(string) A string describing the migration status of the site.',
'site_migration' => '(array) Data about any migration into the site.',
'is_fse_active' => '(bool) If the site has Full Site Editing active or not.',
'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not',
);
Expand All @@ -75,7 +75,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
'is_following',
'meta',
'launch_status',
'migration_status',
'site_migration',
'is_fse_active',
'is_fse_eligible',
);
Expand Down Expand Up @@ -144,7 +144,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {

protected static $jetpack_response_field_additions = array(
'subscribers_count',
'migration_status',
'site_migration',
);

protected static $jetpack_response_field_member_additions = array(
Expand Down Expand Up @@ -391,8 +391,8 @@ protected function render_response_key( $key, &$response, $is_user_logged_in ) {
case 'launch_status' :
$response[ $key ] = $this->site->get_launch_status();
break;
case 'migration_status' :
$response[ $key ] = $this->site->get_migration_status();
case 'site_migration' :
$response[ $key ] = $this->site->get_migration_meta();
break;
case 'is_fse_active':
$response[ $key ] = $this->site->is_fse_active();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WPCOM_JSON_API_GET_Site_V1_2_Endpoint extends WPCOM_JSON_API_GET_Site_Endp
'meta' => '(object) Meta data',
'quota' => '(array) An array describing how much space a user has left for uploads',
'launch_status' => '(string) A string describing the launch status of a site',
'migration_status' => '(string) A string describing the migration status of the site.',
'site_migration' => '(array) Data about any migration into the site.',
'is_fse_active' => '(bool) If the site has Full Site Editing active or not.',
'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not',
);
Expand Down
4 changes: 2 additions & 2 deletions sal/class.json-api-site-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ function get_launch_status() {
return false;
}

function get_migration_status() {
return false;
function get_migration_meta() {
return null;
}

function get_site_segment() {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/lib/plan-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function getPlanData(
space_available: 2100373225472,
},
launch_status: false,
migration_status: 'inactive',
site_migration: null,
is_fse_active: false,
is_fse_eligible: false,
};
Expand Down

0 comments on commit 31e32f1

Please sign in to comment.