This commit is contained in:
Alexey Skobkin 2015-06-02 05:27:19 +03:00
parent 3742f4b06c
commit b7e4374dac

View file

@ -39,6 +39,14 @@ class SubscriptionsManager
$oldSubscribersList[] = $subscription->getSubscriber(); $oldSubscribersList[] = $subscription->getSubscriber();
} }
$isFirstTime = false;
// Preventing to add garbage subscriptions for first processing
// @todo improve algorithm
if ((count($oldSubscribersList) === 0) && (count($newSubscribersList) > 1)) {
$isFirstTime = true;
}
unset($tmpOldSubscribers); unset($tmpOldSubscribers);
$subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList); $subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList);
@ -54,19 +62,22 @@ class SubscriptionsManager
$user->addSubscriber($subscription); $user->addSubscriber($subscription);
// If it's not first processing
if (!$isFirstTime) {
$logEvent = new SubscriptionEvent(); $logEvent = new SubscriptionEvent();
$logEvent $logEvent
->setSubscriber($subscribedUser) ->setSubscriber($subscribedUser)
->setAuthor($user) ->setAuthor($user)
->setAction(SubscriptionEvent::ACTION_SUBSCRIBE) ->setAction(SubscriptionEvent::ACTION_SUBSCRIBE);
;
$user->addNewSubscriberEvent($logEvent); $user->addNewSubscriberEvent($logEvent);
$this->em->persist($subscription);
$this->em->persist($logEvent); $this->em->persist($logEvent);
} }
$this->em->persist($subscription);
}
unset($subscribedList); unset($subscribedList);
/** @var QueryBuilder $unsubscribedQuery */ /** @var QueryBuilder $unsubscribedQuery */