MDL-44950 logstore_database: Make all settings positive for usability
This commit is contained in:
@@ -38,11 +38,11 @@ class store implements \tool_log\log\writer, \core\log\sql_select_reader {
|
||||
/** @var bool $logguests true if logging guest access */
|
||||
protected $logguests;
|
||||
|
||||
/** @var array $excludelevels An array of education levels to exclude */
|
||||
protected $excludelevels = array();
|
||||
/** @var array $includelevels An array of education levels to include */
|
||||
protected $includelevels = array();
|
||||
|
||||
/** @var array $excludeactions An array of actions types to exclude */
|
||||
protected $excludeactions = array();
|
||||
/** @var array $includeactions An array of actions types to include */
|
||||
protected $includeactions = array();
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -53,10 +53,10 @@ class store implements \tool_log\log\writer, \core\log\sql_select_reader {
|
||||
$this->helper_setup($manager);
|
||||
$this->buffersize = $this->get_config('buffersize', 50);
|
||||
$this->logguests = $this->get_config('logguests', 1);
|
||||
$actions = $this->get_config('excludeactions', '');
|
||||
$levels = $this->get_config('excludelevels', '');
|
||||
$this->excludeactions = $actions === '' ? array() : explode(',', $actions);
|
||||
$this->excludelevels = $levels === '' ? array() : explode(',', $levels);
|
||||
$actions = $this->get_config('includeactions', '');
|
||||
$levels = $this->get_config('includelevels', '');
|
||||
$this->includeactions = $actions === '' ? array() : explode(',', $actions);
|
||||
$this->includelevels = $levels === '' ? array() : explode(',', $levels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,8 +113,8 @@ class store implements \tool_log\log\writer, \core\log\sql_select_reader {
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_event_ignored(\core\event\base $event) {
|
||||
if (in_array($event->crud, $this->excludeactions) ||
|
||||
in_array($event->edulevel, $this->excludelevels)
|
||||
if (!in_array($event->crud, $this->includeactions) &&
|
||||
!in_array($event->edulevel, $this->includelevels)
|
||||
) {
|
||||
// Ignore event if the store settings do not want to store it.
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Database log store upgrade.
|
||||
*
|
||||
* @package logstore_database
|
||||
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function xmldb_logstore_database_upgrade($oldversion) {
|
||||
|
||||
if ($oldversion < 2014041700) {
|
||||
// Clean up old config.
|
||||
unset_config('excludelevels', 'logstore_database');
|
||||
unset_config('excludeactions', 'logstore_database');
|
||||
|
||||
// Savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2014041700, 'logstore', 'database');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -33,8 +33,8 @@ $string['databaseschema'] = 'Database schema';
|
||||
$string['databasecollation'] = 'Database collation';
|
||||
$string['databasetable'] = 'Database table';
|
||||
$string['databasetable_help'] = 'Name of the table where logs will be stored. This table should have a structure identical to the one used by logstore_standard (mdl_logstore_standard_log).';
|
||||
$string['excludeactions'] = 'Exclude actions of these types';
|
||||
$string['excludelevels'] = 'Exclude actions with these educational levels';
|
||||
$string['includeactions'] = 'Include actions of these types';
|
||||
$string['includelevels'] = 'Include actions with these educational levels';
|
||||
$string['filters'] = 'Filter logs';
|
||||
$string['filters_help'] = 'Enable filters that exclude some actions from being logged.';
|
||||
$string['logguests'] = 'Log guest actions';
|
||||
|
||||
@@ -63,9 +63,9 @@ if ($hassiteconfig) {
|
||||
$settings->add(new admin_setting_configcheckbox('logstore_database/logguests', get_string('logguests',
|
||||
'logstore_database'), '', '0'));
|
||||
$levels = \logstore_database\helper::get_level_options();
|
||||
$settings->add(new admin_setting_configmulticheckbox('logstore_database/excludelevels', get_string('excludelevels',
|
||||
'logstore_database'), '', array(), $levels));
|
||||
$settings->add(new admin_setting_configmulticheckbox('logstore_database/includelevels', get_string('includelevels',
|
||||
'logstore_database'), '', $levels, $levels));
|
||||
$actions = \logstore_database\helper::get_action_options();
|
||||
$settings->add(new admin_setting_configmulticheckbox('logstore_database/excludeactions', get_string('excludeactions',
|
||||
'logstore_database'), '', array(), $actions));
|
||||
$settings->add(new admin_setting_configmulticheckbox('logstore_database/includeactions', get_string('includeactions',
|
||||
'logstore_database'), '', $actions, $actions));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Fixtures for database log storage testing.
|
||||
*
|
||||
* @package logstore_database
|
||||
* @copyright 2014 onwards Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace logstore_database\test;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class store extends \logstore_database\log\store {
|
||||
/**
|
||||
* Public wrapper for testing.
|
||||
*
|
||||
* @param \core\event\base $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_event_ignored(\core\event\base $event) {
|
||||
return parent::is_event_ignored($event);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/fixtures/event.php');
|
||||
require_once(__DIR__ . '/fixtures/store.php');
|
||||
|
||||
class logstore_database_store_testcase extends advanced_testcase {
|
||||
public function test_log_writing() {
|
||||
@@ -225,6 +226,49 @@ class logstore_database_store_testcase extends advanced_testcase {
|
||||
get_log_manager(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method is_event_ignored.
|
||||
*/
|
||||
public function test_is_event_ignored() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Test guest filtering.
|
||||
set_config('logguests', 0, 'logstore_database');
|
||||
$this->setGuestUser();
|
||||
$event = \logstore_database\event\unittest_executed::create(
|
||||
array('context' => context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)));
|
||||
$logmanager = get_log_manager();
|
||||
$store = new \logstore_database\test\store($logmanager);
|
||||
$this->assertTrue($store->is_event_ignored($event));
|
||||
|
||||
set_config('logguests', 1, 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertFalse($store->is_event_ignored($event));
|
||||
|
||||
// Test action/level filtering.
|
||||
set_config('includelevels', '', 'logstore_database');
|
||||
set_config('includeactions', '', 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertTrue($store->is_event_ignored($event));
|
||||
|
||||
set_config('includelevels', '0,1', 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertTrue($store->is_event_ignored($event));
|
||||
|
||||
set_config('includelevels', '0,1,2', 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertFalse($store->is_event_ignored($event));
|
||||
|
||||
set_config('includelevels', '', 'logstore_database');
|
||||
set_config('includeactions', 'c,r,d', 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertTrue($store->is_event_ignored($event));
|
||||
|
||||
set_config('includeactions', 'c,r,u,d', 'logstore_database');
|
||||
$store = new \logstore_database\test\store($logmanager); // Reload.
|
||||
$this->assertFalse($store->is_event_ignored($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test logmanager::get_supported_reports returns all reports that require this store.
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2014011900; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2014041700; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014011000; // Requires this Moodle version.
|
||||
$plugin->component = 'logstore_database'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
Reference in New Issue
Block a user