move controller service logics into a service

This commit is contained in:
team2
2026-02-27 20:28:51 +01:00
parent 66e16a4ae9
commit dd7bae9678
2 changed files with 46 additions and 22 deletions

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity\TagRebuildJob;
use Doctrine\ORM\EntityManagerInterface;
final readonly class TagRebuildStatusProvider
{
public function __construct(
private EntityManagerInterface $em
) {}
public function getLatestStatus(): ?array
{
$this->em->clear();
$job = $this->em->createQueryBuilder()
->select('j')
->from(TagRebuildJob::class, 'j')
->orderBy('j.createdAt', 'DESC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
if (!$job instanceof TagRebuildJob) {
return null;
}
return [
'status' => $job->getStatus(),
'startedAt' => $job->getStartedAt()?->format(DATE_ATOM),
'finishedAt' => $job->getFinishedAt()?->format(DATE_ATOM),
'error' => $job->getErrorMessage(),
];
}
}