mirror of
https://github.com/moodle/moodle.git
synced 2025-04-23 09:23:09 +02:00
MDL-47900 tool_monitor: created list of rules MUC
This commit is contained in:
parent
ddb4a31d54
commit
475635f52d
admin/tool/monitor
@ -98,6 +98,11 @@ class eventobservers {
|
||||
*/
|
||||
protected function buffer_event(\core\event\base $event) {
|
||||
|
||||
// If there are no subscriptions for this event do not buffer it.
|
||||
if (!\tool_monitor\subscription_manager::event_has_subscriptions($event->eventname, $event->courseid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventdata = $event->get_data();
|
||||
$eventobj = new \stdClass();
|
||||
$eventobj->eventname = $eventdata['eventname'];
|
||||
|
@ -78,6 +78,10 @@ class subscription_manager {
|
||||
);
|
||||
$event = \tool_monitor\event\subscription_created::create($params);
|
||||
$event->trigger();
|
||||
|
||||
// Let's invalidate the cache.
|
||||
$cache = \cache::make('tool_monitor', 'eventsubscriptions');
|
||||
$cache->delete($courseid);
|
||||
}
|
||||
|
||||
return $subscription->id;
|
||||
@ -126,6 +130,10 @@ class subscription_manager {
|
||||
$event = \tool_monitor\event\subscription_deleted::create($params);
|
||||
$event->add_record_snapshot('tool_monitor_subscriptions', $subscription);
|
||||
$event->trigger();
|
||||
|
||||
// Let's invalidate the cache.
|
||||
$cache = \cache::make('tool_monitor', 'eventsubscriptions');
|
||||
$cache->delete($courseid);
|
||||
}
|
||||
|
||||
return $success;
|
||||
@ -198,6 +206,10 @@ class subscription_manager {
|
||||
$event = \tool_monitor\event\subscription_deleted::create($params);
|
||||
$event->add_record_snapshot('tool_monitor_subscriptions', $subscription);
|
||||
$event->trigger();
|
||||
|
||||
// Let's invalidate the cache.
|
||||
$cache = \cache::make('tool_monitor', 'eventsubscriptions');
|
||||
$cache->delete($courseid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,4 +392,68 @@ class subscription_manager {
|
||||
|
||||
return $DB->count_records_sql($sql, array('ruleid' => $ruleid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an event in a particular course has a subscription.
|
||||
*
|
||||
* @param string $eventname the name of the event
|
||||
* @param int $courseid the course id
|
||||
* @return bool returns true if the event has subscriptions in a given course, false otherwise.
|
||||
*/
|
||||
public static function event_has_subscriptions($eventname, $courseid) {
|
||||
global $DB;
|
||||
|
||||
// Check if we can return these from cache.
|
||||
$cache = \cache::make('tool_monitor', 'eventsubscriptions');
|
||||
|
||||
// The SQL we will be using to fill the cache if it is empty.
|
||||
$sql = "SELECT DISTINCT(r.eventname)
|
||||
FROM {tool_monitor_subscriptions} s
|
||||
INNER JOIN {tool_monitor_rules} r
|
||||
ON s.ruleid = r.id
|
||||
WHERE s.courseid = :courseid";
|
||||
|
||||
$sitesubscriptions = $cache->get(0);
|
||||
// If we do not have the site subscriptions in the cache then return them from the DB.
|
||||
if ($sitesubscriptions === false) {
|
||||
// Set the array for the cache.
|
||||
$sitesubscriptions = array();
|
||||
if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => 0))) {
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$sitesubscriptions[$subscription->eventname] = true;
|
||||
}
|
||||
}
|
||||
$cache->set(0, $sitesubscriptions);
|
||||
}
|
||||
|
||||
// Check if a subscription exists for this event site wide.
|
||||
if (isset($sitesubscriptions[$eventname])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the course id is for the site, and we reached here then there is no site wide subscription for this event.
|
||||
if (empty($courseid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$coursesubscriptions = $cache->get($courseid);
|
||||
// If we do not have the course subscriptions in the cache then return them from the DB.
|
||||
if ($coursesubscriptions === false) {
|
||||
// Set the array for the cache.
|
||||
$coursesubscriptions = array();
|
||||
if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => $courseid))) {
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$coursesubscriptions[$subscription->eventname] = true;
|
||||
}
|
||||
}
|
||||
$cache->set($courseid, $coursesubscriptions);
|
||||
}
|
||||
|
||||
// Check if a subscription exists for this event in this course.
|
||||
if (isset($coursesubscriptions[$eventname])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
35
admin/tool/monitor/db/caches.php
Normal file
35
admin/tool/monitor/db/caches.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event monitor cache definitions.
|
||||
*
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$definitions = array(
|
||||
'eventsubscriptions' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 10
|
||||
)
|
||||
);
|
@ -29,6 +29,7 @@ $string['allevents'] = 'All events';
|
||||
$string['allmodules'] = 'All instances';
|
||||
$string['area'] = 'Area';
|
||||
$string['areatomonitor'] = 'Area to monitor';
|
||||
$string['cachedef_rules'] = 'This stores the list of event subscriptions for individual courses';
|
||||
$string['contactadmin'] = 'Contact your administrator to enable it.';
|
||||
$string['core'] = 'Core';
|
||||
$string['currentsubscriptions'] = 'Your current subscriptions';
|
||||
@ -98,4 +99,3 @@ $string['subhelp_help'] = 'This subscription listens for when the event \'{$a->e
|
||||
$string['subscribeto'] = 'Subscribe to rule "{$a}"';
|
||||
$string['taskcleanevents'] = 'Removes any unnecessary event monitor events';
|
||||
$string['unsubscribe'] = 'Unsubscribe';
|
||||
|
||||
|
@ -26,6 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2014111000; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version.
|
||||
$plugin->version = 2014111001; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_monitor'; // Full name of the plugin (used for diagnostics).
|
||||
|
Loading…
x
Reference in New Issue
Block a user