cap340 / cleanmedia Goto Github PK
View Code? Open in Web Editor NEWMagento 2 CLI Command : remove images of deleted product in the /media/catalog/product folder
Magento 2 CLI Command : remove images of deleted product in the /media/catalog/product folder
Counting the file size $size += $file->getSize();
occurs after the file is deleted $this->driverFile->deleteFile($file);
, which leads to an error: SplFileInfo::getSize(): stat failed for /some/path/some_image.jpg
vendor/cap/cleanmedia/Console/Command/CleanMedia.php:118-137
/** @var SplFileInfo $file */
foreach ($iterator as $file) {
if ($isNoCache) {
if (strpos($file, "/cache") !== false) {
continue;
}
}
$filename = $file->getFilename();
if (!in_array($filename, $inDb)) {
$fileRelativePath = str_replace($mediaPath, '', $file->getPathname());
if (!$isDryRun) {
$output->writeln('<comment>REMOVING: </comment>' . $fileRelativePath);
$this->driverFile->deleteFile($file);
} else {
$output->writeln('<comment>DRY-RUN: </comment>' . $fileRelativePath);
}
$count++;
$size += $file->getSize();
}
}
Hi. When running your script I get:
In ErrorHandler.php line 61:
Warning: filesize(): stat failed for myfolder/public_html/pub/media//catalog/product/image/321437726/. in myfolderpublic_html/app/code/Cap/CleanMedia/Console/Command/CleanMedia.php on line 108
And script stops. Can you help please?
magento 2.3.1 version
As I checked further this /321437726/ is empty...
Hi,
I just submitted your module to Packagist so it's available via Composer, do you want to do it yourself so it's related to your account?
Thanks for your work :)
Hi,
Is it possible to run the command in cron? I'm wondering how the prompts (Continue? [Yes/No] for example) will react if I'm running it in cron or background.
Any advice?
Thanks!
Hi,
It would be nice to have an option to limit the number of files the command browses. I just runned it on a Magento with 5M+ files and the NFS server is running down.
Maybe something like php bin/magento cap:clean:media --limit=XXX
.
Every time I try to run it, it warns me I have to run it with dryrun, and will not just delete things.
Please advise.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.