Commit aaffd18b authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Merge branch 'master' of https://git.unicaen.fr/lib/unicaen/open-document into Calc

parents cb24d4a8 17e61ca7
Loading
Loading
Loading
Loading

CHANGELOG.md

0 → 100644
+13 −0
Changes for CHANGELOG.md: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
CHANGELOG
=========

3.0.2
------------------

Meilleur contrôle d'écriture des fichiers et de chargement des données

3.0.1
------------------

Unoconv : pouvoir utiliser un serveur dédié
+66 −6
Changes for src/Document.php: 66 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -71,13 +71,18 @@ class Document
    /**
     * @var string
     */
    private $convCommand = 'unoconv -f pdf -o :outputFile :inputFile';
    private $convCommand = 'unoconv --server=:host -f pdf -o :outputFile :inputFile';

    /**
     * @var string
     */
    private $tmpDir;

    /**
     * @var string
     */
    private $host = '127.0.0.1';

    /**
     * @var array
     */
@@ -554,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);

@@ -587,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.');
        }

@@ -613,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());
        }
@@ -625,7 +639,6 @@ class Document
            $this->getArchive()->addFromString('content.xml', $this->getContent()->saveXML());
        }

        $actualFile = $this->getArchive()->filename;
        $this->getArchive()->close();
        $this->archive = null;

@@ -633,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;
@@ -650,11 +669,19 @@ 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(':inputFile', $origine, $this->getConvCommand());
        $command = str_replace(':host', $this->getHost(), $this->getConvCommand());
        $command = str_replace(':inputFile', $origine, $command);
        $command = str_replace(':outputFile', $destination, $command);
        exec($command, $output, $return);

@@ -682,6 +709,15 @@ class Document



    public function saveToPdf(string $filename)
    {
        $this->odtToPdf($this->getArchive()->filename, $filename);

        return $this;
    }



    /**
     * @return string
     * @throws Exception
@@ -726,6 +762,30 @@ class Document



    /**
     * @return string
     */
    public function getHost(): string
    {
        return $this->host;
    }



    /**
     * @param string $host
     *
     * @return Document
     */
    public function setHost(string $host)
    {
        $this->host = $host;

        return $this;
    }



    /**
     * @param null $prefix
     *