aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php5
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php22
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php23
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php10
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php9
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php16
6 files changed, 23 insertions, 62 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 81ab7788..8a8f3cd7 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -192,8 +192,9 @@ class EntryController extends Controller
192 { 192 {
193 $this->checkUserAction($entry); 193 $this->checkUserAction($entry);
194 194
195 $entry->setDeleted(1); 195 $em = $this->getDoctrine()->getManager();
196 $this->getDoctrine()->getManager()->flush(); 196 $em->remove($entry);
197 $em->flush();
197 198
198 $this->get('session')->getFlashBag()->add( 199 $this->get('session')->getFlashBag()->add(
199 'notice', 200 'notice',
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index b9f7efea..276cfe1c 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -43,7 +43,6 @@ class WallabagRestController extends Controller
43 * parameters={ 43 * parameters={
44 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."}, 44 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."},
45 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."}, 45 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."},
46 * {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false, default '0'", "description"="filter by deleted status."},
47 * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, 46 * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
48 * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, 47 * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
49 * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, 48 * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
@@ -57,7 +56,6 @@ class WallabagRestController extends Controller
57 { 56 {
58 $isArchived = $request->query->get('archive'); 57 $isArchived = $request->query->get('archive');
59 $isStarred = $request->query->get('star'); 58 $isStarred = $request->query->get('star');
60 $isDeleted = $request->query->get('delete', 0);
61 $sort = $request->query->get('sort', 'created'); 59 $sort = $request->query->get('sort', 'created');
62 $order = $request->query->get('order', 'desc'); 60 $order = $request->query->get('order', 'desc');
63 $page = $request->query->get('page', 1); 61 $page = $request->query->get('page', 1);
@@ -67,7 +65,7 @@ class WallabagRestController extends Controller
67 $entries = $this 65 $entries = $this
68 ->getDoctrine() 66 ->getDoctrine()
69 ->getRepository('WallabagCoreBundle:Entry') 67 ->getRepository('WallabagCoreBundle:Entry')
70 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $isDeleted, $sort, $order); 68 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
71 69
72 if (!($entries)) { 70 if (!($entries)) {
73 throw $this->createNotFoundException(); 71 throw $this->createNotFoundException();
@@ -138,8 +136,7 @@ class WallabagRestController extends Controller
138 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, 136 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
139 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."}, 137 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."},
140 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."}, 138 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
141 * {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."}, 139 * }
142 * }
143 * ) 140 * )
144 * @return Entry 141 * @return Entry
145 */ 142 */
@@ -148,7 +145,6 @@ class WallabagRestController extends Controller
148 $title = $request->request->get("title"); 145 $title = $request->request->get("title");
149 $tags = $request->request->get("tags", array()); 146 $tags = $request->request->get("tags", array());
150 $isArchived = $request->request->get("archive"); 147 $isArchived = $request->request->get("archive");
151 $isDeleted = $request->request->get("delete");
152 $isStarred = $request->request->get("star"); 148 $isStarred = $request->request->get("star");
153 149
154 if (!is_null($title)) { 150 if (!is_null($title)) {
@@ -159,10 +155,6 @@ class WallabagRestController extends Controller
159 $entry->setArchived($isArchived); 155 $entry->setArchived($isArchived);
160 } 156 }
161 157
162 if (!is_null($isDeleted)) {
163 $entry->setDeleted($isDeleted);
164 }
165
166 if (!is_null($isStarred)) { 158 if (!is_null($isStarred)) {
167 $entry->setStarred($isStarred); 159 $entry->setStarred($isStarred);
168 } 160 }
@@ -185,15 +177,13 @@ class WallabagRestController extends Controller
185 */ 177 */
186 public function deleteEntriesAction(Entry $entry) 178 public function deleteEntriesAction(Entry $entry)
187 { 179 {
188 if ($entry->isDeleted()) {
189 throw new NotFoundHttpException('This entry is already deleted');
190 }
191
192 $em = $this->getDoctrine()->getManager(); 180 $em = $this->getDoctrine()->getManager();
193 $entry->setDeleted(1); 181 $em->remove($entry);
194 $em->flush(); 182 $em->flush();
195 183
196 return $entry; 184 $json = $this->get('serializer')->serialize($entry, 'json');
185
186 return new Response($json, 200, array('application/json'));
197 } 187 }
198 188
199 /** 189 /**
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 4f57eb0a..e47848b6 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -58,13 +58,6 @@ class Entry
58 private $isStarred = false; 58 private $isStarred = false;
59 59
60 /** 60 /**
61 * @var boolean
62 *
63 * @ORM\Column(name="is_deleted", type="boolean")
64 */
65 private $isDeleted = false;
66
67 /**
68 * @var string 61 * @var string
69 * 62 *
70 * @ORM\Column(name="content", type="text", nullable=true) 63 * @ORM\Column(name="content", type="text", nullable=true)
@@ -283,22 +276,6 @@ class Entry
283 /** 276 /**
284 * @return string 277 * @return string
285 */ 278 */
286 public function isDeleted()
287 {
288 return $this->isDeleted;
289 }
290
291 /**
292 * @param string $isDeleted
293 */
294 public function setDeleted($isDeleted)
295 {
296 $this->isDeleted = $isDeleted;
297 }
298
299 /**
300 * @return string
301 */
302 public function getCreatedAt() 279 public function getCreatedAt()
303 { 280 {
304 return $this->createdAt; 281 return $this->createdAt;
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 32394d2a..005142fc 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -24,7 +24,6 @@ class EntryRepository extends EntityRepository
24 ->leftJoin('e.user', 'u') 24 ->leftJoin('e.user', 'u')
25 ->where('e.isArchived = false') 25 ->where('e.isArchived = false')
26 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 26 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
27 ->andWhere('e.isDeleted=false')
28 ->orderBy('e.createdAt', 'desc') 27 ->orderBy('e.createdAt', 'desc')
29 ->getQuery(); 28 ->getQuery();
30 29
@@ -51,7 +50,6 @@ class EntryRepository extends EntityRepository
51 ->leftJoin('e.user', 'u') 50 ->leftJoin('e.user', 'u')
52 ->where('e.isArchived = true') 51 ->where('e.isArchived = true')
53 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 52 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
54 ->andWhere('e.isDeleted=false')
55 ->orderBy('e.createdAt', 'desc') 53 ->orderBy('e.createdAt', 'desc')
56 ->getQuery(); 54 ->getQuery();
57 55
@@ -78,7 +76,6 @@ class EntryRepository extends EntityRepository
78 ->leftJoin('e.user', 'u') 76 ->leftJoin('e.user', 'u')
79 ->where('e.isStarred = true') 77 ->where('e.isStarred = true')
80 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 78 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
81 ->andWhere('e.isDeleted = false')
82 ->orderBy('e.createdAt', 'desc') 79 ->orderBy('e.createdAt', 'desc')
83 ->getQuery(); 80 ->getQuery();
84 81
@@ -93,13 +90,12 @@ class EntryRepository extends EntityRepository
93 * @param int $userId 90 * @param int $userId
94 * @param bool $isArchived 91 * @param bool $isArchived
95 * @param bool $isStarred 92 * @param bool $isStarred
96 * @param bool $isDeleted
97 * @param string $sort 93 * @param string $sort
98 * @param string $order 94 * @param string $order
99 * 95 *
100 * @return array 96 * @return array
101 */ 97 */
102 public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC') 98 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
103 { 99 {
104 $qb = $this->createQueryBuilder('e') 100 $qb = $this->createQueryBuilder('e')
105 ->where('e.user =:userId')->setParameter('userId', $userId); 101 ->where('e.user =:userId')->setParameter('userId', $userId);
@@ -112,10 +108,6 @@ class EntryRepository extends EntityRepository
112 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); 108 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
113 } 109 }
114 110
115 if (null !== $isDeleted) {
116 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
117 }
118
119 if ('created' === $sort) { 111 if ('created' === $sort) {
120 $qb->orderBy('e.createdAt', $order); 112 $qb->orderBy('e.createdAt', $order);
121 } elseif ('updated' === $sort) { 113 } elseif ('updated' === $sort) {
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 2634141e..99a3a945 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -161,18 +161,15 @@ class EntryControllerTest extends WallabagTestCase
161 $content = $client->getContainer() 161 $content = $client->getContainer()
162 ->get('doctrine.orm.entity_manager') 162 ->get('doctrine.orm.entity_manager')
163 ->getRepository('WallabagCoreBundle:Entry') 163 ->getRepository('WallabagCoreBundle:Entry')
164 ->findOneByIsDeleted(false); 164 ->findOneById(1);
165 165
166 $client->request('GET', '/delete/'.$content->getId()); 166 $client->request('GET', '/delete/'.$content->getId());
167 167
168 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 168 $this->assertEquals(302, $client->getResponse()->getStatusCode());
169 169
170 $res = $client->getContainer() 170 $client->request('GET', '/delete/'.$content->getId());
171 ->get('doctrine.orm.entity_manager')
172 ->getRepository('WallabagCoreBundle:Entry')
173 ->findOneById($content->getId());
174 171
175 $this->assertEquals($res->isDeleted(), true); 172 $this->assertEquals(404, $client->getResponse()->getStatusCode());
176 } 173 }
177 174
178 public function testViewOtherUserEntry() 175 public function testViewOtherUserEntry()
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
index fcfa8ccf..4164e516 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -130,7 +130,7 @@ class WallabagRestControllerTest extends WallabagTestCase
130 $entry = $client->getContainer() 130 $entry = $client->getContainer()
131 ->get('doctrine.orm.entity_manager') 131 ->get('doctrine.orm.entity_manager')
132 ->getRepository('WallabagCoreBundle:Entry') 132 ->getRepository('WallabagCoreBundle:Entry')
133 ->findOneByIsDeleted(false); 133 ->findOneByUser(1);
134 134
135 if (!$entry) { 135 if (!$entry) {
136 $this->markTestSkipped('No content found in db.'); 136 $this->markTestSkipped('No content found in db.');
@@ -140,10 +140,14 @@ class WallabagRestControllerTest extends WallabagTestCase
140 140
141 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 141 $this->assertEquals(200, $client->getResponse()->getStatusCode());
142 142
143 $res = $client->getContainer() 143 // We'll try to delete this entry again
144 ->get('doctrine.orm.entity_manager') 144 $client->request('GET', '/api/salts/admin.json');
145 ->getRepository('WallabagCoreBundle:Entry') 145 $salt = json_decode($client->getResponse()->getContent());
146 ->findOneById($entry->getId()); 146
147 $this->assertEquals($res->isDeleted(), true); 147 $headers = $this->generateHeaders('admin', 'test', $salt[0]);
148
149 $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers);
150
151 $this->assertEquals(404, $client->getResponse()->getStatusCode());
148 } 152 }
149} 153}