diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php index 8efc18a..1446b38 100644 --- a/src/Controller/SnipController.php +++ b/src/Controller/SnipController.php @@ -81,6 +81,15 @@ class SnipController extends AbstractController { $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); + /** + * Temporary solution to prevent editing of old versions + * It technically fully works, but rendering the version history needs an update first + */ + $isLatest = $snip->getActiveVersion() === $snip->getLatestVersion(); + if(!$isLatest) { + $this->addFlash('error', 'Snip is not the latest version, changes will not be saved.'); + } + $form = $this->createForm(SnipType::class, $snip); $form->add('Save', SubmitType::class); if ($snip->getId()) { @@ -89,6 +98,11 @@ class SnipController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + if (!$isLatest) { + return $this->redirectToRoute('snip_single', [ + 'snip' => $snip->getId(), + ]); + } $this->repository->save($snip); $this->contentService->update($snip, $form->get('content')->getData()); diff --git a/src/Service/SnipParser/Twig/SnipTwigExtension.php b/src/Service/SnipParser/Twig/SnipTwigExtension.php index 595a63c..3bf154f 100644 --- a/src/Service/SnipParser/Twig/SnipTwigExtension.php +++ b/src/Service/SnipParser/Twig/SnipTwigExtension.php @@ -35,6 +35,9 @@ class SnipTwigExtension extends AbstractExtension function snipLink(int $id): string { $snip = $this->snipRepo->find($id); + if ($snip === null) { + throw new \Exception(sprintf('Snip not found with id: %d', $id)); + } return sprintf('%s', $this->snipPath($id), $snip); } } \ No newline at end of file