Ticket #46707: 46707.3.diff
| File 46707.3.diff, 6.4 KB (added by , 7 years ago) |
|---|
-
src/wp-admin/includes/class-wp-debug-data.php
1135 1135 } 1136 1136 1137 1137 // Go through the various installation directories and calculate their sizes. 1138 $all_sizes = array( 1139 'wordpress_size' => array( 1140 'path' => ABSPATH, 1141 'size' => 0, 1142 ), 1143 'themes_size' => array( 1144 'path' => trailingslashit( get_theme_root() ), 1145 'size' => 0, 1146 ), 1147 'plugins_size' => array( 1148 'path' => trailingslashit( WP_PLUGIN_DIR ), 1149 'size' => 0, 1150 ), 1151 'uploads_size' => array( 1152 'path' => $upload_dir['basedir'], 1153 'size' => 0, 1154 ), 1138 $paths = array( 1139 'wordpress_size' => trailingslashit( ABSPATH ), 1140 'themes_size' => trailingslashit( get_theme_root() ), 1141 'plugins_size' => trailingslashit( WP_PLUGIN_DIR ), 1142 'uploads_size' => trailingslashit( $upload_dir['basedir'] ), 1155 1143 ); 1156 1144 1145 $exclude = $paths; 1146 unset( $exclude['wordpress_size'] ); 1147 // recurse_dirsize() expects untrailingslashed. 1148 $exclude = array_map( 'untrailingslashit', array_values( $exclude ) ); 1149 1157 1150 $size_total = 0; 1151 $all_sizes = array(); 1158 1152 1159 1153 // Loop over all the directories we want to gather the sizes for. 1160 foreach ( $ all_sizes as $name => $attributes) {1154 foreach ( $paths as $name => $path ) { 1161 1155 $dir_size = null; // Default to timeout. 1156 $results = array( 1157 'path' => $path, 1158 'raw' => 0, 1159 ); 1162 1160 1163 1161 if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) { 1164 $dir_size = recurse_dirsize( $attributes['path'], null, $max_execution_time ); 1162 if ( 'wordpress_size' === $name ) { 1163 $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time ); 1164 } else { 1165 $dir_size = recurse_dirsize( $path, null, $max_execution_time ); 1166 } 1165 1167 } 1166 1168 1167 1169 if ( false === $dir_size ) { 1168 1170 // Error reading. 1169 $ all_sizes[ $name ]['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );1170 $ all_sizes[ $name ]['debug'] = 'not accessible';1171 $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' ); 1172 $results['debug'] = 'not accessible'; 1171 1173 1172 1174 // Stop total size calculation. 1173 1175 $size_total = null; 1174 1176 } elseif ( null === $dir_size ) { 1175 1177 // Timeout. 1176 $ all_sizes[ $name ]['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );1177 $ all_sizes[ $name ]['debug'] = 'timeout while calculating size';1178 $results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' ); 1179 $results['debug'] = 'timeout while calculating size'; 1178 1180 1179 1181 // Stop total size calculation. 1180 1182 $size_total = null; 1181 1183 } else { 1182 $is_subdir = ( strpos( $attributes['path'], ABSPATH ) === 0 ); 1183 1184 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled 1185 if ( null !== $size_total && ( 'wordpress_size' === $name || ! $is_subdir ) ) { 1184 if ( null !== $size_total ) { 1186 1185 $size_total += $dir_size; 1187 1186 } 1188 1187 1189 $all_sizes[ $name ]['size'] = size_format( $dir_size, 2 ); 1190 $all_sizes[ $name ]['debug'] = $all_sizes[ $name ]['size']; 1188 $results['raw'] = $dir_size; 1189 $results['size'] = size_format( $dir_size, 2 ); 1190 $results['debug'] = $results['size'] . " ({$dir_size} bytes)"; 1191 1191 } 1192 1193 $all_sizes[ $name ] = $results; 1192 1194 } 1193 1195 1194 1196 if ( $size_db > 0 ) { … … 1195 1197 $database_size = size_format( $size_db, 2 ); 1196 1198 1197 1199 $all_sizes['database_size'] = array( 1200 'raw' => $size_db, 1198 1201 'size' => $database_size, 1199 'debug' => $database_size ,1202 'debug' => $database_size . " ({$size_db} bytes)", 1200 1203 ); 1201 1204 } else { 1202 1205 $all_sizes['database_size'] = array( … … 1206 1209 } 1207 1210 1208 1211 if ( null !== $size_total && $size_db > 0 ) { 1209 $total_size = size_format( $size_total + $size_db, 2 ); 1212 $total_size = $size_total + $size_db; 1213 $total_size_mb = size_format( $total_size, 2 ); 1210 1214 1211 1215 $all_sizes['total_size'] = array( 1212 'size' => $total_size, 1213 'debug' => $total_size, 1216 'raw' => $total_size, 1217 'size' => $total_size_mb, 1218 'debug' => $total_size_mb . " ({$total_size} bytes)", 1214 1219 ); 1215 1220 } else { 1216 1221 $all_sizes['total_size'] = array( -
src/wp-includes/functions.php
7067 7067 * @since 4.3.0 $exclude parameter added. 7068 7068 * @since 5.2.0 $max_execution_time parameter added. 7069 7069 * 7070 * @param string $directory Full path of a directory. 7071 * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. 7072 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7073 * The timeout is global and is measured from the moment WordPress started to load. 7074 * @return int|false|null Size in MB if a valid directory. False if not. Null if timeout. 7070 * @param string $directory Full path of a directory. 7071 * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths. 7072 * Expected without trailing slash(es). 7073 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7074 * The timeout is global and is measured from the moment WordPress started to load. 7075 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. 7075 7076 */ 7076 7077 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) { 7077 7078 $size = 0; … … 7078 7079 7079 7080 $directory = untrailingslashit( $directory ); 7080 7081 7081 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude) {7082 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) { 7082 7083 return false; 7083 7084 } 7084 7085 7086 if ( 7087 ( is_string( $exclude ) && $directory === $exclude ) || 7088 ( is_array( $exclude ) && in_array( $directory, $exclude, true ) ) 7089 ) { 7090 return false; 7091 } 7092 7085 7093 if ( $max_execution_time === null ) { 7086 7094 // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible. 7087 7095 if ( function_exists( 'ini_get' ) ) {