Merge pull request #382 from bibich/improvements

Improvements
This commit is contained in:
Manuel Raynaud
2014-05-06 09:40:37 +02:00
2 changed files with 44 additions and 14 deletions

View File

@@ -12,6 +12,7 @@
namespace Thelia\Core\Template\Smarty\Assets; namespace Thelia\Core\Template\Smarty\Assets;
use Thelia\Log\Tlog;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\Template\Assets\AssetManagerInterface; use Thelia\Core\Template\Assets\AssetManagerInterface;
@@ -108,6 +109,27 @@ class SmartyAssetsManager
$templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType()); $templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType());
// if it's not a custom template and looking for a different origin (e.g. module)
// we first check if the asset is present in the default "source" (template)
// if not we take the default asset from the assetOrigin (module)
if (! $webAssetTemplate && $assetOrigin !== "0") {
if (isset($templateDirectories[$templateDefinition->getName()]["0"])) {
if (file_exists($templateDirectories[$templateDefinition->getName()]["0"] . DS . $file)) {
// the file exists, we take the default origin
$assetOrigin = "0";
}
}
}
if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) {
// we try with the default origin
if (! $webAssetTemplate && $assetOrigin !== "0") {
$assetOrigin = "0";
} else {
throw new \Exception("Failed to get real path of '/".dirname($file)."'");
}
}
if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) { if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) {
throw new \Exception("Failed to get real path of '/".dirname($file)."'"); throw new \Exception("Failed to get real path of '/".dirname($file)."'");
} }
@@ -119,6 +141,9 @@ class SmartyAssetsManager
$file = str_replace('/', DS, $file); $file = str_replace('/', DS, $file);
} }
$url = "";
// test if file exists before running the process
if (file_exists($assetSource . DS . $file)) {
$url = $this->assetsManager->processAsset( $url = $this->assetsManager->processAsset(
$assetSource . DS . $file, $assetSource . DS . $file,
$assetSource . DS . self::$assetsDirectory, $assetSource . DS . self::$assetsDirectory,
@@ -130,6 +155,7 @@ class SmartyAssetsManager
$filters, $filters,
$debug $debug
); );
}
return $url; return $url;
} }
@@ -138,10 +164,13 @@ class SmartyAssetsManager
{ {
// Opening tag (first call only) // Opening tag (first call only)
if ($repeat) { if ($repeat) {
$url = "";
try {
$url = $this->computeAssetUrl($assetType, $params, $template); $url = $this->computeAssetUrl($assetType, $params, $template);
} catch (\Exception $ex) {
Tlog::getInstance()->addWarning("Failed to get real path of " . $params['file']);
}
$template->assign('asset_url', $url); $template->assign('asset_url', $url);
} elseif (isset($content)) { } elseif (isset($content)) {
return $content; return $content;
} }

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Front\Controller; namespace Front\Controller;
use Front\Front;
use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Exception\PropelException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Thelia\Cart\CartTrait; use Thelia\Cart\CartTrait;