From 9a75cec842ce801a3c043a135d9c14de69aa7894 Mon Sep 17 00:00:00 2001 From: Moon Date: Mon, 11 Sep 2023 15:14:12 -0700 Subject: [PATCH] Record plugin api and install failures to coreprofiler_install_plugin_error track (#39899) * Record plugin api and install failures to coreprofiler_install_plugin_error track * Add changefile(s) from automation for the following project(s): woocommerce * Change to trigger GH jobs --------- Co-authored-by: github-actions --- ...lugin-failure-separately-for-core-profiler | 4 ++ .../src/Admin/API/OnboardingPlugins.php | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 plugins/woocommerce/changelog/update-39699-track-plugin-failure-separately-for-core-profiler diff --git a/plugins/woocommerce/changelog/update-39699-track-plugin-failure-separately-for-core-profiler b/plugins/woocommerce/changelog/update-39699-track-plugin-failure-separately-for-core-profiler new file mode 100644 index 00000000000..417f520081b --- /dev/null +++ b/plugins/woocommerce/changelog/update-39699-track-plugin-failure-separately-for-core-profiler @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Records plugin API requests and installation errors to coreprofiler_install_plugin_error separately for the core profiler. diff --git a/plugins/woocommerce/src/Admin/API/OnboardingPlugins.php b/plugins/woocommerce/src/Admin/API/OnboardingPlugins.php index 4a4b5f44c95..e1b0b0f48f0 100644 --- a/plugins/woocommerce/src/Admin/API/OnboardingPlugins.php +++ b/plugins/woocommerce/src/Admin/API/OnboardingPlugins.php @@ -148,6 +148,9 @@ class OnboardingPlugins extends WC_REST_Data_Controller { true ); } + + add_action( 'woocommerce_plugins_install_error', array( $this, 'log_plugins_install_error' ), 10, 4 ); + add_action( 'woocommerce_plugins_install_api_error', array( $this, 'log_plugins_install_api_error' ), 10, 2 ); } /** @@ -411,4 +414,41 @@ class OnboardingPlugins extends WC_REST_Data_Controller { ), ); } + + public function log_plugins_install_error( $slug, $api, $result, $upgrader ) { + $properties = array( + 'error_message' => sprintf( + /* translators: %s: plugin slug (example: woocommerce-services) */ + __( + 'The requested plugin `%s` could not be installed.', + 'woocommerce' + ), + $slug + ), + 'type' => 'plugin_info_api_error', + 'slug' => $slug, + 'api_version' => $api->version, + 'api_download_link' => $api->download_link, + 'upgrader_skin_message' => implode( ',', $upgrader->skin->get_upgrade_messages() ), + 'result' => is_wp_error( $result ) ? $result->get_error_message() : 'null', + ); + wc_admin_record_tracks_event( 'coreprofiler_install_plugin_error', $properties ); + } + + public function log_plugins_install_api_error( $slug, $api ) { + $properties = array( + 'error_message' => sprintf( + // translators: %s: plugin slug (example: woocommerce-services). + __( + 'The requested plugin `%s` could not be installed. Plugin API call failed.', + 'woocommerce' + ), + $slug + ), + 'type' => 'plugin_install_error', + 'api_error_message' => $api->get_error_message(), + 'slug' => $slug, + ); + wc_admin_record_tracks_event( 'coreprofiler_install_plugin_error', $properties ); + } }