From 95211c384b0d730316e263f903f35e8a9b803eed Mon Sep 17 00:00:00 2001 From: Sergio Mendolia Date: Wed, 20 Sep 2023 13:54:19 +0200 Subject: [PATCH] Fix paths when extracting --- src/Service/BookFileSystemManager.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Service/BookFileSystemManager.php b/src/Service/BookFileSystemManager.php index cd68c461..6e971f66 100644 --- a/src/Service/BookFileSystemManager.php +++ b/src/Service/BookFileSystemManager.php @@ -369,23 +369,28 @@ public function extractCover(Book $book): Book } $cover = current($entries); - shell_exec('unrar e "'.$bookFile->getRealPath().'" "'.$cover.'" /tmp -y'); + $expl = explode('.', $cover); + $coverFile = explode('/', $cover); + $coverFile = end($coverFile); + $ext = end($expl); + $book->setImageExtension($ext); + + shell_exec('unrar e -ep "'.$bookFile->getRealPath().'" "'.$cover.'" -op"/tmp/" -y'); $filesystem->mkdir($this->getCalculatedImagePath($book, true)); try { - $checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$cover)); + $checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$coverFile)); } catch (\Exception $e) { $this->logger->error('Could not calculate checksum', ['book' => $bookFile->getRealPath(), 'exception' => $e->getMessage()]); $checksum = md5(''.time()); } $filesystem->rename( - '/tmp/'.$cover, + '/tmp/'.$coverFile, $this->getCalculatedImagePath($book, true).$this->getCalculatedImageName($book, $checksum), true); $book->setImagePath($this->getCalculatedImagePath($book, false)); $book->setImageFilename($this->getCalculatedImageName($book, $checksum)); - $book->setImageExtension('jpg'); break; case 'pdf':