mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 10:18:56 +02:00
Added some simple time travel mechanism for part view.
In the moment it is not possible to show elements that were deleted.
This commit is contained in:
parent
a9fd1f9c68
commit
464a487a17
15 changed files with 450 additions and 27 deletions
|
@ -27,6 +27,7 @@ namespace App\Repository;
|
|||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\LogSystem\AbstractLogEntry;
|
||||
use App\Entity\LogSystem\ElementCreatedLogEntry;
|
||||
use App\Entity\LogSystem\ElementDeletedLogEntry;
|
||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||
use App\Entity\UserSystem\User;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
@ -63,6 +64,48 @@ class LogEntryRepository extends EntityRepository
|
|||
return $this->findBy(['element' => $element], ['timestamp' => $order], $limit, $offset);
|
||||
}
|
||||
|
||||
public function getTimetravelDataForElement(AbstractDBElement $element, \DateTime $until): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('log');
|
||||
$qb->select('log')
|
||||
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
|
||||
->where('log INSTANCE OF ' . ElementEditedLogEntry::class)
|
||||
->andWhere('log.target_type = :target_type')
|
||||
->andWhere('log.target_id = :target_id')
|
||||
->andWhere('log.timestamp >= :until')
|
||||
->orderBy('log.timestamp', 'DESC');
|
||||
|
||||
$qb->setParameters([
|
||||
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
|
||||
'target_id' => $element->getID(),
|
||||
'until' => $until
|
||||
]);
|
||||
|
||||
$query = $qb->getQuery();
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
public function getElementExistedAtTimestamp(AbstractDBElement $element, \DateTime $timestamp): bool
|
||||
{
|
||||
$qb = $this->createQueryBuilder('log');
|
||||
$qb->select('count(log)')
|
||||
->where('log INSTANCE OF ' . ElementCreatedLogEntry::class)
|
||||
->andWhere('log.target_type = :target_type')
|
||||
->andWhere('log.target_id = :target_id')
|
||||
->andWhere('log.timestamp >= :until')
|
||||
->orderBy('log.timestamp', 'DESC');
|
||||
|
||||
$qb->setParameters([
|
||||
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
|
||||
'target_id' => $element->getID(),
|
||||
'until' => $timestamp
|
||||
]);
|
||||
|
||||
$query = $qb->getQuery();
|
||||
$count = $query->getSingleScalarResult();
|
||||
return !($count > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last log entries ordered by timestamp.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue