Add info message if an exception occurs during the svg to png conversion
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
5b0ce806a3
commit
ceee91d9d4
3 changed files with 19 additions and 3 deletions
|
@ -31,6 +31,7 @@ use OCP\IConfig;
|
|||
use OCP\Files\IAppData;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\ILogger;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class ImageManager {
|
||||
|
@ -45,6 +46,8 @@ class ImageManager {
|
|||
private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
|
||||
/** @var ICacheFactory */
|
||||
private $cacheFactory;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* ImageManager constructor.
|
||||
|
@ -53,16 +56,19 @@ class ImageManager {
|
|||
* @param IAppData $appData
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param ICacheFactory $cacheFactory
|
||||
* @param ILogger $logger
|
||||
*/
|
||||
public function __construct(IConfig $config,
|
||||
IAppData $appData,
|
||||
IURLGenerator $urlGenerator,
|
||||
ICacheFactory $cacheFactory
|
||||
ICacheFactory $cacheFactory,
|
||||
ILogger $logger
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->appData = $appData;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->cacheFactory = $cacheFactory;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function getImageUrl(string $key, bool $useSvg = true): string {
|
||||
|
@ -95,6 +101,7 @@ class ImageManager {
|
|||
* @throws NotPermittedException
|
||||
*/
|
||||
public function getImage(string $key, bool $useSvg = true): ISimpleFile {
|
||||
$pngFile = null;
|
||||
$logo = $this->config->getAppValue('theming', $key . 'Mime', false);
|
||||
$folder = $this->appData->getFolder('images');
|
||||
if ($logo === false || !$folder->fileExists($key)) {
|
||||
|
@ -110,10 +117,14 @@ class ImageManager {
|
|||
$pngFile = $folder->newFile($key . '.png');
|
||||
$pngFile->putContent($finalIconFile->getImageBlob());
|
||||
} catch (\ImagickException $e) {
|
||||
$this->logger->info('The image was requested to be no SVG file, but converting it to PNG failed.', $e->getMessage());
|
||||
$pngFile = null;
|
||||
}
|
||||
} else {
|
||||
$pngFile = $folder->getFile($key . '.png');
|
||||
}
|
||||
}
|
||||
if ($pngFile !== null) {
|
||||
return $pngFile;
|
||||
}
|
||||
return $folder->getFile($key);
|
||||
|
|
|
@ -28,6 +28,7 @@ use OCA\Theming\ThemingDefaults;
|
|||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\ILogger;
|
||||
use OCP\IURLGenerator;
|
||||
use Test\TestCase;
|
||||
use OCP\Files\SimpleFS\ISimpleFolder;
|
||||
|
@ -46,6 +47,8 @@ class ImageManagerTest extends TestCase {
|
|||
private $urlGenerator;
|
||||
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $cacheFactory;
|
||||
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $logger;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -53,11 +56,13 @@ class ImageManagerTest extends TestCase {
|
|||
$this->appData = $this->createMock(IAppData::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
||||
$this->logger = $this->createMock(ILogger::class);
|
||||
$this->imageManager = new ImageManager(
|
||||
$this->config,
|
||||
$this->appData,
|
||||
$this->urlGenerator,
|
||||
$this->cacheFactory
|
||||
$this->cacheFactory,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -954,7 +954,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getURLGenerator(),
|
||||
$c->getMemCacheFactory(),
|
||||
new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
|
||||
new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory()),
|
||||
new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
|
||||
$c->getAppManager()
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue