Loading src/Document.php +34 −4 Original line number Diff line number Diff line Loading @@ -559,6 +559,10 @@ class Document throw new Exception('Zip extension not loaded'); } if (!$data){ throw new Exception('Wrong or empty data'); } $odtFile = $this->tempFileName('odtfile_', 'odt'); file_put_contents($odtFile, $data); Loading Loading @@ -592,7 +596,7 @@ class Document } $this->archive = new ZipArchive(); if (!true === $this->archive->open($odtFile, ZIPARCHIVE::CREATE)) { if (true !== $this->archive->open($odtFile, ZIPARCHIVE::CREATE)) { throw new Exception('OpenDocument file "' . $fileName . '" don\'t readable.'); } Loading @@ -618,6 +622,11 @@ class Document */ private function prepareSaving($filename = null): string { $actualFile = $this->getArchive()->filename; if (!is_writable($actualFile)) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($actualFile).'" not reachable or writable'); } if ($this->isMetaChanged()) { $this->getArchive()->addFromString('meta.xml', $this->getMeta()->saveXML()); } Loading @@ -630,7 +639,6 @@ class Document $this->getArchive()->addFromString('content.xml', $this->getContent()->saveXML()); } $actualFile = $this->getArchive()->filename; $this->getArchive()->close(); $this->archive = null; Loading @@ -638,9 +646,15 @@ class Document if (!$filename) { $filename = $this->tempFileName('odt2pdf_', 'pdf'); } $this->odtToPdf($actualFile, $filename); $actualFile = $filename; }else{ if ($filename && $filename != $actualFile){ if (!is_writable(dirname($filename))) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($filename).'" not reachable or writable'); } copy($actualFile, $filename); } } return $actualFile; Loading @@ -655,8 +669,15 @@ class Document * @return Document * @throws Exception */ public function odtToPdf($origine, $destination): Document public function odtToPdf(string $origine, string $destination): Document { if (!file_exists($origine)){ throw new Exception("File \"$origine\" not reachable or writable."); } if (!is_writable(dirname($destination))) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($destination).'" not reachable or writable'); } $command = $this->getConvCommand(); $command = str_replace(':host', $this->getHost(), $this->getConvCommand()); Loading Loading @@ -688,6 +709,15 @@ class Document public function saveToPdf(string $filename) { $this->odtToPdf($this->getArchive()->filename, $filename); return $this; } /** * @return string * @throws Exception Loading Loading
src/Document.php +34 −4 Original line number Diff line number Diff line Loading @@ -559,6 +559,10 @@ class Document throw new Exception('Zip extension not loaded'); } if (!$data){ throw new Exception('Wrong or empty data'); } $odtFile = $this->tempFileName('odtfile_', 'odt'); file_put_contents($odtFile, $data); Loading Loading @@ -592,7 +596,7 @@ class Document } $this->archive = new ZipArchive(); if (!true === $this->archive->open($odtFile, ZIPARCHIVE::CREATE)) { if (true !== $this->archive->open($odtFile, ZIPARCHIVE::CREATE)) { throw new Exception('OpenDocument file "' . $fileName . '" don\'t readable.'); } Loading @@ -618,6 +622,11 @@ class Document */ private function prepareSaving($filename = null): string { $actualFile = $this->getArchive()->filename; if (!is_writable($actualFile)) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($actualFile).'" not reachable or writable'); } if ($this->isMetaChanged()) { $this->getArchive()->addFromString('meta.xml', $this->getMeta()->saveXML()); } Loading @@ -630,7 +639,6 @@ class Document $this->getArchive()->addFromString('content.xml', $this->getContent()->saveXML()); } $actualFile = $this->getArchive()->filename; $this->getArchive()->close(); $this->archive = null; Loading @@ -638,9 +646,15 @@ class Document if (!$filename) { $filename = $this->tempFileName('odt2pdf_', 'pdf'); } $this->odtToPdf($actualFile, $filename); $actualFile = $filename; }else{ if ($filename && $filename != $actualFile){ if (!is_writable(dirname($filename))) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($filename).'" not reachable or writable'); } copy($actualFile, $filename); } } return $actualFile; Loading @@ -655,8 +669,15 @@ class Document * @return Document * @throws Exception */ public function odtToPdf($origine, $destination): Document public function odtToPdf(string $origine, string $destination): Document { if (!file_exists($origine)){ throw new Exception("File \"$origine\" not reachable or writable."); } if (!is_writable(dirname($destination))) { throw new Exception('Impossible to create or update the document. Directory "'.dirname($destination).'" not reachable or writable'); } $command = $this->getConvCommand(); $command = str_replace(':host', $this->getHost(), $this->getConvCommand()); Loading Loading @@ -688,6 +709,15 @@ class Document public function saveToPdf(string $filename) { $this->odtToPdf($this->getArchive()->filename, $filename); return $this; } /** * @return string * @throws Exception Loading