From 880a0e1c0ba7d0ab3320678b076402379a08c8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Oct 2015 18:08:51 +0200 Subject: implement bookmarklet --- .../CoreBundle/Controller/EntryController.php | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index a9f35c36..f7b52eaf 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -14,6 +14,23 @@ use Pagerfanta\Pagerfanta; class EntryController extends Controller { + /** + * @param Entry $entry + */ + private function updateEntry(Entry $entry) + { + try { + $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + } catch (\Exception $e) { + return false; + } + + return true; + } + /** * @param Request $request * @@ -30,12 +47,7 @@ class EntryController extends Controller $form->handleRequest($request); if ($form->isValid()) { - $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); - - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - + $this->updateEntry($entry); $this->get('session')->getFlashBag()->add( 'notice', 'Entry saved' @@ -49,6 +61,22 @@ class EntryController extends Controller )); } + /** + * @param Request $request + * + * @Route("/bookmarklet", name="bookmarklet") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function addEntryViaBookmarklet(Request $request) + { + $entry = new Entry($this->getUser()); + $entry->setUrl($request->get('url')); + $this->updateEntry($entry); + + return $this->redirect($this->generateUrl('homepage')); + } + /** * @param Request $request * -- cgit v1.2.3