]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
implement delete method
authorNicolas Lœuillet <nicolas@loeuillet.org>
Wed, 4 Feb 2015 16:54:23 +0000 (17:54 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Wed, 4 Feb 2015 16:54:23 +0000 (17:54 +0100)
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Entity/Entries.php
src/Wallabag/CoreBundle/Repository/EntriesRepository.php

index 377a45ae79da8c3b88b46c84863146683916e50c..eb5b43adcb90a524d78f42f8e84243e8c188ed8d 100644 (file)
@@ -177,7 +177,8 @@ class EntryController extends Controller
     public function deleteEntryAction(Request $request, Entries $entry)
     {
         $em = $this->getDoctrine()->getManager();
-        $em->remove($entry);
+        $entry->setDeleted(1);
+        $em->persist($entry);
         $em->flush();
 
         $this->get('session')->getFlashBag()->add(
index 5668d9348627e97fc9c66e6eb4af0a1fbf0fc5f8..fc13b1a8d867c961f84d7b6213cef0b561eec8ea 100644 (file)
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Controller;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Wallabag\CoreBundle\Entity\Entries;
 use Wallabag\CoreBundle\Entity\Tags;
 use Wallabag\CoreBundle\Service\Extractor;
@@ -30,6 +31,8 @@ class WallabagRestController extends Controller
      */
     public function getEntriesAction(Request $request)
     {
+        // TODO isArchived, isStarred et isDeleted ne doivent pas avoir de valeur par défaut
+        // TODO Si on ne passe rien, on ne filtre pas sur le statut.
         $isArchived = $request->query->get('archive', 0);
         $isStarred  = $request->query->get('star', 0);
         $isDeleted  = $request->query->get('delete', 0);
@@ -129,6 +132,16 @@ class WallabagRestController extends Controller
      */
     public function deleteEntriesAction(Entries $entry)
     {
+        if ($entry->isDeleted()) {
+            throw new NotFoundHttpException('This entry is already deleted');
+        }
+
+        $em = $this->getDoctrine()->getManager();
+        $entry->setDeleted(1);
+        $em->persist($entry);
+        $em->flush();
+
+        return $entry;
     }
 
     /**
index 9da5102cae34a1cfe4c0086e47b2d222cf023be8..32e928d2325f64f2ababca7f178c3db6e1c9e1aa 100644 (file)
@@ -66,6 +66,13 @@ class Entries
      */
     private $userId;
 
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="is_deleted", type="decimal", precision=10, scale=0, nullable=true)
+     */
+    private $isDeleted = '0';
+
     /**
      * Get id
      *
@@ -227,4 +234,20 @@ class Entries
     {
         return $this->userId;
     }
+
+    /**
+     * @return string
+     */
+    public function isDeleted()
+    {
+        return $this->isDeleted;
+    }
+
+    /**
+     * @param string $isDeleted
+     */
+    public function setDeleted($isDeleted)
+    {
+        $this->isDeleted = $isDeleted;
+    }
 }
index d87eb373069ebf9ea37ad386cdf2ed891518d8bd..c76b421569433909279c79d2f5fa1e0444472a36 100644 (file)
@@ -25,6 +25,7 @@ class EntriesRepository extends EntityRepository
             ->setMaxResults($maxResults)
             ->where('e.isRead = 0')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
+            ->andWhere('e.isDeleted=0')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -48,6 +49,7 @@ class EntriesRepository extends EntityRepository
             ->setMaxResults($maxResults)
             ->where('e.isRead = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
+            ->andWhere('e.isDeleted=0')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -71,6 +73,7 @@ class EntriesRepository extends EntityRepository
             ->setMaxResults($maxResults)
             ->where('e.isFav = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
+            ->andWhere('e.isDeleted=0')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -86,6 +89,7 @@ class EntriesRepository extends EntityRepository
             ->where('e.isFav =:isStarred')->setParameter('isStarred', $isStarred)
             ->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived)
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
+            ->andWhere('e.isDeleted=0')
             ->getQuery()
             ->getResult(Query::HYDRATE_ARRAY);