From 36137acc2ff2678eab1f0ad3e59ad5b857b78eef Mon Sep 17 00:00:00 2001 From: Sergio Mendolia Date: Wed, 20 Sep 2023 09:19:15 +0200 Subject: [PATCH] Don't fail if checksum is not calculated --- src/Service/BookFileSystemManager.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Service/BookFileSystemManager.php b/src/Service/BookFileSystemManager.php index 5fe9b5a7..a42a4550 100644 --- a/src/Service/BookFileSystemManager.php +++ b/src/Service/BookFileSystemManager.php @@ -360,6 +360,7 @@ public function extractCover(Book $book): Book } $entries = []; + foreach ($archive->getEntries() as $entry) { if (str_contains($entry->getPath(), '.jpg') || str_contains($entry->getPath(), '.jpeg')) { $entries[] = $entry->getPath(); @@ -374,7 +375,12 @@ public function extractCover(Book $book): Book $archive->setOutputDirectory('/tmp')->extractEntry($entries[0]); // extract the archive $filesystem->mkdir($this->getCalculatedImagePath($book, true)); - $checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$entries[0])); + try { + $checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$entries[0])); + } catch (\Exception $e) { + $this->logger->error('Could not calculate checksum', ['book' => $bookFile->getRealPath(), 'exception' => $e->getMessage()]); + $checksum = md5(''.time()); + } $filesystem->rename( '/tmp/'.$entries[0], $this->getCalculatedImagePath($book, true).$this->getCalculatedImageName($book, $checksum),