Example #1
0
 /**
  * @param int $storage
  * @param int $callNum
  * @dataProvider updateFileDataProvider
  */
 public function testCopyFile($storage, $callNum)
 {
     $this->configMock->expects($this->once())->method('getValue')->with(\Magento\Core\Model\File\Storage::XML_PATH_STORAGE_MEDIA, 'default')->will($this->returnValue($storage));
     $dbModelMock = $this->getMockBuilder('Magento\\Core\\Model\\File\\Storage\\Database')->disableOriginalConstructor()->getMock();
     $this->dbStorageFactoryMock->expects($this->exactly($callNum))->method('create')->will($this->returnValue($dbModelMock));
     $dbModelMock->expects($this->exactly($callNum))->method('copyFile')->with('oldName', 'newName');
     $this->helper->copyFile('media-dir/oldName', 'media-dir/newName');
 }
Example #2
0
 /**
  * Move file from tmp path to base path
  *
  * @param string $baseTmpPath
  * @param string $basePath
  * @param string $file
  * @return string
  */
 protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
 {
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = dirname($file) . '/' . \Magento\Core\Model\File\Uploader::getNewFileName($this->getFilePath($basePath, $file));
     $this->_coreFileStorageDatabase->copyFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     $this->_mediaDirectory->renameFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     return str_replace('\\', '/', $destFile);
 }
Example #3
0
 /**
  * Quote item to order item copy process
  *
  * @return $this
  */
 public function copyQuoteToOrder()
 {
     $quoteOption = $this->getConfigurationItemOption();
     try {
         $value = unserialize($quoteOption->getValue());
         if (!isset($value['quote_path'])) {
             throw new \Exception();
         }
         $quotePath = $value['quote_path'];
         $orderPath = $value['order_path'];
         if (!$this->_rootDirectory->isFile($quotePath) || !$this->_rootDirectory->isReadable($quotePath)) {
             throw new \Exception();
         }
         $this->_coreFileStorageDatabase->copyFile($this->_rootDirectory->getAbsolutePath($quotePath), $this->_rootDirectory->getAbsolutePath($orderPath));
     } catch (\Exception $e) {
         return $this;
     }
     return $this;
 }
Example #4
0
 /**
  * Copy image and return new filename.
  *
  * @param string $file
  * @return string
  * @throws Exception
  */
 protected function _copyImage($file)
 {
     try {
         $destinationFile = $this->_getUniqueFileName($file);
         if (!$this->_mediaDirectory->isFile($this->_mediaConfig->getMediaPath($file))) {
             throw new \Exception();
         }
         if ($this->_fileStorageDb->checkDbUsage()) {
             $this->_fileStorageDb->copyFile($this->_mediaDirectory->getAbsolutePath($this->_mediaConfig->getMediaShortUrl($file)), $this->_mediaConfig->getMediaShortUrl($destinationFile));
             $this->_mediaDirectory->delete($this->_mediaConfig->getMediaPath($destinationFile));
         } else {
             $this->_mediaDirectory->copyFile($this->_mediaConfig->getMediaPath($file), $this->_mediaConfig->getMediaPath($destinationFile));
         }
         return str_replace('\\', '/', $destinationFile);
     } catch (\Exception $e) {
         $file = $this->_mediaConfig->getMediaPath($file);
         throw new Exception(__('We couldn\'t copy file %1. Please delete media with non-existing images and try again.', $file));
     }
 }