diff --git a/src/DataFixtures/LogEntryFixtures.php b/src/DataFixtures/LogEntryFixtures.php index cb5d823f..b9788ec0 100644 --- a/src/DataFixtures/LogEntryFixtures.php +++ b/src/DataFixtures/LogEntryFixtures.php @@ -46,11 +46,13 @@ class LogEntryFixtures extends Fixture implements DependentFixtureInterface $category = $this->getReference(Category::class . '_1', Category::class); $logEntry = new ElementCreatedLogEntry($category); + $logEntry->setTimestamp(new \DateTimeImmutable("+1 second")); $logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class)); $logEntry->setComment('Test'); $manager->persist($logEntry); $logEntry = new ElementEditedLogEntry($category); + $logEntry->setTimestamp(new \DateTimeImmutable("+2 second")); $logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class)); $logEntry->setComment('Test'); @@ -78,6 +80,7 @@ class LogEntryFixtures extends Fixture implements DependentFixtureInterface $manager->persist($logEntry); $logEntry = new ElementEditedLogEntry($category); + $logEntry->setTimestamp(new \DateTimeImmutable("+1 second")); $logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class)); $logEntry->setComment('Edit'); $logEntry->setOldData(['name' => 'Test']); @@ -85,6 +88,7 @@ class LogEntryFixtures extends Fixture implements DependentFixtureInterface $manager->persist($logEntry); $logEntry = new ElementDeletedLogEntry($category); + $logEntry->setTimestamp(new \DateTimeImmutable("+2 second")); $logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class)); $logEntry->setOldData(['name' => 'Node 100', 'id' => 100, 'comment' => 'Test comment']); $manager->persist($logEntry); diff --git a/src/Repository/LogEntryRepository.php b/src/Repository/LogEntryRepository.php index daad1a81..bf9909c5 100644 --- a/src/Repository/LogEntryRepository.php +++ b/src/Repository/LogEntryRepository.php @@ -225,7 +225,10 @@ class LogEntryRepository extends DBElementRepository ->leftJoin('log.user', 'user') ->andWhere('log.target_type = :target_type') ->andWhere('log.target_id = :target_id') - ->orderBy('log.timestamp', 'DESC'); + ->orderBy('log.timestamp', 'DESC') + //Use id as fallback, if timestamp is the same (higher id means newer entry) + ->addOrderBy('log.id', 'DESC') + ; $qb->setParameter('target_type', LogTargetType::fromElementClass($element)); $qb->setParameter('target_id', $element->getID());