From 601073e090642c9ee2664c63c644d3ffaa8f301d Mon Sep 17 00:00:00 2001 From: soufiane Date: Thu, 6 Nov 2025 18:36:40 +0100 Subject: [PATCH] wip #7819 @7:00 --- app/Console/Commands/RegisterLinks.php | 33 +++++++++++ app/Jobs/AuditLink.php | 61 ++++++++------------- app/Jobs/registerLinksForAudit.php | 76 ++++++++++++++++++++++++++ app/Models/FluidbookCollection.php | 6 ++ 4 files changed, 137 insertions(+), 39 deletions(-) create mode 100644 app/Console/Commands/RegisterLinks.php create mode 100644 app/Jobs/registerLinksForAudit.php diff --git a/app/Console/Commands/RegisterLinks.php b/app/Console/Commands/RegisterLinks.php new file mode 100644 index 000000000..5c9d488e4 --- /dev/null +++ b/app/Console/Commands/RegisterLinks.php @@ -0,0 +1,33 @@ +c->publications as $publication) { - LinksData::getLinksAndRulers($publication['fluidbook'], $links, $rulers); - - // We want only url link begin with http or https and webvideo link - // type // 10: web video // 2: url - $links = array_filter($links, function($n){ - return ($n['type'] == 2 && preg_match('/https?:\/\//', $n['to']) ) || $n['type'] == 10; - }); - - foreach ($links as $link) { - if($link['video_service'] === "youtube") { - if(FluidbookAuditLink::youtubeVideoExist($link['to'])) { - $link['to'] = "https://youtu.be/".$link['to']; - } - } - - // Error code start with 4 or 5 - // Redirection code start with 3 - $httpCode = FluidbookAuditLink::getHttpCode($link['to']); - $comment = FluidbookAuditLink::getHttpCodeComment($httpCode); - - $externalLinks[] = [ - 'link_id' => $link['uid'], - 'fluidbook_id' => intval($publication['fluidbook']), - 'page' => intval($link['page']), - 'error_code' => str_starts_with($httpCode, 4) || str_starts_with($httpCode, 5) ? $httpCode.$comment : "", - 'first_time_error' => "", // Datetime of the first time we saw this error - 'last_date_test' => date('Y-m-d H:i:s'), - 'url' => $link['to'], - 'new_url' => '', - 'redirection_code' => str_starts_with($httpCode, 3) ? $httpCode : "", - 'final_code_url' => '', - 'final_target' => '', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at'=> date('Y-m-d H:i:s') - ]; - } + $allLinks = FluidbookAuditLink::all(); + + foreach ($allLinks as $fb => $link) { + // Error code start with 4 or 5 + // Redirection code start with 3 + $httpCode = FluidbookAuditLink::getHttpCode($link['url']); + $comment = FluidbookAuditLink::getHttpCodeComment($httpCode); + + $externalLinks[] = [ + 'error_code' => str_starts_with($httpCode, 4) || str_starts_with($httpCode, 5) ? $httpCode.$comment : "", + 'first_time_error' => "", // Datetime of the first time we saw this error + 'last_date_test' => date('Y-m-d H:i:s'), + 'redirection_code' => str_starts_with($httpCode, 3) ? $httpCode : "", + 'final_code_url' => '', + 'final_target' => '', + 'updated_at'=> date('Y-m-d H:i:s') + ]; } - FluidbookAuditLink::updateOrCreate($externalLinks); + FluidbookAuditLink::update($externalLinks); Log::info('Job exécuté avec succès'); } + + public function compareLinks() { + + } } diff --git a/app/Jobs/registerLinksForAudit.php b/app/Jobs/registerLinksForAudit.php new file mode 100644 index 000000000..9a07bfa26 --- /dev/null +++ b/app/Jobs/registerLinksForAudit.php @@ -0,0 +1,76 @@ +pluck('publications')->toArray(), 1); + + $publications = array_map(function($n) { + return $n['fluidbook']; + }, $publications); + + // Utile pour vérifier si la liste des fluidbooks fourni par les collections + // existent vraiment ou s'ils ont été supprimé sans être supprimé dans la collection + $publications = FluidbookPublication::whereIn('id',$publications)->pluck('id'); + + foreach ($publications as $publication) { + // Get all links in current fluidbook + // Access to links in $links variable + LinksData::getLinksAndRulers($publication, $links, $rulers); + + // We want only url link begin with http or https and webvideo link + // type // 10: web video // 2: url + $links = array_filter($links, function($n){ + return ($n['type'] == 2 && preg_match('/https?:\/\//', $n['to']) ) || $n['type'] == 10; + }); + + foreach ($links as $link) { + if(Arr::exists($link,'video_service')) { + if ($link['video_service'] === "youtube") { + if (FluidbookAuditLink::youtubeVideoExist($link['to'])) { + $link['to'] = "https://youtu.be/" . $link['to']; + } + } + } + + $externalLinks[] = [ + 'link_id' => $link['uid'], + 'fluidbook_id' => intval($publication), + 'page' => intval($link['page']), + 'url' => $link['to'], + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at'=> date('Y-m-d H:i:s') + ]; + } + + print_r($publication.' => OK'. PHP_EOL); + } + + FluidbookAuditLink::updateOrCreate($externalLinks); + + Log::info('Job exécuté avec succès'); + } +} diff --git a/app/Models/FluidbookCollection.php b/app/Models/FluidbookCollection.php index 739cf114c..ec6a70932 100644 --- a/app/Models/FluidbookCollection.php +++ b/app/Models/FluidbookCollection.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Console\Commands\RegisterLinks; use App\Fields\FluidbookExportVersion; use App\Fields\FluidbookStatus; use App\Fluidbook\Compiler\Links; @@ -14,6 +15,7 @@ use App\Http\Controllers\Admin\Operations\FluidbookCollection\SettingsExportOper use App\Jobs\AuditLink; use App\Jobs\FluidbookCollectionRefreshIndex; use App\Jobs\GenerateDeliveryThumbnailsPreview; +use App\Jobs\registerLinksForAudit; use App\Models\Base\ToolboxDownloadable; use App\Jobs\RefreshUsersTree; use App\Models\Base\ToolboxStatusModel; @@ -314,6 +316,10 @@ class FluidbookCollection extends ToolboxStatusModel dispatch_sync(new AuditLink($this)); } + public static function registerLinks() { + dispatch_sync(new registerLinksForAudit()); + } + public static function updateHemsleyCollection($data) { $c = self::where('title','=','Audit Hemsley'); $collection = $c->get(); -- 2.39.5