public function import_next(PerchMailChimp_Import $Import) { $MailChimpAPI = $this->get_api_instance(); $campaigns = $MailChimpAPI->get("campaigns", ['count' => $Import->importCount(), 'offset' => $Import->importOffset()]); if ($MailChimpAPI->success()) { if (isset($campaigns['campaigns']) && PerchUtil::count($campaigns['campaigns'])) { $Subscriptions = new PerchMailChimp_Subscriptions($this->api); $Lists = new PerchMailChimp_Lists($this->api); $all_campaigns = $campaigns['campaigns']; foreach ($all_campaigns as $campaign) { $data = $this->map_fields($campaign); $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']); $Campaign->update($data); } if ($Campaign) { $Campaign->import_content($MailChimpAPI); } } // Return so that the cursor within the import is moved forward return ['result' => 'success', 'count' => PerchUtil::count($campaigns['campaigns']), 'message' => sprintf('Imported %d campains', PerchUtil::count($campaigns['campaigns']))]; } else { return ['result' => 'success', 'count' => 0, 'message' => sprintf('Imported all campaigns.')]; } } else { PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error'); } return false; }
public function import_next(PerchMailChimp_Import $Import) { $Lists = new PerchMailChimp_Lists($this->api); $List = $Lists->find($Import->importSourceID()); if (!is_object($List)) { return false; } $MailChimpAPI = $this->get_api_instance(); $listID = $List->listMailChimpID(); $webhooks = $MailChimpAPI->get("lists/{$listID}/webhooks", ['count' => $Import->importCount(), 'offset' => $Import->importOffset()]); if ($MailChimpAPI->success()) { if (isset($webhooks['webhooks']) && PerchUtil::count($webhooks['webhooks'])) { $all_webhooks = $webhooks['webhooks']; foreach ($all_webhooks as $webhook) { $data = $this->map_fields($webhook); $data['listID'] = $List->id(); if (!$this->remote_webhook_exists_locally($webhook['id'])) { $Webhook = $this->create($data); } else { // Webhook exists $Webhook = $this->get_one_by('webhookMailChimpID', $webhook['id']); if ($Webhook) { $Webhook->update($data); } } } // Return so that the cursor within the import is moved forward return ['result' => 'success', 'count' => PerchUtil::count($webhooks['webhooks']), 'message' => sprintf('Imported %d webhooks to list %s.', PerchUtil::count($webhooks['webhooks']), $List->listTitle())]; } else { return ['result' => 'success', 'count' => 0, 'message' => sprintf('Imported all webhooks to list %s.', $List->listTitle())]; } } else { PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error'); } return false; }
public function import_next(PerchMailChimp_Import $Import) { $Lists = new PerchMailChimp_Lists($this->api); $List = $Lists->find($Import->importSourceID()); if (!is_object($List)) { return false; } $MailChimpAPI = $this->get_api_instance(); $listID = $List->listMailChimpID(); $members = $MailChimpAPI->get("lists/{$listID}/members", ['count' => $Import->importCount(), 'offset' => $Import->importOffset()]); if ($MailChimpAPI->success()) { if (isset($members['members']) && PerchUtil::count($members['members'])) { $Subscriptions = new PerchMailChimp_Subscriptions($this->api); $all_members = $members['members']; foreach ($all_members as $member) { $data = $this->map_fields($member); if (!$this->remote_subscriber_exists_locally($member['unique_email_id'])) { //PerchUtil::debug('Importing subscriber: '.$member['email_address']); $Subscriber = $this->create($data); } else { // subscriber exists $Subscriber = $this->get_one_by('subscriberMailChimpID', $member['unique_email_id']); $Subscriber->update($data); } if ($Subscriber) { // create subscription $Subscriptions->create_from_import($List, $Subscriber, $member); } } // Return so that the cursor within the import is moved forward return ['result' => 'success', 'count' => PerchUtil::count($members['members']), 'message' => sprintf('Imported %d subscribers to list %s.', PerchUtil::count($members['members']), $List->listTitle())]; } else { return ['result' => 'success', 'count' => 0, 'message' => sprintf('Imported all subscribers to list %s.', $List->listTitle())]; } } else { PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error'); } return false; }