From 7239aef47f7b8efbde6908207881300dbfeca2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 24 Oct 2023 23:55:14 +0200 Subject: [PATCH] Ensure that the user property is really null in getLastUser function, if the target user was deleted This fixes issue #414 --- src/Repository/LogEntryRepository.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Repository/LogEntryRepository.php b/src/Repository/LogEntryRepository.php index 472993a7..8d1f2d8e 100644 --- a/src/Repository/LogEntryRepository.php +++ b/src/Repository/LogEntryRepository.php @@ -30,7 +30,6 @@ use App\Entity\LogSystem\ElementDeletedLogEntry; use App\Entity\LogSystem\ElementEditedLogEntry; use App\Entity\LogSystem\LogTargetType; use App\Entity\UserSystem\User; -use DateTime; use RuntimeException; /** @@ -219,9 +218,16 @@ class LogEntryRepository extends DBElementRepository protected function getLastUser(AbstractDBElement $element, string $log_class): ?User { $qb = $this->createQueryBuilder('log'); + /** + * The select and join with user here are important, to get true null user values, if the user was deleted. + * This happens for sqlite database, before the SET NULL constraint was added, and doctrine generates a proxy + * entity which fails to resolve, without this line. + * This was the cause of issue #414 (https://github.com/Part-DB/Part-DB-server/issues/414) + */ $qb->select('log') - //->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry') + ->addSelect('user') ->where('log INSTANCE OF '.$log_class) + ->leftJoin('log.user', 'user') ->andWhere('log.target_type = :target_type') ->andWhere('log.target_id = :target_id') ->orderBy('log.timestamp', 'DESC'); @@ -233,6 +239,7 @@ class LogEntryRepository extends DBElementRepository $query = $qb->getQuery(); $query->setMaxResults(1); + /** @var AbstractLogEntry[] $results */ $results = $query->execute(); if (isset($results[0])) {