From 6380d503af3252e0fea8d25e8bbe2f91d5aee1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 10 Nov 2016 16:36:58 +0100 Subject: [PATCH] Css cache folder name fix, route fix and various fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Controller/CssController.php | 5 +++-- core/routes.php | 2 +- lib/private/CssManager.php | 5 +++-- lib/private/Server.php | 2 +- lib/private/Template/CSSResourceLocator.php | 10 ++++++---- lib/private/Template/ResourceLocator.php | 6 ++++-- lib/private/Template/SCSSCacher.php | 14 ++++++++------ lib/public/ICssManager.php | 3 ++- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/core/Controller/CssController.php b/core/Controller/CssController.php index 31ec801d21..323dd21496 100644 --- a/core/Controller/CssController.php +++ b/core/Controller/CssController.php @@ -58,11 +58,12 @@ class CssController extends Controller { * @NoCSRFRequired * * @param string $fileName css filename with extension + * @param string $appName css folder name * @return text/css */ - public function getCss($fileName) { + public function getCss($fileName, $appName) { try { - $cssFile = $this->cssManager->getCss($fileName); + $cssFile = $this->cssManager->getCss($fileName, $appName); } catch(NotFoundException $e) { return new NotFoundResponse(); } diff --git a/core/routes.php b/core/routes.php index dec979c8ce..6f1892d19a 100644 --- a/core/routes.php +++ b/core/routes.php @@ -55,7 +55,7 @@ $application->registerRoutes($this, [ ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], - ['name' => 'Css#getCss', 'url' => '/css/{fileName}', 'verb' => 'GET'], + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], ], 'ocs' => [ ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], diff --git a/lib/private/CssManager.php b/lib/private/CssManager.php index 77e1e421ea..e22cb06930 100644 --- a/lib/private/CssManager.php +++ b/lib/private/CssManager.php @@ -48,11 +48,12 @@ class CssManager implements ICssManager { * Get the css file and return ISimpleFile * * @param string $fileName css filename with extension + * @param string $appName css app name * @return ISimpleFile */ - public function getCss($fileName) { + public function getCss($fileName, $appName) { try { - $folder = $this->appData->getFolder('css'); + $folder = $this->appData->getFolder($appName); } catch(NotFoundException $e) { throw new NotFoundException(); } diff --git a/lib/private/Server.php b/lib/private/Server.php index 2dbf827844..a8825f9ff2 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -419,7 +419,7 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerService('CssManager', function (Server $c) { return new CssManager( - $c->getAppDataDir('server') + $c->getAppDataDir('css') ); }); $this->registerService('Logger', function (Server $c) { diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 8e1cb3a761..b592dd63ae 100755 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -27,11 +27,11 @@ namespace OC\Template; class CSSResourceLocator extends ResourceLocator { - /** @var IAppData */ + /** @var \OCP\Files\IAppData */ protected $appData; /** @var \OCP\IURLGenerator */ protected $urlGenerator; - /** @var \OCP\Files\IConfig */ + /** @var \OC\SystemConfig */ protected $systemConfig; /** @@ -39,9 +39,11 @@ class CSSResourceLocator extends ResourceLocator { * @param string $theme * @param array $core_map * @param array $party_map - * @param IAppData $appData + * @param \OCP\Files\IAppData $appData + * @param \OCP\IURLGenerator $urlGenerator + * @param \OC\SystemConfig $systemConfig */ - public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) { + public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, \OC\SystemConfig $systemConfig) { $this->appData = $appData; $this->urlGenerator = $urlGenerator; $this->systemConfig = $systemConfig; diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php index d5187ef071..07a4387df8 100755 --- a/lib/private/Template/ResourceLocator.php +++ b/lib/private/Template/ResourceLocator.php @@ -111,7 +111,9 @@ abstract class ResourceLocator { * * @param string $root path to check * @param string $file the filename - * @param IAppData $appData the appData folder + * @param \OCP\Files\IAppData $appData + * @param \OCP\IURLGenerator $urlGenerator + * @param \OC\SystemConfig $systemConfig * @param string|null $webRoot base for path, default map $root to $webRoot * @return bool True if the resource was found and cached, false otherwise */ @@ -126,7 +128,7 @@ abstract class ResourceLocator { $systemConfig); if($scssCache->process()) { - $this->append($root, $scssCache->getCachedSCSS(), $webRoot, false); + $this->append($root, $scssCache->getCachedSCSS('core'), $webRoot, false); return true; } else { $this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 800b6b18ba..e72e122155 100755 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -42,7 +42,7 @@ class SCSSCacher { protected $appData; /** @var \OCP\IURLGenerator */ protected $urlGenerator; - /** @var \OCP\Files\IConfig */ + /** @var \OC\SystemConfig */ protected $systemConfig; /** @@ -50,8 +50,10 @@ class SCSSCacher { * @param string $root * @param string $file * @param \OCP\Files\IAppData $appData + * @param \OCP\IURLGenerator $urlGenerator + * @param \OC\SystemConfig $systemConfig */ - public function __construct(\OCP\ILogger $logger, $root, $file, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) { + public function __construct(\OCP\ILogger $logger, $root, $file, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, \OC\SystemConfig $systemConfig) { $this->logger = $logger; $this->appData = $appData; $this->urlGenerator = $urlGenerator; @@ -90,7 +92,6 @@ class SCSSCacher { } else { return $this->cache(); } - return false; } /** @@ -107,7 +108,7 @@ class SCSSCacher { } catch(NotFoundException $e) { return false; } - return false; + return false; } /** @@ -163,9 +164,10 @@ class SCSSCacher { /** * Return the cached css file uri + * @param string $appName the app name * @return string */ - public function getCachedSCSS() { - return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS)), 1); + public function getCachedSCSS($appName) { + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS, 'appName' => $appName)), 1); } } diff --git a/lib/public/ICssManager.php b/lib/public/ICssManager.php index 0af1472b5c..776ffefd82 100644 --- a/lib/public/ICssManager.php +++ b/lib/public/ICssManager.php @@ -32,7 +32,8 @@ interface ICssManager { * Get the css file and return ISimpleFile * * @param string $fileName css filename with extension + * @param string $appName css app name * @return ISimpleFile */ - public function getCss($fileName); + public function getCss($fileName, $appName); }