MDL-17878 new table for logging of changes in admin settings - only changes done through admin UI are logged
This commit is contained in:
+41
-11
@@ -1794,7 +1794,7 @@ class admin_settingpage implements part_of_admin_tree {
|
||||
* Admin settings class. Only exists on setting pages.
|
||||
* Read & write happens at this level; no authentication.
|
||||
*/
|
||||
class admin_setting {
|
||||
abstract class admin_setting {
|
||||
|
||||
public $name;
|
||||
public $visiblename;
|
||||
@@ -1865,18 +1865,46 @@ class admin_setting {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $name
|
||||
* @param <type> $value
|
||||
* @return <type> Write setting to confix table
|
||||
*/
|
||||
public function config_write($name, $value) {
|
||||
return (boolean)set_config($name, $value, $this->plugin);
|
||||
global $DB, $USER, $CFG;
|
||||
|
||||
// make sure it is a real change
|
||||
$oldvalue = get_config($this->plugin, $name);
|
||||
$oldvalue = ($oldvalue === false) ? null : $oldvalue; // normalise
|
||||
$value = is_null($value) ? null : (string)$value;
|
||||
|
||||
if ($oldvalue === $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// store change
|
||||
set_config($name, $value, $this->plugin);
|
||||
|
||||
|
||||
// log change
|
||||
$log = new object();
|
||||
$log->userid = empty($CFG->rolesactive) ? 0 :$USER->id; // 0 as user id during install
|
||||
$log->timemodified = time();
|
||||
$log->plugin = $this->plugin;
|
||||
$log->name = $name;
|
||||
$log->value = $value;
|
||||
$log->oldvalue = $oldvalue;
|
||||
$DB->insert_record('config_log', $log);
|
||||
|
||||
return true; // BC only
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current value of this setting
|
||||
* @return mixed array or string depending on instance, NULL means not set yet
|
||||
*/
|
||||
public function get_setting() {
|
||||
// has to be overridden
|
||||
return NULL;
|
||||
}
|
||||
public abstract function get_setting();
|
||||
|
||||
/**
|
||||
* Returns default setting if exists
|
||||
@@ -1891,10 +1919,7 @@ class admin_setting {
|
||||
* @param mixed string or array, must not be NULL
|
||||
* @return '' if ok, string error message otherwise
|
||||
*/
|
||||
public function write_setting($data) {
|
||||
// should be overridden
|
||||
return '';
|
||||
}
|
||||
public abstract function write_setting($data);
|
||||
|
||||
/**
|
||||
* Return part of form with setting
|
||||
@@ -4533,6 +4558,10 @@ class admin_setting_manageportfolio extends admin_setting {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function write_setting($data) {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function is_related($query) {
|
||||
if (parent::is_related($query)) {
|
||||
return true;
|
||||
@@ -4931,7 +4960,7 @@ function admin_write_settings($formdata) {
|
||||
|
||||
// now update $SITE - it might have been changed
|
||||
$SITE = $DB->get_record('course', array('id'=>$SITE->id));
|
||||
$COURSE = clone($SITE);
|
||||
course_setup($SITE);
|
||||
|
||||
// now reload all settings - some of them might depend on the changed
|
||||
admin_get_root(true);
|
||||
@@ -5427,6 +5456,7 @@ class admin_setting_managerepository extends admin_setting {
|
||||
|
||||
public function write_setting($data) {
|
||||
$url = $this->baseurl . '&new=' . $data;
|
||||
return '';
|
||||
// TODO
|
||||
// Should not use redirect and exit here
|
||||
// Find a better way to do this.
|
||||
|
||||
+21
-3
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20090111" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20090113" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -27,6 +27,24 @@
|
||||
<KEY NAME="plugin_name" TYPE="unique" FIELDS="plugin, name" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="log_config" COMMENT="Changes done in server configuration through admin UI" PREVIOUS="log_display" NEXT="message">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="userid"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="userid" NEXT="plugin"/>
|
||||
<FIELD NAME="plugin" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="plugin" NEXT="value"/>
|
||||
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="oldvalue"/>
|
||||
<FIELD NAME="oldvalue" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="value"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="userid"/>
|
||||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="timemodified" UNIQUE="false" FIELDS="timemodified"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="course" COMMENT="Central course table" PREVIOUS="config_plugins" NEXT="course_categories">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="category"/>
|
||||
@@ -331,7 +349,7 @@
|
||||
<INDEX NAME="cmid" UNIQUE="false" FIELDS="cmid" PREVIOUS="userid-course"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="log_display" COMMENT="For a particular module/action, specifies a moodle table/field" PREVIOUS="log" NEXT="message">
|
||||
<TABLE NAME="log_display" COMMENT="For a particular module/action, specifies a moodle table/field" PREVIOUS="log" NEXT="log_config">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="module"/>
|
||||
<FIELD NAME="module" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="action"/>
|
||||
@@ -346,7 +364,7 @@
|
||||
<INDEX NAME="module-action" UNIQUE="true" FIELDS="module, action"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="message" COMMENT="Stores all unread messages" PREVIOUS="log_display" NEXT="message_read">
|
||||
<TABLE NAME="message" COMMENT="Stores all unread messages" PREVIOUS="log_config" NEXT="message_read">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="useridfrom"/>
|
||||
<FIELD NAME="useridfrom" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="useridto"/>
|
||||
|
||||
@@ -1350,6 +1350,34 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint($result, 2009011101);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009011303) {
|
||||
|
||||
/// Define table config_log to be created
|
||||
$table = new xmldb_table('config_log');
|
||||
|
||||
/// Adding fields to table config_log
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
|
||||
$table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
|
||||
|
||||
/// Adding keys to table config_log
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
|
||||
|
||||
/// Adding indexes to table config_log
|
||||
$table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
|
||||
|
||||
/// Launch create table for config_log
|
||||
$dbman->create_table($table);
|
||||
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2009011303);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2009011301; // YYYYMMDD = date of the last version bump
|
||||
$version = 2009011303; // YYYYMMDD = date of the last version bump
|
||||
// XX = daily increments
|
||||
|
||||
$release = '2.0 dev (Build: 20090113)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user