mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-37562-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
4fd1861c8f
3 changed files with 106 additions and 14 deletions
|
@ -2801,8 +2801,6 @@ function calendar_add_subscription($sub) {
|
||||||
$sub->pollinterval = 0;
|
$sub->pollinterval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache = cache::make('core', 'calendar_subscriptions');
|
|
||||||
|
|
||||||
if (!empty($sub->name)) {
|
if (!empty($sub->name)) {
|
||||||
if (empty($sub->id)) {
|
if (empty($sub->id)) {
|
||||||
$id = $DB->insert_record('event_subscriptions', $sub);
|
$id = $DB->insert_record('event_subscriptions', $sub);
|
||||||
|
@ -2810,9 +2808,7 @@ function calendar_add_subscription($sub) {
|
||||||
return $id;
|
return $id;
|
||||||
} else {
|
} else {
|
||||||
// Why are we doing an update here?
|
// Why are we doing an update here?
|
||||||
$DB->update_record('event_subscriptions', $sub);
|
calendar_update_subscription($sub);
|
||||||
// update cache.
|
|
||||||
$cache->set($sub->id, $sub);
|
|
||||||
return $sub->id;
|
return $sub->id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2920,11 +2916,7 @@ function calendar_process_subscription_row($subscriptionid, $pollinterval, $acti
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$sub->pollinterval = $pollinterval;
|
$sub->pollinterval = $pollinterval;
|
||||||
$DB->update_record('event_subscriptions', $sub);
|
calendar_update_subscription($sub);
|
||||||
|
|
||||||
// update the cache.
|
|
||||||
$cache = cache::make('core', 'calendar_subscriptions');
|
|
||||||
$cache->set($sub->id, $sub);
|
|
||||||
|
|
||||||
// Update the events.
|
// Update the events.
|
||||||
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);
|
||||||
|
@ -3049,13 +3041,33 @@ function calendar_update_subscription_events($subscriptionid) {
|
||||||
$ical = calendar_get_icalendar($sub->url);
|
$ical = calendar_get_icalendar($sub->url);
|
||||||
$return = calendar_import_icalendar_events($ical, $sub->courseid, $subscriptionid);
|
$return = calendar_import_icalendar_events($ical, $sub->courseid, $subscriptionid);
|
||||||
$sub->lastupdated = time();
|
$sub->lastupdated = time();
|
||||||
$DB->update_record('event_subscriptions', $sub);
|
calendar_update_subscription($sub);
|
||||||
// Update the cache.
|
|
||||||
$cache = cache::make('core', 'calendar_subscriptions');
|
|
||||||
$cache->set($subscriptionid, $sub);
|
|
||||||
return $return;
|
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.
|
* Checks to see if the user can edit a given subscription feed.
|
||||||
*
|
*
|
||||||
|
|
77
calendar/tests/calendarical_test.php
Normal file
77
calendar/tests/calendarical_test.php
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar Ical unit tests
|
||||||
|
*
|
||||||
|
* @package core_calendar
|
||||||
|
* @copyright 2013 Ankit Agarwal
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for ical APIs.
|
||||||
|
*
|
||||||
|
* @package core_calendar
|
||||||
|
* @copyright 2013 Ankit Agarwal
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
* @since Moodle 2.5
|
||||||
|
*/
|
||||||
|
class core_calendar_ical_testcase extends advanced_testcase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests set up
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
global $CFG;
|
||||||
|
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_calendar_update_subscription() {
|
||||||
|
$this->resetAfterTest(true);
|
||||||
|
|
||||||
|
$subscription = new stdClass();
|
||||||
|
$subscription->eventtype = 'site';
|
||||||
|
$subscription->name = 'test';
|
||||||
|
$id = calendar_add_subscription($subscription);
|
||||||
|
|
||||||
|
$subscription = new stdClass();
|
||||||
|
$subscription->id = $id;
|
||||||
|
$subscription->name = 'awesome';
|
||||||
|
calendar_update_subscription($subscription);
|
||||||
|
$sub = calendar_get_subscription($id);
|
||||||
|
$this->assertEquals($subscription->name, $sub->name);
|
||||||
|
|
||||||
|
$subscription = new stdClass();
|
||||||
|
$subscription->id = $id;
|
||||||
|
$subscription->name = 'awesome2';
|
||||||
|
$subscription->pollinterval = 604800;
|
||||||
|
calendar_update_subscription($subscription);
|
||||||
|
$sub = calendar_get_subscription($id);
|
||||||
|
$this->assertEquals($subscription->name, $sub->name);
|
||||||
|
$this->assertEquals($subscription->pollinterval, $sub->pollinterval);
|
||||||
|
|
||||||
|
$subscription = new stdClass();
|
||||||
|
$subscription->name = 'awesome4';
|
||||||
|
$this->setExpectedException('coding_exception');
|
||||||
|
calendar_update_subscription($subscription);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,9 @@ required changes in code:
|
||||||
* calendar_update_subscription_events() now throws a dml_exception instead of moodle_exception for bad subscriptions
|
* calendar_update_subscription_events() now throws a dml_exception instead of moodle_exception for bad subscriptions
|
||||||
* calendar_get_mini() function now has optional $placement and $courseid paramaters.
|
* calendar_get_mini() function now has optional $placement and $courseid paramaters.
|
||||||
|
|
||||||
|
optional - no changes needed:
|
||||||
|
* calendar_update_subscription() should now be used to update Ical subscriptions.
|
||||||
|
|
||||||
=== 2.4 ===
|
=== 2.4 ===
|
||||||
|
|
||||||
required changes in code:
|
required changes in code:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue