]> _ Git - cubeextranet.git/commitdiff
wip #3667 @6
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 11 Jun 2020 17:51:41 +0000 (17:51 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 11 Jun 2020 17:51:41 +0000 (17:51 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/DAO/class.ws.dao.document.php
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.pdf.convert.php
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php

index 5a0d936213d132fa6734bbef66022ee07d55017f..af9c93966f3c7cedfcf056c060dbb09e04df006f 100644 (file)
@@ -540,74 +540,8 @@ class wsMaintenance
     {
         global $core;
         cubePHP::neverStop();
-//        $r = $core->con->select('SELECT document_id FROM documents WHERE document_id NOT IN (SELECT document_id FROM book_pages)');
-//        while ($r->fetch()) {
-//            if (file_exists(WS_DOCS . '/' . $r->document_id)) {
-//                $rm = new cubeCommandLine('rm');
-//                $rm->setPath(CONVERTER_PATH);
-//                $rm->setArg('r');
-//                $rm->setArg('f');
-//                $rm->setArg(null, WS_DOCS . '/' . $r->document_id . '/');
-//                $rm->execute();
-//                echo $rm->commande . "<br />";
-//            }
-//        }
-
-//        self::_moveDocs(WS_DOCS, '/data/extranet/www/fluidbook/docs1', 150);
-//        self::_moveDocs('/data/extranet/www/fluidbook/docs1', '/data/extranet/www/fluidbook/docs2', 500);
-//        self::_moveDocs('/data/extranet/www/fluidbook/docs2', '/data/extranet/www/fluidbook/docs3', 100000);
     }
 
-    protected static function _moveDocs($from, $to, $keep, $batch = 250)
-    {
-        $docs = array();
-        $dr = opendir($from);
-        while ($d = readdir($dr)) {
-            if ($d == '.' || $d == '..') {
-                continue;
-            }
-            $d = intval($d);
-            if (!$d) {
-                continue;
-            }
-            $docs[] = intval($d);
-        }
-
-        sort($docs);
-        $docs = array_splice($docs, 0, count($docs) - $keep);
-        if (count($docs)) {
-            $toMove = array_slice($docs, 0, $batch);
-
-            foreach ($toMove as $d) {
-                if (trim($d) == '') {
-                    continue;
-                }
-                $source = $from . '/' . $d . '/';
-                $dest = $to . '/' . $d . '/';
-                if (!file_exists($dest)) {
-                    mkdir($dest, 0777, true);
-                }
-                $rsync = "rsync -av $source $dest";
-                $rm = "rm -rf $source";
-                `$rsync;$rm`;
-                echo $rsync . "\n";
-                echo $rm . "\n";
-            }
-        }
-    }
-
-    public static function moveFluidbookDatas()
-    {
-        $dir = WS_BOOKS . '/final/';
-        $dr = opendir($dir);
-        while ($d = readdir($dr)) {
-            if ($d == '.' || $d == '..' || !is_dir($dir . $d)) {
-                continue;
-            }
-            rename($dir . $d . '/FluidbookDatas.swf', $dir . $d . '/data/fd.swf');
-            rename($dir . $d . '/FluidbookDatasLight.swf', $dir . $d . '/data/fdl.swf');
-        }
-    }
 
     public static function mergeEntreprise($args)
     {
@@ -625,49 +559,6 @@ class wsMaintenance
         $core->refreshWSUsersTree();
     }
 
-    public static function updateLuceneTime()
-    {
-        global $core;
-        $dao = new wsDAOBook($core->con);
-        $books = $dao->selectLuceneTimeNotSet();
-        foreach ($books as $book) {
-            $index = WS_BOOKS . '/search/' . $book->book_id;
-            if (!file_exists($index)) {
-                fb($book->book_id, 'Skip');
-                continue;
-            }
-
-            $mtime = 0;
-            $dr = opendir($index);
-            while ($file = readdir($dr)) {
-                if ($file == '.' || $file == '..') {
-                    continue;
-                }
-                $mtime = max($mtime, filemtime($index . '/' . $file));
-            }
-
-            $c = $core->con->openCursor('books');
-            $c->lucene_time = $mtime;
-            $c->update('WHERE book_id=' . $book->book_id);
-
-            fb($book->book_id, 'Update : ' . $mtime);
-        }
-    }
-
-    public static function makeLuceneIndexes()
-    {
-        global $core;
-
-        cubePHP::neverStop();
-
-        $dao = new wsDAOBook($core->con);
-        $books = $dao->selectLuceneToDo();
-        foreach ($books as $book) {
-            $pages = $dao->getPagesOfBook($book->book_id);
-            $dao->indexPDF($book, $pages);
-        }
-    }
-
     public static function exportSommaire($args)
     {
         global $core;
@@ -767,7 +658,7 @@ class wsMaintenance
 
         $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' AND `update`<=' . $date . ' ORDER BY `update` DESC LIMIT 1');
         if (!$r->count()) {
-            return;
+            return false;
         }
 
         $comp = unserialize($r->composition);
@@ -780,6 +671,18 @@ class wsMaintenance
             $c->document_page = $infos['document_page'];
             $c->insert();
         }
+
+        $daoBook = new wsDAOBook($core->con);
+        $book = $daoBook->selectById($book_id);
+        $parametres = $book->parametres;
+        $parametres->pages = count($comp);
+
+        $c = $core->con->openCursor('books');
+        $c->parametres = serialize($parametres);
+        $c->changedate = TIME;
+        $c->update('WHERE book_id=\'' . $core->con->escape($book_id) . '\'');
+
+        return true;
     }
 
     public static function getV1Translations()
