Merge pull request #25140 from bgrgicak/update/wccom-6777
Return folder_exists error as success
This commit is contained in:
commit
c6b2581a0c
|
@ -15,6 +15,13 @@ defined( 'ABSPATH' ) || exit;
|
|||
*/
|
||||
class WC_WCCOM_Site_Installer {
|
||||
|
||||
/**
|
||||
* Error message returned install_package if the folder already exists.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $folder_exists = 'folder_exists';
|
||||
|
||||
/**
|
||||
* Default state.
|
||||
*
|
||||
|
@ -240,6 +247,7 @@ class WC_WCCOM_Site_Installer {
|
|||
case 'get_product_info':
|
||||
$state_steps[ $product_id ]['download_url'] = $result['download_url'];
|
||||
$state_steps[ $product_id ]['product_type'] = $result['product_type'];
|
||||
$state_steps[ $product_id ]['product_name'] = $result['product_name'];
|
||||
break;
|
||||
case 'download_product':
|
||||
$state_steps[ $product_id ]['download_path'] = $result;
|
||||
|
@ -249,6 +257,12 @@ class WC_WCCOM_Site_Installer {
|
|||
break;
|
||||
case 'move_product':
|
||||
$state_steps[ $product_id ]['installed_path'] = $result['destination'];
|
||||
if ( $result[ self::$folder_exists ] ) {
|
||||
$state_steps[ $product_id ]['warning'] = array(
|
||||
'message' => self::$folder_exists,
|
||||
'plugin_info' => self::get_plugin_info( $state_steps[ $product_id ]['installed_path'] ),
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -287,6 +301,7 @@ class WC_WCCOM_Site_Installer {
|
|||
$result = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
$product_info['product_type'] = $result['_product_type'];
|
||||
$product_info['product_name'] = $result['name'];
|
||||
|
||||
if ( ! empty( $result['_wporg_product'] ) && ! empty( $result['download_link'] ) ) {
|
||||
// For wporg product, download is set already from info response.
|
||||
|
@ -369,7 +384,18 @@ class WC_WCCOM_Site_Installer {
|
|||
),
|
||||
);
|
||||
|
||||
return $upgrader->install_package( $package );
|
||||
$result = $upgrader->install_package( $package );
|
||||
|
||||
/**
|
||||
* If install package returns error 'folder_exists' threat as success.
|
||||
*/
|
||||
if ( is_wp_error( $result ) && array_key_exists( self::$folder_exists, $result->errors ) ) {
|
||||
return array(
|
||||
self::$folder_exists => true,
|
||||
'destination' => $result->error_data[ self::$folder_exists ],
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -511,4 +537,41 @@ class WC_WCCOM_Site_Installer {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get plugin info
|
||||
*
|
||||
* @since 3.9.0
|
||||
* @param string $dir Directory name of the plugin.
|
||||
* @return bool|array
|
||||
*/
|
||||
private static function get_plugin_info( $dir ) {
|
||||
$plugin_folder = basename( $dir );
|
||||
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$plugins = get_plugins();
|
||||
|
||||
$related_plugins = array_filter(
|
||||
$plugins,
|
||||
function( $key ) use ( $plugin_folder ) {
|
||||
return strpos( $key, $plugin_folder . '/' ) === 0;
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
|
||||
if ( 1 === count( $related_plugins ) ) {
|
||||
$plugin_key = array_keys( $related_plugins )[0];
|
||||
$plugin_data = $plugins[ $plugin_key ];
|
||||
return array(
|
||||
'name' => $plugin_data['Name'],
|
||||
'version' => $plugin_data['Version'],
|
||||
'active' => is_plugin_active( $plugin_key ),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue