1 Commits

Author SHA1 Message Date
ext.jeremy.guillot@maxicoffee.domains
969f4569f5 fix(monitoring): corriger la résolution de l'ID chapitre après synchronisation MangaDex
synchronizeChapters() retournait des UUID temporaires générés en mémoire. Ces UUID
n'étant jamais persistés, le Scraping domain ne pouvait pas retrouver le chapitre
(SQLSTATE 22P02 : invalid input syntax for type integer).

- ChapterSynchronizationServiceInterface : retourne float[] (numéros) au lieu de string[] (UUID)
- MangadxChapterSynchronizationService : retourne getNumber() au lieu de getId()
- RefreshMangaChaptersHandler : après save(), retrouve chaque chapitre par manga+numéro
  via findChapterByMangaIdAndNumber() pour obtenir le vrai PK integer avant de dispatcher
  ChapterReadyForScraping
2026-03-27 15:03:05 +01:00
6 changed files with 18 additions and 67 deletions

View File

@@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Domain\Manga\Application\Command\CheckMonitoredMangas;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Messenger\MessageBusInterface;
#[AsCommand(
name: 'app:monitoring:run',
description: 'Déclenche immédiatement la vérification des mangas monitorés (sans attendre le scheduler)',
)]
class RunMonitoringCommand extends Command
{
public function __construct(
private readonly MessageBusInterface $commandBus,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Déclenchement du monitoring des mangas...');
$this->commandBus->dispatch(new CheckMonitoredMangas());
$output->writeln('<info>Vérification lancée. Les nouveaux chapitres détectés seront scrappés via le worker commands.</info>');
return Command::SUCCESS;
}
}

View File

@@ -26,18 +26,26 @@ readonly class RefreshMangaChaptersHandler
throw new \RuntimeException('Manga not found'); throw new \RuntimeException('Manga not found');
} }
// Synchronisation + récupération des nouveaux IDs // Synchronisation + récupération des numéros de nouveaux chapitres
$newChapterIds = $this->chapterSynchronizationService->synchronizeChapters($manga); $newChapterNumbers = $this->chapterSynchronizationService->synchronizeChapters($manga);
// Mise à jour de la date de monitoring // Mise à jour de la date de monitoring
$manga->updateLastMonitoringCheck(new \DateTimeImmutable()); $manga->updateLastMonitoringCheck(new \DateTimeImmutable());
$this->mangaRepository->save($manga); $this->mangaRepository->save($manga);
// Événement de scraping pour chaque nouveau chapitre // Événement de scraping pour chaque nouveau chapitre
foreach ($newChapterIds as $chapterId) { // On retrouve l'ID réel (PK integer) après save() car le chapitre n'a
$this->eventBus->dispatch( // son identifiant définitif qu'une fois persisté en base.
new ChapterReadyForScraping(new ChapterId($chapterId)) foreach ($newChapterNumbers as $chapterNumber) {
$saved = $this->mangaRepository->findChapterByMangaIdAndNumber(
$manga->getId()->getValue(),
$chapterNumber
); );
if ($saved) {
$this->eventBus->dispatch(
new ChapterReadyForScraping(new ChapterId($saved->getId()))
);
}
} }
} }
} }

View File

@@ -9,7 +9,7 @@ interface ChapterSynchronizationServiceInterface
/** /**
* Synchronise les chapitres d'un manga depuis la source externe. * Synchronise les chapitres d'un manga depuis la source externe.
* *
* @return string[] IDs des nouveaux chapitres ajoutés * @return float[] Numéros des nouveaux chapitres ajoutés
*/ */
public function synchronizeChapters(Manga $manga): array; public function synchronizeChapters(Manga $manga): array;
} }

View File

@@ -1,21 +0,0 @@
<?php
namespace App\Domain\Manga\Infrastructure\CommandHandler;
use App\Domain\Manga\Application\Command\CheckMonitoredMangas;
use App\Domain\Manga\Application\CommandHandler\CheckMonitoredMangasHandler;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
readonly class SymfonyCheckMonitoredMangasHandler
{
public function __construct(
private CheckMonitoredMangasHandler $handler,
) {
}
public function __invoke(CheckMonitoredMangas $command): void
{
$this->handler->handle($command);
}
}

View File

@@ -96,11 +96,11 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
$newChapterIds = []; $newChapterIds = [];
// Sauvegarde uniquement les nouveaux chapitres et collecte leurs IDs // Sauvegarde uniquement les nouveaux chapitres et collecte leurs numéros
foreach ($chaptersByNumber as $chapterNumber => $chapter) { foreach ($chaptersByNumber as $chapterNumber => $chapter) {
if (!isset($existingChapters[(float) $chapterNumber])) { if (!isset($existingChapters[(float) $chapterNumber])) {
$manga->addChapter($chapter); $manga->addChapter($chapter);
$newChapterIds[] = $chapter->getId(); $newChapterIds[] = $chapter->getNumber();
} }
} }

View File

@@ -18,8 +18,8 @@ class InMemoryChapterSynchronizationService implements ChapterSynchronizationSer
'synchronized_at' => new \DateTimeImmutable(), 'synchronized_at' => new \DateTimeImmutable(),
]; ];
// Retourne les IDs des chapitres synchronisés (simulation) // Retourne les numéros des chapitres synchronisés (simulation)
return ['chapter-1', 'chapter-2']; return [1.0, 2.0];
} }
/** /**