Browse Source

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

Signed-off-by: Julius Härtl <jus@bitgrid.net>
tags/v15.0.0beta2
Julius Härtl 5 years ago
parent
commit
26b160cc43
No account linked to committer's email address
2 changed files with 21 additions and 4 deletions
  1. 15
    3
      lib/private/Template/IconsCacher.php
  2. 6
    1
      tests/lib/Template/IconsCacherTest.php

+ 15
- 3
lib/private/Template/IconsCacher.php View File



namespace OC\Template; namespace OC\Template;


use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder; use OCP\Files\SimpleFS\ISimpleFolder;
/** @var IURLGenerator */ /** @var IURLGenerator */
protected $urlGenerator; protected $urlGenerator;


/** @var ITimeFactory */
protected $timeFactory;

/** @var string */ /** @var string */
private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\&\=\:\;\+\,]+)[^;]+;/m'; private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\&\=\:\;\+\,]+)[^;]+;/m';


* @param ILogger $logger * @param ILogger $logger
* @param Factory $appDataFactory * @param Factory $appDataFactory
* @param IURLGenerator $urlGenerator * @param IURLGenerator $urlGenerator
* @param ITimeFactory $timeFactory
* @throws \OCP\Files\NotPermittedException * @throws \OCP\Files\NotPermittedException
*/ */
public function __construct(ILogger $logger, public function __construct(ILogger $logger,
Factory $appDataFactory, Factory $appDataFactory,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
ITimeFactory $timeFactory) {
$this->logger = $logger; $this->logger = $logger;
$this->appData = $appDataFactory->get('css'); $this->appData = $appDataFactory->get('css');
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->timeFactory = $timeFactory;


try { try {
$this->folder = $this->appData->getFolder('icons'); $this->folder = $this->appData->getFolder('icons');
} }


public function injectCss() { public function injectCss() {
$mtime = $this->timeFactory->getTime();
$file = $this->getCachedList();
if ($file) {
$mtime = $file->getMTime();
}
// Only inject once // Only inject once
foreach (\OC_Util::$headers as $header) { foreach (\OC_Util::$headers as $header) {
if ( if (
return; 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); \OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true);
} }


}
}

+ 6
- 1
tests/lib/Template/IconsCacherTest.php View File

use OC\Files\AppData\Factory; use OC\Files\AppData\Factory;
use OC\Template\IconsCacher; use OC\Template\IconsCacher;
use OCA\Theming\ThemingDefaults; use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
protected $appData; protected $appData;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
protected $urlGenerator; protected $urlGenerator;
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
private $timeFactory;


protected function setUp() { protected function setUp() {
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(ILogger::class);
$this->appData = $this->createMock(AppData::class); $this->appData = $this->createMock(AppData::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);


/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class); $factory = $this->createMock(Factory::class);
$this->iconsCacher = new IconsCacher( $this->iconsCacher = new IconsCacher(
$this->logger, $this->logger,
$factory, $factory,
$this->urlGenerator
$this->urlGenerator,
$this->timeFactory
); );
} }



Loading…
Cancel
Save