$base_dir ) ); } // Calculate directory size (with timeout protection). $size_data = static::get_directory_size( $base_dir ); $total_size = $size_data['size']; $file_count = $size_data['files']; $size_mb = $total_size / 1024 / 1024; $size_gb = $size_mb / 1024; $details = array( 'uploads_path' => $base_dir, 'total_size' => static::format_bytes( $total_size ), 'size_mb' => round( $size_mb, 2 ), 'file_count' => static::format_number( $file_count ), 'estimated' => $size_data['estimated'], ); if ( $size_data['estimated'] ) { $details['note'] = __( 'Size was estimated due to directory depth. Actual size may vary.', '0-day-analytics' ); } if ( $size_gb > 10 ) { return static::fail( 'medium', sprintf( /* translators: %s: uploads size */ __( 'Your uploads directory is %s. This will take a long time to transfer and may cause issues with some migration methods.', '0-day-analytics' ), static::format_bytes( $total_size ) ), __( 'For large media libraries, consider using rsync or SFTP instead of plugin-based migration. You could also exclude uploads and transfer them separately.', '0-day-analytics' ), $details ); } if ( $size_gb > 5 ) { return static::warning( sprintf( /* translators: 1: uploads size, 2: file count */ __( 'Your uploads directory is %1$s with about %2$s files. Plan for extended transfer time during migration.', '0-day-analytics' ), static::format_bytes( $total_size ), static::format_number( $file_count ) ), __( 'Consider compressing and transferring media separately, or using a migration tool that handles large file transfers in the background.', '0-day-analytics' ), $details ); } if ( $size_gb > 1 ) { return static::info( sprintf( /* translators: 1: uploads size, 2: file count */ __( 'Your uploads directory is %1$s with %2$s files. This is a moderate size that most migration tools can handle.', '0-day-analytics' ), static::format_bytes( $total_size ), static::format_number( $file_count ) ), $details ); } return static::pass( sprintf( /* translators: %s: uploads size */ __( 'Your uploads directory is %s, which is compact and will transfer quickly during migration.', '0-day-analytics' ), static::format_bytes( $total_size ) ), $details ); } /** * Calculate directory size with timeout protection. * * @param string $path Directory path. * @return array Size and file count data. * * @since 4.9.0 */ private static function get_directory_size( $path ) { $size = 0; $files = 0; $estimated = false; $max_depth = 10; $start = time(); $timeout = 10; // 10 second max. $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path, \RecursiveDirectoryIterator::SKIP_DOTS ), \RecursiveIteratorIterator::SELF_FIRST ); $iterator->setMaxDepth( $max_depth ); foreach ( $iterator as $file ) { // Check for timeout. if ( time() - $start > $timeout ) { $estimated = true; break; } if ( $file->isFile() ) { $size += $file->getSize(); ++$files; } } return array( 'size' => $size, 'files' => $files, 'estimated' => $estimated, ); } } }