function xmldb_taoresource_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
//===== 1.9.0 upgrade line ======//
// change the remoteid key to be non-unique
if ($result && $oldversion < 2007101510) {
$table = new XMLDBTable('taoresource_entry');
$index = new XMLDBIndex('remoteid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('remoteid'));
if (index_exists($table, $index)) {
$result = $result && drop_index($table, $index);
}
$result = $result && add_index($table, $index);
}
// change the remoteid key to be non-unique
if ($result && $oldversion < 2007101511) {
$table = new XMLDBTable('taoresource_metadata');
$field = new XMLDBField('entry_id');
// change the field type from ext to int
if (field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && change_field_type($table, $field);
}
}
return $result;
}
function xmldb_tab_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2010072101) {
/// Define field anonymous_response to be added to feedback_completed
$table = new XMLDBTable('tab');
$field = new XMLDBField('displayfp');
if (!field_exists($table, $field)) {
// if field does not exists... add it
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
$result = $result && add_field($table, $field);
}
// original mysql sql code: "ALTER TABLE `mdl_tab` CHANGE `displayfp` `displayfp` TINYINT( 1 ) NOT NULL DEFAULT '0'"
}
return $result;
}
function xmldb_data_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2006121300) {
/// Define field format to be added to data_comments
$table = new XMLDBTable('data_comments');
$field = new XMLDBField('format');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'content');
/// Launch add field format
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007022600) {
/// Define field asearchtemplate to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
/// Launch add field asearchtemplate
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007072200) {
require_once $CFG->dirroot . '/mod/data/lib.php';
// too much debug output
$db->debug = false;
data_update_grades();
$db->debug = true;
}
if ($result && $oldversion < 2007081400) {
/// Define field notification to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('notification');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null, 'editany');
/// Launch add field notification
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007081402) {
/// Define index type-dataid (not unique) to be added to data_fields
$table = new XMLDBTable('data_fields');
$index = new XMLDBIndex('type-dataid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('type', 'dataid'));
/// Launch add index type-dataid
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
/// Define index course (not unique) to be added to data
$table = new XMLDBTable('data');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
/// Launch add index course
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
}
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007101512) {
/// Launch add field asearchtemplate again if does not exists yet - reported on several sites
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
if (!field_exists($table, $field)) {
$result = $result && add_field($table, $field);
}
}
return $result;
}
开发者ID:r007,项目名称:PMoodle,代码行数:72,代码来源:upgrade.php
示例6: xmldb_core_upgrade
//.........这里部分代码省略.........
create_table($table);
$table = new XMLDBTable('style_property');
$table->addFieldInfo('style', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('field', XMLDB_TYPE_CHAR, 100, null, XMLDB_NOTNULL);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('style', 'field'));
$table->addKeyInfo('stylefk', XMLDB_KEY_FOREIGN, array('style'), 'style', array('id'));
create_table($table);
$table = new XMLDBTable('institution');
$field = new XMLDBField('style');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10');
add_field($table, $field);
$key = new XMLDBKey('stylefk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('style'), 'style', array('id'));
add_key($table, $key);
}
if ($oldversion < 2011082200) {
// Doing a direct insert of the new artefact type instead of running upgrade_plugin(), in order to support the
// transition from old profile fields to the new socialprofile artefact in Mahara 1.10
if (!record_exists('artefact_installed_type', 'name', 'html', 'plugin', 'internal')) {
insert_record('artefact_installed_type', (object) array('name' => 'html', 'plugin' => 'internal'));
}
// Move the textbox blocktype into artefact/internal
set_field('blocktype_installed', 'artefactplugin', 'internal', 'name', 'textbox');
if ($data = check_upgrades("blocktype.internal/textbox")) {
upgrade_plugin($data);
}
}
if ($oldversion < 2011082300) {
// Add institution to view_access table
$table = new XMLDBTable('view_access');
$field = new XMLDBField('institution');
$field->setAttributes(XMLDB_TYPE_CHAR, 255, null, null);
if (!field_exists($table, $field)) {
add_field($table, $field);
// Add foreign key
$key = new XMLDBKey('institutionfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('institution'), 'institution', array('name'));
add_key($table, $key);
if (is_postgres()) {
// Update constraint checks
execute_sql('ALTER TABLE {view_access} DROP CONSTRAINT {view_access_check}');
execute_sql('ALTER TABLE {view_access} ADD CHECK (
(accesstype IS NOT NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL AND institution IS NULL ) OR
(accesstype IS NULL AND "group" IS NOT NULL AND usr IS NULL AND token IS NULL AND institution IS NULL ) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NOT NULL AND token IS NULL AND institution IS NULL ) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NOT NULL AND institution IS NULL ) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL AND institution IS NOT NULL))');
} else {
// MySQL doesn't support these types of constraints
}
}
}
if ($oldversion < 2011082400) {
// Add cron entry for cache cleanup
$cron = new StdClass();
$cron->callfunction = 'file_cleanup_old_cached_files';
$cron->minute = '0';
$cron->hour = '1';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
if ($oldversion < 2011082401) {
// Set config value for logged-in profile view access
/**
* This function sets the data in the database to the good format. This function
* have this properties:
* 1 - does not depend on the previous version: it has to discover which changes to apply
* 2 - (a corolary of 1) is idempotent, i.e, f(f(x)) = f(x)
* **/
function wrsqz_update_database()
{
//update shortanswer wirisCASForComputations field
$updates = 0;
$shortanswertable = new XMLDBTable('question_shortanswerwiris');
if (table_exists($shortanswertable)) {
$eqoptionfield = new XMLDBField('eqoption');
if (field_exists($shortanswertable, $eqoptionfield)) {
$saq = get_records('question_shortanswerwiris');
foreach ($saq as $question) {
if (trim($question->eqoption) != '') {
$decodedEqoption = array();
mb_parse_str($question->eqoption, $decodedEqoption);
if (isset($decodedEqoption['wirisCASForComputations'])) {
$wirisCASForComputations = $decodedEqoption['wirisCASForComputations'];
unset($decodedEqoption['wirisCASForComputations']);
$question->eqoption = http_build_query($decodedEqoption, null, '&');
if (!empty($question->options)) {
$options = unserialize($question->options);
} else {
$options = array();
}
$options['wirisCASForComputations'] = $wirisCASForComputations;
$question->options = serialize($options);
update_record('question_shortanswerwiris', $question);
$updates++;
}
}
}
}
}
if ($updates) {
echo utf8_htmlentities(translate('Updated shortanswer wirisCASForComputations field: ')) . $updates . utf8_htmlentities(translate(' records')) . '<br />';
}
}
function xmldb_data_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2006121300) {
/// Define field format to be added to data_comments
$table = new XMLDBTable('data_comments');
$field = new XMLDBField('format');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'content');
/// Launch add field format
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007022600) {
/// Define field asearchtemplate to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
/// Launch add field asearchtemplate
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007072200) {
require_once $CFG->dirroot . '/mod/data/lib.php';
// too much debug output
$db->debug = false;
data_update_grades();
$db->debug = true;
}
if ($result && $oldversion < 2007081400) {
/// Define field notification to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('notification');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null, 'editany');
/// Launch add field notification
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007081402) {
/// Define index type-dataid (not unique) to be added to data_fields
$table = new XMLDBTable('data_fields');
$index = new XMLDBIndex('type-dataid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('type', 'dataid'));
/// Launch add index type-dataid
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
/// Define index course (not unique) to be added to data
$table = new XMLDBTable('data');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
/// Launch add index course
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
}
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007101512) {
/// Launch add field asearchtemplate again if does not exists yet - reported on several sites
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
if (!field_exists($table, $field)) {
$result = $result && add_field($table, $field);
}
}
///Display a warning message about "Required Entries" fix from MDL-16999
if ($result && $oldversion < 2007101514) {
if (!get_config('data', 'requiredentriesfixflag')) {
set_config('requiredentriesfixflag', true, 'data');
// remove old flag
$databases = get_records_sql("SELECT d.*, c.fullname\n FROM {$CFG->prefix}data d, {$CFG->prefix}course c\n WHERE d.course = c.id\n AND (d.requiredentries > 0 OR d.requiredentriestoview > 0)\n ORDER BY c.fullname, d.name");
if (!empty($databases)) {
$a = new object();
$a->text = '';
foreach ($databases as $database) {
$a->text .= "<p>" . $database->fullname . " - " . $database->name . " (course id: " . $database->course . " - database id: " . $database->id . ")</p>";
}
notify(get_string('requiredentrieschanged', 'data', $a));
}
}
}
if ($result && $oldversion < 2007101515) {
// Upgrade all the data->notification currently being
// NULL to 0
$sql = "UPDATE {$CFG->prefix}data SET notification=0 WHERE notification IS NULL";
$result = execute_sql($sql);
$table = new XMLDBTable('data');
$field = new XMLDBField('notification');
// First step, Set NOT NULL
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'editany');
$result = $result && change_field_notnull($table, $field);
// Second step, Set default to 0
$result = $result && change_field_default($table, $field);
}
return $result;
//.........这里部分代码省略.........
请发表评论