mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-27 03:21:01 +00:00
Refactor EntryController
This commit is contained in:
parent
f652f41dab
commit
b00a89e08f
1 changed files with 14 additions and 6 deletions
|
@ -49,8 +49,7 @@ class EntryController extends Controller
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
// check for existing entry, if it exists, redirect to it with a message
|
$existingEntry = $this->checkIfEntryAlreadyExists($entry);
|
||||||
$existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
|
|
||||||
|
|
||||||
if (false !== $existingEntry) {
|
if (false !== $existingEntry) {
|
||||||
$this->get('session')->getFlashBag()->add(
|
$this->get('session')->getFlashBag()->add(
|
||||||
|
@ -87,10 +86,7 @@ class EntryController extends Controller
|
||||||
$entry = new Entry($this->getUser());
|
$entry = new Entry($this->getUser());
|
||||||
$entry->setUrl($request->get('url'));
|
$entry->setUrl($request->get('url'));
|
||||||
|
|
||||||
// check for existing entry, if it exists, redirect to it with a message
|
if (false === $this->checkIfEntryAlreadyExists($entry)) {
|
||||||
$existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
|
|
||||||
|
|
||||||
if (false === $existingEntry) {
|
|
||||||
$this->updateEntry($entry);
|
$this->updateEntry($entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,4 +422,16 @@ class EntryController extends Controller
|
||||||
throw $this->createAccessDeniedException('You can not access this entry.');
|
throw $this->createAccessDeniedException('You can not access this entry.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for existing entry, if it exists, redirect to it with a message.
|
||||||
|
*
|
||||||
|
* @param $entry
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function checkIfEntryAlreadyExists($entry)
|
||||||
|
{
|
||||||
|
return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue