feat: migrer vers Symfony 8, PHP 8.4 et les dépendances majeures associées
- PHP 8.3 → 8.4 (Dockerfile + composer.json) - Symfony 7.0 → 8.0 (tous les composants symfony/*) - API Platform 3.x → 4.x : migration openapiContext → openapi: new Operation(...) - Doctrine DBAL 3 → 4 : suppression use_savepoints, replace prepare/executeQuery - Doctrine ORM 2.x → 3.x : ClassMetadataInfo → ClassMetadata, setParameters → setParameter - Doctrine Bundle 2.x → 3.x, Fixtures Bundle 3.x → 4.x - zenstruck/foundry 1.x → 2.x : ModelFactory → PersistentObjectFactory, getDefaults → defaults - phpmd/phpmd 2.x → 3.x-dev (seule version supportant Symfony 8) - phparkitect 0.3 → 0.8 : NotDependsOnTheseNamespaces prend un array - symfony/mercure-bundle 0.3 → 0.4, symfony/monolog-bundle 3 → 4 - Suppression de runtime/frankenphp-symfony (intégré nativement dans symfony/runtime 8) - worker.Caddyfile : suppression de APP_RUNTIME (détection automatique Symfony 8) - Routes errors.xml/wdt.xml/profiler.xml → .php (Symfony 8 supprime le XML) - Types::ARRAY → Types::JSON dans Entity/Manga.php (DBAL 4 retire array type) - Suppression de src/Schedule.php (doublon vide avec MonitoringSchedule) - Tests : hydra:Collection → Collection, hydra:member → member (API Platform 4)
This commit is contained in:
parent
5a0888eb28
commit
5ed303612a
@@ -4,14 +4,14 @@ namespace App\Domain\Manga\Infrastructure\Service;
|
||||
|
||||
use App\Domain\Manga\Domain\Contract\Service\FileServiceInterface;
|
||||
use App\Domain\Manga\Domain\Exception\CbzFileNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
readonly class FileService implements FileServiceInterface
|
||||
{
|
||||
public function __construct(
|
||||
private string $cbzStoragePath = '/app/public/cbz'
|
||||
private string $cbzStoragePath = '/app/public/cbz',
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ readonly class FileService implements FileServiceInterface
|
||||
|
||||
public function createVolumeCbz(array $cbzPaths, string $volumeName): Response
|
||||
{
|
||||
$tempCbzPath = sys_get_temp_dir() . '/' . $volumeName . '.cbz';
|
||||
$tempCbzPath = sys_get_temp_dir().'/'.$volumeName.'.cbz';
|
||||
|
||||
$cbz = new \ZipArchive();
|
||||
if ($cbz->open($tempCbzPath, \ZipArchive::CREATE) !== true) {
|
||||
if (true !== $cbz->open($tempCbzPath, \ZipArchive::CREATE)) {
|
||||
throw new \RuntimeException('Cannot create CBZ file');
|
||||
}
|
||||
|
||||
@@ -48,23 +48,23 @@ readonly class FileService implements FileServiceInterface
|
||||
}
|
||||
|
||||
$sourceCbz = new \ZipArchive();
|
||||
if ($sourceCbz->open($cbzPath) !== true) {
|
||||
if (true !== $sourceCbz->open($cbzPath)) {
|
||||
continue; // Skip if we can't open the CBZ
|
||||
}
|
||||
|
||||
// Extract all images from the current CBZ
|
||||
for ($i = 0; $i < $sourceCbz->numFiles; $i++) {
|
||||
for ($i = 0; $i < $sourceCbz->numFiles; ++$i) {
|
||||
$fileName = $sourceCbz->getNameIndex($i);
|
||||
$fileInfo = $sourceCbz->statIndex($i);
|
||||
|
||||
// Skip directories and non-image files
|
||||
if ($fileInfo['size'] === 0 || !$this->isImageFile($fileName)) {
|
||||
if (0 === $fileInfo['size'] || !$this->isImageFile($fileName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the file content
|
||||
$imageContent = $sourceCbz->getFromIndex($i);
|
||||
if ($imageContent === false) {
|
||||
if (false === $imageContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ readonly class FileService implements FileServiceInterface
|
||||
// Add the image to the volume CBZ
|
||||
$cbz->addFromString($newFileName, $imageContent);
|
||||
|
||||
$imageCounter++;
|
||||
++$imageCounter;
|
||||
}
|
||||
|
||||
$sourceCbz->close();
|
||||
@@ -88,7 +88,7 @@ readonly class FileService implements FileServiceInterface
|
||||
$response = new BinaryFileResponse($tempCbzPath);
|
||||
$response->setContentDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
$volumeName . '.cbz'
|
||||
$volumeName.'.cbz'
|
||||
);
|
||||
$response->headers->set('Content-Type', 'application/x-cbz');
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ readonly class FilenameAnalyzer implements FilenameAnalyzerInterface
|
||||
|
||||
return new AnalyzedFilename(
|
||||
title: new MangaTitle($cleanedTitle),
|
||||
chapterNumber: $chapterNumber !== null ? new ChapterNumber($chapterNumber) : null,
|
||||
volumeNumber: $volumeNumber !== null ? new VolumeNumber((float) $volumeNumber) : null
|
||||
chapterNumber: null !== $chapterNumber ? new ChapterNumber($chapterNumber) : null,
|
||||
volumeNumber: null !== $volumeNumber ? new VolumeNumber((float) $volumeNumber) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,16 @@
|
||||
namespace App\Domain\Manga\Infrastructure\Service;
|
||||
|
||||
use App\Domain\Manga\Domain\Contract\Service\ImageProcessorInterface;
|
||||
use GuzzleHttp\Client;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\ImageManager;
|
||||
use GuzzleHttp\Client;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
class ImageProcessor implements ImageProcessorInterface
|
||||
{
|
||||
private const string BASE_PATH = '/images';
|
||||
private const string FULL_IMAGES_DIR = self::BASE_PATH . '/full';
|
||||
private const string THUMBNAILS_DIR = self::BASE_PATH . '/thumbnails';
|
||||
private const string FULL_IMAGES_DIR = self::BASE_PATH.'/full';
|
||||
private const string THUMBNAILS_DIR = self::BASE_PATH.'/thumbnails';
|
||||
private const int THUMBNAIL_WIDTH = 300;
|
||||
private const int THUMBNAIL_HEIGHT = 440;
|
||||
private const int FULL_IMAGE_QUALITY = 90;
|
||||
@@ -23,7 +22,7 @@ class ImageProcessor implements ImageProcessorInterface
|
||||
|
||||
public function __construct(
|
||||
private readonly string $publicDir,
|
||||
private readonly Client $httpClient
|
||||
private readonly Client $httpClient,
|
||||
) {
|
||||
$this->imageManager = new ImageManager(new Driver());
|
||||
$this->ensureDirectoriesExist();
|
||||
@@ -34,50 +33,50 @@ class ImageProcessor implements ImageProcessorInterface
|
||||
try {
|
||||
$response = $this->httpClient->get($imageUrl);
|
||||
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
if (200 !== $response->getStatusCode()) {
|
||||
throw new \RuntimeException('Échec du téléchargement de l\'image');
|
||||
}
|
||||
|
||||
$uuid = Uuid::uuid4()->toString();
|
||||
$extension = pathinfo($imageUrl, PATHINFO_EXTENSION) ?: 'jpg';
|
||||
$filename = sprintf('%s.%s', $uuid, $extension);
|
||||
$fullPath = $this->publicDir . self::FULL_IMAGES_DIR . '/' . $filename;
|
||||
$fullPath = $this->publicDir.self::FULL_IMAGES_DIR.'/'.$filename;
|
||||
|
||||
$image = $this->imageManager->read($response->getBody()->getContents());
|
||||
$image->save($fullPath, quality: self::FULL_IMAGE_QUALITY);
|
||||
|
||||
return self::FULL_IMAGES_DIR . '/' . $filename;
|
||||
return self::FULL_IMAGES_DIR.'/'.$filename;
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Erreur lors du téléchargement de l\'image : ' . $e->getMessage());
|
||||
throw new \RuntimeException('Erreur lors du téléchargement de l\'image : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function createThumbnail(string $originalImagePath): string
|
||||
{
|
||||
try {
|
||||
$fullPath = $this->publicDir . $originalImagePath;
|
||||
$fullPath = $this->publicDir.$originalImagePath;
|
||||
if (!file_exists($fullPath)) {
|
||||
throw new \RuntimeException('Image originale non trouvée');
|
||||
}
|
||||
|
||||
$filename = pathinfo($originalImagePath, PATHINFO_BASENAME);
|
||||
$thumbnailPath = $this->publicDir . self::THUMBNAILS_DIR . '/' . $filename;
|
||||
$thumbnailPath = $this->publicDir.self::THUMBNAILS_DIR.'/'.$filename;
|
||||
|
||||
$thumbnail = $this->imageManager->read($fullPath);
|
||||
$thumbnail->cover(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT);
|
||||
$thumbnail->save($thumbnailPath, quality: self::THUMBNAIL_QUALITY);
|
||||
|
||||
return self::THUMBNAILS_DIR . '/' . $filename;
|
||||
return self::THUMBNAILS_DIR.'/'.$filename;
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Erreur lors de la création de la miniature : ' . $e->getMessage());
|
||||
throw new \RuntimeException('Erreur lors de la création de la miniature : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function ensureDirectoriesExist(): void
|
||||
{
|
||||
$directories = [
|
||||
$this->publicDir . self::FULL_IMAGES_DIR,
|
||||
$this->publicDir . self::THUMBNAILS_DIR,
|
||||
$this->publicDir.self::FULL_IMAGES_DIR,
|
||||
$this->publicDir.self::THUMBNAILS_DIR,
|
||||
];
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
|
||||
@@ -14,13 +14,13 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
{
|
||||
public function __construct(
|
||||
private MangadexClientInterface $mangadxClient,
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
private MangaRepositoryInterface $mangaRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function synchronizeChapters(Manga $manga): array
|
||||
{
|
||||
if ($manga->getExternalId() === null) {
|
||||
if (null === $manga->getExternalId()) {
|
||||
throw new \RuntimeException('Manga has no external ID');
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
// Si c'est le premier chapitre avec ce numéro qu'on rencontre
|
||||
$shouldReplaceChapter = true;
|
||||
$chapterNumbers[] = $chapterNumber;
|
||||
} elseif ($language === 'fr') {
|
||||
} elseif ('fr' === $language) {
|
||||
// Le français est toujours prioritaire
|
||||
$shouldReplaceChapter = true;
|
||||
} elseif ($language === 'en' && $chapterLanguages[(string) $chapterNumber] !== 'fr') {
|
||||
} elseif ('en' === $language && 'fr' !== $chapterLanguages[(string) $chapterNumber]) {
|
||||
// L'anglais est prioritaire sur les autres langues, sauf le français
|
||||
$shouldReplaceChapter = true;
|
||||
}
|
||||
@@ -116,13 +116,13 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
private function harmonizeVolumes(array &$chaptersByNumber): void
|
||||
{
|
||||
// Trie les chapitres par numéro pour faciliter la recherche des adjacents
|
||||
uksort($chaptersByNumber, fn ($a, $b) => (float)$a <=> (float)$b);
|
||||
uksort($chaptersByNumber, fn ($a, $b) => (float) $a <=> (float) $b);
|
||||
|
||||
$chapterNumbers = array_keys($chaptersByNumber);
|
||||
$count = count($chapterNumbers);
|
||||
|
||||
// Première passe : harmonisation locale (chapitres adjacents)
|
||||
for ($i = 1; $i < $count - 1; $i++) {
|
||||
for ($i = 1; $i < $count - 1; ++$i) {
|
||||
$prevChapterNum = $chapterNumbers[$i - 1];
|
||||
$currentChapterNum = $chapterNumbers[$i];
|
||||
$nextChapterNum = $chapterNumbers[$i + 1];
|
||||
@@ -136,7 +136,7 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
$nextVolume = $nextChapter->getVolume();
|
||||
|
||||
// Règle 1: Si précédent et suivant sont null, alors actuel aussi
|
||||
if ($prevVolume === null && $nextVolume === null && $currentVolume !== null) {
|
||||
if (null === $prevVolume && null === $nextVolume && null !== $currentVolume) {
|
||||
$chaptersByNumber[$currentChapterNum] = new Chapter(
|
||||
new ChapterId($currentChapter->getId()),
|
||||
$currentChapter->getMangaId(),
|
||||
@@ -150,7 +150,7 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
);
|
||||
}
|
||||
// Règle 2: Si précédent et suivant ont le même volume, alors actuel aussi
|
||||
elseif ($prevVolume !== null && $prevVolume === $nextVolume && $currentVolume !== $prevVolume) {
|
||||
elseif (null !== $prevVolume && $prevVolume === $nextVolume && $currentVolume !== $prevVolume) {
|
||||
$chaptersByNumber[$currentChapterNum] = new Chapter(
|
||||
new ChapterId($currentChapter->getId()),
|
||||
$currentChapter->getMangaId(),
|
||||
@@ -170,25 +170,25 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
}
|
||||
|
||||
/**
|
||||
* Remplit les "trous" de volumes manquants dans une séquence
|
||||
* Remplit les "trous" de volumes manquants dans une séquence.
|
||||
*/
|
||||
private function fillVolumeGaps(array &$chaptersByNumber, array $chapterNumbers): void
|
||||
{
|
||||
$count = count($chapterNumbers);
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$currentChapterNum = $chapterNumbers[$i];
|
||||
$currentChapter = $chaptersByNumber[$currentChapterNum];
|
||||
|
||||
if ($currentChapter->getVolume() !== null) {
|
||||
if (null !== $currentChapter->getVolume()) {
|
||||
continue; // Ce chapitre a déjà un volume
|
||||
}
|
||||
|
||||
// Cherche le volume précédent non-null
|
||||
$prevVolume = null;
|
||||
for ($j = $i - 1; $j >= 0; $j--) {
|
||||
for ($j = $i - 1; $j >= 0; --$j) {
|
||||
$prevChapter = $chaptersByNumber[$chapterNumbers[$j]];
|
||||
if ($prevChapter->getVolume() !== null) {
|
||||
if (null !== $prevChapter->getVolume()) {
|
||||
$prevVolume = $prevChapter->getVolume();
|
||||
break;
|
||||
}
|
||||
@@ -196,9 +196,9 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
|
||||
// Cherche le volume suivant non-null
|
||||
$nextVolume = null;
|
||||
for ($k = $i + 1; $k < $count; $k++) {
|
||||
for ($k = $i + 1; $k < $count; ++$k) {
|
||||
$nextChapter = $chaptersByNumber[$chapterNumbers[$k]];
|
||||
if ($nextChapter->getVolume() !== null) {
|
||||
if (null !== $nextChapter->getVolume()) {
|
||||
$nextVolume = $nextChapter->getVolume();
|
||||
break;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
|
||||
// Priorité au volume précédent : le chapitre appartient à la fin du volume en cours
|
||||
// Couvre les cas : milieu de volume (prev=next), transition entre deux volumes (prev≠next)
|
||||
if ($prevVolume !== null) {
|
||||
if (null !== $prevVolume) {
|
||||
$chaptersByNumber[$currentChapterNum] = new Chapter(
|
||||
new ChapterId($currentChapter->getId()),
|
||||
$currentChapter->getMangaId(),
|
||||
@@ -220,7 +220,7 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
);
|
||||
}
|
||||
// Sinon utilise le volume suivant (chapitres en début de série)
|
||||
elseif ($nextVolume !== null) {
|
||||
elseif (null !== $nextVolume) {
|
||||
$chaptersByNumber[$currentChapterNum] = new Chapter(
|
||||
new ChapterId($currentChapter->getId()),
|
||||
$currentChapter->getMangaId(),
|
||||
|
||||
Reference in New Issue
Block a user