Skip to content

Commit

Permalink
Added size of the found image duplicates to the reports
Browse files Browse the repository at this point in the history
  • Loading branch information
elevinskii committed Mar 4, 2024
1 parent 6a9d9db commit 7556bec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Console/Command/RemoveMediaDuplicates.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->addFilterByDuplicates();

$removedImages = [];
$totalSize = 0;

/** @var Image $image */
foreach ($imageCollection as $image) {
Expand All @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions Model/Gallery/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions Model/Gallery/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 7556bec

Please sign in to comment.