Skip to content

Commit

Permalink
Fixed the snapshots removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Nov 18, 2024
1 parent f06d6a5 commit 2d6af8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Service/SnapshotService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function create(Anr $anr, array $data): Snapshot
public function delete(Anr $anr, int $id): void
{
/** @var Snapshot $snapshot */
$snapshot = $this->snapshotTable->findByIdAndAnr($id, $anr);
$snapshot = $this->snapshotTable->findByIdAndAnrReference($id, $anr);

$this->snapshotTable->remove($snapshot);
}
Expand Down
17 changes: 17 additions & 0 deletions src/Table/SnapshotTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Monarc\FrontOffice\Table;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityNotFoundException;
use Monarc\Core\Table\AbstractTable;
use Monarc\FrontOffice\Entity\Anr;
use Monarc\FrontOffice\Entity\Snapshot;
Expand Down Expand Up @@ -42,4 +43,20 @@ public function findByAnrReferenceAndOrderBy(Anr $anr, array $order): array

return $queryBuilder->getQuery()->getResult();
}

public function findByIdAndAnrReference(int $id, Anr $anr): Snapshot
{
$snapshot = $this->getRepository()->createQueryBuilder('s')
->where('s.id = :id')
->andWhere('s.anrReference = :anr')
->setParameter('id', $id)
->setParameter('anr', $anr)
->getQuery()
->getOneOrNullResult();
if ($snapshot === null) {
throw EntityNotFoundException::fromClassNameAndIdentifier(SnapshotTable::class, [$id, $anr->getId()]);
}

return $snapshot;
}
}

0 comments on commit 2d6af8e

Please sign in to comment.