From 6da1aebc946e6448dd0d5080ee88e79c2bae4666 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 16:24:59 +0200 Subject: Allow to remove all archived entries Since we still support fucking SQLite, we need to retrieve all tags & annotations for archived entries before deleting them. Signed-off-by: Thomas Citharel --- .../AnnotationBundle/Repository/AnnotationRepository.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 8d3f07ee..23f21c3e 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -122,4 +122,20 @@ class AnnotationRepository extends EntityRepository ->setParameter('userId', $userId) ->execute(); } + + /** + * Find all annotations related to archived entries + * + * @param $userId + * @return mixed + */ + public function findAllByArchivedEntriesAndUserId($userId) + { + return $this->createQueryBuilder('a') + ->leftJoin('a.entry', 'e') + ->where('a.user = :userid')->setParameter(':userid', $userId) + ->andWhere('e.isArchived = true') + ->getQuery() + ->getResult(); + } } -- cgit v1.2.3 From 9102851f59d960869b210bb26ab0e9c266781c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 10:53:23 +0200 Subject: Added delete button on Baggy theme --- src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 23f21c3e..3af53805 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -124,9 +124,10 @@ class AnnotationRepository extends EntityRepository } /** - * Find all annotations related to archived entries + * Find all annotations related to archived entries. * * @param $userId + * * @return mixed */ public function findAllByArchivedEntriesAndUserId($userId) -- cgit v1.2.3 From 13a592a1288d7deb49211838368583c0109a5fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 17:03:08 +0200 Subject: Renamed methods --- src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 3af53805..da361308 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -130,7 +130,7 @@ class AnnotationRepository extends EntityRepository * * @return mixed */ - public function findAllByArchivedEntriesAndUserId($userId) + public function findAllArchivedEntriesByUser($userId) { return $this->createQueryBuilder('a') ->leftJoin('a.entry', 'e') -- cgit v1.2.3 From 2c3e148b0029a094431622feac79fafcd0d43fc8 Mon Sep 17 00:00:00 2001 From: adev Date: Sun, 7 May 2017 17:21:30 +0200 Subject: Displays an error with an annotation with a too long quote Fix #2762 --- .../Controller/WallabagAnnotationController.php | 49 +++++++++++++--------- .../AnnotationBundle/Entity/Annotation.php | 7 +++- .../AnnotationBundle/Form/EditAnnotationType.php | 18 ++++++++ .../AnnotationBundle/Form/NewAnnotationType.php | 35 ++++++++++++++++ src/Wallabag/AnnotationBundle/Form/RangeType.php | 19 +++++++++ 5 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 src/Wallabag/AnnotationBundle/Form/EditAnnotationType.php create mode 100644 src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php create mode 100644 src/Wallabag/AnnotationBundle/Form/RangeType.php (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index c13a034f..2b4b0e8d 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -7,6 +7,8 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Wallabag\AnnotationBundle\Entity\Annotation; +use Wallabag\AnnotationBundle\Form\EditAnnotationType; +use Wallabag\AnnotationBundle\Form\NewAnnotationType; use Wallabag\CoreBundle\Entity\Entry; class WallabagAnnotationController extends FOSRestController @@ -49,25 +51,25 @@ class WallabagAnnotationController extends FOSRestController $data = json_decode($request->getContent(), true); $em = $this->getDoctrine()->getManager(); - $annotation = new Annotation($this->getUser()); + $annotation->setEntry($entry); - $annotation->setText($data['text']); - if (array_key_exists('quote', $data)) { - $annotation->setQuote($data['quote']); - } - if (array_key_exists('ranges', $data)) { - $annotation->setRanges($data['ranges']); - } + $form = $this->get('form.factory')->createNamed('', NewAnnotationType::class, $annotation, [ + 'csrf_protection' => false, + 'allow_extra_fields' => true, + ]); + $form->submit($data); - $annotation->setEntry($entry); + if ($form->isValid()) { + $em->persist($annotation); + $em->flush(); - $em->persist($annotation); - $em->flush(); + $json = $this->get('serializer')->serialize($annotation, 'json'); - $json = $this->get('serializer')->serialize($annotation, 'json'); + return JsonResponse::fromJsonString($json); + } - return (new JsonResponse())->setJson($json); + return $form; } /** @@ -86,16 +88,23 @@ class WallabagAnnotationController extends FOSRestController { $data = json_decode($request->getContent(), true); - if (!is_null($data['text'])) { - $annotation->setText($data['text']); - } + $form = $this->get('form.factory')->createNamed('', EditAnnotationType::class, $annotation, [ + 'csrf_protection' => false, + 'allow_extra_fields' => true, + ]); + $form->submit($data); - $em = $this->getDoctrine()->getManager(); - $em->flush(); + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($annotation); + $em->flush(); - $json = $this->get('serializer')->serialize($annotation, 'json'); + $json = $this->get('serializer')->serialize($annotation, 'json'); - return (new JsonResponse())->setJson($json); + return JsonResponse::fromJsonString($json); + } + + return $form; } /** diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php index 0838f5aa..c8e41649 100644 --- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php +++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php @@ -8,6 +8,7 @@ use JMS\Serializer\Annotation\Exclude; use JMS\Serializer\Annotation\VirtualProperty; use JMS\Serializer\Annotation\SerializedName; use JMS\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; @@ -56,7 +57,11 @@ class Annotation /** * @var string * - * @ORM\Column(name="quote", type="string") + * @Assert\Length( + * max = 10000, + * maxMessage = "validator.quote_length_too_high" + * ) + * @ORM\Column(name="quote", type="text") * * @Groups({"entries_for_user", "export_all"}) */ diff --git a/src/Wallabag/AnnotationBundle/Form/EditAnnotationType.php b/src/Wallabag/AnnotationBundle/Form/EditAnnotationType.php new file mode 100644 index 00000000..3b587478 --- /dev/null +++ b/src/Wallabag/AnnotationBundle/Form/EditAnnotationType.php @@ -0,0 +1,18 @@ +add('text', null, [ + 'empty_data' => '', + ]) + ; + } +} diff --git a/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php new file mode 100644 index 00000000..c73c3ded --- /dev/null +++ b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php @@ -0,0 +1,35 @@ +add('text', null, [ + 'empty_data' => '', + ]) + ->add('quote', null, [ + 'empty_data' => null, + ]) + ->add('ranges', CollectionType::class, [ + 'entry_type' => RangeType::class, + 'allow_add' => true, + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Annotation::class, + ]); + } +} diff --git a/src/Wallabag/AnnotationBundle/Form/RangeType.php b/src/Wallabag/AnnotationBundle/Form/RangeType.php new file mode 100644 index 00000000..0647375e --- /dev/null +++ b/src/Wallabag/AnnotationBundle/Form/RangeType.php @@ -0,0 +1,19 @@ +add('start') + ->add('startOffset') + ->add('end') + ->add('endOffset') + ; + } +} -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../Controller/WallabagAnnotationController.php | 2 +- .../AnnotationBundle/Entity/Annotation.php | 10 +++---- .../Repository/AnnotationRepository.php | 32 +++++++++++----------- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 2b4b0e8d..8d7b6ee9 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -3,9 +3,9 @@ namespace Wallabag\AnnotationBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Wallabag\AnnotationBundle\Entity\Annotation; use Wallabag\AnnotationBundle\Form\EditAnnotationType; use Wallabag\AnnotationBundle\Form\NewAnnotationType; diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php index c8e41649..04d83001 100644 --- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php +++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php @@ -3,14 +3,14 @@ namespace Wallabag\AnnotationBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Exclude; -use JMS\Serializer\Annotation\VirtualProperty; -use JMS\Serializer\Annotation\SerializedName; +use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Groups; +use JMS\Serializer\Annotation\SerializedName; +use JMS\Serializer\Annotation\VirtualProperty; use Symfony\Component\Validator\Constraints as Assert; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\UserBundle\Entity\User; /** * Annotation. @@ -139,7 +139,7 @@ class Annotation */ public function timestamps() { - if (is_null($this->createdAt)) { + if (null === $this->createdAt) { $this->createdAt = new \DateTime(); } $this->updatedAt = new \DateTime(); diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index da361308..014c29b6 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -9,22 +9,6 @@ use Doctrine\ORM\EntityRepository; */ class AnnotationRepository extends EntityRepository { - /** - * Return a query builder to used by other getBuilderFor* method. - * - * @param int $userId - * - * @return QueryBuilder - */ - private function getBuilderByUser($userId) - { - return $this->createQueryBuilder('a') - ->leftJoin('a.user', 'u') - ->andWhere('u.id = :userId')->setParameter('userId', $userId) - ->orderBy('a.id', 'desc') - ; - } - /** * Retrieves all annotations for a user. * @@ -139,4 +123,20 @@ class AnnotationRepository extends EntityRepository ->getQuery() ->getResult(); } + + /** + * Return a query builder to used by other getBuilderFor* method. + * + * @param int $userId + * + * @return QueryBuilder + */ + private function getBuilderByUser($userId) + { + return $this->createQueryBuilder('a') + ->leftJoin('a.user', 'u') + ->andWhere('u.id = :userId')->setParameter('userId', $userId) + ->orderBy('a.id', 'desc') + ; + } } -- cgit v1.2.3 From 927c9e796ff6fad2bf82a965234f52932cdee657 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 6 Jul 2017 09:00:37 +0200 Subject: Add EntityTimestampsTrait to handle dates Refactorize timestamps() method to avoid re-writing it on each entity --- src/Wallabag/AnnotationBundle/Entity/Annotation.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php index 04d83001..a180d504 100644 --- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php +++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php @@ -10,6 +10,7 @@ use JMS\Serializer\Annotation\SerializedName; use JMS\Serializer\Annotation\VirtualProperty; use Symfony\Component\Validator\Constraints as Assert; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; use Wallabag\UserBundle\Entity\User; /** @@ -22,6 +23,8 @@ use Wallabag\UserBundle\Entity\User; */ class Annotation { + use EntityTimestampsTrait; + /** * @var int * @@ -133,18 +136,6 @@ class Annotation return $this->text; } - /** - * @ORM\PrePersist - * @ORM\PreUpdate - */ - public function timestamps() - { - if (null === $this->createdAt) { - $this->createdAt = new \DateTime(); - } - $this->updatedAt = new \DateTime(); - } - /** * Get created. * -- cgit v1.2.3 From 52b84c11a5b5474cd45271d937a46c6adfdf2749 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sat, 29 Jul 2017 22:51:50 +0200 Subject: Fix some namespaces and phpdoc --- src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 014c29b6..b44f7e64 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -3,6 +3,8 @@ namespace Wallabag\AnnotationBundle\Repository; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; +use Wallabag\AnnotationBundle\Entity\Annotation; /** * AnnotationRepository. -- cgit v1.2.3 From f40c88eb1fa349aab600f9c1c94364f317fe62dd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 9 Oct 2017 16:45:09 +0200 Subject: Jump to Symfony 3.3 & update others deps Also update tests urls --- .../AnnotationBundle/Controller/WallabagAnnotationController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/AnnotationBundle') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 8d7b6ee9..f3090e65 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -31,7 +31,7 @@ class WallabagAnnotationController extends FOSRestController $total = count($annotationRows); $annotations = ['total' => $total, 'rows' => $annotationRows]; - $json = $this->get('serializer')->serialize($annotations, 'json'); + $json = $this->get('jms_serializer')->serialize($annotations, 'json'); return (new JsonResponse())->setJson($json); } @@ -64,7 +64,7 @@ class WallabagAnnotationController extends FOSRestController $em->persist($annotation); $em->flush(); - $json = $this->get('serializer')->serialize($annotation, 'json'); + $json = $this->get('jms_serializer')->serialize($annotation, 'json'); return JsonResponse::fromJsonString($json); } @@ -99,7 +99,7 @@ class WallabagAnnotationController extends FOSRestController $em->persist($annotation); $em->flush(); - $json = $this->get('serializer')->serialize($annotation, 'json'); + $json = $this->get('jms_serializer')->serialize($annotation, 'json'); return JsonResponse::fromJsonString($json); } @@ -124,7 +124,7 @@ class WallabagAnnotationController extends FOSRestController $em->remove($annotation); $em->flush(); - $json = $this->get('serializer')->serialize($annotation, 'json'); + $json = $this->get('jms_serializer')->serialize($annotation, 'json'); return (new JsonResponse())->setJson($json); } -- cgit v1.2.3