From: skodak Date: Tue, 13 Jan 2009 19:02:00 +0000 (+0000) Subject: MDL-17878 new table for logging of changes in admin settings - only changes done... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=301bf0b29cf33b55e4be901872d3071cc49f4304;p=moodle.git MDL-17878 new table for logging of changes in admin settings - only changes done through admin UI are logged --- diff --git a/lib/adminlib.php b/lib/adminlib.php index 2afc2e1b00..371652010e 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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 $name + * @param $value + * @return 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. diff --git a/lib/db/install.xml b/lib/db/install.xml index 3088dbbd58..1818bb8db5 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -27,6 +27,24 @@ + + + + + + + + + + + + + + + + + +
@@ -331,7 +349,7 @@
- +
@@ -346,7 +364,7 @@
- +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6476c2fa8a..8dff907cd3 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/version.php b/version.php index a9c0d019f1..70cd245bf8 100644 --- a/version.php +++ b/version.php @@ -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