Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to always load the latest icons-vars.css file #12408

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/private/Template/IconsCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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');
Expand Down Expand Up @@ -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 (
Expand All @@ -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);
}

}
}
7 changes: 6 additions & 1 deletion tests/lib/Template/IconsCacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -63,7 +67,8 @@ protected function setUp() {
$this->iconsCacher = new IconsCacher(
$this->logger,
$factory,
$this->urlGenerator
$this->urlGenerator,
$this->timeFactory
);
}

Expand Down