Пример #1
0
 function testListAddSync()
 {
     $time = time();
     // only run if key / list have been set properly
     if ($this->api_key && $this->api_list_id) {
         $test_address = 'dev+testlistaddsync' . $time . '@cashmusic.org';
         $add_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'addaddresstolist', 'address' => $test_address, 'list_id' => $this->test_list_id, 'do_not_verify' => true, 'service_opt_in' => false));
         $this->assertTrue($add_request->response['payload']);
         $mc = new MailchimpSeed($this->cash_user_id, $this->mailchimp_connection_id);
         $members = $mc->listMembers();
         $member_count = count($members['data']);
         // this is a little weird because it's testing the last member of the subcriber list
         // pretty much *should* work but down the line a recursive search would be better to
         // avoid problems when 2 people test at once.
         $this->assertTrue($members['data'][$member_count - 1]['email'] == $test_address);
         $remove_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'removeaddress', 'address' => $test_address, 'list_id' => $this->test_list_id));
         // test that it's been removed on our end
         $this->assertTrue($remove_request->response['payload']);
         $members = $mc->listMembers();
         // post-add total members - post-remove total members should equal one if it's been
         // removed from the subscribers list correctly on the mailchimp end
         $this->assertEqual($member_count - count($members['data']), 1);
     }
 }
Пример #2
0
 /**
  * Does all the messy bits to make sure a list is synced with a 3rd-party
  * email service if that's the kind of thing you're into...
  *
  */
 protected function doListSync($list_id, $api_url = false)
 {
     $list_info = $this->getList($list_id);
     // settings are called connections now
     $connection_id = $list_info['connection_id'];
     $user_id = $list_info['user_id'];
     if ($connection_id) {
         $connection_type = $this->getConnectionType($connection_id);
         switch ($connection_type) {
             case 'com.mailchimp':
                 $mc = new MailchimpSeed($user_id, $connection_id);
                 $mailchimp_members = sort($mc->listMembers());
                 // TODO: fix hard-coded limit...TO-DONE!
                 $local_members = $this->getUsersForList($list_id, false);
                 $mailchimp_count = $mailchimp_members['total'];
                 $local_count = count($local_members);
                 if ($local_count > 0 || $mailchimp_count > 0) {
                     // test that sync is needed
                     $remote_diff = array_diff($mailchimp_members, $local_members);
                     $local_diff = array_diff($local_members, $mailchimp_members);
                     // TODO: implement these functions
                     $this->addToRemoteList($list_id, $local_diff);
                     $this->addToLocalList($list_id, $remote_diff);
                 }
             default:
                 return false;
         }
     }
 }