コード例 #1
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @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
ファイル: S3.php プロジェクト: arkadedigital/magento2-s3
 public function saveFile($filename)
 {
     $file = $this->mediaHelper->collectFileInfo($this->getMediaBaseDirectory(), $filename);
     try {
         $this->client->putObject(['ACL' => 'public-read', 'Body' => $file['content'], 'Bucket' => $this->getBucket(), 'ContentType' => \GuzzleHttp\Psr7\mimetype_from_filename($file['filename']), 'Key' => $filename]);
     } catch (\Exception $e) {
     }
     return $this;
 }
コード例 #3
0
ファイル: Database.php プロジェクト: nja78/magento2
 /**
  * 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;
 }
コード例 #4
0
ファイル: File.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * 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;
 }