_filesystemStorage = $filesystemStorage; $this->_coreFileStorageDb = $coreFileStorageDb; $this->_storage = $storage; parent::__construct($context); } /** * Return saved storage code * * @return int */ public function getCurrentStorageCode() { if ($this->_currentStorage === null) { $this->_currentStorage = (int)$this->scopeConfig->getValue( \Magento\MediaStorage\Model\File\Storage::XML_PATH_STORAGE_MEDIA, 'default' ); } return $this->_currentStorage; } /** * Retrieve file system storage model * * @return \Magento\MediaStorage\Model\File\Storage\File */ public function getStorageFileModel() { return $this->_filesystemStorage; } /** * Check if storage is internal * * @param int|null $storage * @return bool */ public function isInternalStorage($storage = null) { $storage = $storage !== null ? (int)$storage : $this->getCurrentStorageCode(); return in_array($storage, $this->_internalStorageList); } /** * Retrieve storage model * * @param int|null $storage * @param array $params * @return \Magento\Framework\Model\AbstractModel|bool */ public function getStorageModel($storage = null, $params = []) { return $this->_storage->getStorageModel($storage, $params); } /** * Check if needed to copy file from storage to file system and * if file exists in the storage * * @param string $filename * @return bool|int */ public function processStorageFile($filename) { if ($this->isInternalStorage()) { return false; } $dbHelper = $this->_coreFileStorageDb; $relativePath = $dbHelper->getMediaRelativePath($filename); $file = $this->getStorageModel()->loadByFilename($relativePath); if (!$file->getId()) { return false; } return $this->saveFileToFileSystem($file); } /** * Save file to file system * * @param \Magento\MediaStorage\Model\File\Storage\Database $file * @return bool|int */ public function saveFileToFileSystem($file) { return $this->getStorageFileModel()->saveFile($file, true); } }