baldwin-agency / magento2-module-image-cleanup

Magento 2 module which can cleanup old image files that are no longer being used
MIT License
54 stars 4 forks source link

The custom webp file extension is not being excluded. #3

Closed hgati closed 1 year ago

hgati commented 1 year ago

I am saving images with a .ngx.webp file extension as dynamic images. I have named nginx-related webp images as .ngx.webp in order to control webp images in nginx. This is because there are also manually uploaded files with the .webp extension, and I need to distinguish them so that I can later delete only the nginx-related webp files. So, I have configured it as follows to exclude ngx.webp, but it doesn't seem to be excluded.

The Result.

hostep commented 1 year ago

This probably happens because instead of replacing the .jpg file extension with .ngx.webp, it gets appended, so it becomes .jpg.ngx.webp.

Do you have the opportunity to remove .jpg from the filename? I have the suspicion that the module won't delete those files anymore after doing so.

Alternatively, we could try to change this piece of code from:

            foreach ($alternativeExtensions as $ext) {
                $extraFiles[] = $fileWithoutExtension . '.' . $ext;
            }

to:

            foreach ($alternativeExtensions as $ext) {
                $extraFiles[] = $fileWithoutExtension . '.' . $ext;
                $extraFiles[] = $filename . '.' . $ext;
            }

That might also solve your problem.

Would you be able to find some time to test this?

hgati commented 1 year ago

It gets appended as follows.

hostep commented 1 year ago

Okay, so this change fixes it in your case? It no longer tries to delete those images now?

I don't think there are downsides to this fix. So if you can confirm, I'll add this fix in a new version a bit later this week.

hgati commented 1 year ago

Okay, so this change fixes it in your case? It no longer tries to delete those images now?

I don't think there are downsides to this fix. So if you can confirm, I'll add this fix in a new version a bit later this week.

I will back up over 7,000 images from the live server to the local development server, test them, and let you know the results.

hgati commented 1 year ago

Okay, It has been deleted as expected.

Continue with the deletion of these [y/N]?

Cleaned up 18 files, was able to cleanup

hostep commented 1 year ago

Fix for this was released in version 1.2.2.

Thanks for reporting this case and confirming the fix!