From 26b160cc439d0d3396fe54ee7222a0642bfbd022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 12 Nov 2018 11:00:56 +0100 Subject: [PATCH] Make sure to always load the latest icons-vars.css file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Template/IconsCacher.php | 18 +++++++++++++++--- tests/lib/Template/IconsCacherTest.php | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/private/Template/IconsCacher.php b/lib/private/Template/IconsCacher.php index c91bf13ad5373..1020cd24dcded 100644 --- a/lib/private/Template/IconsCacher.php +++ b/lib/private/Template/IconsCacher.php @@ -24,6 +24,7 @@ namespace OC\Template; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFolder; @@ -46,6 +47,9 @@ class IconsCacher { /** @var IURLGenerator */ protected $urlGenerator; + /** @var ITimeFactory */ + protected $timeFactory; + /** @var string */ private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\&\=\:\;\+\,]+)[^;]+;/m'; @@ -58,14 +62,17 @@ class IconsCacher { * @param ILogger $logger * @param Factory $appDataFactory * @param IURLGenerator $urlGenerator + * @param ITimeFactory $timeFactory * @throws \OCP\Files\NotPermittedException */ public function __construct(ILogger $logger, Factory $appDataFactory, - IURLGenerator $urlGenerator) { + IURLGenerator $urlGenerator, + ITimeFactory $timeFactory) { $this->logger = $logger; $this->appData = $appDataFactory->get('css'); $this->urlGenerator = $urlGenerator; + $this->timeFactory = $timeFactory; try { $this->folder = $this->appData->getFolder('icons'); @@ -216,6 +223,11 @@ public function getCachedList() { } public function injectCss() { + $mtime = $this->timeFactory->getTime(); + $file = $this->getCachedList(); + if ($file) { + $mtime = $file->getMTime(); + } // Only inject once foreach (\OC_Util::$headers as $header) { if ( @@ -225,8 +237,8 @@ public function injectCss() { return; } } - $linkToCSS = $this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName]); + $linkToCSS = $this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName, 'v' => $mtime]); \OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true); } -} \ No newline at end of file +} diff --git a/tests/lib/Template/IconsCacherTest.php b/tests/lib/Template/IconsCacherTest.php index c537323e0eb66..cc6224f322870 100644 --- a/tests/lib/Template/IconsCacherTest.php +++ b/tests/lib/Template/IconsCacherTest.php @@ -28,6 +28,7 @@ use OC\Files\AppData\Factory; use OC\Template\IconsCacher; use OCA\Theming\ThemingDefaults; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; @@ -46,10 +47,13 @@ class IconsCacherTest extends \Test\TestCase { protected $appData; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ protected $urlGenerator; + /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $timeFactory; protected function setUp() { $this->logger = $this->createMock(ILogger::class); $this->appData = $this->createMock(AppData::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ $factory = $this->createMock(Factory::class); @@ -63,7 +67,8 @@ protected function setUp() { $this->iconsCacher = new IconsCacher( $this->logger, $factory, - $this->urlGenerator + $this->urlGenerator, + $this->timeFactory ); }