aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-04-09 13:44:54 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-04-09 13:44:54 +0200
commitb00a89e08f8811297cf81f71ead1433a101d5737 (patch)
tree30a35f686d0e056d64d5a775f1b6b30db342c788 /src
parentf652f41dab0b456d24295c8ff47155f28e63f1ed (diff)
downloadwallabag-b00a89e08f8811297cf81f71ead1433a101d5737.tar.gz
wallabag-b00a89e08f8811297cf81f71ead1433a101d5737.tar.zst
wallabag-b00a89e08f8811297cf81f71ead1433a101d5737.zip
Refactor EntryController
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 1d0df889..177597ba 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(
@@ -87,10 +86,7 @@ class EntryController extends Controller
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 88
90 // check for existing entry, if it exists, redirect to it with a message 89 if (false === $this->checkIfEntryAlreadyExists($entry)) {
91 $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
92
93 if (false === $existingEntry) {
94 $this->updateEntry($entry); 90 $this->updateEntry($entry);
95 } 91 }
96 92
@@ -426,4 +422,16 @@ class EntryController extends Controller
426 throw $this->createAccessDeniedException('You can not access this entry.'); 422 throw $this->createAccessDeniedException('You can not access this entry.');
427 } 423 }
428 } 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 public function checkIfEntryAlreadyExists($entry)
434 {
435 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
436 }
429} 437}