Vinai / nicer-image-names

Magento extension to build catalog image file names from product attributes so they have neat descriptive names.
77 stars 31 forks source link

empty filename in Magento 1.9.0.1 on category page #27

Closed luemic closed 8 years ago

luemic commented 8 years ago

Hi, I got the following issue with this extension in Magento version 1.9.0.1 the filename of the cached images is empty e.g.

mage.dev/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/m/s/msj000t_1/.jpg'

Kind regards

Michael

luemic commented 8 years ago

After some diggin I found that Netzarbeiter_NicerImageNames_Model_Image::setBaseFile($file) is the cause for the trouble.

Vinai commented 8 years ago

In what way? What is your file name template configuration? What is the original file name?

luemic commented 8 years ago

I could reproduce the issue with the default configuration on a standard Magento 1.9.0.1 and the base configuration of the module. I Think it's related to

// Check that generated filename is not longer than 255
            $maxfilelen = 255;
            if (strlen(basename($file) . $extension) > $maxfilelen) {
                $file = substr($file, 0, ($maxfilelen - strlen($extension) + strlen(dirname($file))));
                $file = $file . '.' . $extension;
            }
Vinai commented 8 years ago

What OS are you running on? That code is so old, it has been running fine for me for years on OS X and CentOS at least.

luemic commented 8 years ago

OS is Ubuntu 14.04

Vinai commented 8 years ago

How deep is your directory tree? Maybe the directory path is already longer then 255 characters?

mikemanger commented 8 years ago

That code should just restrict the filename and not the full path.. there is another check just below that to restrict the directory (default max length of 1024) which I think is more likely to be the issue. Could you check what PHP_MAXPATHLEN is set to?

My fault for not doing those unit tests :8ball:

Vinai commented 8 years ago

Unfortunately the code in question is not covered by tests. I wrote the module before I started with those. Looking through the code, I must admit it is a mess.
Regarding your question though, PHP_MAXPATHLEN is set to 1024 on OS X and CentOS.

Note that the method \Netzarbeiter_NicerImageNames_Model_Image::setBaseFile() is actually executed twice. Once before \Netzarbeiter_NicerImageNames_Model_Image::$_niceCacheName is set, and once after.
The first time happens while \Mage_Catalog_Helper_Image::init() executes line 163.
The second time happens while \Mage_Catalog_Helper_Image::__toString() executes line 352.
In the first run the resulting image file name is indeed just a directory with only the file name extension. The second time the generated image name is set and used. Just something to keep in mind while debugging - you want to see the state during the second execution of \Netzarbeiter_NicerImageNames_Model_Image::setBaseFile(), because those are the values that end up being used.

luemic commented 8 years ago

Argh, someone installed a conflicting extension on the "clean" system, so the error occured on this system as well. Fixing the conflict fixed the empty images problem :). Sorry for any inconvenience.

Vinai commented 8 years ago

Thanks for the update, glad it's resolved!