Fix occurrences where Installer_Error exception is returned instead of being thrown (#43108)

* Fix occurrences where Installer_Error exception is returned instead of being thrown.

* Add changefile(s) from automation for the following project(s): woocommerce

* Add @throws tag in function comment.
This commit is contained in:
Denis Dvali 2024-01-04 02:59:08 +04:00 committed by GitHub
parent 70b22764a9
commit 280fe7cd51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix an error in plugin auto-installer triggered in certain installation failure scenarios.

View File

@ -50,6 +50,8 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
* Activate plugin.
*
* @param int $product_id Product ID.
* @return void
* @throws WC_REST_WCCOM_Site_Installer_Error If plugin activation failed.
*/
private function activate_plugin( $product_id ) {
// Clear plugins cache used in `WC_Helper::get_local_woo_plugins`.
@ -74,13 +76,13 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
}
if ( empty( $filename ) ) {
return new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
throw new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
}
$result = activate_plugin( $filename );
if ( is_wp_error( $result ) ) {
return new Installer_Error( Installer_Error_Codes::PLUGIN_ACTIVATION_ERROR, $result->get_error_message() );
throw new Installer_Error( Installer_Error_Codes::PLUGIN_ACTIVATION_ERROR, $result->get_error_message() );
}
}
@ -88,6 +90,8 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
* Activate theme.
*
* @param int $product_id Product ID.
* @return void
* @throws WC_REST_WCCOM_Site_Installer_Error If theme activation failed.
*/
private function activate_theme( $product_id ) {
// Clear plugins cache used in `WC_Helper::get_local_woo_themes`.
@ -112,7 +116,7 @@ class WC_WCCOM_Site_Installation_Step_Activate_Product implements WC_WCCOM_Site_
}
if ( empty( $theme_slug ) ) {
return new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
throw new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
}
switch_theme( $theme_slug );

View File

@ -114,7 +114,7 @@ class WC_WCCOM_Site_Installation_Step_Get_Product_Info implements WC_WCCOM_Site_
$updates = WC_Helper_Updater::get_update_data();
if ( empty( $updates[ $product_id ]['package'] ) ) {
return new Installer_Error( Installer_Error_Codes::WCCOM_PRODUCT_MISSING_PACKAGE );
throw new Installer_Error( Installer_Error_Codes::WCCOM_PRODUCT_MISSING_PACKAGE );
}
return $updates[ $product_id ]['package'];

View File

@ -33,13 +33,16 @@ class WC_WCCOM_Site_Installation_Step_Unpack_Product implements WC_WCCOM_Site_In
/**
* Run the step installation process.
*
* @return WC_WCCOM_Site_Installation_State
* @throws WC_REST_WCCOM_Site_Installer_Error If the package unpacked path is not returned.
*/
public function run() {
$upgrader = WC_WCCOM_Site_Installer::get_wp_upgrader();
$unpacked_path = $upgrader->unpack_package( $this->state->get_download_path(), true );
if ( empty( $unpacked_path ) ) {
return new Installer_Error( Installer_Error_Codes::MISSING_UNPACKED_PATH );
throw new Installer_Error( Installer_Error_Codes::MISSING_UNPACKED_PATH );
}
$this->state->set_unpacked_path( $unpacked_path );