Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Unable to instantiate the catalog import uploader with $filePath set #51

@piotrekkaminski

Description

@piotrekkaminski

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions