$importresults = ''; $formdata = $form->get_data(); if (!empty($formdata)) { require_sesskey(); // Must have sesskey for all actions. $subscriptionid = calendar_add_subscription($formdata); if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) { // Blank the URL if it's a file import. $formdata->url = ''; $calendar = $form->get_file_content('importfile'); $ical = new iCalendar(); $ical->unserialize($calendar); $importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid); } else { try { $importresults = calendar_update_subscription_events($subscriptionid); } catch (moodle_exception $e) { // Delete newly added subscription and show invalid url error. calendar_delete_subscription($subscriptionid); print_error($e->errorcode, $e->module, $PAGE->url); } } // Redirect to prevent refresh issues. redirect($PAGE->url, $importresults); } else { if (!empty($subscriptionid)) { // The user is wanting to perform an action upon an existing subscription. require_sesskey(); // Must have sesskey for all actions. if (calendar_can_edit_subscription($subscriptionid)) { try {
/** * Update calendar subscriptions. * * @return bool */ function calendar_cron() { global $CFG, $DB; // In order to execute this we need bennu. require_once $CFG->libdir . '/bennu/bennu.inc.php'; mtrace('Updating calendar subscriptions:'); cron_trace_time_and_memory(); $time = time(); $subscriptions = $DB->get_records_sql('SELECT * FROM {event_subscriptions} WHERE pollinterval > 0 AND lastupdated + pollinterval < ?', array($time)); foreach ($subscriptions as $sub) { mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}"); try { $log = calendar_update_subscription_events($sub->id); mtrace(trim(strip_tags($log))); } catch (moodle_exception $ex) { mtrace('Error updating calendar subscription: ' . $ex->getMessage()); } } mtrace('Finished updating calendar subscriptions.'); return true; }