--- /dev/null
+<?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);
+ }
+}
}
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() {
+
+ }
}
--- /dev/null
+<?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');
+ }
+}
namespace App\Models;
+use App\Console\Commands\RegisterLinks;
use App\Fields\FluidbookExportVersion;
use App\Fields\FluidbookStatus;
use App\Fluidbook\Compiler\Links;
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;
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();