Example #1
0
 /**
  * Check whether file to move exists. Getting unique name
  *
  * @param string $file
  * @param bool $forTmp
  * @return string
  */
 protected function getUniqueFileName($file, $forTmp = false)
 {
     if ($this->fileStorageDb->checkDbUsage()) {
         $destFile = $this->fileStorageDb->getUniqueFilename($this->mediaConfig->getBaseMediaUrlAddition(), $file);
     } else {
         $destinationFile = $forTmp ? $this->mediaDirectory->getAbsolutePath($this->mediaConfig->getTmpMediaPath($file)) : $this->mediaDirectory->getAbsolutePath($this->mediaConfig->getMediaPath($file));
         $destFile = dirname($file) . '/' . FileUploader::getNewFileName($destinationFile);
     }
     return $destFile;
 }
Example #2
0
 /**
  * Get filename which is not duplicated with other files in media temporary and media directories
  *
  * @param string $fileName
  * @param string $dispretionPath
  * @return string
  */
 protected function _getNotDuplicatedFilename($fileName, $dispretionPath)
 {
     $fileMediaName = $dispretionPath . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName($this->_mediaConfig->getMediaPath($fileName));
     $fileTmpMediaName = $dispretionPath . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName($this->_mediaConfig->getTmpMediaPath($fileName));
     if ($fileMediaName != $fileTmpMediaName) {
         if ($fileMediaName != $fileName) {
             return $this->_getNotDuplicatedFileName($fileMediaName, $dispretionPath);
         } elseif ($fileTmpMediaName != $fileName) {
             return $this->_getNotDuplicatedFilename($fileTmpMediaName, $dispretionPath);
         }
     }
     return $fileMediaName;
 }
Example #3
0
 /**
  * move image from tmp to catalog dir
  *
  * @param string $file
  * @return string path
  */
 public function moveImageFromTmp($file)
 {
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destinationFile = $this->getUniqueFileName($file);
     /** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
     $storageHelper = $this->fileStorageDb;
     if ($storageHelper->checkDbUsage()) {
         $storageHelper->renameFile($this->mediaConfig->getTmpMediaShortUrl($file), $this->mediaConfig->getMediaShortUrl($destinationFile));
         $this->mediaDirectory->delete($this->mediaConfig->getTmpMediaPath($file));
         $this->mediaDirectory->delete($this->getAttributeSwatchPath($destinationFile));
     } else {
         $this->mediaDirectory->renameFile($this->mediaConfig->getTmpMediaPath($file), $this->getAttributeSwatchPath($destinationFile));
     }
     return str_replace('\\', '/', $destinationFile);
 }