require_once($CFG->dirroot.'/lib/uploadlib.php');
- //Sets a name/value pair in backup_config table
+ //Sets a name/value pair in config_plugin table
function backup_set_config($name, $value) {
- global $DB;
-
- if ($DB->get_field("backup_config", "name", array("name"=>$name))) {
- return $DB->set_field("backup_config", "value", $value, array("name"=>$name));
- } else {
- $config = new object();
- $config->name = $name;
- $config->value = $value;
- return $DB->insert_record("backup_config", $config);
- }
+ return set_config($name, $value, 'backup');
}
- //Gets all the information from backup_config table
+ //Gets all the information from config_plugin table
function backup_get_config() {
- global $DB;
-
- $backup_config = null;
- if ($configs = $DB->get_records("backup_config")) {
- foreach ($configs as $config) {
- $backup_config[$config->name] = $config->value;
- }
- }
+ $backup_config = get_config('backup');
return (object)$backup_config;
}
function config_read($name) {
global $CFG;
- if ($this->plugin === 'backup') {
- require_once($CFG->dirroot.'/backup/lib.php');
- $backupconfig = backup_get_config();
- if (isset($backupconfig->$name)) {
- return $backupconfig->$name;
- } else {
- return NULL;
- }
-
- } else if (!empty($this->plugin)) {
+ if (!empty($this->plugin)) {
$value = get_config($this->plugin, $name);
return $value === false ? NULL : $value;
}
function config_write($name, $value) {
- global $CFG;
- if ($this->plugin === 'backup') {
- require_once($CFG->dirroot.'/backup/lib.php');
- return (boolean)backup_set_config($name, $value);
- } else {
- return (boolean)set_config($name, $value, $this->plugin);
- }
+ return (boolean)set_config($name, $value, $this->plugin);
}
/**
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20090110" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090111" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
- <TABLE NAME="repository_instance_config" COMMENT="The config for intances" PREVIOUS="repository_instances" NEXT="backup_config">
+ <TABLE NAME="repository_instance_config" COMMENT="The config for intances" PREVIOUS="repository_instances" NEXT="backup_files">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="instanceid"/>
<FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
- <TABLE NAME="backup_config" COMMENT="To store backup configuration variables" PREVIOUS="repository_instance_config" NEXT="backup_files">
- <FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
- <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="value"/>
- <FIELD NAME="value" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name"/>
- </FIELDS>
- <KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
- </KEYS>
- <INDEXES>
- <INDEX NAME="name" UNIQUE="true" FIELDS="name"/>
- </INDEXES>
- </TABLE>
- <TABLE NAME="backup_files" COMMENT="To store and recode ids to user and course files" PREVIOUS="backup_config" NEXT="backup_ids">
+ <TABLE NAME="backup_files" COMMENT="To store and recode ids to user and course files" PREVIOUS="repository_instance_config" NEXT="backup_ids">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="backup_code"/>
<FIELD NAME="backup_code" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="file_type"/>
upgrade_main_savepoint($result, 2009011100);
}
+ if ($result && $oldversion < 2009011101) {
+ /// Migrate backup settings to core plugin config table
+ $configs = $DB->get_records('backup_config');
+ foreach ($configs as $config) {
+ set_config($config->name, $config->value, 'backup');
+ }
+
+ /// Define table to be dropped
+ $table = new xmldb_table('backup_config');
+
+ /// Launch drop table for old backup config
+ $dbman->drop_table($table);
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2009011101);
+ }
+
return $result;
}
$config = new object();
$config->name = $name;
$config->value = $value;
- return $DB->insert_record('config', $config);
+ return $DB->insert_record('config', $config, false);
}
} else { // plugin scope
$config->plugin = $plugin;
$config->name = $name;
$config->value = $value;
- return $DB->insert_record('config_plugins', $config);
+ return $DB->insert_record('config_plugins', $config, false);
}
}
}
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2009011100; // YYYYMMDD = date of the last version bump
+ $version = 2009011101; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20090111)'; // Human-friendly version name