/** * Copy image and return new filename. * * @param string $file * @return string */ protected function _copyImage($file) { try { $destinationFile = $this->_getUniqueFileName($file); if (!$this->_filesystem->isFile($this->_getConfig()->getMediaPath($file), $this->_baseMediaPath)) { throw new Exception(); } if (Mage::helper('Mage_Core_Helper_File_Storage_Database')->checkDbUsage()) { Mage::helper('Mage_Core_Helper_File_Storage_Database')->copyFile($this->_getConfig()->getMediaShortUrl($file), $this->_getConfig()->getMediaShortUrl($destinationFile)); $this->_filesystem->delete($this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath); } else { $this->_filesystem->copy($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath); } return str_replace(DS, '/', $destinationFile); } catch (Exception $e) { $file = $this->_getConfig()->getMediaPath($file); Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Failed to copy file %s. Please, delete media with non-existing images and try again.', $file)); } }
/** * Quote item to order item copy process * * @return Mage_Catalog_Model_Product_Option_Type_File */ public function copyQuoteToOrder() { $quoteOption = $this->getConfigurationItemOption(); try { $value = unserialize($quoteOption->getValue()); if (!isset($value['quote_path'])) { throw new Exception(); } $quoteFileFullPath = Mage::getBaseDir() . $value['quote_path']; if (!$this->_filesystem->isFile($quoteFileFullPath) || !$this->_filesystem->isReadable($quoteFileFullPath)) { throw new Exception(); } $orderFileFullPath = Mage::getBaseDir() . $value['order_path']; $dir = pathinfo($orderFileFullPath, PATHINFO_DIRNAME); $this->_createWriteableDir($dir); Mage::helper('Mage_Core_Helper_File_Storage_Database')->copyFile($quoteFileFullPath, $orderFileFullPath); $this->_filesystem->copy($quoteFileFullPath, $orderFileFullPath); } catch (Exception $e) { return $this; } return $this; }
/** * Check, if requested theme file has public access, and move it to public folder, if the file has no public access * * @param string $themeFile * @param array $params * @return string * @throws Magento_Exception */ protected function _publishViewFile($themeFile, $params) { $themeFile = $this->_extractScope($themeFile, $params); $sourcePath = $this->getViewFile($themeFile, $params); $minifiedSourcePath = $this->_minifiedPathForStaticFiles($sourcePath); if ($minifiedSourcePath && !Mage::getIsDeveloperMode() && $this->_filesystem->has($minifiedSourcePath)) { $sourcePath = $minifiedSourcePath; $themeFile = $this->_minifiedPathForStaticFiles($themeFile); } if (!$this->_filesystem->has($sourcePath)) { throw new Magento_Exception("Unable to locate theme file '{$sourcePath}'."); } if (!$this->_needToProcessFile($sourcePath)) { return $sourcePath; } $allowPublication = (string) Mage::getConfig()->getNode(self::XML_PATH_ALLOW_DUPLICATION); if ($allowPublication || $this->_getExtension($themeFile) == self::CONTENT_TYPE_CSS) { $targetPath = $this->_buildPublicViewRedundantFilename($themeFile, $params); } else { $targetPath = $this->_buildPublicViewSufficientFilename($sourcePath, $params); $this->_setPublicFileIntoCache($themeFile, $params, $targetPath); } $targetPath = $this->_buildPublicViewFilename($targetPath); /* Validate whether file needs to be published */ if ($this->_getExtension($themeFile) == self::CONTENT_TYPE_CSS) { $cssContent = $this->_getPublicCssContent($sourcePath, dirname($targetPath), $themeFile, $params); } $fileMTime = $this->_filesystem->getMTime($sourcePath); if (!$this->_filesystem->has($targetPath) || $fileMTime != $this->_filesystem->getMTime($targetPath)) { $publicDir = dirname($targetPath); if (!$this->_filesystem->isDirectory($publicDir)) { $this->_filesystem->createDirectory($publicDir, 0777); } if (isset($cssContent)) { $this->_filesystem->write($targetPath, $cssContent); $this->_filesystem->touch($targetPath, $fileMTime); } elseif ($this->_filesystem->isFile($sourcePath)) { $this->_filesystem->copy($sourcePath, $targetPath); $this->_filesystem->touch($targetPath, $fileMTime); } elseif (!$this->_filesystem->isDirectory($targetPath)) { $this->_filesystem->createDirectory($targetPath, 0777); } } $this->_getFallback($params)->notifyViewFilePublished($targetPath, $themeFile, $params['module']); return $targetPath; }
/** * Create preview image copy * * @return Mage_Core_Model_Theme */ public function createPreviewImageCopy() { $filePath = $this->_getImagePathPreview() . DIRECTORY_SEPARATOR . $this->getPreviewImage(); $destinationFileName = Varien_File_Uploader::getNewFileName($filePath); $this->_filesystem->copy($this->_getImagePathPreview() . DIRECTORY_SEPARATOR . $this->getPreviewImage(), $this->_getImagePathPreview() . DIRECTORY_SEPARATOR . $destinationFileName); $this->setPreviewImage($destinationFileName); return $this; }