Skip to content

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

@brideo

Description

@brideo

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions