Merge branch 'MDL-48107_master' of https://github.com/markn86/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2014-11-08 11:19:59 +01:00
commit bea7509414
7 changed files with 49 additions and 27 deletions

View File

@ -53,13 +53,9 @@ class eventobservers {
* @param \core\event\course_deleted $event The course deleted event.
*/
public static function course_deleted(\core\event\course_deleted $event) {
$rules = rule_manager::get_rules_by_courseid($event->courseid);
$context = null;
if ($event->contextlevel == CONTEXT_COURSE) {
$context = $event->get_context();
}
$rules = rule_manager::get_rules_by_courseid($event->courseid, 0, 0, false);
foreach ($rules as $rule) {
rule_manager::delete_rule($rule->id, $context);
rule_manager::delete_rule($rule->id, $event->get_context());
}
}

View File

@ -216,14 +216,23 @@ class rule_manager {
* @param int $courseid course id of the rule.
* @param int $limitfrom Limit from which to fetch rules.
* @param int $limitto Limit to which rules need to be fetched.
* @param bool $includesite Determines whether we return site wide rules or not.
*
* @return array List of rules for the given course id, also includes system wide rules.
* @return array List of rules for the given course id, if specified will also include site rules.
*/
public static function get_rules_by_courseid($courseid, $limitfrom = 0, $limitto = 0) {
public static function get_rules_by_courseid($courseid, $limitfrom = 0, $limitto = 0, $includesite = true) {
global $DB;
$select = "courseid = ? OR courseid = ?";
$orderby = "courseid DESC, name ASC";
return self::get_instances($DB->get_records_select('tool_monitor_rules', $select, array(0, $courseid), $orderby,
$select = 'courseid = ?';
$params = array();
$params[] = $courseid;
if ($includesite) {
$select .= ' OR courseid = ?';
$params[] = 0;
}
$orderby = 'courseid DESC, name ASC';
return self::get_instances($DB->get_records_select('tool_monitor_rules', $select, $params, $orderby,
'*', $limitfrom, $limitto));
}

View File

@ -82,7 +82,8 @@ $string['norules'] = 'There are no event monitoring rules.';
$string['pluginname'] = 'Event monitor';
$string['processevents'] = 'Process events';
$string['rulename'] = 'Rule name';
$string['ruleareyousure'] = 'Are you sure you want to delete rule "{$a}"?';
$string['ruleareyousure'] = 'Are you sure you want to delete the rule "{$a}"?';
$string['ruleareyousureextra'] = 'There are {$a} subscription(s) to this rule that will also be deleted.';
$string['rulecopysuccess'] = 'Rule successfully duplicated';
$string['ruledeletesuccess'] = 'Rule successfully deleted';
$string['rulehelp'] = 'Rule details';
@ -91,9 +92,9 @@ $string['rulenopermissions'] = 'You do not have permissions to "{$a} a rule"';
$string['rulescansubscribe'] = 'Rules you can subscribe to';
$string['selectacourse'] = 'Select a course';
$string['selectcourse'] = 'Visit this report at course level to get a list of possible modules';
$string['subareyousure'] = 'Are you sure you want to delete this subscription for the rule "{$a}"?';
$string['subcreatesuccess'] = "Subscription successfully created";
$string['subdeletesuccess'] = "Subscription successfully removed";
$string['subareyousure'] = 'Are you sure you want to delete the subscription to the rule "{$a}"?';
$string['subcreatesuccess'] = 'Subscription successfully created';
$string['subdeletesuccess'] = 'Subscription successfully removed';
$string['subhelp'] = 'Subscription details';
$string['subhelp_help'] = 'This subscription listens for when the event \'{$a->eventname}\' has been triggered in \'{$a->moduleinstance}\' {$a->frequency} time(s) in {$a->minutes} minute(s).';
$string['subscribeto'] = 'Subscribe to rule "{$a}"';

View File

@ -94,8 +94,12 @@ if (!empty($action) && $ruleid) {
$rule->delete_rule();
echo $OUTPUT->notification(get_string('ruledeletesuccess', 'tool_monitor'), 'notifysuccess');
} else {
echo $OUTPUT->confirm(get_string('ruleareyousure', 'tool_monitor', $rule->get_name($context)),
$confirmurl, $cancelurl);
$strconfirm = get_string('ruleareyousure', 'tool_monitor', $rule->get_name($context));
if ($numberofsubs = $DB->count_records('tool_monitor_subscriptions', array('ruleid' => $ruleid))) {
$strconfirm .= '<br />';
$strconfirm .= get_string('ruleareyousureextra', 'tool_monitor', $numberofsubs);
}
echo $OUTPUT->confirm($strconfirm, $confirmurl, $cancelurl);
echo $OUTPUT->footer();
exit();
}

View File

@ -69,7 +69,7 @@ Feature: tool_monitor_rule
And I follow "Course 1"
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I click on "Delete rule" "link"
Then I should see "Are you sure you want to delete rule \"New rule course level\"?"
Then I should see "Are you sure you want to delete the rule \"New rule course level\"?"
And I press "Continue"
And I should see "Rule successfully deleted"
And I should not see "New rule course level"
@ -129,7 +129,7 @@ Feature: tool_monitor_rule
Given I log in as "admin"
And I navigate to "Event monitoring rules" node in "Site administration > Reports"
When I click on "Delete rule" "link"
Then I should see "Are you sure you want to delete rule \"New rule site level\"?"
Then I should see "Are you sure you want to delete the rule \"New rule site level\"?"
And I press "Continue"
And I should see "Rule successfully deleted"
And I should not see "New rule site level"

View File

@ -70,7 +70,7 @@ Feature: tool_monitor_subscriptions
And I follow "Subscribe to rule \"New rule course level\""
And I should see "Subscription successfully created"
When I click on "Delete subscription" "link" in the "New rule course level" "table_row"
And I should see "Are you sure you want to delete this subscription for the rule \"New rule course level\"?"
And I should see "Are you sure you want to delete the subscription to the rule \"New rule course level\"?"
And I press "Continue"
Then I should see "Subscription successfully removed"
And "#toolmonitorsubs_r0" "css_element" should not exist
@ -91,7 +91,7 @@ Feature: tool_monitor_subscriptions
And I should see "Subscription successfully created"
And "#toolmonitorsubs_r0" "css_element" should exist
When I click on "Delete subscription" "link" in the "New rule site level" "table_row"
And I should see "Are you sure you want to delete this subscription for the rule \"New rule site level\"?"
And I should see "Are you sure you want to delete the subscription to the rule \"New rule site level\"?"
And I press "Continue"
Then I should see "Subscription successfully removed"
And "#toolmonitorsubs_r0" "css_element" should not exist

View File

@ -82,26 +82,38 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$monitorgenerator->create_subscription($sub);
}
// Add a site rule.
$rule = new stdClass();
$rule->userid = $user->id;
$rule->courseid = 0;
$rule->plugin = 'core';
$monitorgenerator->create_rule($rule);
// Verify that if we do not specify that we do not want the site rules, they are returned.
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id);
$this->assertCount(11, $courserules);
// Verify data before course delete.
$totalrules = \tool_monitor\rule_manager::get_rules_by_plugin('test');
$this->assertCount(20, $totalrules);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id, 0, 0, false);
$this->assertCount(10, $courserules);
$totalsubs = $DB->get_records('tool_monitor_subscriptions');
$this->assertCount(20, $totalsubs);
$this->assertEquals(20, $DB->count_records('tool_monitor_subscriptions'));
$coursesubs = \tool_monitor\subscription_manager::get_user_subscriptions_for_course($course1->id, 0, 0, $user->id);
$this->assertCount(10, $coursesubs);
// Let us delete the course now.
delete_course($course1->id, false);
// Confirm the site rule still exists.
$this->assertEquals(1, $DB->count_records('tool_monitor_rules', array('courseid' => 0)));
// Verify data after course delete.
$totalrules = \tool_monitor\rule_manager::get_rules_by_plugin('test');
$this->assertCount(10, $totalrules);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id, 0, 0, false);
$this->assertCount(0, $courserules); // Making sure all rules are deleted.
$totalsubs = $DB->get_records('tool_monitor_subscriptions');
$this->assertCount(10, $totalsubs);
$this->assertEquals(10, $DB->count_records('tool_monitor_subscriptions'));
$coursesubs = \tool_monitor\subscription_manager::get_user_subscriptions_for_course($course1->id, 0, 0, $user->id);
$this->assertCount(0, $coursesubs); // Making sure all subscriptions are deleted.
}