]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Symfony Upgrade Fixer FTW
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index 2f3fd6a9348ab6ec26c0ae1b301de95610e3778b..c1b5a71ba046dde16e5adc67057ffd6ecdbc1c89 100644 (file)
@@ -2,16 +2,16 @@
 
 namespace Wallabag\CoreBundle\Controller;
 
+use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Pagerfanta;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 use Wallabag\CoreBundle\Entity\Entry;
-use Wallabag\CoreBundle\Form\Type\NewEntryType;
-use Wallabag\CoreBundle\Form\Type\EditEntryType;
 use Wallabag\CoreBundle\Filter\EntryFilterType;
-use Pagerfanta\Adapter\DoctrineORMAdapter;
-use Pagerfanta\Pagerfanta;
+use Wallabag\CoreBundle\Form\Type\EditEntryType;
+use Wallabag\CoreBundle\Form\Type\NewEntryType;
 
 class EntryController extends Controller
 {
@@ -48,6 +48,19 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
+            // check for existing entry, if it exists, redirect to it with a message
+            $existingEntry = $this->get('wallabag_core.entry_repository')
+                ->existByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
+
+            if (false !== $existingEntry) {
+                $this->get('session')->getFlashBag()->add(
+                    'notice',
+                    'Entry already saved on '.$existingEntry['createdAt']->format('d-m-Y')
+                );
+
+                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry['id'])));
+            }
+
             $this->updateEntry($entry);
             $this->get('session')->getFlashBag()->add(
                 'notice',
@@ -266,6 +279,33 @@ class EntryController extends Controller
         );
     }
 
+    /**
+     * Reload an entry.
+     * Refetch content from the website and make it readable again.
+     *
+     * @param Entry $entry
+     *
+     * @Route("/reload/{id}", requirements={"id" = "\d+"}, name="reload_entry")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function reloadAction(Entry $entry)
+    {
+        $this->checkUserAction($entry);
+
+        $message = 'Entry reloaded';
+        if (false === $this->updateEntry($entry)) {
+            $message = 'Failed to reload entry';
+        }
+
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            $message
+        );
+
+        return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
+    }
+
     /**
      * Changes read status for an entry.
      *
@@ -347,7 +387,7 @@ class EntryController extends Controller
         );
 
         // don't redirect user to the deleted entry
-        return $this->redirect($url !== $request->headers->get('referer') ?: $this->generateUrl('homepage'));
+        return $this->redirect($url !== $request->headers->get('referer') ? $request->headers->get('referer') : $this->generateUrl('homepage'));
     }
 
     /**