mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-05 17:01:24 +00:00
Refactor findByDocumentFilename to use findOneByPrefix and implement findOneByPrefix in StoredObjectRepository
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user