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

Plugin Install: Bump MC stat on success or fail. #21893

Merged
merged 4 commits into from
Nov 29, 2021
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
7 changes: 6 additions & 1 deletion projects/plugins/jetpack/_inc/lib/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

require_once 'class.jetpack-automatic-install-skin.php';

use Automattic\Jetpack\A8c_Mc_Stats;

/**
* Plugins management tools.
*/
Expand Down Expand Up @@ -41,7 +43,6 @@ public static function install_and_activate_plugin( $slug ) {
if ( ! current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'not_allowed', __( 'You are not allowed to activate plugins on this site.', 'jetpack' ) );
}

$activated = activate_plugin( $plugin_id );
if ( is_wp_error( $activated ) ) {
return $activated;
Expand All @@ -67,10 +68,12 @@ public static function install_plugin( $slug ) {
$skin = new Jetpack_Automatic_Install_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$zip_url = self::generate_wordpress_org_plugin_download_link( $slug );
$mc_stats = new A8c_Mc_Stats();

$result = $upgrader->install( $zip_url );

if ( is_wp_error( $result ) ) {
$mc_stats->add( 'install-plugin', "fail-$slug" );
return $result;
}

Expand All @@ -92,9 +95,11 @@ public static function install_plugin( $slug ) {
$error_code = 'no_package';
}

$mc_stats->add( 'install-plugin', "fail-$slug" );
return new WP_Error( $error_code, $error, 400 );
}

$mc_stats->add( 'install-plugin', "success-$slug" );
return (array) $upgrader->skin->get_upgrade_messages();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Bump stat on plugin installs.