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

Jetpack: check for other plugins before uninstall cleanup. #33920

Merged
merged 8 commits into from
Nov 3, 2023
Merged
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: minor
Type: added

Add a method to check if Jetpack is ready for uninstall cleanup.
2 changes: 1 addition & 1 deletion projects/packages/connection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.58.x-dev"
"dev-trunk": "1.59.x-dev"
}
},
"config": {
Expand Down
14 changes: 14 additions & 0 deletions projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2558,4 +2558,18 @@ public static function get_site_id() {
}
return (int) $site_id;
}

/**
* Check if Jetpack is ready for uninstall cleanup.
*
* @param string $current_plugin_slug The current plugin's slug.
*
* @return bool
*/
public static function is_ready_for_cleanup( $current_plugin_slug ) {
$active_plugins = get_option( Plugin_Storage::ACTIVE_PLUGINS_OPTION_NAME );

return empty( $active_plugins ) || ! is_array( $active_plugins )
|| ( count( $active_plugins ) === 1 && array_key_exists( $current_plugin_slug, $active_plugins ) );
}
}
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '1.58.3';
const PACKAGE_VERSION = '1.59.0-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
42 changes: 42 additions & 0 deletions projects/packages/connection/tests/php/test_Manager_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,46 @@ public function test_disconnect_site_will_remove_tracked_package_versions() {
public function filter_api_constant( $value, $name ) {
return constant( __NAMESPACE__ . "\Utils::DEFAULT_$name" );
}

/**
* Test the `is_ready_for_cleanup()` method with the negative result (has other connected plugins).
*
* @return void
*/
public function test_is_ready_for_cleanup_no() {
$option_filter = function () {
return array(
'jetpack-backup' => array(
'name' => 'Jetpack Backup',
),
);
};

add_filter( 'pre_option_jetpack_connection_active_plugins', $option_filter );
$is_ready = Manager::is_ready_for_cleanup( 'jetpack' );
remove_filter( 'pre_option_jetpack_connection_active_plugins', $option_filter );

$this->assertFalse( $is_ready );
}

/**
* Test the `is_ready_for_cleanup()` method with the positive result (no other connected plugins).
*
* @return void
*/
public function test_is_ready_for_cleanup_yes() {
$option_filter = function () {
return array(
'jetpack' => array(
'name' => 'Jetpack',
),
);
};

add_filter( 'pre_option_jetpack_connection_active_plugins', $option_filter );
$is_ready = Manager::is_ready_for_cleanup( 'jetpack' );
remove_filter( 'pre_option_jetpack_connection_active_plugins', $option_filter );

$this->assertTrue( $is_ready );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/backup/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/boost/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/inspect/composer.lock

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: compat

Do not cleanup options on plugin uninstall if there are other connected plugins to let them stay connected.
4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

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

6 changes: 6 additions & 0 deletions projects/plugins/jetpack/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Automattic\Jetpack\Backup\Helper_Script_Manager;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Sync\Sender;

/**
Expand All @@ -27,6 +28,11 @@ function jetpack_uninstall() {

require JETPACK__PLUGIN_DIR . 'vendor/autoload_packages.php';

if ( method_exists( Connection_Manager::class, 'is_ready_for_cleanup' ) && ! Connection_Manager::is_ready_for_cleanup( dirname( plugin_basename( __FILE__ ) ) ) ) {
// There are other active Jetpack plugins, no need for cleanup.
return;
}

Jetpack_Options::delete_all_known_options();

// Delete all legacy options.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/migration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"automattic/jetpack-autoloader": true,
"automattic/jetpack-composer-plugin": true
},
"autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_migrationⓥ1_0_1"
"autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_migrationⓥ1_0_2_alpha"
}
}
4 changes: 2 additions & 2 deletions projects/plugins/migration/composer.lock

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

2 changes: 1 addition & 1 deletion projects/plugins/migration/wpcom-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Move to WordPress.com
* Plugin URI: https://wordpress.org/plugins/wpcom-migration
* Description: A WordPress plugin that helps users to migrate their sites to WordPress.com.
* Version: 1.0.1
* Version: 1.0.2-alpha
* Author: Automattic
* Author URI: https://wordpress.com/
* License: GPLv2 or later
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/protect/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/search/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/social/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/starter-plugin/composer.lock

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,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/videopress/composer.lock

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

Loading