From @brideo on October 13, 2016 0:45
Preconditions
- Magento 2.0.x or 2.1.0 is installed CE or EE
- Module is setup with class and
Magento\CatalogImportExport\Model\Import\UploaderFactory in the construct
Steps to reproduce
- Using the factory pattern you instantiate the class
Magento\CatalogImportExport\Model\Import\Uploader with $filePath defined
Actual and Expected result
- Exception is thrown because
$this->_directory is not set
- Class should be instantiated
Additional information
So there is a bug in this class:
Magento\CatalogImportExport\Model\Import\Uploader:
I am using this and instantiating it within my own class like so:
/**
* Importer constructor.
*
* @param Config\File $file
*/
public function __construct(File $file, UploaderFactory $uploaderFactory) {
$this->uploader = $uploaderFactory->create(['filePath' => $file->getFilePath()]);
}
The __construct of Magento\CatalogImportExport\Model\Import\Uploader looks like this:
public function __construct(
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb,
\Magento\MediaStorage\Helper\File\Storage $coreFileStorage,
\Magento\Framework\Image\AdapterFactory $imageFactory,
\Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $validator,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Filesystem\File\ReadFactory $readFactory,
$filePath = null
) {
if ($filePath !== null) {
$this->_setUploadFile($filePath);
}
$this->_imageFactory = $imageFactory;
$this->_coreFileStorageDb = $coreFileStorageDb;
$this->_coreFileStorage = $coreFileStorage;
$this->_validator = $validator;
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$this->_readFactory = $readFactory;
}
You can see that the _setUploadFile method is called which uses $this->_directory which has not been set yet, unless I'm missing something.
Cheers!
Copied from original issue: magento/magento2#6981
From @brideo on October 13, 2016 0:45
Preconditions
Magento\CatalogImportExport\Model\Import\UploaderFactoryin the constructSteps to reproduce
Magento\CatalogImportExport\Model\Import\Uploaderwith$filePathdefinedActual and Expected result
$this->_directoryis not setAdditional information
So there is a bug in this class:
Magento\CatalogImportExport\Model\Import\Uploader:I am using this and instantiating it within my own class like so:
The
__constructofMagento\CatalogImportExport\Model\Import\Uploaderlooks like this:You can see that the
_setUploadFilemethod is called which uses$this->_directorywhich has not been set yet, unless I'm missing something.Cheers!
Copied from original issue: magento/magento2#6981