]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7868 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Feb 2026 17:55:58 +0000 (18:55 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Feb 2026 17:55:58 +0000 (18:55 +0100)
app/Jobs/AuditLinkRegister.php
app/Models/LinkShortener.php
app/Models/ShortLink.php

index 4cd82e6c77362d3ec103ef25eee89307825a0ce3..1b5fb77ae177130b1181dee0ba4654c3974ec3c5 100644 (file)
@@ -6,6 +6,7 @@ use App\Fluidbook\Link\LinksData;
 use App\Models\FluidbookAuditLink;
 use App\Models\FluidbookPublication;
 use App\Models\FluidbookCollection;
+use App\Models\ShortLink;
 use Fluidbook\Tools\Links\Link as LinkAlias;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\DB;
@@ -105,5 +106,7 @@ class AuditLinkRegister extends Base
         }
         //Log::info('Deleted ' . count($missing) . ' links');
         //Log::info('Job exécuté avec succès');
+
+        ShortLink::touchChangeFile();
     }
 }
index 179bb25e64cf93abd9d99af7948f68b2b1fc4ae6..a4db242b4d8dcd47d624e79eb149288e83ce2338 100644 (file)
@@ -62,9 +62,13 @@ class LinkShortener extends ToolboxModel
         return $res->longurl ?? false;
     }
 
-    public static function shorturl($url, $shortener)
+    public static function shorturl($url, $shortener, $force = true)
     {
-        return cache()->remember('shorturl_' . $shortener . '_' . $url, 3600, function () use ($url, $shortener) {
+        $cacheKey = 'shorturl_' . $shortener . '_' . $url;
+        if ($force) {
+            cache()->delete($cacheKey);
+        }
+        return cache()->remember($cacheKey, 3600, function () use ($url, $shortener) {
             $res = self::_request('shorturl', ['url' => $url], $shortener, $code);
             if ($code === 200) {
 
index e3134dba7a53ec507890e186ed2d2059c3ceedff..eb5c0b26a6981e5eaef9cec39748943d75e2c867 100644 (file)
@@ -11,6 +11,7 @@ use Cubist\Backpack\Magic\Fields\URL;
 use Cubist\Backpack\Magic\Traits\CustomDataSource;
 use Cubist\Util\Files\Files;
 use DateTime;
+use Illuminate\Support\Facades\Log;
 
 class ShortLink extends ToolboxModel
 {
@@ -63,30 +64,28 @@ class ShortLink extends ToolboxModel
 
         $data = [];
         foreach (LinkShortener::getAvaiableShorteners(true) as $id => $s) {
-            try {
-                foreach (LinkShortener::listAll($id)->result as $i) {
-                    $shorturl = 'https://' . $s['domain'] . '/' . $i->keyword;
-                    $time = new DateTime($i->timestamp);
-                    $d = [
-                        'id' => hash('sha256', $id . '/' . $i->keyword),
-                        'shortlink' => $shorturl,
-                        'url' => $i->url,
-                        'server' => $id,
-                        'created_at' => $time,
-                        'updated_at' => $time,
-                        'deleted_at' => null,
-                        'created_ok' => '1',
-                        'owner' => $s['owner'],
-                    ];
-                    if (isset($auditLinks[$i->url])) {
-                        $d = array_merge($d, $auditLinks[$i->url]);
-                    } else {
-                        continue;
-                    }
-                    $data[$d['id']] = $d;
-                }
-            } catch (\Exception $e) {
 
+            foreach (LinkShortener::listAll($id)->result as $i) {
+                $shorturl = 'https://' . $s['domain'] . '/' . $i->keyword;
+                $time = new DateTime($i->timestamp);
+                $d = [
+                    'id' => hash('sha256', $id . '/' . $i->keyword),
+                    'shortlink' => $shorturl,
+                    'url' => $i->url,
+                    'server' => $id,
+                    'created_at' => $time,
+                    'updated_at' => $time,
+                    'deleted_at' => null,
+                    'created_ok' => '1',
+                    'owner' => $s['owner'],
+                ];
+                if (isset($auditLinks[$i->url])) {
+                    $d = array_merge($d, $auditLinks[$i->url]);
+                } else {
+                    continue;
+                }
+                $d['fluidbook_links']=json_encode($d['fluidbook_links']);
+                $data[$d['id']] = $d;
             }
         }
         return $data;
@@ -97,6 +96,11 @@ 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)) {