diff --git a/calendar/lib.php b/calendar/lib.php index e0c9b83041f..e26bc6a82f3 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3056,6 +3056,29 @@ function calendar_update_subscription_events($subscriptionid) { return $return; } +/** + * Update a calendar subscription. Also updates the associated cache. + * + * @param stdClass|array $subscription Subscription record. + * @throws coding_exception If something goes wrong + * @since Moodle 2.5 + */ +function calendar_update_subscription($subscription) { + global $DB; + + if (is_array($subscription)) { + $subscription = (object)$subscription; + } + if (empty($subscription->id) || !$DB->record_exists('event_subscriptions', array('id' => $subscription->id))) { + throw new coding_exception('Cannot update a subscription without a valid id'); + } + + $DB->update_record('event_subscriptions', $subscription); + // Update cache. + $cache = cache::make('core', 'calendar_subscriptions'); + $cache->set($subscription->id, $subscription); +} + /** * Checks to see if the user can edit a given subscription feed. *