Fully implement snip db storage
This commit is contained in:
@ -14,28 +14,28 @@ class HistoryController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SnipServiceFactory $snipServiceFactory,
|
||||
)
|
||||
{
|
||||
}
|
||||
) {}
|
||||
|
||||
#[Route('/', name: '_index')]
|
||||
public function index(Snip $snip): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
||||
|
||||
$snipService = $this->snipServiceFactory->create($snip);
|
||||
return $this->render('history/index.html.twig', [
|
||||
'snip' => $snip,
|
||||
'commits' => $this->snipServiceFactory->createGit($snip)->getHistory(),
|
||||
'versions' => $snipService->getVersions(),
|
||||
'latestVersion' => $snipService->getLatestVersion(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/set/{commit}', name: '_set')]
|
||||
public function set(Snip $snip, string $commit): Response
|
||||
#[Route('/set/{version}', name: '_set')]
|
||||
public function set(Snip $snip, string $version): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
||||
|
||||
$this->snipServiceFactory->createGit($snip)->setCommit($commit);
|
||||
$this->addFlash('success', 'Snip version set to ' . $commit);
|
||||
$this->snipServiceFactory->create($snip)->setVersion($version);
|
||||
$this->addFlash('success', 'Snip version set to ' . $version);
|
||||
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
|
||||
}
|
||||
}
|
@ -48,7 +48,8 @@ class SnipController extends AbstractController
|
||||
{
|
||||
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
|
||||
|
||||
$snipService = $this->snipServiceFactory->createGit($snip);
|
||||
$snipService = $this->snipServiceFactory->create($snip);
|
||||
dump($snipService);
|
||||
return $this->render('snip/single.html.twig', [
|
||||
'snip' => $snip,
|
||||
'content' => $pl->parse($snipService->get()),
|
||||
@ -62,7 +63,7 @@ class SnipController extends AbstractController
|
||||
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
|
||||
|
||||
$response = new Response(
|
||||
$pl->clean($this->snipServiceFactory->createGit($snip)->get()),
|
||||
$pl->clean($this->snipServiceFactory->create($snip)->get()),
|
||||
Response::HTTP_OK,
|
||||
['Content-Type' => 'text/html']
|
||||
);
|
||||
@ -87,13 +88,13 @@ class SnipController extends AbstractController
|
||||
$form = $this->createForm(SnipType::class, $snip);
|
||||
$form->add('Save', SubmitType::class);
|
||||
if ($snip->getId()) {
|
||||
$form->get('content')->setData($this->snipServiceFactory->createGit($snip)->get());
|
||||
$form->get('content')->setData($this->snipServiceFactory->create($snip)->get());
|
||||
}
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->repository->save($snip);
|
||||
$this->snipServiceFactory->createGit($snip)->update($form->get('content')->getData());
|
||||
$this->snipServiceFactory->create($snip)->update($form->get('content')->getData());
|
||||
|
||||
$this->addFlash('success', sprintf('Snip "%s" saved', $snip));
|
||||
|
||||
@ -126,7 +127,7 @@ class SnipController extends AbstractController
|
||||
$form = $this->createForm(ConfirmationType::class);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->snipServiceFactory->createGit($snip)->delete();
|
||||
$this->snipServiceFactory->create($snip)->delete();
|
||||
$this->repository->remove($snip);
|
||||
$this->addFlash('success', sprintf('Snip "%s" deleted', $snip));
|
||||
return $this->redirectToRoute('snip_index');
|
||||
|
Reference in New Issue
Block a user