Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-37432 Calendar: If Calendar url is invalid then remove invalid su…

…bscription
  • Loading branch information...
commit a19a913d7d70b3ff87ba386fb0d09d8e0e05fdad 1 parent 76657ed
@rajeshtaneja rajeshtaneja authored
Showing with 29 additions and 4 deletions.
  1. +16 −2 calendar/lib.php
  2. +13 −2 calendar/managesubscriptions.php
View
18 calendar/lib.php
@@ -2866,8 +2866,7 @@ function calendar_process_subscription_row($subscriptionid, $pollinterval, $acti
return "<p>".get_string('subscriptionupdated', 'calendar', $sub->name)."</p>" . calendar_update_subscription_events($subscriptionid);
case $strremove:
- $DB->delete_records('event', array('subscriptionid' => $subscriptionid));
- $DB->delete_records('event_subscriptions', array('id' => $subscriptionid));
+ calendar_delete_subscription($subscriptionid);
return get_string('subscriptionremoved', 'calendar', $sub->name);
break;
@@ -2878,6 +2877,21 @@ function calendar_process_subscription_row($subscriptionid, $pollinterval, $acti
}
/**
+ * Delete subscription and all related events.
+ *
+ * @param int|stdClass $subscription subscription or it's id, which needs to be deleted.
+ */
+function calendar_delete_subscription($subscription) {
+ global $DB;
+
+ if (is_object($subscription)) {
+ $subscription = $subscription->id;
+ }
+ // Delete subscription and related events.
+ $DB->delete_records('event', array('subscriptionid' => $subscription));
+ $DB->delete_records('event_subscriptions', array('id' => $subscription));
+}
+/**
* From a URL, fetch the calendar and return an iCalendar object.
*
* @param string $url The iCalendar URL
View
15 calendar/managesubscriptions.php
@@ -75,7 +75,13 @@
$ical->unserialize($calendar);
$importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid);
} else {
- $importresults = calendar_update_subscription_events($subscriptionid);
+ 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);
@@ -83,7 +89,12 @@
// 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)) {
- $importresults = calendar_process_subscription_row($subscriptionid, $pollinterval, $action);
+ try {
+ $importresults = calendar_process_subscription_row($subscriptionid, $pollinterval, $action);
+ } catch (moodle_exception $e) {
+ // If exception caught, then user should be redirected to page where he/she came from.
+ print_error($e->errorcode, $e->module, $PAGE->url);
+ }
} else {
print_error('nopermissions', 'error', $PAGE->url, get_string('managesubscriptions', 'calendar'));
}
Please sign in to comment.
Something went wrong with that request. Please try again.