/**
  * Batch update Mailchimp with new contacts that need to be subscribed, or
  * have changed data including unsubscribes.
  */
 public static function syncPushToMailchimp(CRM_Queue_TaskContext $ctx, $listID, $dry_run)
 {
     CRM_Mailchimp_Utils::checkDebug('Start-CRM_Mailchimp_Form_Sync syncPushAdd $listID= ', $listID);
     // Do the batch update. Might take a while :-O
     $sync = new CRM_Mailchimp_Sync($listID);
     $sync->dry_run = $dry_run;
     // this generates updates and unsubscribes
     $stats[$listID] = $sync->updateMailchimpFromCivi();
     // Finally, finish up by removing the two temporary tables
     //CRM_Mailchimp_Sync::dropTemporaryTables();
     static::updatePushStats($stats);
     return CRM_Queue_Task::TASK_SUCCESS;
 }
 /**
  * @throws \CRM_Mailchimp_Exception
  * @throws \Exception
  */
 public function testPushDoesNotUnsubscribeDuplicates()
 {
     try {
         // Put a contact on MC list, not in CiviCRM, and make dupes in CiviCRM
         // so we can't sync.
         $this->createTitanic();
         // Now sync.
         $sync = new CRM_Mailchimp_Sync(static::$test_list_id);
         // Collect data from CiviCRM - no-one in membership group.
         $sync->collectCiviCrm('push');
         $this->assertEquals(0, $sync->countCiviCrmMembers());
         // Collect from Mailchimp.
         $sync->collectMailchimp('push');
         $this->assertEquals(1, $sync->countMailchimpMembers());
         $matches = $sync->matchMailchimpMembersToContacts();
         $this->assertEquals(['bySubscribers' => 0, 'byUniqueEmail' => 0, 'byNameEmail' => 0, 'bySingle' => 0, 'totalMatched' => 0, 'newContacts' => 0, 'failures' => 1], $matches);
         // Nothing is insync.
         $in_sync = $sync->removeInSync('push');
         $this->assertEquals(0, $in_sync);
         // Send updates to Mailchimp - nothing should be updated.
         $stats = $sync->updateMailchimpFromCivi();
         $this->assertEquals(0, $stats['updates']);
         $this->assertEquals(0, $stats['unsubscribes']);
         $this->assertEquals(0, $stats['additions']);
     } catch (CRM_Mailchimp_Exception $e) {
         // Spit out request and response for debugging.
         print "Request:\n";
         print_r($e->request);
         print "Response:\n";
         print_r($e->response);
         // re-throw exception.
         throw $e;
     }
 }