]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7199 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Nov 2024 13:54:44 +0000 (14:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Nov 2024 13:54:44 +0000 (14:54 +0100)
.docker/images/php/Dockerfile
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
app/Jobs/Maintenance/ListWorkingSymlinks.php [new file with mode: 0644]
app/Jobs/Maintenance/RemoveDuplicates.php
app/Models/FluidbookPublication.php

index 645253fce06f4072802ad4bd1320712ba08704fd..c16d7e286073bcbd68d66101bca4f6e9910080d6 100644 (file)
@@ -69,7 +69,7 @@ RUN apt -y --no-install-recommends install sshfs python3 python3-pip
 RUN apt -y --no-install-recommends install openssh-server rsyslog
 RUN apt -y --no-install-recommends install wine libwine wine64
 RUN apt -y --no-install-recommends install pdfposter rename
-RUN apt -y --no-install-recommends install jdupes
+RUN apt -y --no-install-recommends install jdupes symlinks
 RUN apt -y --no-install-recommends install dnsutils
 
 RUN apt -y --no-install-recommends install locales
index 169af7ade3148588630275e444f5712683ab9746..9e19a725d9bd98caabc461077fe6e266c49195b6 100644 (file)
@@ -4,20 +4,16 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
 
 // __('!!Paramètres des fluidbooks')
 
-use App\Fluidbook\Compiler\Compiler;
 use App\Fluidbook\Link\LinksData;
 use App\Models\FluidbookPublication;
 use App\Models\User;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
 use Cubist\Util\Files\Files;
 use Illuminate\Http\UploadedFile;
-use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Route;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
-use Illuminate\Support\Facades\Broadcast;
 use Illuminate\Support\Str;
 use Illuminate\Http\Request;
-use Prologue\Alerts\Facades\Alert;
 
 
 trait LinksOperation
diff --git a/app/Jobs/Maintenance/ListWorkingSymlinks.php b/app/Jobs/Maintenance/ListWorkingSymlinks.php
new file mode 100644 (file)
index 0000000..9308e98
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+
+namespace App\Jobs\Maintenance;
+
+use App\Jobs\Base;
+use App\Models\FluidbookPublication;
+use Cubist\Util\Text;
+
+class ListWorkingSymlinks extends Base
+{
+
+
+    public function handle()
+    {
+        foreach (FluidbookPublication::withoutGlobalScopes()->where('created_ok', 1)->get() as $fluidbook) {
+            static::parseFluidbookDir($fluidbook);
+        }
+    }
+
+    /**
+     * @param $fluidbook FluidbookPublication|int
+     * @return void
+     */
+
+    protected static function parseFluidbookDir($fluidbook)
+    {
+        if (!($fluidbook instanceof FluidbookPublication)) {
+            $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($fluidbook);
+        }
+
+        /* @var $fluidbook FluidbookPublication */
+        $dir = $fluidbook->getAssetDir();
+        if (!file_exists($dir)) {
+            echo 'skip ' . $dir . " (not exists)\n";
+            return;
+        }
+        echo 'check ' . $dir . "\n";
+        $output = `symlinks -rv $dir`;
+        $changed = false;
+        $outlinks = Text::explodeNewLines($output);
+        if (!count($outlinks)) {
+            echo 'skip ' . $dir . " (no symlinks)\n";
+            return;
+        }
+        $links = static::getWorkingSymlinks();
+        foreach ($outlinks as $l) {
+            if (preg_match('/absolute: (.*) -> (.*)/', $l, $matches)) {
+                $link = $matches[1];
+                $target = $matches[2];
+                if (!isset($links[$target])) {
+                    $links[$target] = [];
+                }
+                if (!isset($links[$target][$link])) {
+                    $links[$target][$link] = true;
+                    $changed = true;
+                }
+            }
+        }
+        if (!$changed) {
+            echo 'skip ' . $dir . " (nothing changed)\n";
+            return;
+        }
+        static::saveWorkingSymlinks($links);
+    }
+
+    protected static function _getCacheFile()
+    {
+        return protected_path('fluidbookpublication/cache/working_symlinks.json');
+    }
+
+    public static function getWorkingSymlinks()
+    {
+       if(!file_exists(static::_getCacheFile())) {
+           return [];
+       }
+        return json_decode(file_get_contents(static::_getCacheFile()), true) ?? [];
+    }
+
+    public static function saveWorkingSymlinks($links)
+    {
+        file_put_contents(static::_getCacheFile(), json_encode($links));
+    }
+}
index da8da62853fd3fc1b413fa83b7f2e97ff8e25730..dad71619f7d961d01e968d9789524fa237e8736c 100644 (file)
@@ -17,5 +17,6 @@ class RemoveDuplicates extends Base
             $jdupes->setArg(null, $directory);
             $jdupes->execute();
         }
+        ListWorkingSymlinks::dispatchSync();
     }
 }
index f466277a9c323f75b844dfbbb41a88d7b02e4345..90ab9efbf1e87306a54b6ccdf66134623e2dd87c 100644 (file)
@@ -607,6 +607,10 @@ class FluidbookPublication extends ToolboxStatusModel
         return $this->protected_path('fluidbookpublication/final/' . $dir . '/' . ($scormVariant ? 'scorm' : 'online'));
     }
 
+    public function _getFreeFileRootDirectory()
+    {
+        return Files::mkdir($this->protected_path('fluidbookpublication/working/'));
+    }
 
     public function getAssetDir()
     {