Refactor findByDocumentFilename to use findOneByPrefix and implement findOneByPrefix in StoredObjectRepository

This commit is contained in:
2025-12-22 14:21:13 +01:00
parent ef89f37ec3
commit ed3fd429a4
2 changed files with 21 additions and 5 deletions

View File

@@ -54,6 +54,26 @@ final readonly class StoredObjectRepository implements StoredObjectRepositoryInt
return $this->repository->findOneBy($criteria);
}
/**
* Finds a single stored object by a prefix value.
*
* @param string $value the prefix value to search for
*
* @return StoredObject|null the stored object matching the prefix, or null if none found
*
* @throws \Doctrine\ORM\NonUniqueResultException if multiple results are found for the given prefix
*/
public function findOneByPrefix(string $value): ?StoredObject
{
$qb = $this->repository->createQueryBuilder('s');
$qb
->where($qb->expr()->like(':value', $qb->expr()->concat('s.prefix', $qb->expr()->literal('%'))))
->setParameter('value', $value);
return $qb->getQuery()->getOneOrNullResult();
}
public function findByExpired(\DateTimeImmutable $expiredAtDate): iterable
{
$qb = $this->repository->createQueryBuilder('stored_object');

View File

@@ -75,11 +75,7 @@ final readonly class ChillDocumentManager implements DocumentManagerInterface
*/
public function findByDocumentFilename(string $documentFilename): ?Document
{
return $this->storedObjectRepository->findOneBy(
[
'filename' => $documentFilename,
]
);
return $this->storedObjectRepository->findOneByPrefix($documentFilename);
}
public function findByDocumentId(string $documentId): ?Document