コード例 #1
0
ファイル: Image.php プロジェクト: shabbirvividads/magento2
 /**
  * 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;
 }
コード例 #2
0
 /**
  * @param string $localFilePath
  * @return string
  */
 protected function appendNewFileName($localFilePath)
 {
     $destinationFile = $this->appendAbsoluteFileSystemPath($localFilePath);
     $fileName = Uploader::getNewFileName($destinationFile);
     $fileInfo = pathinfo($localFilePath);
     return $fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileName;
 }