コード例 #1
0
 public function import_one($campaignMailChimpID)
 {
     $MailChimpAPI = $this->get_api_instance();
     $campaign = $MailChimpAPI->get("campaigns/{$campaignMailChimpID}");
     if ($MailChimpAPI->success()) {
         $data = $this->map_fields($campaign);
         $Lists = new PerchMailChimp_Lists($this->api);
         $List = $Lists->get_one_by('listMailChimpID', $campaign['recipients']['list_id']);
         if ($List) {
             $data['listID'] = $List->id();
         }
         if (!$this->remote_campaign_exists_locally($campaign['id'])) {
             $Campaign = $this->create($data);
         } else {
             // Campaign exists
             $Campaign = $this->get_one_by('campaignMailChimpID', $campaign['id']);
             $Compaign->update($data);
         }
         if ($Campaign) {
             $Campaign->import_content($MailChimpAPI);
         }
     } else {
         PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error');
     }
     return false;
 }
コード例 #2
0
 public function import()
 {
     $MailChimpAPI = $this->get_api_instance();
     $lists = $MailChimpAPI->get("lists");
     if ($MailChimpAPI->success()) {
         if (isset($lists['lists']) && PerchUtil::count($lists['lists'])) {
             $all_lists = $lists['lists'];
             foreach ($all_lists as $list) {
                 $data = $this->map_fields($list);
                 if (!$this->remote_list_exists_locally($list['id'])) {
                     PerchUtil::debug('Importing list: ' . $list['id']);
                     $this->create($data);
                 } else {
                     $Lists = new PerchMailChimp_Lists($this->api);
                     $List = $Lists->get_one_by('listMailChimpID', $list['id']);
                     if ($List) {
                         $List->update($data);
                     }
                 }
             }
         }
     } else {
         PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error');
     }
 }
コード例 #3
0
 public function update_subscription($listMailChimpID, $subStatus)
 {
     $Lists = new PerchMailChimp_Lists($this->api);
     $List = $Lists->get_one_by('listMailChimpID', $listMailChimpID);
     if (!is_object($List)) {
         return false;
     }
     $Subscriptions = new PerchMailChimp_Subscriptions($this->api);
     $Subscription = $Subscriptions->find_subscription($List, $this);
     if (is_object($Subscription)) {
         $Subscription->update(['subStatus' => $subStatus, 'subUpdated' => date('Y-m-d H:i:s')]);
         return true;
     }
     return false;
 }
コード例 #4
0
 public function lookup_and_create(array $data)
 {
     if ($this->remote_subscriber_exists_locally($data['id'])) {
         return $this->get_one_by('subscriberMailChimpID', $data['id']);
     }
     $Lists = new PerchMailChimp_Lists($this->api);
     $List = $Lists->get_one_by('listMailChimpID', $data['list_id']);
     if (!is_object($List)) {
         return false;
     }
     $MailChimpAPI = $this->get_api_instance();
     $listID = $List->listMailChimpID();
     $hash = $MailChimpAPI->subscriberHash($data['email']);
     $member = $MailChimpAPI->get("lists/{$listID}/members/{$hash}");
     if ($MailChimpAPI->success()) {
         $Subscriptions = new PerchMailChimp_Subscriptions($this->api);
         $sub_data = $this->map_fields($member);
         $sub_data['subscriberCreated'] = date('Y-m-d H:i:s');
         $Subscriber = $this->create($sub_data);
         if ($Subscriber) {
             // create subscription
             $Subscriptions->create_from_import($List, $Subscriber, $member);
         }
     }
 }