From ed3fd429a471e6e16bc984af07776b1e4a562714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 22 Dec 2025 14:21:13 +0100 Subject: [PATCH] Refactor `findByDocumentFilename` to use `findOneByPrefix` and implement `findOneByPrefix` in `StoredObjectRepository` --- .../Repository/StoredObjectRepository.php | 20 +++++++++++++++++++ .../src/Service/Wopi/ChillDocumentManager.php | 6 +----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Repository/StoredObjectRepository.php b/src/Bundle/ChillDocStoreBundle/Repository/StoredObjectRepository.php index d48792bc9..11b8b3890 100644 --- a/src/Bundle/ChillDocStoreBundle/Repository/StoredObjectRepository.php +++ b/src/Bundle/ChillDocStoreBundle/Repository/StoredObjectRepository.php @@ -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'); diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php index ad3fa2068..720e1b182 100644 --- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php +++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php @@ -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