SubscriptionsManager logging added.
This commit is contained in:
parent
30faaa7b08
commit
1df09fa68d
|
@ -37,7 +37,10 @@ services:
|
||||||
# Point subscription manager
|
# Point subscription manager
|
||||||
app.point.subscriptions_manager:
|
app.point.subscriptions_manager:
|
||||||
class: Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager
|
class: Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager
|
||||||
arguments: [ '@doctrine.orm.entity_manager', '@event_dispatcher' ]
|
arguments:
|
||||||
|
- '@doctrine.orm.entity_manager'
|
||||||
|
- '@event_dispatcher'
|
||||||
|
- '@logger'
|
||||||
|
|
||||||
|
|
||||||
# Factories
|
# Factories
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Service;
|
namespace Skobkin\Bundle\PointToolsBundle\Service;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
|
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
|
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||||
|
@ -21,11 +22,17 @@ class SubscriptionsManager
|
||||||
*/
|
*/
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var LoggerInterface
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct(EntityManager $entityManager, EventDispatcherInterface $eventDispatcher)
|
|
||||||
|
public function __construct(EntityManager $entityManager, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->em = $entityManager;
|
$this->em = $entityManager;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,16 +49,16 @@ class SubscriptionsManager
|
||||||
$oldSubscribersList[] = $subscription->getSubscriber();
|
$oldSubscribersList[] = $subscription->getSubscriber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->logger->debug('Counting user subscribers diff', ['user_id' => $user->getId()]);
|
||||||
|
|
||||||
$subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList);
|
$subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList);
|
||||||
$unsubscribedList = $this->getUsersListsDiff($oldSubscribersList, $newSubscribersList);
|
$unsubscribedList = $this->getUsersListsDiff($oldSubscribersList, $newSubscribersList);
|
||||||
|
|
||||||
|
$this->logger->debug(sprintf('User has %d subscribed and %d unsubscribed users', count($subscribedList), count($unsubscribedList)));
|
||||||
|
|
||||||
$this->processSubscribedUsers($user, $subscribedList);
|
$this->processSubscribedUsers($user, $subscribedList);
|
||||||
$this->processUnsubscribedUsers($user, $unsubscribedList);
|
$this->processUnsubscribedUsers($user, $unsubscribedList);
|
||||||
|
|
||||||
// Removing users from database
|
|
||||||
// @todo Maybe remove via ORM
|
|
||||||
$this->em->getRepository('SkobkinPointToolsBundle:Subscription')->removeSubscribers($user, $unsubscribedList);
|
|
||||||
|
|
||||||
$this->dispatchSubscribersUpdatedEvent($user, $subscribedList, $unsubscribedList);
|
$this->dispatchSubscribersUpdatedEvent($user, $subscribedList, $unsubscribedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +91,8 @@ class SubscriptionsManager
|
||||||
*/
|
*/
|
||||||
private function processSubscribedUsers(User $user, array $subscribers)
|
private function processSubscribedUsers(User $user, array $subscribers)
|
||||||
{
|
{
|
||||||
|
$this->logger->debug('Processing subscribed users');
|
||||||
|
|
||||||
foreach ($subscribers as $subscriber) {
|
foreach ($subscribers as $subscriber) {
|
||||||
$subscription = new Subscription($user, $subscriber);
|
$subscription = new Subscription($user, $subscriber);
|
||||||
|
|
||||||
|
@ -103,12 +112,18 @@ class SubscriptionsManager
|
||||||
*/
|
*/
|
||||||
private function processUnsubscribedUsers(User $user, array $subscribers)
|
private function processUnsubscribedUsers(User $user, array $subscribers)
|
||||||
{
|
{
|
||||||
|
$this->logger->debug('Processing unsubscribed users');
|
||||||
|
|
||||||
foreach ($subscribers as $subscriber) {
|
foreach ($subscribers as $subscriber) {
|
||||||
$logEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_UNSUBSCRIBE);
|
$logEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_UNSUBSCRIBE);
|
||||||
$this->em->persist($logEvent);
|
$this->em->persist($logEvent);
|
||||||
|
|
||||||
$user->addNewSubscriberEvent($logEvent);
|
$user->addNewSubscriberEvent($logEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removing users from database
|
||||||
|
// @todo Maybe remove via ORM
|
||||||
|
$this->em->getRepository('SkobkinPointToolsBundle:Subscription')->removeSubscribers($user, $subscribers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue