function process_sendy_chunks($chunks, $sendyurl, $resturl, $sendylistid, $sendyapikey, $correctresults) { foreach ($chunks as $chunk) { $curl = new curly(); $requests = array(); foreach ($chunk as $site) { if ($resturl == '/subscribe') { // Need to check the email address' status before subscribing. $emailstatus = get_sendy_status($sendyurl, $sendyapikey, $sendylistid, trim($site->contactemail)); if ($emailstatus != 'Email does not exist in list') { // They are either already subscribed or have been previously subscribed but unsubscribed so leave them alone. debugging('Updating sendy @' . $sendyurl . $resturl . ' for list ' . $sendylistid . ' skipped site id->' . $site->id . ' email->' . $site->contactemail . ' as the email status is:' . $emailstatus, DEBUG_DEVELOPER); continue; } } $params = array('name' => $site->contactname, 'email' => trim($site->contactemail), 'list' => $sendylistid, 'boolean' => 'true'); $paramspost = $curl->format_postdata_for_curlcall($params); $request = array('url' => $sendyurl . $resturl, 'CURLOPT_POST' => 1, 'CURLOPT_POSTFIELDS' => $paramspost); $requests[] = $request; $chunkparams[] = $params; } // REST CALLS. $results = $curl->multi($requests); for ($i = 0; $i < count($results); $i++) { if (!in_array($results[$i], $correctresults)) { debugging('Updating sendy @' . $sendyurl . $resturl . ' for list ' . $sendylistid . ' had errors for site id->' . $chunk[$i]->id . ' email->' . $chunk[$i]->contactemail . ' :' . $results[$i], DEBUG_DEVELOPER); } } } }
require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . "/local/hub/admin/forms.php"; admin_externalpage_setup('checkemailsendystatus'); $hub = new local_hub(); $mform = new local_hub_checkemailsendystatus_form(); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('checkemailsendystatus', 'local_hub')); if ($data = $mform->get_data()) { $sendyurl = get_config('local_hub', 'sendyurl'); $sendylistid = get_config('local_hub', 'sendylistid'); $sendyapikey = get_config('local_hub', 'sendyapikey'); // Check for config.php overrides. if (isset($CFG->sendyurl)) { $sendyurl = $CFG->sendyurl; } if (isset($CFG->sendylistid)) { $sendylistid = $CFG->sendylistid; } if (isset($CFG->sendyapikey)) { $sendyapikey = $CFG->sendyapikey; } if (empty($sendyurl) || empty($sendylistid) || empty($sendyapikey)) { print_error('mailinglistnotconfigured', 'local_hub'); } $a = new stdClass(); $a->email = $data->email; $a->status = get_sendy_status($sendyurl, $sendyapikey, $sendylistid, $data->email); echo $OUTPUT->notification(get_string('emailsendystatus', 'local_hub', $a), 'notifysuccess'); } $mform->display(); echo $OUTPUT->footer();