@@ -1661,6 +1564,110 @@ class wsMaintenance
             $exporter->export($id, $x, 'install_hosting', 'online', "/airtahitiexport/" . $id, '');
         }
     }
+
+    public static function restoreAllCompositions()
+    {
+        global $core;
+        $dao = new wsDAOBook($core->con);
+        $books = $dao->selectAll();
+        foreach ($books as $book) {
+            if (!$book->parametres->pages) {
+                self::restoreComposition([$book->book_id]);
+                echo 'restored ' . $book->book_id . '<br>';
+            }
+        }
+    }
+
+    public static function fixMissingDocs()
+    {
+        global $core;
+        $r = $core->con->select('SELECT DISTINCT `document_id`,`book_id` FROM `book_pages`');
+        $fixed = [];
+        $unfixed = [];
+        while ($r->fetch()) {
+            if (file_exists(WS_DOCS . '/' . $r->document_id . '/original.pdf')) {
+                continue;
+            }
+            if (!isset($fixed[$r->book_id]) && !isset($unfixed[$r->book_id])) {
+                if (self::fixMissing([$r->book_id])) {
+                    $fixed[$r->book_id] = true;
+                } else {
+                    $unfixed[$r->book_id] = true;
+                    continue;
+                }
+            }
+            break;
+        }
+
+        echo 'fixed : ' . print_r($fixed, true) . "<br>";
+        echo 'unfixed : ' . print_r($unfixed, true) . "<br>";
+    }
+
+    protected static function fixMissing($args)
+    {
+        global $core;
+
+        $book_id = $args[0];
+
+        $places = [
+            WS_BOOKS . '/pdf/' . $book_id . '/original.pdf',
+            WS_BOOKS . '/pdf/' . $book_id . '/normal.pdf',
+            WS_BOOKS . '/final/' . $book_id . '/data/document.pdf',
+            WS_BOOKS . '/html5/' . $book_id . '/data/document.pdf',
+        ];
+
+        $ok = false;
+        foreach ($places as $place) {
+            if (!file_exists($place) || filesize($place) === 0) {
+                continue;
+            }
+            $ok = true;
+            break;
+        }
+
+        if (!$ok) {
+            echo 'backup pdf not found';
+            return false;
+        }
+
+
+        set_time_limit(0);
+        ignore_user_abort(true);
+
+        $daoBook = new wsDAOBook($core->con);
+        /** @var wsBook $book */
+        $dao = new wsDAODocument($core->con);
+
+        // Create a new doc
+        $data = array();
+        $data['proprietaire'] = $core->user->utilisateur_id;
+        $data['pages'] = 0;
+        $data['version'] = 2;
+        $data['file'] = cubeFiles::tidyName('original.pdf');
+        $li = new wsDocumentLocalInfos();
+        $li->fileName = 'original.pdf';
+        $li->fileSize = filesize($place);
+        $li->creationDate = filemtime($place);
+        $li->modificationDate = filemtime($place);
+        $data['localInfos'] = $li;
+        $data['conversionInfos'] = new wsDocumentConversionInfos();
+        $document = $dao->sauve($data);
+        $document->copyOriginalFromFile($place);
+        $document->globalOperations();
+        $document->processAllPages();
+        $dao->updateFromObject($document);
+
+        $n = $document->getPagesNumber();
+        $did = $document->document_id;
+        $pages = [];
+        for ($i = 1; $i <= $n; $i++) {
+            $p = new stdClass();
+            $p->document_id = $did;
+            $p->document_page = $i;
+            $pages[$i] = $p;
+        }
+        $daoBook->setComposition($book_id, $pages, false);
+    }
 }
 
 
