refactored repositories and DB queries (#5026)
* removed unused teams from export order * added new paginator for query instead of querybuilder * added field hydrate enums * hide PARTIAL deprecation * never log deprecations in production * replaced InvoiceLoader with native Doctrine feature * prevent excessive permission queries * support loading customers of team * improved findByIds * internalized API * fix null string deprecations
This commit is contained in:
@@ -15,46 +15,40 @@ use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @implements LoaderInterface<Timesheet>
|
||||
*/
|
||||
final class TimesheetLoader implements LoaderInterface
|
||||
{
|
||||
public function __construct(private EntityManagerInterface $entityManager, private bool $fullyHydrated = false, private bool $basicHydrated = true)
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly bool $fullyHydrated = false
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|Timesheet> $results
|
||||
* @param array<Timesheet> $results
|
||||
*/
|
||||
public function loadResults(array $results): void
|
||||
{
|
||||
if (empty($results)) {
|
||||
if (\count($results) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ids = array_map(function ($timesheet) {
|
||||
if ($timesheet instanceof Timesheet) {
|
||||
// make sure that this potential doctrine proxy is initialized and filled with all data
|
||||
$timesheet->getType();
|
||||
$ids = array_filter(array_unique(array_map(function (Timesheet $timesheet) {
|
||||
// make sure that this potential doctrine proxy is initialized and filled with all data
|
||||
$timesheet->getType();
|
||||
|
||||
return $timesheet->getId();
|
||||
}
|
||||
|
||||
return $timesheet;
|
||||
}, $results);
|
||||
return $timesheet->getId();
|
||||
}, $results)), function ($value) { return $value !== null; });
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
/** @var array<Timesheet> $timesheets */
|
||||
$timesheets = $qb->select('PARTIAL t.{id}', 'project')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'project')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$projectIds = array_map(function ($timesheet) {
|
||||
return $timesheet->getProject()->getId();
|
||||
}, $timesheets);
|
||||
$projectIds = array_filter(array_unique(array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getProject()?->getId();
|
||||
}, $results)), function ($value) { return $value !== null; });
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
@@ -76,9 +70,9 @@ final class TimesheetLoader implements LoaderInterface
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_map(function ($project) {
|
||||
$customerIds = array_filter(array_unique(array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
}, $projects);
|
||||
}, $projects)), function ($value) { return $value !== null; });
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL c.{id}', 'meta')
|
||||
@@ -89,18 +83,10 @@ final class TimesheetLoader implements LoaderInterface
|
||||
->execute();
|
||||
}
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'activity')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.activity', 'activity')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$activityIds = array_filter(array_map(function (Timesheet $timesheet) {
|
||||
return $timesheet->getActivity()?->getId();
|
||||
}, $timesheets), function ($id): bool {
|
||||
}, $results), function ($id): bool {
|
||||
return $id !== null;
|
||||
});
|
||||
|
||||
@@ -113,30 +99,12 @@ final class TimesheetLoader implements LoaderInterface
|
||||
->execute();
|
||||
}
|
||||
|
||||
if ($this->basicHydrated) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'user')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.user', 'user')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'tags')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.tags', 'tags')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'meta')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.meta', 'meta')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('PARTIAL t.{id}', 'tags')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.tags', 'tags')
|
||||
->andWhere($qb->expr()->in('t.id', $ids))
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user