refactor(scraping): DDD refactoring — stockage images individuelles
Le domaine Scraping ne génère plus d'archives CBZ ni ne modifie les
entités du domaine Manga directement. Il scrape, stocke les images
individuellement, et émet un événement partagé.
- Suppression : CbzGeneratorInterface, CbzGenerator, CbzGenerationRequest,
CbzPath, CbzGenerationException
- Suppression : save() de ChapterRepositoryInterface (Scraping)
- Suppression : cbzPath du modèle Chapter (Scraping)
- Ajout : ImageStorageInterface + LocalImageStorage
(stockage dans {MANGA_DATA_PATH}/pages/{chapterId}/)
- ScrapeChapterHandler utilise ImageStorage au lieu du générateur CBZ
- ChapterScraped déplacé dans Domain/Shared/Domain/Event/
avec jobId, chapterId, pagesDirectory, pageCount
- Routing Messenger ajouté
- Ajout : ChapterScrapedEventListener + ChapterScrapedMessageHandler
pour mettre à jour Chapter.pagesDirectory via le Repository Manga
- LegacyChapterRepository en dual-mode :
pagesDirectory en priorité, fallback cbzPath (backward compat)
- Requêtes prev/next : filtrent pagesDirectory IS NOT NULL OR cbzPath IS NOT NULL
- ChapterContext expose pagesDirectory
- phparkitect.php : App\Domain\Shared\Domain\Event autorisé dans
les couches Application (correction violations pré-existantes
ChapterImported/VolumeImported + nouvelle ChapterScraped)
- 218/218 tests passent (+3 nouveaux)
- InMemoryImageStorage créé pour les tests unitaires
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d444f86315
commit
c311cfe80c
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Domain\Scraping\Infrastructure\EventSubscriber;
|
||||
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScraped;
|
||||
use App\Domain\Shared\Domain\Event\ChapterScraped;
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
||||
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
||||
|
||||
@@ -15,9 +15,6 @@ readonly class LegacyChapterRepository implements ChapterRepositoryInterface
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un chapitre par son identifiant
|
||||
*/
|
||||
public function getById(string $id): ?Chapter
|
||||
{
|
||||
$chapterEntity = $this->entityManager->getRepository(EntityChapter::class)->find($id);
|
||||
@@ -31,7 +28,6 @@ readonly class LegacyChapterRepository implements ChapterRepositoryInterface
|
||||
mangaId: $chapterEntity->getManga()->getId(),
|
||||
chapterNumber: $chapterEntity->getNumber(),
|
||||
volumeNumber: $chapterEntity->getVolume(),
|
||||
cbzPath: $chapterEntity->getCbzPath(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,26 +50,6 @@ readonly class LegacyChapterRepository implements ChapterRepositoryInterface
|
||||
mangaId: $entity->getManga()->getId(),
|
||||
chapterNumber: $entity->getNumber(),
|
||||
volumeNumber: $entity->getVolume(),
|
||||
cbzPath: $entity->getCbzPath(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ChapterNotFoundException
|
||||
*/
|
||||
public function save(Chapter $chapter): void
|
||||
{
|
||||
$chapterEntity = $this->entityManager->getRepository(EntityChapter::class)->findOneBy([
|
||||
'id' => $chapter->id,
|
||||
]);
|
||||
|
||||
if (!$chapterEntity) {
|
||||
throw new ChapterNotFoundException();
|
||||
}
|
||||
|
||||
$chapterEntity->setCbzPath($chapter->cbzPath);
|
||||
|
||||
$this->entityManager->persist($chapterEntity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Scraping\Infrastructure\Service;
|
||||
|
||||
use App\Domain\Scraping\Domain\Contract\Service\CbzGeneratorInterface;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\CbzGenerationRequest;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\CbzPath;
|
||||
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;
|
||||
|
||||
readonly class CbzGenerator implements CbzGeneratorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private MangaPathManagerInterface $mangaPathManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function generate(CbzGenerationRequest $request): CbzPath
|
||||
{
|
||||
$cbzPath = $this->mangaPathManager->buildChapterCbzPath(
|
||||
$request->getMangaTitle(),
|
||||
$request->getPublicationYear(),
|
||||
$request->getVolumeNumber(),
|
||||
$request->getChapterNumber(),
|
||||
);
|
||||
$this->mangaPathManager->createCbzArchive($request->getFiles(), $cbzPath);
|
||||
return new CbzPath($cbzPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Scraping\Infrastructure\Service;
|
||||
|
||||
use App\Domain\Scraping\Domain\Contract\Service\ImageStorageInterface;
|
||||
|
||||
readonly class LocalImageStorage implements ImageStorageInterface
|
||||
{
|
||||
public function __construct(private string $storagePath)
|
||||
{
|
||||
}
|
||||
|
||||
public function storeChapterImages(string $chapterId, array $localImagePaths): string
|
||||
{
|
||||
$targetDir = $this->storagePath . '/pages/' . $chapterId;
|
||||
|
||||
if (!is_dir($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
sort($localImagePaths);
|
||||
|
||||
foreach ($localImagePaths as $index => $localPath) {
|
||||
$extension = pathinfo($localPath, PATHINFO_EXTENSION) ?: 'jpg';
|
||||
$targetFile = sprintf('%s/%03d.%s', $targetDir, $index + 1, $extension);
|
||||
copy($localPath, $targetFile);
|
||||
}
|
||||
|
||||
return $targetDir;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user