Skip to content

Commit 3170d79

Browse files
authored
Fix 500 when the imagick config file does not exists (#3386)
1 parent 50e467b commit 3170d79

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

app/Actions/Diagnostics/Pipes/Checks/ImagickPdfCheck.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
*/
2323
class ImagickPdfCheck implements DiagnosticPipe
2424
{
25+
public const DETAILS = [
26+
'Make sure to have the policy.xml file in `/etc/ImageMagick-6/policy.xml`.',
27+
'Verify that the file contains the line <policy domain="coder" rights="read|write" pattern="PDF"/> .',
28+
];
29+
2530
/**
2631
* {@inheritDoc}
2732
*/
@@ -40,18 +45,24 @@ public function handle(array &$data, \Closure $next): array
4045
}
4146

4247
try {
48+
if (!file_exists('/etc/ImageMagick-6/policy.xml')) {
49+
$data[] = DiagnosticData::warn('The policy.xml file does not exist at the expected location: /etc/ImageMagick-6/policy.xml.', self::class, self::DETAILS);
50+
51+
return $next($data);
52+
}
53+
4354
$imagic_policy = file_get_contents('/etc/ImageMagick-6/policy.xml');
4455
if (1 === preg_match('/<policy domain="coder" rights="none" pattern="PDF"/', $imagic_policy)) {
4556
$data[] = DiagnosticData::warn('Imagick is not allowed to create thumbs for pdf files.', self::class,
4657
['Verify that the /etc/ImageMagick-6/policy.xml file contains the line <policy domain="coder" rights="read|write" pattern="PDF"/> .']);
4758
}
4859
} catch (FilesystemException) {
49-
$data[] = DiagnosticData::warn('Could not determine whether Imagick is allowed to work with pdf files.', self::class, [
50-
'Make sure to have the policy.xml file in `/etc/ImageMagick-6/policy.xml`.',
51-
'Verify that the file contains the line <policy domain="coder" rights="read|write" pattern="PDF"/> .',
52-
]);
60+
$data[] = DiagnosticData::warn('Could not determine whether Imagick is allowed to work with pdf files.', self::class, self::DETAILS);
5361
} catch (PcreException) {
5462
// Just ignore.
63+
} catch (\Exception $e) {
64+
$data[] = DiagnosticData::error('An unexpected error occurred while checking Imagick PDF support.', self::class, self::DETAILS);
65+
// Just ignore all other exceptions.
5566
}
5667

5768
return $next($data);

0 commit comments

Comments
 (0)