]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure to always load the latest icons-vars.css file 12739/head
authorJulius Härtl <jus@bitgrid.net>
Mon, 12 Nov 2018 10:00:56 +0000 (11:00 +0100)
committerJulius Härtl <jus@bitgrid.net>
Fri, 7 Dec 2018 22:30:28 +0000 (23:30 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/private/Template/IconsCacher.php
tests/lib/Template/IconsCacherTest.php

index f3660442dc5d5d5fe80218e196c7bb78495c05bd..49c5929e3d6594dfd4c7ba9f1ae6ce06a33ce928 100644 (file)
@@ -24,6 +24,7 @@ declare (strict_types = 1);
 
 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';
 
@@ -56,13 +60,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');
@@ -131,6 +139,11 @@ class IconsCacher {
        }
 
        public function injectCss() {
+               $mtime = $this->timeFactory->getTime();
+               $file = $this->getCachedCSS();
+               if ($file) {
+                       $mtime = $file->getMTime();
+               }
                // Only inject once
                foreach (\OC_Util::$headers as $header) {
                        if (
@@ -140,8 +153,8 @@ class IconsCacher {
                                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
+}
index d6a9908989c5946aff6ce6dcef57a589c2575158..27d35699d63f92d1ea3c637b4143bed09d3cd0c3 100644 (file)
@@ -28,6 +28,7 @@ use OC\Files\AppData\AppData;
 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 @@ class IconsCacherTest extends \Test\TestCase {
                $this->iconsCacher = new IconsCacher(
                        $this->logger,
                        $factory,
-                       $this->urlGenerator
+                       $this->urlGenerator,
+                       $this->timeFactory
                );
        }