index 2292a227627d83d6483f8719da369fdb3670c03e..426baa2138fadc525ed6ad78dc8b1aea41798788 100644 (file)
@@ -142,7 +142,8 @@ class wsDAOBook extends commonDAO
         return $res;
     }
 
-    public function selectAll(){
+    public function selectAll()
+    {
         $table = 'books_vue';
         $sql = 'SELECT * FROM ' . $table;
         $r = $this->con->select($sql);
@@ -874,12 +875,14 @@ class wsDAOBook extends commonDAO
         return true;
     }
 
-    public function setComposition($book_id, $pages)
+    public function setComposition($book_id, $pages, $setNumerotation = true)
     {
         $numerotation = array();
         $nb_pages = 0;
         foreach ($pages as $p) {
-            $numerotation[] = $p->virtual;
+            if($setNumerotation) {
+                $numerotation[] = $p->virtual;
+            }
             $nb_pages++;
         }
 
@@ -889,7 +892,9 @@ class wsDAOBook extends commonDAO
 
         $c = $this->con->openCursor('books');
         $c->parametres = serialize($parametres);
-        $c->numerotation = implode(',', $numerotation);
+        if($setNumerotation) {
+            $c->numerotation = implode(',', $numerotation);
+        }
         $c->changedate = TIME;
 
         // Check if composition need to be updated
@@ -1283,7 +1288,7 @@ class wsDAOBook extends commonDAO
 
     public function copy($source, $dest)
     {
-        if(!file_exists($source)){
+        if (!file_exists($source)) {
             return;
         }
         copy($source, $dest);
index 355a4e8e66f0181ec83ae67b1e036a601411336f..8139da5e8c57e29084ddc37a7e22c834717ab6d4 100644 (file)
@@ -63,6 +63,9 @@ class wsDAODocument extends commonDAO
         return $this->factory($r);
     }
 
+    /**
+     * @return wsDocument
+     */
     public function cree()
     {
         $document = new wsDocument();
index 38fdd394b56da14c0ec7934dbf425fa43ecd4dd3..f4e69dc2d2df4ac6f5903c4b30336fffdb25da03 100644 (file)
@@ -102,6 +102,11 @@ class wsDocument extends cubeMetier
         move_uploaded_file($tmp_file, $this->in);
     }
 
+    public function copyOriginalFromFile($file)
+    {
+        copy($file, $this->in);
+    }
+
     public function copyOriginalFromOlderVersion()
     {
         if (!file_exists($this->in)) {
@@ -668,7 +673,7 @@ class wsDocument extends cubeMetier
             $this->makeShotPNM($page, 'html/h' . $r . '-', $r * $rratio, $q, 4, null, false);
             $this->makeShotPNM($page, 'html/t' . $r . '-', $r * $rratio, $q);
         }
-        $this->makeSVGFile($page);
+        $this->makeSVGFile($page, false);
     }
 
     public function makeMobileFirstFiles($page)
@@ -682,9 +687,12 @@ class wsDocument extends cubeMetier
         }
     }
 
-    public function makeSVGFile($page)
+    public function makeSVGFile($page, $force = true)
     {
         $svgFile = $this->out . '/html/fp' . $page . '.svg';
+        if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) {
+            return;
+        }
 
         $pdftocairo = new cubeCommandLine('pdftocairo');
         $pdftocairo->setPath(CONVERTER_PATH);
@@ -868,8 +876,9 @@ class wsDocument extends cubeMetier
                 $program = 'pdf2swf';
             }
 
