mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Ensure that the user property is really null in getLastUser function, if the target user was deleted
This fixes issue #414
This commit is contained in:
parent
91cab91c81
commit
7239aef47f
1 changed files with 9 additions and 2 deletions
|
@ -30,7 +30,6 @@ use App\Entity\LogSystem\ElementDeletedLogEntry;
|
||||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||||
use App\Entity\LogSystem\LogTargetType;
|
use App\Entity\LogSystem\LogTargetType;
|
||||||
use App\Entity\UserSystem\User;
|
use App\Entity\UserSystem\User;
|
||||||
use DateTime;
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -219,9 +218,16 @@ class LogEntryRepository extends DBElementRepository
|
||||||
protected function getLastUser(AbstractDBElement $element, string $log_class): ?User
|
protected function getLastUser(AbstractDBElement $element, string $log_class): ?User
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('log');
|
$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')
|
$qb->select('log')
|
||||||
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
|
->addSelect('user')
|
||||||
->where('log INSTANCE OF '.$log_class)
|
->where('log INSTANCE OF '.$log_class)
|
||||||
|
->leftJoin('log.user', 'user')
|
||||||
->andWhere('log.target_type = :target_type')
|
->andWhere('log.target_type = :target_type')
|
||||||
->andWhere('log.target_id = :target_id')
|
->andWhere('log.target_id = :target_id')
|
||||||
->orderBy('log.timestamp', 'DESC');
|
->orderBy('log.timestamp', 'DESC');
|
||||||
|
@ -233,6 +239,7 @@ class LogEntryRepository extends DBElementRepository
|
||||||
|
|
||||||
$query = $qb->getQuery();
|
$query = $qb->getQuery();
|
||||||
$query->setMaxResults(1);
|
$query->setMaxResults(1);
|
||||||
|
|
||||||
/** @var AbstractLogEntry[] $results */
|
/** @var AbstractLogEntry[] $results */
|
||||||
$results = $query->execute();
|
$results = $query->execute();
|
||||||
if (isset($results[0])) {
|
if (isset($results[0])) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue