From: Vincent Vanwaelscappel Date: Mon, 9 Feb 2026 17:55:58 +0000 (+0100) Subject: wip #7868 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=010292b24a96cbfaebe7be641596027a05b16632;p=fluidbook-toolbox.git wip #7868 @1 --- diff --git a/app/Jobs/AuditLinkRegister.php b/app/Jobs/AuditLinkRegister.php index 4cd82e6c7..1b5fb77ae 100644 --- a/app/Jobs/AuditLinkRegister.php +++ b/app/Jobs/AuditLinkRegister.php @@ -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(); } } diff --git a/app/Models/LinkShortener.php b/app/Models/LinkShortener.php index 179bb25e6..a4db242b4 100644 --- a/app/Models/LinkShortener.php +++ b/app/Models/LinkShortener.php @@ -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) { diff --git a/app/Models/ShortLink.php b/app/Models/ShortLink.php index e3134dba7..eb5c0b26a 100644 --- a/app/Models/ShortLink.php +++ b/app/Models/ShortLink.php @@ -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)) {