From be463487cc195026b11e92f1d6d6276f5851b97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Feb 2015 07:45:32 +0100 Subject: [PATCH] rename Entries to Entry --- .../CoreBundle/Controller/EntryController.php | 26 ++++---- .../Controller/WallabagRestController.php | 25 ++++---- .../Entity/{Entries.php => Entry.php} | 63 +++++++++---------- .../Helper/{Entries.php => Entry.php} | 2 +- ...riesRepository.php => EntryRepository.php} | 3 +- 5 files changed, 58 insertions(+), 61 deletions(-) rename src/Wallabag/CoreBundle/Entity/{Entries.php => Entry.php} (84%) rename src/Wallabag/CoreBundle/Helper/{Entries.php => Entry.php} (78%) rename src/Wallabag/CoreBundle/Repository/{EntriesRepository.php => EntryRepository.php} (97%) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index eb5b43ad..6326d31f 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -5,8 +5,8 @@ namespace Wallabag\CoreBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Repository; -use Wallabag\CoreBundle\Entity\Entries; use Wallabag\CoreBundle\Service\Extractor; use Wallabag\CoreBundle\Helper\Url; @@ -19,7 +19,7 @@ class EntryController extends Controller */ public function addEntryAction(Request $request) { - $entry = new Entries(); + $entry = new Entry(); $entry->setUserId(1); $form = $this->createFormBuilder($entry) @@ -60,7 +60,7 @@ class EntryController extends Controller */ public function showUnreadAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findUnreadByUser(1, 0); @@ -79,7 +79,7 @@ class EntryController extends Controller */ public function showArchiveAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findArchiveByUser(1, 0); @@ -98,7 +98,7 @@ class EntryController extends Controller */ public function showStarredAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findStarredByUser(1, 0); @@ -112,11 +112,11 @@ class EntryController extends Controller /** * Shows entry content * - * @param Entries $entry + * @param Entry $entry * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") * @return \Symfony\Component\HttpFoundation\Response */ - public function viewAction(Entries $entry) + public function viewAction(Entry $entry) { return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', @@ -128,11 +128,11 @@ class EntryController extends Controller * Changes read status for an entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function toggleArchiveAction(Request $request, Entries $entry) + public function toggleArchiveAction(Request $request, Entry $entry) { $entry->toggleArchive(); $this->getDoctrine()->getManager()->flush(); @@ -149,11 +149,11 @@ class EntryController extends Controller * Changes favorite status for an entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function toggleStarAction(Request $request, Entries $entry) + public function toggleStarAction(Request $request, Entry $entry) { $entry->toggleStar(); $this->getDoctrine()->getManager()->flush(); @@ -170,11 +170,11 @@ class EntryController extends Controller * Deletes entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function deleteEntryAction(Request $request, Entries $entry) + public function deleteEntryAction(Request $request, Entry $entry) { $em = $this->getDoctrine()->getManager(); $entry->setDeleted(1); diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 75de58f7..1df18247 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -6,7 +6,7 @@ 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\Entry; use Wallabag\CoreBundle\Entity\Tags; use Wallabag\CoreBundle\Service\Extractor; @@ -27,7 +27,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, * } * ) - * @return Entries + * @return Entry */ public function getEntriesAction(Request $request) { @@ -42,7 +42,7 @@ class WallabagRestController extends Controller $entries = $this ->getDoctrine() - ->getRepository('WallabagCoreBundle:Entries') + ->getRepository('WallabagCoreBundle:Entry') ->findEntries(1, $isArchived, $isStarred, $isDeleted, $sort, $order); if (!is_array($entries)) { @@ -60,9 +60,9 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) - * @return Entries + * @return Entry */ - public function getEntryAction(Entries $entry) + public function getEntryAction(Entry $entry) { return $entry; } @@ -77,6 +77,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, * } * ) + * @return Entry */ public function postEntriesAction(Request $request) { @@ -84,7 +85,7 @@ class WallabagRestController extends Controller $url = $request->request->get('url'); $content = Extractor::extract($url); - $entry = new Entries(); + $entry = new Entry(); $entry->setUserId(1); $entry->setUrl($url); $entry->setTitle($request->request->get('title') ?: $content->getTitle()); @@ -111,8 +112,9 @@ class WallabagRestController extends Controller * {"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.."}, * } * ) + * @return Entry */ - public function patchEntriesAction(Entries $entry, Request $request) + public function patchEntriesAction(Entry $entry, Request $request) { $title = $request->request->get("title"); $tags = $request->request->get("tags", array()); @@ -150,8 +152,9 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * @return Entry */ - public function deleteEntriesAction(Entries $entry) + public function deleteEntriesAction(Entry $entry) { if ($entry->isDeleted()) { throw new NotFoundHttpException('This entry is already deleted'); @@ -173,7 +176,7 @@ class WallabagRestController extends Controller * } * ) */ - public function getEntriesTagsAction(Entries $entry) + public function getEntriesTagsAction(Entry $entry) { } @@ -189,7 +192,7 @@ class WallabagRestController extends Controller * } * ) */ - public function postEntriesTagsAction(Entries $entry) + public function postEntriesTagsAction(Entry $entry) { } @@ -203,7 +206,7 @@ class WallabagRestController extends Controller * } * ) */ - public function deleteEntriesTagsAction(Entries $entry, Tags $tag) + public function deleteEntriesTagsAction(Entry $entry, Tags $tag) { } diff --git a/src/Wallabag/CoreBundle/Entity/Entries.php b/src/Wallabag/CoreBundle/Entity/Entry.php similarity index 84% rename from src/Wallabag/CoreBundle/Entity/Entries.php rename to src/Wallabag/CoreBundle/Entity/Entry.php index f06a2940..70c1dc08 100644 --- a/src/Wallabag/CoreBundle/Entity/Entries.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -6,23 +6,23 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** - * Entries + * Entry * - * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntriesRepository") - * @ORM\Table(name="entries") + * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") + * @ORM\Table(name="entry") * @ORM\HasLifecycleCallbacks() * */ -class Entries +class Entry { /** * @var integer * - * @ORM\Column(name="id", type="integer", nullable=true) + * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ - private $id = null; + private $id; /** * @var string @@ -42,21 +42,21 @@ class Entries /** * @var boolean * - * @ORM\Column(name="is_archived", type="boolean", nullable=true, options={"default" = false}) + * @ORM\Column(name="is_archived", type="boolean") */ private $isArchived = false; /** * @var boolean * - * @ORM\Column(name="is_starred", type="boolean", nullable=true, options={"default" = false}) + * @ORM\Column(name="is_starred", type="boolean") */ private $isStarred = false; /** * @var boolean * - * @ORM\Column(name="is_deleted", type="boolean", nullable=true, options={"default" = false}) + * @ORM\Column(name="is_deleted", type="boolean") */ private $isDeleted = false; @@ -70,14 +70,14 @@ class Entries /** * @var date * - * @ORM\Column(name="created_at", type="datetime", nullable=true) + * @ORM\Column(name="created_at", type="datetime") */ private $createdAt; /** * @var date * - * @ORM\Column(name="updated_at", type="datetime", nullable=true) + * @ORM\Column(name="updated_at", type="datetime") */ private $updatedAt; @@ -136,8 +136,8 @@ class Entries /** * Set title * - * @param string $title - * @return Entries + * @param string $title + * @return Entry */ public function setTitle($title) { @@ -159,8 +159,8 @@ class Entries /** * Set url * - * @param string $url - * @return Entries + * @param string $url + * @return Entry */ public function setUrl($url) { @@ -182,8 +182,8 @@ class Entries /** * Set isArchived * - * @param string $isArchived - * @return Entries + * @param string $isArchived + * @return Entry */ public function setArchived($isArchived) { @@ -212,8 +212,8 @@ class Entries /** * Set isStarred * - * @param string $isStarred - * @return Entries + * @param string $isStarred + * @return Entry */ public function setStarred($isStarred) { @@ -242,8 +242,8 @@ class Entries /** * Set content * - * @param string $content - * @return Entries + * @param string $content + * @return Entry */ public function setContent($content) { @@ -265,8 +265,8 @@ class Entries /** * Set userId * - * @param string $userId - * @return Entries + * @param string $userId + * @return Entry */ public function setUserId($userId) { @@ -309,15 +309,6 @@ class Entries return $this->createdAt; } - /** - * @param mixed $createdAt - * @ORM\PrePersist - */ - public function setCreatedAt() - { - $this->createdAt = new \DateTime(); - } - /** * @return string */ @@ -327,11 +318,15 @@ class Entries } /** - * @param string $updatedAt + * @ORM\PrePersist * @ORM\PreUpdate */ - public function setUpdatedAt() + public function timestamps() { + if (is_null($this->createdAt)) { + $this->createdAt = new \DateTime(); + } + $this->updatedAt = new \DateTime(); } diff --git a/src/Wallabag/CoreBundle/Helper/Entries.php b/src/Wallabag/CoreBundle/Helper/Entry.php similarity index 78% rename from src/Wallabag/CoreBundle/Helper/Entries.php rename to src/Wallabag/CoreBundle/Helper/Entry.php index 6eeca4ff..219711b3 100644 --- a/src/Wallabag/CoreBundle/Helper/Entries.php +++ b/src/Wallabag/CoreBundle/Helper/Entry.php @@ -2,6 +2,6 @@ namespace Wallabag\CoreBundle\Helper; -class Entries +class Entry { } diff --git a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php similarity index 97% rename from src/Wallabag/CoreBundle/Repository/EntriesRepository.php rename to src/Wallabag/CoreBundle/Repository/EntryRepository.php index 9965317a..f4c803f9 100644 --- a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -5,9 +5,8 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\Query; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Pagination\Paginator; -use Wallabag\CoreBundle\Entity\Entries; -class EntriesRepository extends EntityRepository +class EntryRepository extends EntityRepository { /** * Retrieves unread entries for a user -- 2.41.0