]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7819 @11:00
authorsoufiane <soufiane@cubedesigners.com>
Wed, 29 Oct 2025 13:46:04 +0000 (14:46 +0100)
committersoufiane <soufiane@cubedesigners.com>
Wed, 29 Oct 2025 13:46:04 +0000 (14:46 +0100)
app/Console/Commands/AuditLink.php [new file with mode: 0644]
app/Jobs/AuditLink.php [new file with mode: 0644]
app/Models/FluidbookAuditLink.php
app/Models/FluidbookCollection.php

diff --git a/app/Console/Commands/AuditLink.php b/app/Console/Commands/AuditLink.php
new file mode 100644 (file)
index 0000000..140c91d
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\FluidbookCollection;
+use App\Models\FluidbookAuditLink;
+
+class AuditLink extends ToolboxCommand
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'collection:audit-link {id} {--sync}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Audit link in fluidbook collection';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle()
+    {
+        //
+        $c = FluidbookCollection::find($this->argument('id'));
+        $c->runAuditLink($this->option('sync', false));
+        //$f->generateThumbnailsPreview($this->option('sync', false));
+    }
+}
diff --git a/app/Jobs/AuditLink.php b/app/Jobs/AuditLink.php
new file mode 100644 (file)
index 0000000..effa0cf
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Fluidbook\Link\LinksData;
+use App\Models\FluidbookPublication;
+use App\Models\FluidbookCollection;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Log;
+
+class AuditLink extends Base
+{
+    public $c;
+    /**
+     * Create a new job instance.
+     */
+    public function __construct(FluidbookCollection $collection) {
+        $this->c = $collection;
+    }
+    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) {
+                $externalLinks[] = [
+                    'fluidbook_id' => $publication['fluidbook'],
+                    'page' => $link['page'],
+                    'link_id' => $link['uid'],
+                    'error_code' => false,
+                    'first_time_error' => '', // Datetime of the first time we saw this error
+                    'last_date_test' => '',
+                    'url' => $link['to'],
+                    'new_url' => '',
+                    'redirection_code' => '',
+                    'final_code_url' => '',
+                    'final_target' => '',
+                ];
+            }
+            //$externalLinks[] = array_filter($links);
+        }
+        dd($externalLinks);
+
+        Log::info('Job exécuté avec succès');
+    }
+}
index 2f5c2b0f5f5679c4de43a3bade84edb84d823a01..e02b909d38ea91b549d75a43a0d29bacaa02ec9a 100644 (file)
@@ -29,6 +29,7 @@ class FluidbookAuditLink extends ToolboxModel
         $this->addField('link_id', Integer::class, '',[]);
         $this->addField('error_code', Text::class, '',[]);
         $this->addField('first_time_error', Text::class, '',[]);
+        $this->addField('last_date_test', Text::class, '',[]);
         $this->addField('url', Text::class, '',[]);
         $this->addField('new_url', Text::class, '',[]);
         $this->addField('redirection_code', Text::class, '',[]);
index 32acd8a200fc17845bade148733da3a247394e27..7db402ac951e06bc66b33aaf138460c18fbc628a 100644 (file)
@@ -4,12 +4,15 @@ namespace App\Models;
 
 use App\Fields\FluidbookExportVersion;
 use App\Fields\FluidbookStatus;
+use App\Fluidbook\Compiler\Links;
 use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
 use App\Http\Controllers\Admin\Operations\ChangestatusOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookCollection\DownloadOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookCollection\PreviewOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookCollection\SettingsExportOperation;
+use App\Jobs\AuditLink;
 use App\Jobs\FluidbookCollectionRefreshIndex;
+use App\Jobs\GenerateDeliveryThumbnailsPreview;
 use App\Models\Base\ToolboxDownloadable;
 use App\Jobs\RefreshUsersTree;
 use App\Models\Base\ToolboxStatusModel;
@@ -249,7 +252,7 @@ class FluidbookCollection extends ToolboxStatusModel
                 ["name" => ".*", "type" => "auto"]
             ]
         ];
-        
+
         $client = $this->_connectToSearchServer();
         $client->collections['fluidbooks']->delete();
         $client->collections->create($booksSchema);
@@ -262,4 +265,10 @@ class FluidbookCollection extends ToolboxStatusModel
         dispatch(new FluidbookCollectionRefreshIndex($this->id));
         return $res;
     }
+
+    public function runAuditLink($sync = false)
+    {
+        dispatch_sync(new AuditLink($this));
+        //dispatch(new GenerateDeliveryThumbnailsPreview($this, 'mobile'))->onQueue('theme');
+    }
 }