Merge branch 'main' of ssh://git.homelab.nestor-server.fr:2222/colgora/Mangarr
All checks were successful
Build and Deploy / deploy (push) Successful in 1m46s

# Conflicts:
#	src/Domain/Manga/Application/CommandHandler/DeleteChapterHandler.php
#	src/Domain/Manga/Application/CommandHandler/EditMultipleChaptersHandler.php
#	src/Domain/Manga/Application/EventListener/ChapterImportedEventListener.php
#	src/Domain/Manga/Application/EventListener/VolumeImportedEventListener.php
#	src/Domain/Manga/Application/Response/ChapterResponse.php
#	src/Domain/Manga/Infrastructure/ApiPlatform/State/Provider/DeleteCbzProvider.php
#	src/Domain/Manga/Infrastructure/ApiPlatform/State/Provider/DeleteChapterProvider.php
#	src/Domain/Manga/Infrastructure/Persistence/Repository/LegacyChapterRepository.php
This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-09 20:47:43 +01:00
33 changed files with 549 additions and 550 deletions

View File

@@ -3,19 +3,17 @@
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\DeleteCbz;
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Service\FileServiceInterface;
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
use App\Domain\Manga\Domain\Exception\CbzFileNotFoundException;
use App\Domain\Manga\Domain\Model\Chapter;
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
use App\Domain\Shared\Domain\Contract\CommandInterface;
readonly class DeleteCbzHandler implements CommandHandlerInterface
{
public function __construct(
private ChapterRepositoryInterface $chapterRepository,
private MangaRepositoryInterface $mangaRepository,
private FileServiceInterface $fileService
) {
}
@@ -24,33 +22,18 @@ readonly class DeleteCbzHandler implements CommandHandlerInterface
{
assert($command instanceof DeleteCbz);
$chapter = $this->chapterRepository->findVisibleById($command->chapterId);
$chapter = $this->mangaRepository->findVisibleChapterById($command->chapterId);
if (!$chapter) {
throw new ChapterNotFoundException($command->chapterId);
}
// Check if chapter has a CBZ file
if (!$chapter->isAvailable()) {
throw new CbzFileNotFoundException($command->chapterId);
}
// Delete the physical CBZ file
// Note: We'll need to get the CBZ path from somewhere, likely from a legacy repository
// For now, we'll just mark the chapter as not available
// Update chapter to mark CBZ as not available
$updatedChapter = new Chapter(
new ChapterId($chapter->getId()),
$chapter->getMangaId(),
$chapter->getNumber(),
$chapter->getTitle(),
$chapter->getVolume(),
$chapter->isVisible(),
null,
$chapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
$manga = $this->mangaRepository->findById($chapter->getMangaId()->getValue());
$manga->removeChapterPages($chapter);
$this->mangaRepository->save($manga);
}
}

View File

@@ -3,17 +3,15 @@
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\DeleteChapter;
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
use App\Domain\Manga\Domain\Model\Chapter;
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
use App\Domain\Shared\Domain\Contract\CommandInterface;
readonly class DeleteChapterHandler implements CommandHandlerInterface
{
public function __construct(
private ChapterRepositoryInterface $chapterRepository
private MangaRepositoryInterface $mangaRepository
) {
}
@@ -21,23 +19,14 @@ readonly class DeleteChapterHandler implements CommandHandlerInterface
{
assert($command instanceof DeleteChapter);
$chapter = $this->chapterRepository->findVisibleById($command->chapterId);
$chapter = $this->mangaRepository->findVisibleChapterById($command->chapterId);
if (!$chapter) {
throw new ChapterNotFoundException($command->chapterId);
}
$updatedChapter = new Chapter(
id: new ChapterId($chapter->getId()),
mangaId: $chapter->getMangaId(),
number: $chapter->getNumber(),
title: $chapter->getTitle(),
volume: $chapter->getVolume(),
isVisible: false,
cbzPath: $chapter->getCbzPath(),
createdAt: $chapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
$manga = $this->mangaRepository->findById($chapter->getMangaId()->getValue());
$manga->hideChapter($chapter);
$this->mangaRepository->save($manga);
}
}

View File

@@ -3,36 +3,36 @@
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\EditMultipleChapters;
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
readonly class EditMultipleChaptersHandler
{
public function __construct(
private ChapterRepositoryInterface $chapterRepository
private MangaRepositoryInterface $mangaRepository
) {
}
public function handle(EditMultipleChapters $command): void
{
foreach ($command->chapters as $chapterData) {
$chapter = $this->chapterRepository->findById($chapterData->id);
$chapter = $this->mangaRepository->findChapterById($chapterData->id);
if (!$chapter) {
throw new ChapterNotFoundException($chapterData->id);
}
$updatedChapter = $chapter;
$manga = $this->mangaRepository->findById($chapter->getMangaId()->getValue());
if ($chapterData->title !== null) {
$updatedChapter = $updatedChapter->updateTitle($chapterData->title);
$manga->updateChapterTitle($chapter, $chapterData->title);
}
if ($chapterData->volume !== null) {
$updatedChapter = $updatedChapter->updateVolume($chapterData->volume);
$manga->updateChapterVolume($chapter, $chapterData->volume);
}
$this->chapterRepository->save($updatedChapter);
$this->mangaRepository->save($manga);
}
}
}

View File

@@ -30,5 +30,6 @@ readonly class FetchMangaChaptersHandler
// Synchronisation initiale (pas d'événements)
$this->chapterSynchronizationService->synchronizeChapters($manga);
$this->mangaRepository->save($manga);
}
}

