diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-06-14 16:55:44 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-06-14 17:36:02 +0200 |
commit | ceee91d9d455eed8b01942bc56767c69077e9f3f (patch) | |
tree | 1392d7c0fe0046b0ae0212a5ee7e2c0283b5a2e7 /apps/theming | |
parent | 5b0ce806a3679b34ae3a6f8e6ae32a0b513a4ca9 (diff) | |
download | nextcloud-server-ceee91d9d455eed8b01942bc56767c69077e9f3f.tar.gz nextcloud-server-ceee91d9d455eed8b01942bc56767c69077e9f3f.zip |
Add info message if an exception occurs during the svg to png conversion
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/ImageManager.php | 13 | ||||
-rw-r--r-- | apps/theming/tests/ImageManagerTest.php | 7 |
2 files changed, 18 insertions, 2 deletions
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 5d7c11b6e4c..dfbdb582da6 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -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); diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 6bfa5b330a6..38f5fb04969 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -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 ); } |