From 969f4569f5ca8fe0773a88cb07950d9e173f096d Mon Sep 17 00:00:00 2001 From: "ext.jeremy.guillot@maxicoffee.domains" Date: Fri, 27 Mar 2026 15:03:05 +0100 Subject: [PATCH] =?UTF-8?q?fix(monitoring):=20corriger=20la=20r=C3=A9solut?= =?UTF-8?q?ion=20de=20l'ID=20chapitre=20apr=C3=A8s=20synchronisation=20Man?= =?UTF-8?q?gaDex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../RefreshMangaChaptersHandler.php | 18 +++++++++++++----- .../ChapterSynchronizationServiceInterface.php | 2 +- .../MangadxChapterSynchronizationService.php | 4 ++-- .../InMemoryChapterSynchronizationService.php | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Domain/Manga/Application/CommandHandler/RefreshMangaChaptersHandler.php b/src/Domain/Manga/Application/CommandHandler/RefreshMangaChaptersHandler.php index 4e58337..67f6702 100644 --- a/src/Domain/Manga/Application/CommandHandler/RefreshMangaChaptersHandler.php +++ b/src/Domain/Manga/Application/CommandHandler/RefreshMangaChaptersHandler.php @@ -26,18 +26,26 @@ readonly class RefreshMangaChaptersHandler throw new \RuntimeException('Manga not found'); } - // Synchronisation + récupération des nouveaux IDs - $newChapterIds = $this->chapterSynchronizationService->synchronizeChapters($manga); + // Synchronisation + récupération des numéros de nouveaux chapitres + $newChapterNumbers = $this->chapterSynchronizationService->synchronizeChapters($manga); // Mise à jour de la date de monitoring $manga->updateLastMonitoringCheck(new \DateTimeImmutable()); $this->mangaRepository->save($manga); // Événement de scraping pour chaque nouveau chapitre - foreach ($newChapterIds as $chapterId) { - $this->eventBus->dispatch( - new ChapterReadyForScraping(new ChapterId($chapterId)) + // On retrouve l'ID réel (PK integer) après save() car le chapitre n'a + // son identifiant définitif qu'une fois persisté en base. + foreach ($newChapterNumbers as $chapterNumber) { + $saved = $this->mangaRepository->findChapterByMangaIdAndNumber( + $manga->getId()->getValue(), + $chapterNumber ); + if ($saved) { + $this->eventBus->dispatch( + new ChapterReadyForScraping(new ChapterId($saved->getId())) + ); + } } } } diff --git a/src/Domain/Manga/Domain/Contract/Service/ChapterSynchronizationServiceInterface.php b/src/Domain/Manga/Domain/Contract/Service/ChapterSynchronizationServiceInterface.php index ff44389..1e93473 100644 --- a/src/Domain/Manga/Domain/Contract/Service/ChapterSynchronizationServiceInterface.php +++ b/src/Domain/Manga/Domain/Contract/Service/ChapterSynchronizationServiceInterface.php @@ -9,7 +9,7 @@ interface ChapterSynchronizationServiceInterface /** * 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; } diff --git a/src/Domain/Manga/Infrastructure/Service/MangadxChapterSynchronizationService.php b/src/Domain/Manga/Infrastructure/Service/MangadxChapterSynchronizationService.php index a935770..d76f021 100644 --- a/src/Domain/Manga/Infrastructure/Service/MangadxChapterSynchronizationService.php +++ b/src/Domain/Manga/Infrastructure/Service/MangadxChapterSynchronizationService.php @@ -96,11 +96,11 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz $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) { if (!isset($existingChapters[(float) $chapterNumber])) { $manga->addChapter($chapter); - $newChapterIds[] = $chapter->getId(); + $newChapterIds[] = $chapter->getNumber(); } } diff --git a/tests/Domain/Manga/Adapter/InMemoryChapterSynchronizationService.php b/tests/Domain/Manga/Adapter/InMemoryChapterSynchronizationService.php index 5ce6b30..53a8cd2 100644 --- a/tests/Domain/Manga/Adapter/InMemoryChapterSynchronizationService.php +++ b/tests/Domain/Manga/Adapter/InMemoryChapterSynchronizationService.php @@ -18,8 +18,8 @@ class InMemoryChapterSynchronizationService implements ChapterSynchronizationSer 'synchronized_at' => new \DateTimeImmutable(), ]; - // Retourne les IDs des chapitres synchronisés (simulation) - return ['chapter-1', 'chapter-2']; + // Retourne les numéros des chapitres synchronisés (simulation) + return [1.0, 2.0]; } /**