* 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;
}
}
+ /**
+ *
+ * @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
* @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
return true;
}
+ public function write_setting($data) {
+ return '';
+ }
+
public function is_related($query) {
if (parent::is_related($query)) {
return true;
// 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);
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.
<?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"
>
<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"/>
<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"/>
<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"/>
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;
}
// 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