]> _ Git - fluidbook-toolbox.git/commitdiff
wip #8000 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Feb 2026 15:54:54 +0000 (16:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Feb 2026 15:54:54 +0000 (16:54 +0100)
app/Fluidbook/Link/LinksData.php
app/Jobs/AuditLink.php
app/Jobs/AuditLinkRegister.php
app/Models/ShortLink.php

index e03fe845eb1978e93cd4dfc5daeb597ec3fa4589..30b6d83eb7c23e42788ca3e2b45615fc2a5fceb1 100644 (file)
@@ -552,7 +552,7 @@ class LinksData
         self::_fixLinks($links);
     }
 
-    public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [])
+    public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [], $triggerJobs = true)
     {
         /** @var FluidbookPublication $fluidbook */
         $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($book_id);
@@ -572,10 +572,13 @@ class LinksData
         file_put_contents($base . '.links3.gz', gzencode(json_encode($lr)));
         copy($base . '.links3.gz', $latestLinks);
         copy($base . '.meta3.gz', $latestMeta);
-
+        
         $fluidbook->touch();
-        if ($fluidbook->linkShortener && $fluidbook->linkShortener != "none") {
-            AuditLinkRegister::dispatch();
+
+        if ($triggerJobs) {
+            if ($fluidbook->linkShortener && $fluidbook->linkShortener != "none") {
+                AuditLinkRegister::dispatch();
+            }
         }
     }
 
index 572b045739dbd36664a55f4a689eb23359314374..eacf5adce7ad6f7e2a01aa2b51a3e8b31e0682dc 100644 (file)
@@ -45,7 +45,6 @@ class AuditLink extends Base
         HTTP::setCookieFile(Files::mkdir(protected_path('fluidbookpublication/linkaudit')) . 'cookies.txt');
 
         $this->extracted($urls);
-        Log::info('Job exécuté avec succès');
         ShortLink::touchChangeFile();
     }
 
index d8eef35f7659a1dfe5ae1a1ebb0d052fc2c31311..eaa1adafb7aca7a2382b1b436f90234cfd0366c3 100644 (file)
@@ -105,7 +105,8 @@ class AuditLinkRegister extends Base
         //Log::info('Deleted ' . count($missing) . ' links');
         //Log::info('Job exécuté avec succès');
 
+        $f = $this->isSync() ? 'dispatchSync' : 'dispatch';
+        AuditLink::$f(count($externalLinks));
         ShortLink::touchChangeFile();
-        AuditLink::dispatch(count($externalLinks));
     }
 }
index 1d557419a97ca36bc700ada6f39194839b5743e5..2398eff27fc0748406783471efe114f2c1ad8548 100644 (file)
@@ -3,6 +3,9 @@
 namespace App\Models;
 
 use App\Fields\ShortLinkFluidbooks;
+use App\Fluidbook\Link\Link;
+use App\Fluidbook\Link\LinksData;
+use App\Jobs\AuditLinkRegister;
 use App\Models\Base\ToolboxModel;
 use Carbon\Carbon;
 use Cubist\Backpack\CubistBackpackServiceProvider;
@@ -12,6 +15,7 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Fields\URL;
 use Cubist\Backpack\Magic\Traits\CustomDataSource;
 use Cubist\Util\Files\Files;
+use Cubist\Util\WebVideo;
 use DateTime;
 
 class ShortLink extends ToolboxModel
@@ -115,15 +119,36 @@ class ShortLink extends ToolboxModel
         return Files::mkdir(resource_path('shortlink')) . 'lastchange';
     }
 
-    public static function shouldRefreshDatabase()
-    {
-        return true;
-    }
-
     public function onSaved(): bool
     {
-        if ($this->url !== LinkShortener::expand($this->shortlink, $this->server)) {
+        $formerValue = LinkShortener::expand($this->shortlink, $this->server);
+        if ($this->url !== $formerValue) {
             LinkShortener::updateURL($this->shortlink, $this->url, $this->server);
+            $fbl = json_decode($this->fluidbook_links, true);
+            if (count($fbl) > 0) {
+                $fluidbooks = [];
+                foreach ($fbl as $l) {
+                    if (!isset($fluidbooks[$l['fluidbook_id']])) {
+                        $fluidbooks[$l['fluidbook_id']] = [];
+                    }
+                    $fluidbooks[$l['fluidbook_id']][$l['link_id']] = $l;
+                }
+
+                foreach ($fluidbooks as $id => $changedLinks) {
+                    LinksData::getLinksAndRulers($id, $links, $rulers);
+                    foreach ($changedLinks as $uid => $l) {
+                        $currentLink = $links[$uid];
+                        if ($currentLink['type'] == Link::WEBVIDEO && $currentLink['video_service'] == 'youtube') {
+                            $links[$uid]['to'] = WebVideo::_findVideoId($this->url, 'youtube');
+                        } else {
+                            $links[$uid]['to'] = $this->uid;
+                        }
+                    }
+                    LinksData::saveLinksInFile($id, backpack_user()->id, __('Lien court :shortlink édité', ['shortlink' => $this->shortlink]), $links, $rulers, [], [], false);
+                }
+            }
+            AuditLinkRegister::dispatchSync();
+            static::touchChangeFile();
         }
         return parent::onSaved();
     }