Skip to content

Commit 72ab9ed

Browse files
committed
Make sure to always load the latest icons-vars.css file
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 76a4619 commit 72ab9ed

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/private/Template/IconsCacher.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace OC\Template;
2626

27+
use OCP\AppFramework\Utility\ITimeFactory;
2728
use OCP\Files\IAppData;
2829
use OCP\Files\NotFoundException;
2930
use OCP\Files\SimpleFS\ISimpleFolder;
@@ -46,6 +47,9 @@ class IconsCacher {
4647
/** @var IURLGenerator */
4748
protected $urlGenerator;
4849

50+
/** @var ITimeFactory */
51+
protected $timeFactory;
52+
4953
/** @var string */
5054
private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']([a-zA-Z0-9-_\~\/\.\?\=]+)[^;]+;/m';
5155

@@ -56,13 +60,17 @@ class IconsCacher {
5660
* @param ILogger $logger
5761
* @param Factory $appDataFactory
5862
* @param IURLGenerator $urlGenerator
63+
* @param ITimeFactory $timeFactory
64+
* @throws \OCP\Files\NotPermittedException
5965
*/
6066
public function __construct(ILogger $logger,
6167
Factory $appDataFactory,
62-
IURLGenerator $urlGenerator) {
68+
IURLGenerator $urlGenerator,
69+
ITimeFactory $timeFactory) {
6370
$this->logger = $logger;
6471
$this->appData = $appDataFactory->get('css');
6572
$this->urlGenerator = $urlGenerator;
73+
$this->timeFactory = $timeFactory;
6674

6775
try {
6876
$this->folder = $this->appData->getFolder('icons');
@@ -131,6 +139,11 @@ public function getCachedCSS() {
131139
}
132140

133141
public function injectCss() {
142+
$mtime = $this->timeFactory->getTime();
143+
$file = $this->getCachedCSS();
144+
if ($file) {
145+
$mtime = $file->getMTime();
146+
}
134147
// Only inject once
135148
foreach (\OC_Util::$headers as $header) {
136149
if (
@@ -140,8 +153,8 @@ public function injectCss() {
140153
return;
141154
}
142155
}
143-
$linkToCSS = $this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName]);
156+
$linkToCSS = $this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName, 'v' => $mtime]);
144157
\OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true);
145158
}
146159

147-
}
160+
}

tests/lib/Template/IconsCacherTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OC\Files\AppData\Factory;
2929
use OC\Template\IconsCacher;
3030
use OCA\Theming\ThemingDefaults;
31+
use OCP\AppFramework\Utility\ITimeFactory;
3132
use OCP\Files\IAppData;
3233
use OCP\Files\NotFoundException;
3334
use OCP\Files\SimpleFS\ISimpleFile;
@@ -46,10 +47,13 @@ class IconsCacherTest extends \Test\TestCase {
4647
protected $appData;
4748
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
4849
protected $urlGenerator;
50+
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
51+
private $timeFactory;
4952

5053
protected function setUp() {
5154
$this->logger = $this->createMock(ILogger::class);
5255
$this->appData = $this->createMock(AppData::class);
56+
$this->timeFactory = $this->createMock(ITimeFactory::class);
5357

5458
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
5559
$factory = $this->createMock(Factory::class);
@@ -63,7 +67,8 @@ protected function setUp() {
6367
$this->iconsCacher = new IconsCacher(
6468
$this->logger,
6569
$factory,
66-
$this->urlGenerator
70+
$this->urlGenerator,
71+
$this->timeFactory
6772
);
6873
}
6974

0 commit comments

Comments
 (0)