MDL-41266 fix coding style issues

This commit is contained in:
Petr Škoda
2014-02-28 14:52:27 +08:00
parent 0d9d9efb65
commit 0852f9c625
35 changed files with 262 additions and 219 deletions
+4 -1
View File
@@ -33,6 +33,9 @@ defined('MOODLE_INTERNAL') || die();
* @package tool_log
* @copyright 2014 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @property string $component Frankenstyle plugin name initialised in store trait.
* @property string $store short plugin name initialised in store trait.
*/
trait reader {
/**
@@ -62,7 +65,7 @@ trait reader {
/**
* If the current user can access current store or not.
*
* @param \context $context.
* @param \context $context
*
* @return bool
*/
-1
View File
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helper trait store.
*
+4 -5
View File
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helper trait writer
*
@@ -29,20 +28,20 @@ defined('MOODLE_INTERNAL') || die();
/**
* Helper trait writer. Adds buffer support for the store.
* \tool_log\helper\store must be included before using this trait.
*
*
* @package tool_log
* @copyright 2014 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait writer {
/** @var array $buffer buffer of events.*/
/** @var array $buffer buffer of events. */
protected $buffer = array();
/** @var array $buffer buffer size of events.*/
/** @var array $buffer buffer size of events. */
protected $buffersize;
/** @var int $count Counter.*/
/** @var int $count Counter. */
protected $count = 0;
/**
+11 -10
View File
@@ -33,7 +33,7 @@ class manager implements \core\log\manager {
/** @var \tool_log\log\writer[] $writers list of initialised log writers */
protected $writers;
/** @var \tool_log\log\store[] $stores */
/** @var \tool_log\log\store[] $stores list of all enabled stores */
protected $stores;
/**
@@ -84,7 +84,8 @@ class manager implements \core\log\manager {
try {
$writer->write($event, $this);
} catch (\Exception $e) {
debugging('Exception detected when logging event '.$event->eventname.' in '.$plugin.': '.$e->getMessage(), DEBUG_NORMAL, $e->getTrace());
debugging('Exception detected when logging event ' . $event->eventname . ' in ' . $plugin . ': ' .
$e->getMessage(), DEBUG_NORMAL, $e->getTrace());
}
}
}
@@ -146,15 +147,15 @@ class manager implements \core\log\manager {
*
* NOTE: this is hardcoded to legacy log store plugin, hopefully we can get rid of it soon.
*
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|\stdClass $user If log regards $user other than $USER
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|\stdClass $user If log regards $user other than $USER
*/
public function legacy_add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
public function legacy_add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0) {
$this->init();
if (isset($this->stores['logstore_legacy'])) {
$this->stores['logstore_legacy']->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
+1 -1
View File
@@ -17,7 +17,7 @@
/**
* Log store writer interface.
*
* @package core
* @package tool_log
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -39,7 +39,7 @@ class logstore extends base {
}
$enabled = array_flip(explode(',', $enabled));
return isset($enabled['logstore_'.$this->name]);
return isset($enabled['logstore_' . $this->name]);
}
public function get_settings_section_name() {
@@ -68,7 +68,7 @@ class logstore extends base {
}
public static function get_manage_url() {
return new moodle_url('/admin/settings.php', array('section'=>'managelogging'));
return new moodle_url('/admin/settings.php', array('section' => 'managelogging'));
}
public function is_uninstall_allowed() {
@@ -79,7 +79,7 @@ class logstore extends base {
$enabled = get_config('tool_log', 'enabled_stores');
if ($enabled) {
$enabled = array_flip(explode(',', $enabled));
unset($enabled['logstore_'.$this->name]);
unset($enabled['logstore_' . $this->name]);
$enabled = array_flip($enabled);
set_config('enabled_stores', implode(',', $enabled), 'tool_log');
}
+32 -28
View File
@@ -96,22 +96,22 @@ class tool_log_setting_managestores extends admin_setting {
* @param string $query
* @return string
*/
public function output_html($data, $query='') {
public function output_html($data, $query = '') {
global $OUTPUT, $PAGE;
// Display strings.
$strup = get_string('up');
$strdown = get_string('down');
$strsettings = get_string('settings');
$strenable = get_string('enable');
$strdisable = get_string('disable');
$strup = get_string('up');
$strdown = get_string('down');
$strsettings = get_string('settings');
$strenable = get_string('enable');
$strdisable = get_string('disable');
$struninstall = get_string('uninstallplugin', 'core_admin');
$strversion = get_string('version');
$strversion = get_string('version');
$pluginmanager = core_plugin_manager::instance();
$available = \tool_log\log\manager::get_store_plugins();
$enabled = get_config('tool_log', 'enabled_stores');
$enabled = get_config('tool_log', 'enabled_stores');
if (!$enabled) {
$enabled = array();
} else {
@@ -132,16 +132,16 @@ class tool_log_setting_managestores extends admin_setting {
$return .= $OUTPUT->box_start('generalbox loggingui');
$table = new html_table();
$table->head = array(get_string('name'), $strversion, $strenable, $strup.'/'.$strdown, $strsettings, $struninstall);
$table->head = array(get_string('name'), $strversion, $strenable, $strup . '/' . $strdown, $strsettings, $struninstall);
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign', 'centeralign');
$table->id = 'logstoreplugins';
$table->attributes['class'] = 'admintable generaltable';
$table->data = array();
$table->data = array();
// Iterate through store plugins and add to the display table.
$updowncount = 1;
$storecount = count($enabled);
$url = new moodle_url('/admin/tool/log/stores.php', array('sesskey'=>sesskey()));
$url = new moodle_url('/admin/tool/log/stores.php', array('sesskey' => sesskey()));
$printed = array();
foreach ($allstores as $store => $unused) {
$plugininfo = $pluginmanager->get_plugin_info($store);
@@ -158,21 +158,23 @@ class tool_log_setting_managestores extends admin_setting {
// Hide/show links.
if (isset($enabled[$store])) {
$aurl = new moodle_url($url, array('action'=>'disable', 'store'=>$store));
$aurl = new moodle_url($url, array('action' => 'disable', 'store' => $store));
$hideshow = "<a href=\"$aurl\">";
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"$strdisable\" /></a>";
$isenabled = true;
$displayname = "<span>$name</span>";
} else if (isset($available[$store])) {
$aurl = new moodle_url($url, array('action'=>'enable', 'store'=>$store));
$hideshow = "<a href=\"$aurl\">";
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"$strenable\" /></a>";
$isenabled = false;
$displayname = "<span class=\"dimmed_text\">$name</span>";
} else {
$hideshow = '';
$isenabled = false;
$displayname = '<span class="notifyproblem">'.$name.'</span>';
if (isset($available[$store])) {
$aurl = new moodle_url($url, array('action' => 'enable', 'store' => $store));
$hideshow = "<a href=\"$aurl\">";
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"$strenable\" /></a>";
$isenabled = false;
$displayname = "<span class=\"dimmed_text\">$name</span>";
} else {
$hideshow = '';
$isenabled = false;
$displayname = '<span class="notifyproblem">' . $name . '</span>';
}
}
if ($PAGE->theme->resolve_image_location('icon', $store, false)) {
$icon = $OUTPUT->pix_icon('icon', '', $store, array('class' => 'icon pluginicon'));
@@ -184,14 +186,14 @@ class tool_log_setting_managestores extends admin_setting {
$updown = '';
if ($isenabled) {
if ($updowncount > 1) {
$aurl = new moodle_url($url, array('action'=>'up', 'store'=>$store));
$aurl = new moodle_url($url, array('action' => 'up', 'store' => $store));
$updown .= "<a href=\"$aurl\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"$strup\" class=\"iconsmall\" /></a>&nbsp;";
} else {
$updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"iconsmall\" alt=\"\" />&nbsp;";
}
if ($updowncount < $storecount) {
$aurl = new moodle_url($url, array('action'=>'down', 'store'=>$store));
$aurl = new moodle_url($url, array('action' => 'down', 'store' => $store));
$updown .= "<a href=\"$aurl\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"$strdown\" class=\"iconsmall\" /></a>";
} else {
@@ -203,10 +205,12 @@ class tool_log_setting_managestores extends admin_setting {
// Add settings link.
if (!$version) {
$settings = '';
} else if ($surl = $plugininfo->get_settings_url()) {
$settings = html_writer::link($surl, $strsettings);
} else {
$settings = '';
if ($surl = $plugininfo->get_settings_url()) {
$settings = html_writer::link($surl, $strsettings);
} else {
$settings = '';
}
}
// Add uninstall info.
@@ -216,13 +220,13 @@ class tool_log_setting_managestores extends admin_setting {
}
// Add a row to the table.
$table->data[] = array($icon.$displayname, $version, $hideshow, $updown, $settings, $uninstall);
$table->data[] = array($icon . $displayname, $version, $hideshow, $updown, $settings, $uninstall);
$printed[$store] = true;
}
$return .= html_writer::table($table);
$return .= get_string('configlogplugins', 'tool_log').'<br />'.get_string('tablenosave', 'admin');
$return .= get_string('configlogplugins', 'tool_log') . '<br />' . get_string('tablenosave', 'admin');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
+2 -2
View File
@@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();
$observers = array (
array (
$observers = array(
array(
'eventname' => '*',
'callback' => '\tool_log\log\observer::store',
'internal' => false, // This means that we get events only after transaction commit.
+2 -1
View File
@@ -18,7 +18,8 @@
* Logging subplugins.
*
* @package tool_log
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$subplugins = array('logstore'=>'admin/tool/log/store');
$subplugins = array('logstore' => 'admin/tool/log/store');
+1 -1
View File
@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
/**
* Execute cron actions.
+1 -1
View File
@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
if ($hassiteconfig) {
$ADMIN->add('modules', new admin_category('logging', new lang_string('logging', 'tool_log')));
@@ -23,7 +23,7 @@
*/
namespace logstore_database;
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
/**
@@ -39,12 +39,12 @@ class helper {
*/
public static function get_drivers() {
return array(
'native/mysqli' => \moodle_database::get_driver_instance('mysqli', 'native')->get_name(),
'native/mysqli' => \moodle_database::get_driver_instance('mysqli', 'native')->get_name(),
'native/mariadb' => \moodle_database::get_driver_instance('mariadb', 'native')->get_name(),
'native/pgsql' => \moodle_database::get_driver_instance('pgsql', 'native')->get_name(),
'native/oci' => \moodle_database::get_driver_instance('oci', 'native')->get_name(),
'native/sqlsrv' => \moodle_database::get_driver_instance('sqlsrv', 'native')->get_name(),
'native/mssql' => \moodle_database::get_driver_instance('mssql', 'native')->get_name()
'native/pgsql' => \moodle_database::get_driver_instance('pgsql', 'native')->get_name(),
'native/oci' => \moodle_database::get_driver_instance('oci', 'native')->get_name(),
'native/sqlsrv' => \moodle_database::get_driver_instance('sqlsrv', 'native')->get_name(),
'native/mssql' => \moodle_database::get_driver_instance('mssql', 'native')->get_name()
);
}
@@ -55,9 +55,9 @@ class helper {
*/
public static function get_level_options() {
return array(
\core\event\base::LEVEL_TEACHING => get_string('teaching', 'logstore_database'),
\core\event\base::LEVEL_TEACHING => get_string('teaching', 'logstore_database'),
\core\event\base::LEVEL_PARTICIPATING => get_string('participating', 'logstore_database'),
\core\event\base::LEVEL_OTHER => get_string('other', 'logstore_database'),
\core\event\base::LEVEL_OTHER => get_string('other', 'logstore_database'),
);
}
@@ -29,8 +29,8 @@ class store implements \tool_log\log\writer, \core\log\reader {
use \tool_log\helper\store,
\tool_log\helper\reader,
\tool_log\helper\writer {
dispose as helper_dispose;
}
dispose as helper_dispose;
}
/** @var \moodle_database $extdb */
protected $extdb;
@@ -57,7 +57,6 @@ class store implements \tool_log\log\writer, \core\log\reader {
$levels = $this->get_config('excludelevels', '');
$this->excludeactions = $actions === '' ? array() : explode(',', $actions);
$this->excludelevels = $levels === '' ? array() : explode(',', $levels);
}
/**
@@ -111,7 +110,7 @@ class store implements \tool_log\log\writer, \core\log\reader {
/**
* Insert events in bulk to the database.
*
* @param $events
* @param \core\event\base[] $events
*/
protected function insert_events($events) {
if (!$this->init()) {
@@ -125,7 +124,8 @@ class store implements \tool_log\log\writer, \core\log\reader {
// Filter events.
foreach ($events as $event) {
if (in_array($event->crud, $this->excludeactions) ||
in_array($event->edulevel, $this->excludelevels)) {
in_array($event->edulevel, $this->excludelevels)
) {
// Ignore event if the store settings do not want to store it.
continue;
}
@@ -159,10 +159,10 @@ class store implements \tool_log\log\writer, \core\log\reader {
* Get an array of events based on the passed on params.
*
* @param string $selectwhere select conditions.
* @param array $params params.
* @param string $sort sortorder.
* @param int $limitfrom limit constraints.
* @param int $limitnum limit constraints.
* @param array $params params.
* @param string $sort sortorder.
* @param int $limitfrom limit constraints.
* @param int $limitnum limit constraints.
*
* @return array|\core\event\base[] array of events.
*/
@@ -201,7 +201,7 @@ class store implements \tool_log\log\writer, \core\log\reader {
* Get number of events present for the given select clause.
*
* @param string $selectwhere select conditions.
* @param array $params params.
* @param array $params params.
*
* @return int Number of events available for the given conditions
*/
+8 -8
View File
@@ -34,32 +34,32 @@ if ($hassiteconfig) {
// Database settings.
$link = html_writer::link($testurl, get_string('testsettings', 'logstore_database'), array('target' => '_blank'));
$settings->add(new admin_setting_heading('dbsettings', get_string('databasesettings', 'logstore_database'),
get_string('databasesettings_help', 'logstore_database', $link)));
get_string('databasesettings_help', 'logstore_database', $link)));
$settings->add(new admin_setting_configselect('logstore_database/dbdriver', get_string('databasetypehead', 'install'), '',
'', $drivers));
'', $drivers));
$settings->add(new admin_setting_configtext('logstore_database/dbhost', get_string('databasehost', 'install'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbuser', get_string('databaseuser', 'install'), '', ''));
$settings->add(new admin_setting_configpasswordunmask('logstore_database/dbpass', get_string('databasepass', 'install'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbname', get_string('databasename', 'install'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbtable', get_string('databasetable', 'logstore_database'),
get_string('databasetable_help', 'logstore_database'), ''));
get_string('databasetable_help', 'logstore_database'), ''));
$settings->add(new admin_setting_configcheckbox('logstore_database/dbpersist', get_string('databasepersist',
'logstore_database'), '', '0'));
'logstore_database'), '', '0'));
$settings->add(new admin_setting_configtext('logstore_database/dbsocket', get_string('databasesocket', 'install'), '',
''));
''));
$settings->add(new admin_setting_configtext('logstore_database/dbport', get_string('databaseport', 'install'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbschema', get_string('databaseschema',
'logstore_database'), '', ''));
'logstore_database'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbcollation', get_string('databasecollation',
'logstore_database'), '', ''));
'logstore_database'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/buffersize', get_string('buffersize',
'logstore_database'), get_string('buffersize_help', 'logstore_database'), 50));
// Filters.
$settings->add(new admin_setting_heading('filters', get_string('filters', 'logstore_database'), get_string('filters_help',
'logstore_database')));
'logstore_database')));
$settings->add(new admin_setting_configcheckbox('logstore_database/logguests', get_string('logguests',
'logstore_database'), '', '0'));
$levels = \logstore_database\helper::get_level_options();
@@ -22,8 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../../../../config.php');
require_once($CFG->dirroot. '/lib/adminlib.php');
require_once('../../../../../config.php');
require_once($CFG->dirroot . '/lib/adminlib.php');
require_login();
$context = context_system::instance();
@@ -88,14 +88,14 @@ if (!in_array($dbtable, $tables)) {
echo $OUTPUT->footer();
die();
}
echo $OUTPUT->notification('Table '. $dbtable. ' found.', 'notifysuccess');
echo $OUTPUT->notification('Table ' . $dbtable . ' found.', 'notifysuccess');
$cols = $db->get_columns($dbtable);
if (empty($cols)) {
echo $OUTPUT->notification('Can not read external table.', 'notifyproblem');
} else {
$columns = array_keys((array)$cols);
echo $OUTPUT->notification('External table contains following columns:<br />'.implode(', ', $columns), 'notifysuccess');
echo $OUTPUT->notification('External table contains following columns:<br />' . implode(', ', $columns), 'notifysuccess');
}
$db->dispose();
+3 -3
View File
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace logstore_database\event;
/**
* Fixtures for database log storage testing.
*
@@ -24,6 +22,8 @@ namespace logstore_database\event;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_database\event;
defined('MOODLE_INTERNAL') || die();
@@ -42,6 +42,6 @@ class unittest_executed extends \core\event\base {
}
public function get_url() {
return new \moodle_url('/somepath/somefile.php', array('id'=>$this->data['other']['sample']));
return new \moodle_url('/somepath/somefile.php', array('id' => $this->data['other']['sample']));
}
}
@@ -22,9 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
require_once (__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/event.php');
class logstore_database_store_testcase extends advanced_testcase {
public function test_log_writing() {
@@ -40,18 +40,18 @@ class logstore_database_store_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$module1 = $this->getDataGenerator()->create_module('resource', array('course'=>$course1));
$module1 = $this->getDataGenerator()->create_module('resource', array('course' => $course1));
$course2 = $this->getDataGenerator()->create_course();
$module2 = $this->getDataGenerator()->create_module('resource', array('course'=>$course2));
$module2 = $this->getDataGenerator()->create_module('resource', array('course' => $course2));
// Fake the settings, we will abuse the standard plugin table here...
$parts = explode('_', get_class($DB));
set_config('dbdriver', $parts[1].'/'.$parts[0], 'logstore_database');
set_config('dbdriver', $parts[1] . '/' . $parts[0], 'logstore_database');
set_config('dbhost', $CFG->dbhost, 'logstore_database');
set_config('dbuser', $CFG->dbuser, 'logstore_database');
set_config('dbpass', $CFG->dbpass, 'logstore_database');
set_config('dbname', $CFG->dbname, 'logstore_database');
set_config('dbtable', $CFG->prefix.'logstore_standard_log', 'logstore_database');
set_config('dbtable', $CFG->prefix . 'logstore_standard_log', 'logstore_database');
if (!empty($CFG->dboptions['dbpersist'])) {
set_config('dbpersist', 1, 'logstore_database');
} else {
@@ -97,7 +97,8 @@ class logstore_database_store_testcase extends advanced_testcase {
$this->setCurrentTimeStart();
$this->setUser(0);
$event1 = \logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)));
$event1 = \logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
$event1->trigger();
$logs = $DB->get_records('logstore_standard_log', array(), 'id ASC');
@@ -117,7 +118,8 @@ class logstore_database_store_testcase extends advanced_testcase {
\core\session\manager::loginas($user1->id, context_system::instance());
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
$event2 = \logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module2->cmid), 'other'=>array('sample'=>6, 'xx'=>9)));
$event2 = \logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9)));
$event2->trigger();
$_SESSION['SESSION'] = new \stdClass();
@@ -157,23 +159,31 @@ class logstore_database_store_testcase extends advanced_testcase {
$store = $stores['logstore_database'];
$DB->delete_records('logstore_standard_log');
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$store->flush();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(8, $DB->count_records('logstore_standard_log'));
// Test guest logging setting.
@@ -184,19 +194,23 @@ class logstore_database_store_testcase extends advanced_testcase {
get_log_manager(true);
$this->setUser(null);
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$this->setGuestUser();
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$this->setUser($user1);
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(1, $DB->count_records('logstore_standard_log'));
$this->setUser($user2);
\logstore_database\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
set_config('enabled_stores', '', 'tool_log');
+2 -2
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014011900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->version = 2014011900; // 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).
@@ -25,7 +25,6 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class legacy_logged extends \core\event\base {
public function init() {
@@ -37,7 +36,7 @@ class legacy_logged extends \core\event\base {
}
public function get_description() {
return $this->other['module'].' '.$this->other['action'].' '.$this->other['info'];
return $this->other['module'] . ' ' . $this->other['action'] . ' ' . $this->other['info'];
}
public function get_url() {
@@ -33,13 +33,14 @@ class store implements \tool_log\log\store, \core\log\reader {
public function __construct(\tool_log\log\manager $manager) {
$this->helper_setup($manager);
}
/** @var array list of db fields which needs to be replaced for legacy log query */
protected $standardtolegacyfields = array(
'timecreated' => 'time',
'courseid' => 'course',
'contextinstanceid' => 'cmid',
'origin' => 'ip'
);
'timecreated' => 'time',
'courseid' => 'course',
'contextinstanceid' => 'cmid',
'origin' => 'ip'
);
public function get_events($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
global $DB;
@@ -60,7 +61,7 @@ class store implements \tool_log\log\store, \core\log\reader {
try {
$records = $DB->get_records_select('log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);
} catch (\moodle_exception $ex) {
debugging("error converting legacy event data ". $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
debugging("error converting legacy event data " . $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
}
foreach ($records as $data) {
@@ -85,7 +86,7 @@ class store implements \tool_log\log\store, \core\log\reader {
try {
return $DB->count_records_select('log', $selectwhere, $params);
} catch (\moodle_exception $ex) {
debugging("error converting legacy event data ". $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
debugging("error converting legacy event data " . $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
return 0;
}
}
@@ -94,7 +95,7 @@ class store implements \tool_log\log\store, \core\log\reader {
global $CFG, $DB;
// Delete old logs to save space (this might need a timer to slow it down...).
if (!empty($CFG->loglifetime)) { // value in days
if (!empty($CFG->loglifetime)) { // Value in days.
$loglifetime = time(0) - ($CFG->loglifetime * 3600 * 24);
$DB->delete_records_select("log", "time < ?", array($loglifetime));
mtrace(" Deleted old log records");
@@ -107,12 +108,12 @@ class store implements \tool_log\log\store, \core\log\reader {
/**
* Legacy add_to_log() code.
*
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|\stdClass $user If log regards $user other than $USER
*/
public function legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user) {
@@ -131,7 +132,7 @@ class store implements \tool_log\log\store, \core\log\reader {
if ($user) {
$userid = $user;
} else {
if (\core\session\manager::is_loggedinas()) { // Don't log.
if (\core\session\manager::is_loggedinas()) { // Don't log.
return;
}
$userid = empty($USER->id) ? '0' : $USER->id;
@@ -143,7 +144,7 @@ class store implements \tool_log\log\store, \core\log\reader {
}
}
$REMOTE_ADDR = getremoteaddr();
$remoteaddr = getremoteaddr();
$timenow = time();
if (!empty($url)) { // Could break doing html_entity_decode on an empty var.
@@ -156,38 +157,42 @@ class store implements \tool_log\log\store, \core\log\reader {
// database so that it doesn't cause a DB error. Log a warning so that
// developers can avoid doing things which are likely to cause this on a
// routine basis.
if(!empty($info) && \core_text::strlen($info)>255) {
$info = \core_text::substr($info,0,252).'...';
debugging('Warning: logged very long info',DEBUG_DEVELOPER);
if (!empty($info) && \core_text::strlen($info) > 255) {
$info = \core_text::substr($info, 0, 252) . '...';
debugging('Warning: logged very long info', DEBUG_DEVELOPER);
}
// If the 100 field size is changed, also need to alter print_log in course/lib.php.
if(!empty($url) && \core_text::strlen($url)>100) {
$url = \core_text::substr($url,0,97).'...';
debugging('Warning: logged very long URL',DEBUG_DEVELOPER);
if (!empty($url) && \core_text::strlen($url) > 100) {
$url = \core_text::substr($url, 0, 97) . '...';
debugging('Warning: logged very long URL', DEBUG_DEVELOPER);
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->logwrites++;};
if (defined('MDL_PERFDB')) {
global $PERF;
$PERF->logwrites++;
};
$log = array('time'=>$timenow, 'userid'=>$userid, 'course'=>$courseid, 'ip'=>$REMOTE_ADDR, 'module'=>$module,
'cmid'=>$cm, 'action'=>$action, 'url'=>$url, 'info'=>$info);
$log = array('time' => $timenow, 'userid' => $userid, 'course' => $courseid, 'ip' => $remoteaddr,
'module' => $module, 'cmid' => $cm, 'action' => $action, 'url' => $url, 'info' => $info);
try {
$DB->insert_record_raw('log', $log, false);
} catch (\dml_exception $e) {
debugging('Error: Could not insert a new entry to the Moodle log. '. $e->error, DEBUG_ALL);
debugging('Error: Could not insert a new entry to the Moodle log. ' . $e->errorcode, DEBUG_ALL);
// MDL-11893, alert $CFG->supportemail if insert into log failed.
if ($CFG->supportemail and empty($CFG->noemailever)) {
// Function email_to_user is not usable because email_to_user tries to write to the logs table,
// and this will get caught in an infinite loop, if disk is full.
$site = get_site();
$subject = 'Insert into log failed at your moodle site '.$site->fullname;
$message = "Insert into log table failed at ". date('l dS \of F Y h:i:s A') .".\n It is possible that your disk is full.\n\n";
$subject = 'Insert into log failed at your moodle site ' . $site->fullname;
$message = "Insert into log table failed at " . date('l dS \of F Y h:i:s A') .
".\n It is possible that your disk is full.\n\n";
$message .= "The failed query parameters are:\n\n" . var_export($log, true);
$lasttime = get_config('admin', 'lastloginserterrormail');
if(empty($lasttime) || time() - $lasttime > 60*60*24) { // limit to 1 email per day
if (empty($lasttime) || time() - $lasttime > 60 * 60 * 24) { // Limit to 1 email per day.
// Using email directly rather than messaging as they may not be able to log in to access a message.
mail($CFG->supportemail, $subject, $message);
set_config('lastloginserterrormail', time(), 'admin');
+5 -5
View File
@@ -26,13 +26,13 @@ defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'logstore/legacy:read' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
),
),
);
+12 -12
View File
@@ -33,18 +33,18 @@ if ($hassiteconfig) {
new lang_string('logguests', 'admin'),
new lang_string('logguests_help', 'admin'), 1));
$options = array(0 => new lang_string('neverdeletelogs'),
1000 => new lang_string('numdays', '', 1000),
365 => new lang_string('numdays', '', 365),
180 => new lang_string('numdays', '', 180),
150 => new lang_string('numdays', '', 150),
120 => new lang_string('numdays', '', 120),
90 => new lang_string('numdays', '', 90),
60 => new lang_string('numdays', '', 60),
35 => new lang_string('numdays', '', 35),
10 => new lang_string('numdays', '', 10),
5 => new lang_string('numdays', '', 5),
2 => new lang_string('numdays', '', 2));
$options = array(0 => new lang_string('neverdeletelogs'),
1000 => new lang_string('numdays', '', 1000),
365 => new lang_string('numdays', '', 365),
180 => new lang_string('numdays', '', 180),
150 => new lang_string('numdays', '', 150),
120 => new lang_string('numdays', '', 120),
90 => new lang_string('numdays', '', 90),
60 => new lang_string('numdays', '', 60),
35 => new lang_string('numdays', '', 35),
10 => new lang_string('numdays', '', 10),
5 => new lang_string('numdays', '', 5),
2 => new lang_string('numdays', '', 2));
$settings->add(new admin_setting_configselect('loglifetime',
new lang_string('loglifetime', 'admin'),
+5 -4
View File
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace logstore_legacy\event;
/**
* Fixtures for legacy logging testing.
*
@@ -24,6 +22,8 @@ namespace logstore_legacy\event;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_legacy\event;
defined('MOODLE_INTERNAL') || die();
@@ -42,7 +42,7 @@ class unittest_executed extends \core\event\base {
}
public function get_url() {
return new \moodle_url('/somepath/somefile.php', array('id'=>$this->data['other']['sample']));
return new \moodle_url('/somepath/somefile.php', array('id' => $this->data['other']['sample']));
}
public static function get_legacy_eventname() {
@@ -58,6 +58,7 @@ class unittest_executed extends \core\event\base {
if ($this->contextlevel == CONTEXT_MODULE) {
$cmid = $this->contextinstanceid;
}
return array($this->data['courseid'], 'core_unittest', 'view', 'unittest.php?id='.$this->data['other']['sample'], 'bbb', $cmid);
return array($this->data['courseid'], 'core_unittest', 'view',
'unittest.php?id=' . $this->data['other']['sample'], 'bbb', $cmid);
}
}
@@ -22,9 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
require_once (__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/event.php');
class logstore_legacy_store_testcase extends advanced_testcase {
public function test_log_writing() {
@@ -35,9 +35,9 @@ class logstore_legacy_store_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$module1 = $this->getDataGenerator()->create_module('resource', array('course'=>$course1));
$module1 = $this->getDataGenerator()->create_module('resource', array('course' => $course1));
$course2 = $this->getDataGenerator()->create_course();
$module2 = $this->getDataGenerator()->create_module('resource', array('course'=>$course2));
$module2 = $this->getDataGenerator()->create_module('resource', array('course' => $course2));
// Enable legacy logging plugin.
set_config('enabled_stores', 'logstore_legacy', 'tool_log');
@@ -50,11 +50,13 @@ class logstore_legacy_store_testcase extends advanced_testcase {
$this->setCurrentTimeStart();
$this->setUser(0);
$event1 = \logstore_legacy\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)));
$event1 = \logstore_legacy\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
$event1->trigger();
$this->setUser($user1);
$event2 = \logstore_legacy\event\unittest_executed::create(array('context'=>context_course::instance($course2->id), 'other'=>array('sample'=>6, 'xx'=>11)));
$event2 = \logstore_legacy\event\unittest_executed::create(
array('context' => context_course::instance($course2->id), 'other' => array('sample' => 6, 'xx' => 11)));
$event2->trigger();
$this->setUser($user2);
@@ -126,7 +128,8 @@ class logstore_legacy_store_testcase extends advanced_testcase {
set_config('loglegacy', 0, 'logstore_legacy');
get_log_manager(true);
\logstore_legacy\event\unittest_executed::create(array('context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_legacy\event\unittest_executed::create(
array('context' => \context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
add_to_log($course1->id, 'xxxx', 'yyyy', '', '7', 0, 0);
//$this->assertDebuggingCalled();
$this->assertEquals(4, $DB->count_records('log'));
@@ -136,7 +139,8 @@ class logstore_legacy_store_testcase extends advanced_testcase {
set_config('loglegacy', 1, 'logstore_legacy');
get_log_manager(true);
\logstore_legacy\event\unittest_executed::create(array('context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_legacy\event\unittest_executed::create(
array('context' => \context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
add_to_log($course1->id, 'xxxx', 'yyyy', '', '7', 0, 0);
//$this->assertDebuggingCalled();
$this->assertEquals(4, $DB->count_records('log'));
+2 -2
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->component = 'logstore_legacy'; // Full name of the plugin (used for diagnostics).
@@ -116,7 +116,7 @@ class store implements \tool_log\log\writer, \core\log\sql_reader {
// NOTE: we should do this only once a day, new cron will deal with this.
if ($loglifetime > 0) {
$loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days.
$loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days.
$DB->delete_records_select("logstore_standard_log", "timecreated < ?", array($loglifetime));
mtrace(" Deleted old log records from standard store.");
}
+5 -5
View File
@@ -26,13 +26,13 @@ defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'logstore/standard:read' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
),
),
);
+11 -11
View File
@@ -31,18 +31,18 @@ if ($hassiteconfig) {
new lang_string('logguests_help', 'core_admin'), 1));
$options = array(
0 => new lang_string('neverdeletelogs'),
0 => new lang_string('neverdeletelogs'),
1000 => new lang_string('numdays', '', 1000),
365 => new lang_string('numdays', '', 365),
180 => new lang_string('numdays', '', 180),
150 => new lang_string('numdays', '', 150),
120 => new lang_string('numdays', '', 120),
90 => new lang_string('numdays', '', 90),
60 => new lang_string('numdays', '', 60),
35 => new lang_string('numdays', '', 35),
10 => new lang_string('numdays', '', 10),
5 => new lang_string('numdays', '', 5),
2 => new lang_string('numdays', '', 2));
365 => new lang_string('numdays', '', 365),
180 => new lang_string('numdays', '', 180),
150 => new lang_string('numdays', '', 150),
120 => new lang_string('numdays', '', 120),
90 => new lang_string('numdays', '', 90),
60 => new lang_string('numdays', '', 60),
35 => new lang_string('numdays', '', 35),
10 => new lang_string('numdays', '', 10),
5 => new lang_string('numdays', '', 5),
2 => new lang_string('numdays', '', 2));
$settings->add(new admin_setting_configselect('logstore_standard/loglifetime',
new lang_string('loglifetime', 'core_admin'),
new lang_string('configloglifetime', 'core_admin'), 0, $options));
+3 -3
View File
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace logstore_standard\event;
/**
* Fixtures for standard log storage testing.
*
@@ -24,6 +22,8 @@ namespace logstore_standard\event;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_standard\event;
defined('MOODLE_INTERNAL') || die();
@@ -42,6 +42,6 @@ class unittest_executed extends \core\event\base {
}
public function get_url() {
return new \moodle_url('/somepath/somefile.php', array('id'=>$this->data['other']['sample']));
return new \moodle_url('/somepath/somefile.php', array('id' => $this->data['other']['sample']));
}
}
@@ -22,9 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
require_once (__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/event.php');
class logstore_standard_store_testcase extends advanced_testcase {
public function test_log_writing() {
@@ -36,9 +36,9 @@ class logstore_standard_store_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$module1 = $this->getDataGenerator()->create_module('resource', array('course'=>$course1));
$module1 = $this->getDataGenerator()->create_module('resource', array('course' => $course1));
$course2 = $this->getDataGenerator()->create_course();
$module2 = $this->getDataGenerator()->create_module('resource', array('course'=>$course2));
$module2 = $this->getDataGenerator()->create_module('resource', array('course' => $course2));
// Enable logging plugin.
set_config('enabled_stores', 'logstore_standard', 'tool_log');
@@ -59,7 +59,8 @@ class logstore_standard_store_testcase extends advanced_testcase {
$this->setCurrentTimeStart();
$this->setUser(0);
$event1 = \logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)));
$event1 = \logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
$event1->trigger();
$logs = $DB->get_records('logstore_standard_log', array(), 'id ASC');
@@ -79,7 +80,8 @@ class logstore_standard_store_testcase extends advanced_testcase {
\core\session\manager::loginas($user1->id, context_system::instance());
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
$event2 = \logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module2->cmid), 'other'=>array('sample'=>6, 'xx'=>9)));
$event2 = \logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9)));
$event2->trigger();
$_SESSION['SESSION'] = new \stdClass();
@@ -119,23 +121,31 @@ class logstore_standard_store_testcase extends advanced_testcase {
$store = $stores['logstore_standard'];
$DB->delete_records('logstore_standard_log');
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$store->flush();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(8, $DB->count_records('logstore_standard_log'));
// Test guest logging setting.
@@ -146,19 +156,23 @@ class logstore_standard_store_testcase extends advanced_testcase {
get_log_manager(true);
$this->setUser(null);
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$this->setGuestUser();
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$this->setUser($user1);
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(1, $DB->count_records('logstore_standard_log'));
$this->setUser($user2);
\logstore_standard\event\unittest_executed::create(array('context'=>context_module::instance($module1->cmid), 'other'=>array('sample'=>5, 'xx'=>10)))->trigger();
\logstore_standard\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
set_config('enabled_stores', '', 'tool_log');
+2 -2
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014013000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014012400; // Requires this Moodle version.
$plugin->version = 2014013000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014012400; // Requires this Moodle version.
$plugin->component = 'logstore_standard'; // Full name of the plugin (used for diagnostics).
+4 -4
View File
@@ -23,10 +23,10 @@
*/
require_once('../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir . '/adminlib.php');
$action = required_param('action', PARAM_ALPHANUMEXT);
$enrol = required_param('store', PARAM_PLUGIN);
$enrol = required_param('store', PARAM_PLUGIN);
$PAGE->set_url('/admin/tool/log/stores.php');
$PAGE->set_context(context_system::instance());
@@ -35,7 +35,7 @@ require_login();
require_capability('moodle/site:config', context_system::instance());
require_sesskey();
$all = \tool_log\log\manager::get_store_plugins();
$all = \tool_log\log\manager::get_store_plugins();
$enabled = get_config('tool_log', 'enabled_stores');
if (!$enabled) {
$enabled = array();
@@ -43,7 +43,7 @@ if (!$enabled) {
$enabled = array_flip(explode(',', $enabled));
}
$return = new moodle_url('/admin/settings.php', array('section'=>'managelogging'));
$return = new moodle_url('/admin/settings.php', array('section' => 'managelogging'));
$syscontext = context_system::instance();
+2 -2
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014011000; // Requires this Moodle version.
$plugin->component = 'tool_log'; // Full name of the plugin (used for diagnostics).
+1
View File
@@ -31,6 +31,7 @@ class dummy_manager implements manager {
public function get_readers() {
return array();
}
public function dispose() {
}
}
-2
View File
@@ -35,8 +35,6 @@ interface sql_reader extends reader {
* Note: this table must be used for reading only,
* it is strongly recommended to use this in complex reports only.
*
* TODO: define the standard log columns - watch out for "level" reserved word!
*
* @return string
*/
public function get_log_table();