View File

@@ -3,20 +3,15 @@
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\ImportChapter;
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\Exception\ChapterNotFoundException;
use App\Domain\Manga\Domain\Model\Chapter;
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;
use Ramsey\Uuid\Uuid;
readonly class ImportChapterHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private ChapterRepositoryInterface $chapterRepository,
private MangaPathManagerInterface $pathManager
) {
}
@@ -35,7 +30,7 @@ readonly class ImportChapterHandler
}
// 3. Check if chapter exists
$existingChapter = $this->chapterRepository->findByMangaIdAndChapterNumber(
$existingChapter = $this->mangaRepository->findChapterByMangaIdAndNumber(
$command->mangaId,
$command->chapterNumber
);
@@ -47,37 +42,20 @@ readonly class ImportChapterHandler
// 4. Save the CBZ file to storage using the path manager
$cbzPath = $this->saveCbzFile($command, $manga, $existingChapter);
// 5. Update existing chapter with new CBZ path
$updatedChapter = new Chapter(
id: new ChapterId($existingChapter->getId()),
mangaId: $existingChapter->getMangaId(),
number: $existingChapter->getNumber(),
title: $existingChapter->getTitle(),
volume: $existingChapter->getVolume(),
isVisible: $existingChapter->isVisible(),
cbzPath: $cbzPath,
createdAt: $existingChapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
// 5. Update existing chapter with new path through the aggregate
$manga->updateChapterPages($existingChapter, $cbzPath, $existingChapter->getPageCount());
$this->mangaRepository->save($manga);
}
/**
* 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(ImportChapter $command, \App\Domain\Manga\Domain\Model\Manga $manga, Chapter $chapter): string
private function saveCbzFile(ImportChapter $command, \App\Domain\Manga\Domain\Model\Manga $manga, \App\Domain\Manga\Domain\Model\Chapter $chapter): string
{
// Build the final CBZ path using the path manager (creates directories)
$volumeNumber = $chapter->getVolume() ?? 0;
$cbzPath = $this->pathManager->buildChapterCbzPath(
$manga->getTitle()->getValue(),
@@ -86,7 +64,6 @@ readonly class ImportChapterHandler
(string)$command->chapterNumber
);
// Write the binary content directly to the CBZ path
if (!file_put_contents($cbzPath, $command->fileBinary)) {
throw new \RuntimeException('Failed to save CBZ file');
}

View File

@@ -3,18 +3,14 @@
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;
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;
readonly class ImportVolumeHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private ChapterRepositoryInterface $chapterRepository,
private MangaPathManagerInterface $pathManager
) {
}
@@ -33,7 +29,7 @@ readonly class ImportVolumeHandler
}
// 3. Get all chapters for this volume
$chapters = $this->chapterRepository->findByMangaIdAndVolume(
$chapters = $this->mangaRepository->findChaptersByMangaIdAndVolume(
$command->mangaId,
$command->volumeNumber
);
@@ -47,46 +43,28 @@ 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 through the aggregate
foreach ($chapters as $chapter) {
$updatedChapter = new Chapter(
id: new ChapterId($chapter->getId()),
mangaId: $chapter->getMangaId(),
number: $chapter->getNumber(),
title: $chapter->getTitle(),
volume: $chapter->getVolume(),
isVisible: $chapter->isVisible(),
cbzPath: $cbzPath,
createdAt: $chapter->getCreatedAt()
);
$this->chapterRepository->save($updatedChapter);
$manga->updateChapterPages($chapter, $cbzPath, $chapter->getPageCount());
}
$this->mangaRepository->save($manga);
}
/**
* 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');
}