Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Path '/etc/passwd' is out of working directory '/tmp'
  */
 public function testTouchIsolation()
 {
     $filesystem = new Magento_Filesystem($this->_getDefaultAdapterMock());
     $filesystem->setWorkingDirectory('/tmp');
     $filesystem->touch('/etc/passwd');
 }