From 3ca9d53194d2a52ea3798d447cd70ffc2e595fcf Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 24 Feb 2017 18:29:05 -0600 Subject: [PATCH 1/3] Fix SCSS usage in apps * fix the web root detection of the ResourceLocator for apps Signed-off-by: Morris Jobke --- lib/private/Template/ResourceLocator.php | 33 +++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php index e22ebdcab7d7d..9015bf5d97c48 100755 --- a/lib/private/Template/ResourceLocator.php +++ b/lib/private/Template/ResourceLocator.php @@ -117,7 +117,38 @@ protected function appendIfExist($root, $file, $webRoot = null) { */ protected function append($root, $file, $webRoot = null, $throw = true) { if (!$webRoot) { - $webRoot = $this->mapping[$root]; + $tmpRoot = $root; + /* + * traverse the potential web roots upwards in the path + * + * example: + * - root: /srv/www/apps/myapp + * - available mappings: ['/srv/www'] + * + * First we check if a mapping for /srv/www/apps/myapp is available, + * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a + * valid web root + */ + do { + if (isset($this->mapping[$tmpRoot])) { + $webRoot = $this->mapping[$tmpRoot]; + break; + } + + if ($tmpRoot === '/') { + $webRoot = ''; + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ + 'app' => 'lib', + 'root' => $root, + 'file' => $file, + 'webRoot' => $webRoot, + 'throw' => $throw ? 'true' : 'false' + ]); + break; + } + $tmpRoot = dirname($tmpRoot); + } while(true); + } $this->resources[] = array($root, $webRoot, $file); From f7ebf1d47d40f42f22356e04c53d08a350aaf2cd Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 10 Mar 2017 19:13:44 +0100 Subject: [PATCH 2/3] SCSS files don't exist on the default fs so just add them to the resource list Signed-off-by: Roeland Jago Douma --- lib/private/Template/CSSResourceLocator.php | 50 ++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 3a474a1ecfd93..5f210ef307a49 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -88,7 +88,8 @@ protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { if (is_file($root.'/'.$file)) { if($this->scssCacher !== null) { if($this->scssCacher->process($root, $file, $app)) { - $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false); + + $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true); return true; } else { $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); @@ -101,4 +102,51 @@ protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { } return false; } + + public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { + if (!$scss) { + parent::append($root, $file, $webRoot, $throw); + } else { + if (!$webRoot) { + $tmpRoot = $root; + /* + * traverse the potential web roots upwards in the path + * + * example: + * - root: /srv/www/apps/myapp + * - available mappings: ['/srv/www'] + * + * First we check if a mapping for /srv/www/apps/myapp is available, + * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a + * valid web root + */ + do { + if (isset($this->mapping[$tmpRoot])) { + $webRoot = $this->mapping[$tmpRoot]; + break; + } + + if ($tmpRoot === '/') { + $webRoot = ''; + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ + 'app' => 'lib', + 'root' => $root, + 'file' => $file, + 'webRoot' => $webRoot, + 'throw' => $throw ? 'true' : 'false' + ]); + break; + } + $tmpRoot = dirname($tmpRoot); + } while(true); + + } + + if ($throw && $tmpRoot === '/') { + throw new ResourceNotFoundException($file, $webRoot); + } + + $this->resources[] = array($tmpRoot, $webRoot, $file); + } + } } From f86b5c2ebba9aaa76bbcc1dfc660f430b246d1a4 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 10 Mar 2017 20:00:34 +0100 Subject: [PATCH 3/3] Properly calculate webdir using the serverroot Signed-off-by: Roeland Jago Douma --- lib/private/Template/SCSSCacher.php | 15 +++++++++++---- lib/private/TemplateLayout.php | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 744ea80761e9e..b55cd0b93b09a 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -46,17 +46,26 @@ class SCSSCacher { /** @var SystemConfig */ protected $systemConfig; + /** @var string */ + protected $serverRoot; + /** * @param ILogger $logger * @param IAppData $appData * @param IURLGenerator $urlGenerator * @param SystemConfig $systemConfig + * @param string $serverRoot */ - public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) { + public function __construct(ILogger $logger, + IAppData $appData, + IURLGenerator $urlGenerator, + SystemConfig $systemConfig, + $serverRoot) { $this->logger = $logger; $this->appData = $appData; $this->urlGenerator = $urlGenerator; $this->systemConfig = $systemConfig; + $this->serverRoot = $serverRoot; } /** @@ -74,9 +83,7 @@ public function process($root, $file, $app) { $path = implode('/', $path); - $webDir = explode('/', $file); - array_pop($webDir); - $webDir = implode('/', $webDir); + $webDir = substr($path, strlen($this->serverRoot)+1); try { $folder = $this->appData->getFolder($app); diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index ccd53c9cafabf..680bfbbfec1de 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -216,7 +216,8 @@ static public function findStylesheetFiles($styles, $compileScss = true) { \OC::$server->getLogger(), \OC::$server->getAppDataDir('css'), \OC::$server->getURLGenerator(), - \OC::$server->getSystemConfig() + \OC::$server->getSystemConfig(), + \OC::$SERVERROOT ); } else { $SCSSCacher = null;