diff --git a/Console/Command/RemoveMediaDuplicates.php b/Console/Command/RemoveMediaDuplicates.php index 06ec41a..308ff5f 100644 --- a/Console/Command/RemoveMediaDuplicates.php +++ b/Console/Command/RemoveMediaDuplicates.php @@ -60,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ->addFilterByDuplicates(); $removedImages = []; + $totalSize = 0; /** @var Image $image */ foreach ($imageCollection as $image) { @@ -72,13 +73,18 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $removedImages[] = $duplicateImage; + $totalSize += $duplicateImage->getFileSize(); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); } } $output->writeln( - sprintf('Number of images successfully removed: %d', count($removedImages)) + sprintf( + 'Number of images successfully removed: %d with size of %.2f MB', + count($removedImages), + $totalSize / 1024 / 1024 + ) ); return Cli::RETURN_SUCCESS; diff --git a/Model/Gallery/Image.php b/Model/Gallery/Image.php index 14da1a1..932113b 100644 --- a/Model/Gallery/Image.php +++ b/Model/Gallery/Image.php @@ -66,6 +66,26 @@ public function getPathInfo(): PathInfo ->setData($pathInfo); } + /** + * Retrieve image size + * + * @return int + * @throws FileSystemException + */ + public function getFileSize(): int + { + $absolutePath = $this->getAbsolutePath(); + + $fileSize = @filesize($absolutePath); + if (!$fileSize) { + throw new FileSystemException( + __('Cannot define filesize for the image by path %1', [$absolutePath]) + ); + } + + return $fileSize; + } + /** * Calculate hash for the image * diff --git a/Model/Gallery/ImageInterface.php b/Model/Gallery/ImageInterface.php index 405851c..b2abb40 100644 --- a/Model/Gallery/ImageInterface.php +++ b/Model/Gallery/ImageInterface.php @@ -23,6 +23,14 @@ public function getCatalogPath(): string; */ public function getPathInfo(): PathInfo; + /** + * Retrieve image size + * + * @return int + * @throws FileSystemException + */ + public function getFileSize(): int; + /** * Calculate hash for the image *