Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan Checks: store less info locally and simplify logic #38937

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions projects/packages/plans/changelog/update-plan-check-storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Local plan info storage: truncate the data stored locally. Remove the "available" feature information as it is not used in our codebase.
2 changes: 1 addition & 1 deletion projects/packages/plans/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-plans",
"version": "0.4.7",
"version": "0.4.8-alpha",
"description": "Fetch information about Jetpack Plans from wpcom",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/plans/#readme",
"bugs": {
Expand Down
10 changes: 10 additions & 0 deletions projects/packages/plans/src/class-current-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ public static function update_from_sites_response( $response ) {
* @return bool Were the subscriptions successfully updated?
*/
private static function store_data_in_option( $option, $data ) {
/*
* The endpoint returns a big array of "available" features.
* We do not use it, so we truncate it before to save our local option.
*/
if ( 'jetpack_active_plan' === $option ) {
if ( isset( $data['features']['available'] ) ) {
unset( $data['features']['available'] );
}
}

$result = update_option( $option, $data, true );

// If something goes wrong with the update, so delete the current option and then update it.
Expand Down
123 changes: 3 additions & 120 deletions projects/packages/plans/tests/php/test-current-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,76 +155,18 @@ private function get_free_plan() {
'user_is_owner' => false,
'is_free' => true,
'features' => array(
'active' => array(
'active' => array(
'akismet',
'support',
),
'available' => array(
'akismet' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-backups' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-backup-archive' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-storage-space' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-automated-restores' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'simple-payments' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'support' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_personal',
'jetpack_premium_monthly',
'jetpack_business_monthly',
'jetpack_personal_monthly',
),
'premium-themes' => array(
'jetpack_business',
'jetpack_business_monthly',
),
'vaultpress-security-scanning' => array(
'jetpack_business',
'jetpack_business_monthly',
),
'polldaddy' => array(
'jetpack_business',
'jetpack_business_monthly',
),
),
),
);
}

private function get_changed_personal_plan() {
$changed_personal_plan = $this->get_personal_plan();

$changed_personal_plan['features']['available']['test_feature'] = array( 'jetpack_free' );
$changed_personal_plan['features']['active'][] = 'test_feature';
return $changed_personal_plan;
}

Expand All @@ -237,68 +179,9 @@ private function get_personal_plan() {
'user_is_owner' => false,
'is_free' => false,
'features' => array(
'active' => array(
'active' => array(
'support',
),
'available' => array(
'akismet' => array(
'jetpack_free',
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'support' => array(
'jetpack_free',
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
'jetpack_personal_monthly',
),
'vaultpress-backups' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-backup-archive' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-storage-space' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'vaultpress-automated-restores' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'simple-payments' => array(
'jetpack_premium',
'jetpack_business',
'jetpack_premium_monthly',
'jetpack_business_monthly',
),
'premium-themes' => array(
'jetpack_business',
'jetpack_business_monthly',
),
'vaultpress-security-scanning' => array(
'jetpack_business',
'jetpack_business_monthly',
),
'polldaddy' => array(
'jetpack_business',
'jetpack_business_monthly',
),
),
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-plan-check-storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Block Editor: consider all blocks to be available on WoA sites, to simplify logic and improve performance.
22 changes: 4 additions & 18 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,34 +1183,20 @@ private static function get_site_specific_features() {
public static function set_availability_for_plan( $slug ) {
$slug = self::remove_extension_prefix( $slug );

// Check if the block is available for the current plan.
if ( Jetpack_Plan::supports( $slug ) ) {
self::set_extension_available( $slug );
return;
}

// Check what's the minimum plan where the feature is available.
$plan = '';
$features_data = array();
$is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
$is_atomic_site = ( new Host() )->is_woa_site();

if ( $is_simple_site || $is_atomic_site ) {
// Simple sites.
if ( $is_simple_site ) {
$features_data = self::get_site_specific_features();
} else {
// Atomic sites.
$option = get_option( 'jetpack_active_plan' );
if ( isset( $option['features'] ) ) {
$features_data = $option['features'];
}
}

$plan = '';
if ( ( new Host() )->is_wpcom_simple() ) {
$features_data = self::get_site_specific_features();
if ( ! empty( $features_data['available'][ $slug ] ) ) {
$plan = $features_data['available'][ $slug ][0];
}
} else {
// Jetpack sites.
$plan = Jetpack_Plan::get_minimum_plan_for_feature( $slug );
}

Expand Down
Loading