]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6598 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 3 Jan 2024 11:34:45 +0000 (12:34 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 3 Jan 2024 11:34:45 +0000 (12:34 +0100)
app/Fluidbook/Farm.php
app/Models/FluidbookDocument.php

index 9451ccf9be8131653eda5d74a91565876d63d9c8..ae9670212336b0f8f716cffcd9342be8f9a04a3d 100644 (file)
@@ -194,9 +194,27 @@ class Farm
 
     public static function fixPDF($pdf, $out)
     {
-        return self::_getFile(['operation' => 'fixpdf',
-            'pdf' => $pdf,
-            'out' => $out], 0, false, true);
+        return static::lock($pdf, 'fix', function () use ($pdf, $out) {
+            if (file_exists($out) && filesize($out) > 0 && filemtime($out) >= filemtime($pdf)) {
+                return $out;
+            }
+
+            return self::_getFile(['operation' => 'fixpdf',
+                'pdf' => $pdf,
+                'out' => $out], 0, false, true);
+        });
+    }
+
+    public static function lock($pdf, $operation, $callback)
+    {
+        $lockFile = $pdf . '.' . $operation . '.lock';
+        while (file_exists($lockFile) && filemtime($lockFile) > time() - 3600) {
+            sleep(30);
+        }
+        touch($lockFile);
+        $res = $callback();
+        unlink($lockFile);
+        return $res;
     }
 
     public static function cutPDF($pdf, $mode, $out)
index fff829a03f81b70bc5395c0a2ae1806915da14b6..fa9ce4ec7dcb438f88fca5eb97596c67ac2fc012 100644 (file)
@@ -193,9 +193,9 @@ class FluidbookDocument extends ToolboxModel
     {
         $fixed = $this->getPDFSource('fixed');
         $original = $this->getPDFSource('original');
-        if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
+
             Farm::fixPDF($original, $fixed);
-        }
+
         return $fixed;
     }