]> _ Git - cubeextranet.git/commitdiff
wait #3955 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 16 Oct 2020 09:43:53 +0000 (09:43 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 16 Oct 2020 09:43:53 +0000 (09:43 +0000)
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.pdf.convert.php

index 44faa63ed553809a8d57496397ef02eeba3b02bb..c16eb74db89c784d2edaa680a6952b36539a146b 100644 (file)
@@ -126,6 +126,10 @@ class wsDocument extends cubeMetier
             $in = $this->in;
         }
 
+        if (!$force && file_exists($this->infos)) {
+            return;
+        }
+
         $fwstk = new cubeCommandLine('fwstk.sh');
         $fwstk->setPath(CONVERTER_PATH);
         $fwstk->setArg('--input ' . $in);
@@ -397,6 +401,7 @@ class wsDocument extends cubeMetier
 
 
         $dir = rtrim($this->out . $version, '/') . '/';
+        $minsize = 1;
         if ($format === 'svg') {
             $prefix = $withGraphics ? 'f' : 't';
             $file = $dir . $prefix . 'o' . $page;
@@ -404,22 +409,46 @@ class wsDocument extends cubeMetier
                 $file .= '-' . $resolution;
             }
             $file .= '.svg';
+            $reffile = $this->makeSVGFile($page);
+            $minsize = 100;
         } else if ($format === 'png' || $format === 'jpg') {
             $prefix = $withText ? 't' : 'h';
             if ($resolution === 'thumb') {
                 $file = $dir . 'p' . $page . '.' . $format;
             } else {
                 $file = $dir . $prefix . $page . '-' . $resolution . '.' . $format;
+                $alt = $dir . $prefix . $resolution . '-' . $page . '.' . $format;
             }
         }
+
+        $do = false;
         if (!file_exists($file)) {
+            if (isset($alt) && file_exists($alt)) {
+                rename($alt, $file);
+                $do = false;
+            } else {
+                $do = true;
+            }
+        } else if (filesize($file) < $minsize) {
+            $do = true;
+        } else if (isset($reffile) && filemtime($file) < filemtime($reffile)) {
+            $do = true;
+        }
+
+        if ($do) {
             $this->makeFile($file, $page, $format, $resolution, $withText, $withGraphics, $version);
         }
         return $file;
     }
 
-    public function makeFile($file, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true)
+    public function makeFile($file, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
     {
+        $lock = $file . '.lock';
+        if (file_exists($lock) && filemtime($lock) > time() - 300) {
+            sleep(10);
+            return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version);
+        }
+        touch($lock);
         if ($format === 'jpeg') {
             $format = 'jpg';
         }
@@ -433,10 +462,11 @@ class wsDocument extends cubeMetier
             if ($resolution === 'thumb') {
                 wsPDFConvert::makeMiniShot($this->getSplittedPDFPage($page), $file, 1, $format);
             } else {
-                $rr = version === 'html' ? $this->getResolutionRatio() : $this->getMobileFirstRatio();
+                $rr = $version === 'html' ? $this->getResolutionRatio() : $this->getMobileFirstRatio();
                 wsPDFConvert::makeShotPNM($this->getSplittedPDFPage($page), $file, 1, '', $resolution * $rr, 85, 4, $withText, null, null, $format);
             }
         }
+        unlink($lock);
     }
 
     public function cutDocument($mode)
@@ -539,7 +569,7 @@ class wsDocument extends cubeMetier
     {
         $svgFile = $this->out . '/html/fp' . $page . '.svg';
         if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) {
-            return;
+            return $svgFile;
         }
         wsPDFConvert::makeBaseSVGFile($this->getSplittedPDFPage($page), $svgFile, 1);
         return $svgFile;
@@ -548,10 +578,6 @@ class wsDocument extends cubeMetier
     public function makeTextSVGFile($page, $out, $force = false)
     {
         $in = $this->makeSVGFile($page);
-        $do = $force || !file_exists($out) || filesize($out) < 100 || filemtime($in) > filemtime($out) || filemtime($out) < filemtime(__FILE__);
-        if (!$do) {
-            return;
-        }
         wsPDFConvert::makeTextSVGFile($in, $out);
         wsTools::optimizeSVG($out, $out);
     }
index 4749d2ce2901dbc8f49ef9e3a647acd0f92f0bf7..c88871bd9adc7542401675e4cff8c5d7ddfc14a7 100644 (file)
@@ -105,7 +105,7 @@ class wsPDFConvert
     {\r
 \r
         // Fabrication des thumbanails avec ghostscript\r
-        $gs = new cubeCommandLine('gs', null, true);\r
+        $gs = new CubeIT_CommandLine('gs', null, true);\r
         $gs->setPath(CONVERTER_PATH);\r
         $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
         $gs->setArg('-dBATCH');\r
@@ -146,7 +146,7 @@ class wsPDFConvert
         $antialiasing = $antialiasing ? 'yes' : 'no';\r
         $freetype = $texts ? 'yes' : 'no';\r
         // Exporte les fichiers\r
-        $pdftoppm = new cubeCommandLine('/usr/local/bin/pdftoppm', null, true);\r
+        $pdftoppm = new CubeIT_CommandLine('/usr/local/bin/pdftoppm', null, true);\r
         $pdftoppm->setPath(CONVERTER_PATH);\r
 \r
         $pdftoppm->setArg('f', $page);\r