Skip to content

Commit 1e55e8c

Browse files
committed
fix: unable to generate qr code when forum logo is not accessible
1 parent dde79cf commit 1e55e8c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Services/QrCodeGenerator.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
use Flarum\Settings\SettingsRepositoryInterface;
2121
use Illuminate\Contracts\Filesystem\Cloud;
2222
use Illuminate\Contracts\Filesystem\Factory;
23+
use Psr\Log\LoggerInterface;
2324

2425
class QrCodeGenerator
2526
{
2627
protected Cloud $assetsFilesystem;
2728

28-
public function __construct(protected SettingsRepositoryInterface $settings, Factory $filesystemFactory)
29+
public function __construct(protected SettingsRepositoryInterface $settings, Factory $filesystemFactory, protected LoggerInterface $logger)
2930
{
3031
$this->assetsFilesystem = $filesystemFactory->disk('flarum-assets');
3132
}
@@ -44,11 +45,16 @@ public function generate(string $text, bool $asDataUri = false): string
4445
->validateResult(false)
4546
->backgroundColor(new Color(255, 255, 255, 1));
4647

47-
if ($this->settings->get('ianm-twofactor.admin.settings.forum_logo_qr') && $this->getLogoUrl()) {
48-
$builder
49-
->logoPath($this->getLogoUrl())
50-
->logoResizeToWidth($this->settings->get('ianm-twofactor.admin.settings.forum_logo_qr_width') ?? 100)
51-
->logoPunchoutBackground(true);
48+
try {
49+
if ($this->settings->get('ianm-twofactor.admin.settings.forum_logo_qr') && $this->getLogoUrl()) {
50+
$builder
51+
->logoPath($this->getLogoUrl())
52+
->logoResizeToWidth($this->settings->get('ianm-twofactor.admin.settings.forum_logo_qr_width') ?? 100)
53+
->logoPunchoutBackground(true);
54+
}
55+
}
56+
catch (\Exception $e) {
57+
$this->logger->error('[ianm/twofactor] Could not add logo to QR code: '.$e->getMessage());
5258
}
5359

5460
$result = $builder->build();

0 commit comments

Comments
 (0)