composer require swiftotter/image-import-path-fix
php bin/magento module:enable SwiftOtter_ImageImportPathFix
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Where to begin on this one? This bug fix is for Magento 2.1.2 (latest as of 1/9/17). Nginx and MySQL. Folder structure is a little different
than normal, so that may account for why this bug wasn't found sooner. Nginx is pointed to
Folder structure: * current > symlinked to: /path/to/releases/release-2 * link * media * import * catalog * product * var * log * report * releases * release-1 * app * pub * index.php * media > symlinked to: link/media * ... * var > symlinked to: link/var * release-2 * app * pub * index.php * media > symlinked to: link/media * ... * var > symlinked to: link/var
The root issue is inconsistent handling of the
Magento's initial file is
cwd for this file is
/path/to/releases/release-2/pub/. However, a feature of
\Magento\Framework\Filesystem\Directory\ReadInterface->getAbsolutePath() is that it removes
/pub from the path structure.
This works well, until trying to use relative paths in combination with vanilla PHP functions, such as
There are two facets: the
tmp directory (where the files are coming from) and the
dest directory (where the files are going to).
Both have unique challenges.
tmp directory comes from the "Images File Directory". Magento strips out the reference to
pub/ at the end. As the
is inside the
pub folder, it is unclear as to how to reference this folder. The patch deals with this by providing an additional lookup path.
I am not sure if this was also causing issues, but the
tmp directory was relative and not absolute. This caused problems for the
directory, so I have patched the
tmp as well.
This was home to another inconsistency. When creating / setting the folder in
the paths are initially checked as absolute paths. However, when it is used in
validateDestination() is called. Inside this function is the use of
is_writable() with a relative path.
My solution is to make the destination file be absolute. This seems to fix the problem and should work with any environment.