- Monitoring chapters
- possibilities for ToolBarButton.html.twig to have tailwind classes see ChapterListToolbar.php
- Makefile scheduler command
- Makefile make:message command
This commit is contained in:
Jérémy Guillot
2024-07-20 19:40:48 +02:00
parent 7fc2f15f6b
commit ff59aa5d77
21 changed files with 818 additions and 283 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace App\MessageHandler;
use App\Entity\Chapter;
use App\Entity\Manga;
use App\Message\DownloadChapter;
use App\Message\RefreshAndDownloadChapters;
use App\Repository\MangaRepository;
use App\Service\MangadexProvider;
use App\Service\NotificationService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
#[AsMessageHandler]
final readonly class RefreshAndDownloadChaptersHandler
{
public function __construct(
private MangaRepository $mangaRepository,
private MangadexProvider $mangadexProvider,
private EntityManagerInterface $entityManager,
private MessageBusInterface $bus
)
{
}
public function __invoke(RefreshAndDownloadChapters $message): void
{
$mangas = $this->mangaRepository->findBy(['monitored' => true]);
foreach ($mangas as $manga) {
$chapters = $this->refreshMangas($manga);
if (empty($chapters)) {
continue;
}
/** @var Chapter $chapter */
foreach ($chapters as $chapter) {
$this->bus->dispatch(new DownloadChapter($chapter->getId()));
}
}
}
private function refreshMangas(Manga $manga): array
{
$lastChapters = $this->mangadexProvider->addAllChaptersToManga($manga);
foreach ($lastChapters as $chapter) {
$this->entityManager->persist($chapter);
}
$this->entityManager->persist($manga);
$this->entityManager->flush();
return $lastChapters;
}
}