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();
}
$isFirstTime = false;
// Preventing to add garbage subscriptions for first processing
// @todo improve algorithm
if ((count($oldSubscribersList) === 0) && (count($newSubscribersList) > 1)) {
$isFirstTime = true;
}
unset($tmpOldSubscribers);
$subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList);
@ -54,17 +62,20 @@ class SubscriptionsManager
$user->addSubscriber($subscription);
$logEvent = new SubscriptionEvent();
$logEvent
->setSubscriber($subscribedUser)
->setAuthor($user)
->setAction(SubscriptionEvent::ACTION_SUBSCRIBE)
;
// If it's not first processing
if (!$isFirstTime) {
$logEvent = new SubscriptionEvent();
$logEvent
->setSubscriber($subscribedUser)
->setAuthor($user)
->setAction(SubscriptionEvent::ACTION_SUBSCRIBE);
$user->addNewSubscriberEvent($logEvent);
$user->addNewSubscriberEvent($logEvent);
$this->em->persist($logEvent);
}
$this->em->persist($subscription);
$this->em->persist($logEvent);
}
unset($subscribedList);