aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-02-24 11:34:36 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-05-30 11:47:39 +0200
commit61351218f90df455c6edcc530bfc746d60b43a12 (patch)
treeabb1945e9f9c648ac686eb67bb1386eb175f72d3 /src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php
parentd181bd728565454ec53d960f321ed0a4c3bf26c8 (diff)
downloadwallabag-61351218f90df455c6edcc530bfc746d60b43a12.tar.gz
wallabag-61351218f90df455c6edcc530bfc746d60b43a12.tar.zst
wallabag-61351218f90df455c6edcc530bfc746d60b43a12.zip
Save changes
PHP CS Fixed Events on changes Renamed field First draft for migration (create table Change) Added setter for tag in EntryTaggedEvent Fixed migration for Change table Added API route for entry history Removed deletion history
Diffstat (limited to 'src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php')
-rw-r--r--src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php b/src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php
new file mode 100644
index 00000000..1ba18a4f
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Subscriber/ChangesSubscriber.php
@@ -0,0 +1,59 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Subscriber;
4
5use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6use Doctrine\ORM\EntityManager;
7use Psr\Log\LoggerInterface;
8use Wallabag\CoreBundle\Entity\Change;
9use Wallabag\CoreBundle\Event\EntryTaggedEvent;
10use Wallabag\CoreBundle\Event\EntryUpdatedEvent;
11
12class ChangesSubscriber implements EventSubscriberInterface
13{
14 /** @var LoggerInterface $logger */
15 private $logger;
16
17 /** @var EntityManager $em */
18 private $em;
19
20 public function __construct(EntityManager $em, LoggerInterface $logger)
21 {
22 $this->logger = $logger;
23 $this->em = $em;
24 }
25
26 public static function getSubscribedEvents()
27 {
28 return [
29 EntryUpdatedEvent::NAME => 'onEntryUpdated',
30 EntryTaggedEvent::NAME => 'onEntryTagged',
31 ];
32 }
33
34 /**
35 * @param EntryUpdatedEvent $event
36 */
37 public function onEntryUpdated(EntryUpdatedEvent $event)
38 {
39 $change = new Change(Change::MODIFIED_TYPE, $event->getEntry());
40
41 $this->em->persist($change);
42 $this->em->flush();
43
44 $this->logger->debug('saved updated entry '.$event->getEntry()->getId().' event ');
45 }
46
47 /**
48 * @param EntryTaggedEvent $event
49 */
50 public function onEntryTagged(EntryTaggedEvent $event)
51 {
52 $change = new Change(Change::CHANGED_TAG_TYPE, $event->getEntry());
53
54 $this->em->persist($change);
55 $this->em->flush();
56
57 $this->logger->debug('saved (un)tagged entry '.$event->getEntry()->getId().' event ');
58 }
59}