Skip to content

Commit

Permalink
Merge branch 'wip-mdl-37432-m24' of git://github.com/rajeshtaneja/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_24_STABLE
  • Loading branch information
stronk7 committed Jan 21, 2013
2 parents dc5e0d1 + a19a913 commit cf3e5c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
18 changes: 16 additions & 2 deletions calendar/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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); return "<p>".get_string('subscriptionupdated', 'calendar', $sub->name)."</p>" . calendar_update_subscription_events($subscriptionid);


case $strremove: case $strremove:
$DB->delete_records('event', array('subscriptionid' => $subscriptionid)); calendar_delete_subscription($subscriptionid);
$DB->delete_records('event_subscriptions', array('id' => $subscriptionid));
return get_string('subscriptionremoved', 'calendar', $sub->name); return get_string('subscriptionremoved', 'calendar', $sub->name);
break; break;


Expand All @@ -2877,6 +2876,21 @@ function calendar_process_subscription_row($subscriptionid, $pollinterval, $acti
return ''; return '';
} }


/**
* 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. * From a URL, fetch the calendar and return an iCalendar object.
* *
Expand Down
15 changes: 13 additions & 2 deletions calendar/managesubscriptions.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,15 +75,26 @@
$ical->unserialize($calendar); $ical->unserialize($calendar);
$importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid); $importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid);
} else { } 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 to prevent refresh issues.
redirect($PAGE->url, $importresults); redirect($PAGE->url, $importresults);
} else if (!empty($subscriptionid)) { } else if (!empty($subscriptionid)) {
// The user is wanting to perform an action upon an existing subscription. // The user is wanting to perform an action upon an existing subscription.
require_sesskey(); // Must have sesskey for all actions. require_sesskey(); // Must have sesskey for all actions.
if (calendar_can_edit_subscription($subscriptionid)) { 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 { } else {
print_error('nopermissions', 'error', $PAGE->url, get_string('managesubscriptions', 'calendar')); print_error('nopermissions', 'error', $PAGE->url, get_string('managesubscriptions', 'calendar'));
} }
Expand Down
4 changes: 3 additions & 1 deletion calendar/managesubscriptions_form.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public function validation($data, $files) {
} }
} }
} else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) { } else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) {
if (clean_param($data['url'], PARAM_URL) !== $data['url']) { // Clean input calendar url.
$url = clean_param($data['url'], PARAM_URL);
if (empty($url) || ($url !== $data['url'])) {
$errors['url'] = get_string('invalidurl', 'error'); $errors['url'] = get_string('invalidurl', 'error');
} }
} else { } else {
Expand Down

0 comments on commit cf3e5c4

Please sign in to comment.