Exemplo n.º 1
0
 public function testFiles()
 {
     $timestamp = '200000';
     $templateId = 5;
     $shopId = 4;
     $templateMock = $this->createTemplateMock($templateId);
     $shopMock = $this->createShopMock($shopId, $templateMock);
     $filenameHash = $timestamp . '_' . md5($timestamp . $templateId . $shopId . \Shopware::REVISION);
     $expected = '/my/root/dir/web/cache/' . $filenameHash . '.css';
     $this->assertEquals($expected, $this->pathResolver->getCssFilePath($shopMock, $timestamp));
     $expected = '/my/root/dir/web/cache/' . $filenameHash . '.js';
     $this->assertEquals($expected, $this->pathResolver->getJsFilePath($shopMock, $timestamp));
 }
Exemplo n.º 2
0
 /**
  * Helper function which returns all smarty directories for the
  * passed templates.
  * The function returns an array with all smarty directories
  * for the inheritance of the passed template.
  *
  * @param \Shopware\Models\Shop\Template $template
  * @return array
  */
 private function getSmartyDirectoriesRecursive(Shop\Template $template)
 {
     $directories = array($this->pathResolver->getSmartyDirectory($template));
     if ($template->getParent() instanceof Shop\Template) {
         $directories = array_merge($directories, $this->getSmartyDirectoriesRecursive($template->getParent()));
     }
     return $directories;
 }
Exemplo n.º 3
0
 /**
  * Returns the theme preview thumbnail.
  *
  * @param \Shopware\Models\Shop\Template $theme
  * @return null|string
  */
 private function getThemeImage(Shop\Template $theme)
 {
     $directory = $this->pathResolver->getDirectory($theme);
     $thumbnail = $directory . '/preview.png';
     if (!file_exists($thumbnail)) {
         return null;
     }
     $thumbnail = file_get_contents($thumbnail);
     return 'data:image/png;base64,' . base64_encode($thumbnail);
 }
Exemplo n.º 4
0
 /**
  * Removes the database entries for themes which file no more exist.
  */
 private function removeDeletedThemes()
 {
     $themes = $this->repository->createQueryBuilder('templates');
     $themes->where('templates.version = 3')->andWhere('templates.pluginId IS NULL');
     $themes = $themes->getQuery()->getResult(AbstractQuery::HYDRATE_OBJECT);
     /**@var $theme Shop\Template */
     foreach ($themes as $theme) {
         $directory = $this->pathResolver->getDirectory($theme);
         if (!file_exists($directory)) {
             $this->entityManager->remove($theme);
         }
     }
     $this->entityManager->flush();
 }
Exemplo n.º 5
0
 /**
  * Helper function to clear the theme cache directory
  * before the new css and js files are compiled.
  *
  * @param array $names
  */
 private function clearDirectory($names = array())
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->pathResolver->getCacheDirectory(), \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
     /** @var \SplFileInfo $path */
     foreach ($iterator as $path) {
         if ($path->getFilename() == '.gitkeep') {
             continue;
         }
         if (!$this->fileNameMatch($path->getFilename(), $names)) {
             continue;
         }
         if ($path->isDir()) {
             rmdir($path->__toString());
         } else {
             unlink($path->__toString());
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Clear theme cache
  */
 public function clearThemeCache()
 {
     $this->clearDirectory($this->themePathResolver->getCacheDirectory());
 }
Exemplo n.º 7
0
 /**
  * Helper function to generate the full theme directory name.
  * example: /var/www/engine/Shopware/Themes/MyTheme
  *
  * @param $name
  * @return string
  */
 private function getThemeDirectory($name)
 {
     return $this->pathResolver->getFrontendThemeDirectory() . DIRECTORY_SEPARATOR . $name;
 }