refactor(manga): merge ChapterRepositoryInterface into MangaRepositoryInterface + pagesDirectory

- Supprime ChapterRepositoryInterface du domaine Manga (et ses implémentations
  LegacyChapterRepository et InMemoryChapterRepository)
- Déplace toutes les méthodes chapter vers MangaRepositoryInterface avec nommage
  explicite (findChapterById, findVisibleChapterById, updateChapter, deleteChapter, etc.)
- Remplace cbzPath par pagesDirectory + pageCount dans le modèle Chapter
  (transition : toChapterDomain conserve un fallback cbzPath pour les données existantes,
  updateChapter synchronise les deux colonnes jusqu'à la Phase 4)
- Ajoute la migration Doctrine (pages_directory, page_count sur la table chapter)
- Met à jour tous les handlers, listeners, query handlers et state providers du domaine
  Manga pour injecter uniquement MangaRepositoryInterface
- Adapte les tests unitaires et InMemoryMangaRepository avec les nouvelles méthodes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-09 17:54:35 +01:00
parent dae215dd3d
commit c50f1638ee
27 changed files with 410 additions and 419 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\ImportVolume;
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Manga\Domain\Model\Chapter;
@@ -14,7 +13,6 @@ readonly class ImportVolumeHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private ChapterRepositoryInterface $chapterRepository,
private MangaPathManagerInterface $pathManager
) {}
@@ -32,7 +30,7 @@ readonly class ImportVolumeHandler
}
// 3. Get all chapters for this volume
$chapters = $this->chapterRepository->findByMangaIdAndVolume(
$chapters = $this->mangaRepository->findChaptersByMangaIdAndVolume(
$command->mangaId,
$command->volumeNumber
);
@@ -46,7 +44,8 @@ readonly class ImportVolumeHandler
// 4. Save the CBZ file to storage using the path manager
$cbzPath = $this->saveCbzFile($command, $manga);
// 5. Update all chapters with the volume CBZ path
// 5. Update all chapters with the volume path
// Note: pagesDirectory holds CBZ path during transition; Phase 3 will store individual images
foreach ($chapters as $chapter) {
$updatedChapter = new Chapter(
id: new ChapterId($chapter->getId()),
@@ -55,37 +54,29 @@ readonly class ImportVolumeHandler
title: $chapter->getTitle(),
volume: $chapter->getVolume(),
isVisible: $chapter->isVisible(),
cbzPath: $cbzPath,
pagesDirectory: $cbzPath,
pageCount: $chapter->getPageCount(),
createdAt: $chapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
$this->mangaRepository->updateChapter($updatedChapter);
}
}
/**
* Validate that the binary data is a valid CBZ (ZIP) file
*/
private function isValidCbzFile(string $fileBinary): bool
{
// CBZ files are ZIP archives, check for ZIP magic number
$zipMagicNumber = "\x50\x4b\x03\x04"; // PK\x03\x04
return strpos($fileBinary, $zipMagicNumber) === 0;
}
/**
* Save the CBZ file to storage and return the path
*/
private function saveCbzFile(ImportVolume $command, \App\Domain\Manga\Domain\Model\Manga $manga): string
{
// Build the final CBZ path using the path manager (creates directories)
$cbzPath = $this->pathManager->buildVolumeCbzPath(
$manga->getTitle()->getValue(),
(string)$manga->getPublicationYear(),
$command->volumeNumber
);
// Write the binary content directly to the CBZ path
if (!file_put_contents($cbzPath, $command->fileBinary)) {
throw new \RuntimeException('Failed to save CBZ file');
}
@@ -93,7 +84,3 @@ readonly class ImportVolumeHandler
return $cbzPath;
}
}