aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php6
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php20
2 files changed, 20 insertions, 6 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 744e1a60..da671a61 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -43,8 +43,8 @@ class WallabagRestController extends FOSRestController
43 { 43 {
44 $this->validateAuthentication(); 44 $this->validateAuthentication();
45 45
46 $isArchived = (int) $request->query->get('archive'); 46 $isArchived = (null === $request->query->get('archive')) ? null : (bool) $request->query->get('archive');
47 $isStarred = (int) $request->query->get('starred'); 47 $isStarred = (null === $request->query->get('starred')) ? null : (bool) $request->query->get('starred');
48 $sort = $request->query->get('sort', 'created'); 48 $sort = $request->query->get('sort', 'created');
49 $order = $request->query->get('order', 'desc'); 49 $order = $request->query->get('order', 'desc');
50 $page = (int) $request->query->get('page', 1); 50 $page = (int) $request->query->get('page', 1);
@@ -52,7 +52,7 @@ class WallabagRestController extends FOSRestController
52 52
53 $pager = $this->getDoctrine() 53 $pager = $this->getDoctrine()
54 ->getRepository('WallabagCoreBundle:Entry') 54 ->getRepository('WallabagCoreBundle:Entry')
55 ->findEntries($this->getUser()->getId(), (bool) $isArchived, (bool) $isStarred, $sort, $order); 55 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
56 56
57 $pager->setCurrentPage($page); 57 $pager->setCurrentPage($page);
58 $pager->setMaxPerPage($perPage); 58 $pager->setMaxPerPage($perPage);
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index fa633031..cba58858 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -49,8 +49,7 @@ class EntryController extends Controller
49 $form->handleRequest($request); 49 $form->handleRequest($request);
50 50
51 if ($form->isValid()) { 51 if ($form->isValid()) {
52 // check for existing entry, if it exists, redirect to it with a message 52 $existingEntry = $this->checkIfEntryAlreadyExists($entry);
53 $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
54 53
55 if (false !== $existingEntry) { 54 if (false !== $existingEntry) {
56 $this->get('session')->getFlashBag()->add( 55 $this->get('session')->getFlashBag()->add(
@@ -86,7 +85,10 @@ class EntryController extends Controller
86 { 85 {
87 $entry = new Entry($this->getUser()); 86 $entry = new Entry($this->getUser());
88 $entry->setUrl($request->get('url')); 87 $entry->setUrl($request->get('url'));
89 $this->updateEntry($entry); 88
89 if (false === $this->checkIfEntryAlreadyExists($entry)) {
90 $this->updateEntry($entry);
91 }
90 92
91 return $this->redirect($this->generateUrl('homepage')); 93 return $this->redirect($this->generateUrl('homepage'));
92 } 94 }
@@ -420,4 +422,16 @@ class EntryController extends Controller
420 throw $this->createAccessDeniedException('You can not access this entry.'); 422 throw $this->createAccessDeniedException('You can not access this entry.');
421 } 423 }
422 } 424 }
425
426 /**
427 * Check for existing entry, if it exists, redirect to it with a message.
428 *
429 * @param $entry
430 *
431 * @return array|bool
432 */
433 private function checkIfEntryAlreadyExists($entry)
434 {
435 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
436 }
423} 437}