| | 948 | /** |
| | 949 | * Send upgrade WP_Error data to WordPress.org. |
| | 950 | * |
| | 951 | * @since 5.7.0 |
| | 952 | * |
| | 953 | * @global string $wp_version The WordPress version string. |
| | 954 | * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
| | 955 | * @param WP_Error $result WP_Error data from failed upgrade process. |
| | 956 | * @param int $start_time Time that run() started. |
| | 957 | * @param string $method Name of method sending data. |
| | 958 | * |
| | 959 | * @return void |
| | 960 | */ |
| | 961 | public function send_error_data( $result, $start_time, $method = null ) { |
| | 962 | global $wp_version, $wp_filesystem; |
| | 963 | |
| | 964 | if ( ! is_wp_error( $result ) ) { |
| | 965 | return; |
| | 966 | } |
| | 967 | $stats = array( |
| | 968 | 'process' => $method, |
| | 969 | 'update_type' => null, |
| | 970 | 'name' => null, |
| | 971 | 'update_version' => null, |
| | 972 | 'success' => false, |
| | 973 | 'fs_method' => $wp_filesystem->method, |
| | 974 | 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ), |
| | 975 | 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', |
| | 976 | 'time_taken' => time() - $start_time, |
| | 977 | 'wp_version' => $wp_version, |
| | 978 | 'error_code' => $result->get_error_code(), |
| | 979 | 'error_message' => $result->get_error_message(), |
| | 980 | 'error_data' => $result->get_error_data(), |
| | 981 | ); |
| | 982 | if ( $this instanceof Plugin_Upgrader ) { |
| | 983 | if ( isset( $this->skin->plugin_info ) ) { |
| | 984 | $stats['update_type'] = 'manual_plugin_update'; |
| | 985 | $stats['name'] = $this->skin->plugin_info['Name']; |
| | 986 | $stats['update_version'] = $this->skin->plugin_info['Version']; |
| | 987 | } else { |
| | 988 | $stats['update_type'] = 'automatic_plugin_update'; |
| | 989 | } |
| | 990 | wp_update_plugins( $stats ); |
| | 991 | } |
| | 992 | if ( $this instanceof Theme_Upgrader ) { |
| | 993 | if ( isset( $this->skin->theme_info )) { |
| | 994 | $stats['update_type'] = 'manual_theme_update'; |
| | 995 | $stats['name'] = $this->skin->theme_info->get('Name'); |
| | 996 | $stats['update_version'] = $this->skin->theme_info->get('Version'); |
| | 997 | } else { |
| | 998 | $stats['update_type'] = 'automatic_theme_update'; |
| | 999 | } |
| | 1000 | wp_update_themes( $stats ); |
| | 1001 | } |
| | 1002 | } |
| | 1003 | |
| | 1004 | /** |
| | 1005 | * Copy the plugin/theme being upgraded into a rollback directory. |
| | 1006 | * |
| | 1007 | * @uses 'upgrader_pre_install' filter. |
| | 1008 | * |
| | 1009 | * @param bool $true Boolean response to 'upgrader_pre_install' filter. |
| | 1010 | * Default is true. |
| | 1011 | * @param array $hook_extra Array of data for plugin/theme being updated. |
| | 1012 | * |
| | 1013 | * @return bool |
| | 1014 | */ |
| | 1015 | public function zip_to_rollback_dir( $true, $hook_extra ) { |
| | 1016 | global $wp_filesystem; |
| | 1017 | $rollback_dir = WP_CONTENT_DIR . '/upgrade/rollback/'; |
| | 1018 | $type = key( $hook_extra ); |
| | 1019 | $slug = 'plugin' === $type ? dirname( $hook_extra['plugin'] ) : $hook_extra['theme']; |
| | 1020 | $src = 'plugin' === $type ? WP_PLUGIN_DIR . "/{$slug}" : get_theme_root(). "/{$slug}"; |
| | 1021 | if ( $wp_filesystem->mkdir( $rollback_dir ) ) { |
| | 1022 | $path_prefix = strlen( $src ) + 1; |
| | 1023 | $zip = new ZipArchive(); |
| | 1024 | |
| | 1025 | if ( true === $zip->open( "{$rollback_dir}{$slug}.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) { |
| | 1026 | $files = new RecursiveIteratorIterator( |
| | 1027 | new RecursiveDirectoryIterator( $src ), |
| | 1028 | RecursiveIteratorIterator::LEAVES_ONLY |
| | 1029 | ); |
| | 1030 | |
| | 1031 | foreach ( $files as $name => $file ) { |
| | 1032 | // Skip directories (they would be added automatically). |
| | 1033 | if ( ! $file->isDir() ) { |
| | 1034 | // Get real and relative path for current file. |
| | 1035 | $file_path = $file->getRealPath(); |
| | 1036 | $relative_path = substr( $file_path, $path_prefix ); |
| | 1037 | |
| | 1038 | // Add current file to archive. |
| | 1039 | $zip->addFile( $file_path, $relative_path ); |
| | 1040 | } |
| | 1041 | } |
| | 1042 | |
| | 1043 | $zip->close(); |
| | 1044 | } |
| | 1045 | } |
| | 1046 | |
| | 1047 | return $true; |
| | 1048 | } |