This commit is contained in:
User
2025-01-18 19:05:23 -05:00
parent 3f282d6ecd
commit 14938f63df
23 changed files with 652 additions and 177 deletions

71
app/Jobs/ComicUpsert.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace App\Jobs;
use App\Models\Author;
use App\Models\Comic;
use App\Models\Image;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class ComicUpsert implements ShouldQueue
{
use IsMonitored, Queueable;
/**
* Create a new job instance.
*/
public function __construct(
public array $comic,
) {}
/**
* Execute the job.
*/
public function handle(): void
{
$this->queueProgress(0);
Log::info("JOB ComicUpsert START");
$comicsUpsertArray = [];
$authorsUpsertArray = [];
foreach ($this->comic['list'] as $comic) {
$comicsUpsertArray[] = [
'pathword' => $comic['path_word'],
'uuid' => '',
'name' => $comic['name'],
'alias' => '{}',
'description' => '',
'cover' => $comic['cover'],
'upstream_updated_at' => $comic['datetime_updated'] ?? null,
];
foreach ($comic['author'] as $author) {
$authorsUpsertArray[] = [
'name' => $author['name']
];
}
}
// Do an upsert for comics
Comic::upsert($comicsUpsertArray, uniqueBy: 'pathword', update: ['upstream_updated_at']);
Author::upsert($authorsUpsertArray, uniqueBy: 'name');
// Had to do a second pass to insert the relationships
foreach ($this->comic['list'] as $comic) {
// Get the comic id
$comicObj = Comic::where('pathword', $comic['path_word'])->first();
foreach ($comic['author'] as $author) {
$authorObj = Author::where('name', $author['name'])->first();
$comicObj->authors()->sync($authorObj);
}
}
Log::info('JOB ComicUpsert END');
$this->queueProgress(100);
}
}

View File

@@ -6,10 +6,11 @@ use App\Models\Image;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class ImageUpsert implements ShouldQueue
{
use Queueable;
use IsMonitored, Queueable;
/**
* Create a new job instance.
@@ -25,7 +26,12 @@ class ImageUpsert implements ShouldQueue
*/
public function handle(): void
{
$this->queueProgress(0);
Log::info("JOB ImageUpsert START, comicId: {$this->comicId}, chapterId: {$this->chapterId}");
$this->queueData([
'comicId' => $this->comicId,
'chapterId' => $this->chapterId,
]);
$arrayForUpsert = [];
@@ -47,5 +53,6 @@ class ImageUpsert implements ShouldQueue
Image::upsert($arrayForUpsert, uniqueBy: 'url');
Log::info('JOB ImageUpsert END');
$this->queueProgress(100);
}
}

View File

@@ -6,10 +6,11 @@ use App\Remote\CopyManga;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class RemotePrefetch implements ShouldQueue
{
use Queueable;
use IsMonitored, Queueable;
/**
* Create a new job instance.
@@ -24,11 +25,17 @@ class RemotePrefetch implements ShouldQueue
*/
public function handle(): void
{
$this->queueProgress(0);
$copyManga = new CopyManga();
switch ($this->action) {
case 'chapter':
Log::info("JOB RemotePrefetch START, action '{$this->action}', Pathword: {$this->parameters['pathword']}, UUID: {$this->parameters['uuid']}");
$this->queueData([
'action' => $this->action,
'pathword' => $this->parameters['pathword'],
'uuid' => $this->parameters['uuid']
]);
$copyManga->chapter($this->parameters['pathword'], $this->parameters['uuid']);
@@ -37,15 +44,25 @@ class RemotePrefetch implements ShouldQueue
case 'chapters':
// TODO:
break;
case 'index':
// TODO
break;
case 'tags':
// TODO
case 'comics':
Log::info("JOB RemotePrefetch START, action '{$this->action}', Offset: {$this->parameters['offset']}");
$this->queueData([
'action' => $this->action,
'offset' => $this->parameters['offset'],
'limit' => $this->parameters['limit'],
'top' => $this->parameters['top'],
'params' => $this->parameters['params']
]);
$copyManga->comics($this->parameters['offset'], $this->parameters['limit'], $this->parameters['top'], $this->parameters['params']);
Log::info("JOB RemotePrefetch END, action '{$this->action}'");
break;
default:
Log::info("JOB RemotePrefetch Unknown action '{$this->action}'");
break;
}
$this->queueProgress(100);
}
}