]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7819 @7:00
authorsoufiane <soufiane@cubedesigners.com>
Thu, 6 Nov 2025 17:36:40 +0000 (18:36 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 6 Nov 2025 17:36:40 +0000 (18:36 +0100)
app/Console/Commands/RegisterLinks.php [new file with mode: 0644]
app/Jobs/AuditLink.php
app/Jobs/registerLinksForAudit.php [new file with mode: 0644]
app/Models/FluidbookCollection.php

diff --git a/app/Console/Commands/RegisterLinks.php b/app/Console/Commands/RegisterLinks.php
new file mode 100644 (file)
index 0000000..5c9d488
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\FluidbookCollection;
+use App\Models\FluidbookAuditLink;
+
+class RegisterLinks extends ToolboxCommand
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'collection:register-links {--sync}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Register links in database for audit';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle()
+    {
+        //
+        FluidbookCollection::registerLinks($this);
+    }
+}
index e1dcb3d9ac2eb9ea500dbfd452f5133f2e6ce364..1c8817bbe333134b9f320a8f4fcfd7bd5bea957c 100644 (file)
@@ -22,48 +22,31 @@ class AuditLink extends Base
     }
     public function handle()
     {
-        $externalLinks = [];
-        foreach ($this->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 (file)
index 0000000..9a07bfa
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Fluidbook\Link\LinksData;
+use App\Models\FluidbookAuditLink;
+use App\Models\FluidbookPublication;
+use App\Models\FluidbookCollection;
+use Cubist\Net\Util;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
+use mysql_xdevapi\Exception;
+
+class registerLinksForAudit extends Base
+{
+    /**
+     * Create a new job instance.
+     */
+    public function __construct() {
+    }
+
+    public function handle()
+    {
+        $externalLinks = [];
+
+        $publications = Arr::flatten(FluidbookCollection::where('enable_audit',1)->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');
+    }
+}
index 739cf114c4ada2eb94585e194cc4cf1cc3b29729..ec6a709323aca138c17849eb73b6d3b44d1de7b6 100644 (file)
@@ -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();