/** * Move files from TMP folder into destination folder * * @param string $tmpPath * @param string $destPath * @return bool */ protected function _moveFile($tmpPath, $destPath) { if ($this->_directory->isFile($tmpPath)) { return $this->_directory->copyFile($tmpPath, $destPath); } else { return false; } }
/** * Duplicate temporary images * * @param string $file * @return string */ public function duplicateImageFromTmp($file) { $file = $this->getFilenameFromTmp($file); $destinationFile = $this->getUniqueFileName($file, true); if ($this->fileStorageDb->checkDbUsage()) { $this->fileStorageDb->copyFile($this->mediaDirectory->getAbsolutePath($this->mediaConfig->getTmpMediaShortUrl($file)), $this->mediaConfig->getTmpMediaShortUrl($destinationFile)); } else { $this->mediaDirectory->copyFile($this->mediaConfig->getTmpMediaPath($file), $this->mediaConfig->getTmpMediaPath($destinationFile)); } return str_replace('\\', '/', $destinationFile); }
/** * Move files from TMP folder into destination folder * * @param string $tmpPath * @param string $destPath * @return bool */ protected function _moveFile($tmpPath, $destPath) { if ($this->_directory->isFile($tmpPath)) { $tmpRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($tmpPath)); $destinationRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($destPath)); $isSameFile = $tmpRealPath === $destinationRealPath; return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath); } else { return false; } }
/** * Copy image and return new filename. * * @param string $file * @return string * @throws \Magento\Framework\Exception\LocalizedException */ 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 LocalizedException(__('We couldn\'t copy file %1. Please delete media with non-existing images and try again.', $file)); } }
/** * Create preview image duplicate * * @param ThemeInterface $theme * @return bool */ public function createPreviewImageCopy(ThemeInterface $theme) { $previewDir = $this->themeImagePath->getImagePreviewDirectory(); $sourcePath = $theme->getThemeImage()->getPreviewImagePath(); $sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath); if (!$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) { return false; } $isCopied = false; try { $destinationFileName = \Magento\Framework\File\Uploader::getNewFileName($sourcePath); $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName); $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory); $this->theme->setPreviewImage($destinationFileName); } catch (\Magento\Framework\Filesystem\FilesystemException $e) { $this->theme->setPreviewImage(null); $this->logger->critical($e); } return $isCopied; }
/** * Publish file * * @param WriteInterface $rootDir * @param WriteInterface $targetDir * @param string $sourcePath * @param string $destinationPath * @return bool */ public function publishFile(WriteInterface $rootDir, WriteInterface $targetDir, $sourcePath, $destinationPath) { return $rootDir->copyFile($sourcePath, $destinationPath, $targetDir); }