MDL-17847 moev backup_config to config_plugin table

This commit is contained in:
skodak
2009-01-11 15:49:35 +00:00
parent db5af9346a
commit eb6a973cdf
6 changed files with 29 additions and 56 deletions
+4 -20
View File
@@ -4,30 +4,14 @@
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;
}
+2 -17
View File
@@ -1830,16 +1830,7 @@ class admin_setting {
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;
@@ -1853,13 +1844,7 @@ class admin_setting {
}
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);
}
/**
+3 -16
View File
@@ -1,5 +1,5 @@
<?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"
>
@@ -2003,7 +2003,7 @@
<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"/>
@@ -2014,20 +2014,7 @@
<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"/>
+17
View File
@@ -1333,6 +1333,23 @@ function xmldb_main_upgrade($oldversion) {
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;
}
+2 -2
View File
@@ -702,7 +702,7 @@ function set_config($name, $value, $plugin=NULL) {
$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
@@ -720,7 +720,7 @@ function set_config($name, $value, $plugin=NULL) {
$config->plugin = $plugin;
$config->name = $name;
$config->value = $value;
return $DB->insert_record('config_plugins', $config);
return $DB->insert_record('config_plugins', $config, false);
}
}
}
+1 -1
View File
@@ -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 = 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