Ejemplo n.º 1
0
 /**
  * @param MailingList $list
  */
 public function saveList(MailingList $list)
 {
     if (!$list->getId()) {
         $this->em->persist($list);
     }
     $this->em->flush($list);
 }
Ejemplo n.º 2
0
 public function synchroniseList(MailingList $list, \Closure $logger)
 {
     $now = new \DateTime();
     $size = 10;
     $lastSync = $list->getSyncedAt() ? $list->getSyncedAt()->format('Y-m-d H:i:s') : null;
     $updates = $this->client()->get(sprintf('lists/%s/members', $list->getRemoteListId()), ['since_last_changed' => $lastSync, 'offset' => 0, 'count' => $size]);
     $count = $updates['total_items'];
     $i = 0;
     for ($offset = 0; $offset < $count; $offset += $size) {
         if ($offset > 0) {
             $updates = $this->client()->get(sprintf('lists/%s/members', $list->getRemoteListId()), ['since_last_changed' => $lastSync, 'offset' => $offset - 1, 'count' => $size]);
             $count = $updates['total_items'];
         }
         foreach ($updates['members'] as $member) {
             ++$i;
             $subscription = $this->subscriptionManager->findOrCreate($list, $member['email_address']);
             $subscription->setEmail($member['email_address']);
             $subscription->setStatus($this->statusMap[$member['status']]);
             $subscription->setUpdatedAt(new \DateTime($member['last_changed']));
             $subscription->setSyncedAt($now);
             $this->subscriptionManager->save($subscription);
             $logger(sprintf('Processed updates from MailChimp for %s - %d/%d', $member['email_address'], $i, $updates['total_items']));
         }
     }
     $subscriptions = $this->subscriptionManager->findOutOfSync($list, $now);
     $i = 0;
     foreach ($subscriptions as $subscription) {
         ++$i;
         $this->client()->post(sprintf('lists/%s/members', $list->getRemoteListId()), ['email_address' => $subscription->getEmail(), 'status' => array_search($subscription->getStatus(), $this->statusMap)]);
         $logger(sprintf('Processed updates to MailChimp for %s - %d/%d', $subscription->getEmail(), $i, count($subscriptions)));
     }
     $list->setSyncedAt($now);
     $this->subscriptionManager->saveList($list);
 }
Ejemplo n.º 3
0
 /**
  * @param MailingList $list
  * @param \DateTime   $since
  *
  * @return array
  */
 public function findInListOutOfSync(MailingList $list)
 {
     return $this->createQueryBuilder('s')->innerjoin('s.mailingList', 'm')->andWhere('m.id = :list_id')->andWhere('s.updatedAt > s.syncedAt OR s.syncedAt IS NULL')->setParameters(['list_id' => $list->getId()])->getQuery()->getResult();
 }