]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Provide a way to delete tagging rules
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index b73e9eecd52e5aeb81e0c72e75fdf3a97f0c290a..6769799b7f35e2f6693311fac517d4e4f1d723bd 100644 (file)
@@ -6,7 +6,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Wallabag\CoreBundle\Entity\Entry;
-use Wallabag\CoreBundle\Service\Extractor;
 use Wallabag\CoreBundle\Form\Type\NewEntryType;
 use Wallabag\CoreBundle\Form\Type\EditEntryType;
 use Wallabag\CoreBundle\Filter\EntryFilterType;
@@ -15,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
      *
@@ -31,15 +47,7 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
-            $content = Extractor::extract($entry->getUrl());
-
-            $entry->setTitle($content->getTitle());
-            $entry->setContent($content->getBody());
-
-            $em = $this->getDoctrine()->getManager();
-            $em->persist($entry);
-            $em->flush();
-
+            $this->updateEntry($entry);
             $this->get('session')->getFlashBag()->add(
                 'notice',
                 'Entry saved'
@@ -53,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
      *
@@ -196,7 +220,7 @@ class EntryController extends Controller
                 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
         }
 
-        $form = $this->get('form.factory')->create(new EntryFilterType());
+        $form = $this->get('form.factory')->create(new EntryFilterType($repository, $this->getUser()));
 
         if ($request->query->has($form->getName())) {
             // manually bind values from the request
@@ -292,10 +316,9 @@ class EntryController extends Controller
     }
 
     /**
-     * Deletes entry.
+     * Deletes entry and redirect to the homepage.
      *
-     * @param Request $request
-     * @param Entry   $entry
+     * @param Entry $entry
      *
      * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
      *