public function run() { $result = false; switch ($this->importType()) { case 'subscribers': $Subscribers = new PerchMailChimp_Subscribers($this->api); $result = $Subscribers->import_next($this); break; case 'campaigns': $Campaigns = new PerchMailChimp_Campaigns($this->api); $result = $Campaigns->import_next($this); break; case 'webhooks': $Webhooks = new PerchMailChimp_Webhooks($this->api); $result = $Webhooks->import_next($this); break; } if ($result && $result['result'] == 'success') { if ($result['count'] < $this->importCount()) { // looks like that's all the pages, so self-delete. PerchUtil::debug('Result count is ' . $result['count']); PerchUtil::debug('Import count is ' . $this->importCount()); PerchUtil::debug('Deleting.'); $this->delete(); return; } $this->update(['importOffset' => $this->importOffset() + $this->importCount()]); return $result; } return $result; }
<?php $Form = $API->get('Form'); $Paging = $API->get('Paging'); $Paging->set_per_page(20); $Lists = new PerchMailChimp_Lists($API); $lists = $Lists->all(); // Run an import if there is one $Imports = new PerchMailChimp_Imports($API); $Import = $Imports->get_next_import('webhooks'); $Webhooks = new PerchMailChimp_Webhooks($API); if (is_object($Import)) { $message = $HTML->warning_message('Webhooks are still importing.'); $Import->run(); } else { if ($Form->submitted()) { foreach ($lists as $List) { $Webhooks->import($List); $Webhooks->set_up($List); } } } $webhooks = $Webhooks->all($Paging); if (!PerchUtil::count($webhooks)) { foreach ($lists as $List) { $Webhooks->import($List); $Webhooks->set_up($List); } $webhooks = $Webhooks->all($Paging); }