-            $pdf2swf = new cubeCommandLine($program, null, true);
+            $pdf2swf = new CubeIT_CommandLine($program, null, true);
             $pdf2swf->setPath(CONVERTER_PATH);
+            $pdf2swf->setTimeout(120);
 
             $pdf2swf->setArg('p', 1);
             $flashversion = 10;
index 1c22e933c9abf6eadf342f952d271b6e61681e67..aa7ed7c4b08cd320ab16a6cb7af40af7c16f6f99 100644 (file)
@@ -43,7 +43,7 @@ class wsPDFConvert {
                }\r
        }\r
 \r
-       protected function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null) {\r
+       protected static function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null) {\r
 \r
                // Fabrication des thumbanails avec ghostscript\r
                $gs = new cubeCommandLine('gs', null, true);\r
@@ -77,7 +77,7 @@ class wsPDFConvert {
                $gs->execute();\r
        }\r
 \r
-       protected function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null) {\r
+       protected static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null) {\r
                $tmp = cubeFiles::tempnam();\r
 \r
                $antialiasing = $antialiasing ? 'yes' : 'no';\r
index 63873f17d4da90ac782d4daaa3bb1b3cd6958a55..c0d8b5b37c5556a8629a02a2380140891017d081 100644 (file)
@@ -203,6 +203,11 @@ class wsUtil
 \r
 \r
         if ($invalid) {\r
+\r
+            if (file_exists($originalPDF)) {\r
+                self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf');\r
+            }\r
+\r
             $pdfList = array();\r
             $pagesList = array();\r
             $nb_pages = array();\r
index 2503360ccc985860b9a33e4cdaa5fd13eb7b410a..2c1881e337bd18cca497c0e9dc1dde1e1f5f8d96 100644 (file)
@@ -1622,7 +1622,8 @@ class wsHTML5Compiler
 
     protected function writeConfig()
     {
-        return 'var SETTINGS=' . json_encode($this->config) . ';' . "\n";
+        $c = json_encode($this->config);
+        return 'var SETTINGS=' . $c . ';' . "\n";
     }
 
     protected function writeCountries()
index 66044c46463195da50118d51eca0b959950bc13f..f85517cf41b71917c647ba13362fd80d8e324a72 100644 (file)
@@ -1378,12 +1378,16 @@ class htmlMultimediaLink extends wsHTML5Link
                 $this->compiler->htmlmultimedia[] = $i;
             }
 
-            foreach ($this->_config['injectcss'] as $i) {
+            if (isset($this->_config['injectcss'])) {
+                foreach ($this->_config['injectcss'] as $i) {
 
+                }
             }
 
-            foreach ($this->_config['injectjs'] as $i) {
-                $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i;
+            if (isset($this->_config['injectjs'])) {
+                foreach ($this->_config['injectjs'] as $i) {
+                    $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i;
+                }
             }