示例#1
0
 /**
  * @expectedException \Magento\Framework\Model\Exception
  * @expectedExceptionMessage File mediaDir/path is not readable
  */
 public function testCollectFileInfoNotReadable()
 {
     $content = 'content';
     $mediaDirectory = 'mediaDir';
     $relativePath = 'relativePath';
     $path = 'path';
     $this->dirMock->expects($this->once())->method('getRelativePath')->with($mediaDirectory . '/' . $path)->will($this->returnValue($relativePath));
     $this->dirMock->expects($this->once())->method('isFile')->with($relativePath)->will($this->returnValue(true));
     $this->dirMock->expects($this->once())->method('isReadable')->with($relativePath)->will($this->returnValue(false));
     $this->dirMock->expects($this->never())->method('readFile')->with($relativePath)->will($this->returnValue($content));
     $this->helper->collectFileInfo($mediaDirectory, $path);
 }
示例#2
0
 /**
  * Store file into database
  *
  * @param  string $filename
  * @return $this
  */
 public function saveFile($filename)
 {
     $fileInfo = $this->_mediaHelper->collectFileInfo($this->getMediaBaseDirectory(), $filename);
     $filePath = $fileInfo['directory'];
     $directory = $this->_directoryFactory->create()->loadByPath($filePath);
     if (!$directory->getId()) {
         $directory = $this->getDirectoryModel()->createRecursive($filePath);
     }
     $fileInfo['directory_id'] = $directory->getId();
     $this->_getResource()->saveFile($fileInfo);
     return $this;
 }
示例#3
0
 /**
  * Export files list in defined range
  *
  * @param  int $offset
  * @param  int $count
  * @return array|bool
  */
 public function exportFiles($offset = 0, $count = 1)
 {
     $slice = $this->collectData($offset, $count, 'files');
     if (!$slice) {
         return false;
     }
     $result = [];
     foreach ($slice as $fileName) {
         try {
             $fileInfo = $this->_mediaHelper->collectFileInfo($this->getMediaBaseDirectory(), $fileName);
         } catch (\Exception $e) {
             $this->_logger->critical($e);
             continue;
         }
         $result[] = $fileInfo;
     }
     return $result;
 }