Пример #1
0
 /**
  * If DB file storage is on - find there, otherwise - just file_exists
  *
  * @param string $filename relative path
  * @return bool
  */
 protected function _isFile($filename)
 {
     if ($this->_fileStorageHelper->checkDbUsage() && !$this->getMediaDirectory()->isFile($filename)) {
         $this->_fileStorageHelper->saveFileToFilesystem($filename);
     }
     return $this->getMediaDirectory()->isFile($filename);
 }
Пример #2
0
 /**
  * @param array $optionValue
  * @return void
  */
 protected function initFilePath($optionValue)
 {
     /**
      * @see \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::validate
      *              There setUserValue() sets correct fileFullPath only for
      *              quote_path. So we must form both full paths manually and
      *              check them.
      */
     $checkPaths = [];
     if (isset($optionValue['quote_path'])) {
         $checkPaths[] = $optionValue['quote_path'];
     }
     if (isset($optionValue['order_path']) && !$this->useQuotePath) {
         $checkPaths[] = $optionValue['order_path'];
     }
     foreach ($checkPaths as $path) {
         if (!$this->rootDirectory->isFile($path)) {
             if (!$this->coreFileStorageDatabase->saveFileToFilesystem($path)) {
                 continue;
             }
         }
         $this->fileFullPath = $this->rootDirectory->getAbsolutePath($path);
         $this->fileRelativePath = $path;
         break;
     }
 }
Пример #3
0
 /**
  * If DB file storage is on - find there, otherwise - just file_exists
  *
  * @param string $filename relative file path
  * @return bool
  */
 protected function checkIsFile($filename)
 {
     if ($this->fileStorageDatabase->checkDbUsage() && !$this->mediaDirectory->isFile($filename)) {
         $this->fileStorageDatabase->saveFileToFilesystem($filename);
     }
     return $this->mediaDirectory->isFile($filename);
 }
Пример #4
0
 /**
  * Check if file exist in filesystem and try to re-create it from database record if negative.
  * @param string $file
  * @return bool|int
  */
 public function ensureFileInFilesystem($file)
 {
     $result = true;
     if (!$this->_mediaDirectory->isFile($file)) {
         $result = $this->_coreFileStorageDatabase->saveFileToFilesystem($file);
     }
     return $result;
 }
Пример #5
0
 /**
  * @param bool $expected
  * @param int $storage
  * @param int $callNum
  * @param int $id
  * @param int $callSaveFile
  * @dataProvider saveFileToFileSystemDataProvider
  */
 public function testSaveFileToFileSystem($expected, $storage, $callNum, $id = 0, $callSaveFile = 0)
 {
     $this->configMock->expects($this->once())->method('getValue')->with(\Magento\MediaStorage\Model\File\Storage::XML_PATH_STORAGE_MEDIA, 'default')->will($this->returnValue($storage));
     $dbModelMock = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\Storage\\Database')->disableOriginalConstructor()->getMock();
     $this->dbStorageFactoryMock->expects($this->exactly($callNum))->method('create')->will($this->returnValue($dbModelMock));
     $dbModelMock->expects($this->exactly($callNum))->method('loadByFilename')->with('filename')->will($this->returnSelf());
     $dbModelMock->expects($this->exactly($callNum))->method('getId')->will($this->returnValue($id));
     $dbModelMock->expects($this->exactly($callSaveFile))->method('getData')->will($this->returnValue(['data']));
     $this->fileStorageMock->expects($this->exactly($callSaveFile))->method('saveFile')->will($this->returnValue(true));
     $this->assertEquals($expected, $this->helper->saveFileToFilesystem('media-dir/filename'));
 }
Пример #6
0
 /**
  * First check this file on FS
  * If it doesn't exist - try to download it from DB
  *
  * @param string $filename
  * @return bool
  */
 protected function _fileExists($filename)
 {
     if ($this->_mediaDirectory->isFile($filename)) {
         return true;
     } else {
         return $this->_coreFileStorageDatabase->saveFileToFilesystem($this->_mediaDirectory->getAbsolutePath($filename));
     }
 }