本文整理汇总了PHP中rename_field函数的典型用法代码示例。如果您正苦于以下问题:PHP rename_field函数的具体用法?PHP rename_field怎么用?PHP rename_field使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename_field函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_format_slides_upgrade
function xmldb_format_slides_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2011043000) {
/// Add Background positon-x and position-y fields
$table = new xmldb_table('format_slides');
$field1 = new xmldb_field('image_pos_x', XMLDB_TYPE_TEXT);
$field2 = new xmldb_field('image_pos_y', XMLDB_TYPE_TEXT);
// Conditionally change fields
if ($dbman->field_exists($table, $field1)) {
rename_field($table, $field1, 'bg_position');
}
if ($dbman->field_exists($table, $field2)) {
rename_field($table, $field2, 'height');
}
// slides savepoint reached
upgrade_plugin_savepoint(true, 2011043000, 'format_slides');
}
return true;
}
示例2: xmldb_lesson_upgrade
function xmldb_lesson_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2006091802) {
/// Changing nullability of field response on table lesson_answers to null
$table = new XMLDBTable('lesson_answers');
$field = new XMLDBField('response');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'answer');
/// Launch change of nullability for field response
$result = $result && change_field_notnull($table, $field);
}
if ($result && $oldversion < 2006091803) {
/// Changing nullability of field useranswer on table lesson_attempts to null
$table = new XMLDBTable('lesson_attempts');
$field = new XMLDBField('useranswer');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'correct');
/// Launch change of nullability for field useranswer
$result = $result && change_field_notnull($table, $field);
}
if ($result && $oldversion < 2007020201) {
/// Changing nullability of field answer on table lesson_answers to null
$table = new XMLDBTable('lesson_answers');
$field = new XMLDBField('answer');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'timemodified');
/// Launch change of nullability for field answer
$result = $result && change_field_notnull($table, $field);
}
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007072201) {
$table = new XMLDBTable('lesson');
$field = new XMLDBField('usegrademax');
$field2 = new XMLDBField('usemaxgrade');
/// Rename lesson->usegrademax to lesson->usemaxgrade. Some old sites can have it incorrect. MDL-13177
if (field_exists($table, $field) && !field_exists($table, $field2)) {
/// Set field specs
$field->setAttributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0', 'ongoing');
/// Launch rename field usegrademax to usemaxgrade
$result = $result && rename_field($table, $field, 'usemaxgrade');
}
}
if ($result && $oldversion < 2008112601) {
require_once $CFG->dirroot . '/mod/lesson/lib.php';
// too much debug output
$db->debug = false;
lesson_update_grades();
$db->debug = true;
}
return $result;
}
示例3: wiki_merge_wikitable_fields
/**
* Private function.
*
* This function adds/modifies fields of ewiki 'wiki table' to look
* like nwiki 'wiki table'
*
* @return boolean. true for success and false in case of error
*/
function wiki_merge_wikitable_fields()
{
$table = new XMLDBTable('wiki');
$field = new XMLDBField('summary');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, null);
$result = rename_field($table, $field, 'intro');
$field = new XMLDBField('introformat');
$field->setAttributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro');
$result = $result && add_field($table, $field);
$field = new XMLDBField('editable');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1', 'timemodified');
$result = $result && add_field($table, $field);
$field = new XMLDBField('attach');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'editable');
$result = $result && add_field($table, $field);
$field = new XMLDBField('upload');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'attach');
$result = $result && add_field($table, $field);
$field = new XMLDBField('restore');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'upload');
$result = $result && add_field($table, $field);
$field = new XMLDBField('editor');
$field->setAttributes(XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, 'dfwiki', 'restore');
$result = $result && add_field($table, $field);
$field = new XMLDBField('groupmode');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'editor');
$result = $result && add_field($table, $field);
$field = new XMLDBField('studentmode');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'groupmode');
$result = $result && add_field($table, $field);
$field = new XMLDBField('teacherdiscussion');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'studentmode');
$result = $result && add_field($table, $field);
$field = new XMLDBField('studentdiscussion');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'teacherdiscussion');
$result = $result && add_field($table, $field);
$field = new XMLDBField('editanothergroup');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'studentdiscussion');
$result = $result && add_field($table, $field);
$field = new XMLDBField('editanotherstudent');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'editanothergroup');
$result = $result && add_field($table, $field);
return $result;
}
示例4: xmldb_enrol_authorize_upgrade
function xmldb_enrol_authorize_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2006111700) {
$table = new XMLDBTable('enrol_authorize');
if (!field_exists($table, new XMLDBField('refundinfo'))) {
$field = new XMLDBField('cclastfour');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'paymentmethod');
$result = $result && rename_field($table, $field, 'refundinfo');
}
}
if ($result && $oldversion < 2006112900) {
if (isset($CFG->an_login)) {
if (empty($CFG->an_login)) {
unset_config('an_login');
} else {
$result = $result && set_config('an_login', rc4encrypt($CFG->an_login), 'enrol/authorize') && unset_config('an_login');
}
}
if (isset($CFG->an_tran_key)) {
if (empty($CFG->an_tran_key)) {
unset_config('an_tran_key');
} else {
$result = $result && set_config('an_tran_key', rc4encrypt($CFG->an_tran_key), 'enrol/authorize') && unset_config('an_tran_key');
}
}
if (isset($CFG->an_password)) {
if (empty($CFG->an_password)) {
unset_config('an_password');
} else {
$result = $result && set_config('an_password', rc4encrypt($CFG->an_password), 'enrol/authorize') && unset_config('an_password');
}
}
}
return $result;
}
示例5: xmldb_attforblock_upgrade
function xmldb_attforblock_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 < 2008021904) {
//New version in version.php
global $USER;
if ($sessions = get_records('attendance_sessions', 'takenby', 0)) {
foreach ($sessions as $sess) {
if (count_records('attendance_log', 'attsid', $sess->id) > 0) {
$sess->takenby = $USER->id;
$sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
$sess->description = addslashes($sess->description);
$result = update_record('attendance_sessions', $sess) and $result;
}
}
}
}
if ($oldversion < 2008102401 and $result) {
$table = new XMLDBTable('attforblock');
$field = new XMLDBField('grade');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'name');
$result = $result && add_field($table, $field);
$table = new XMLDBTable('attendance_sessions');
$field = new XMLDBField('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field);
// $field = new XMLDBField('creator');
// $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
// $result = $result && change_field_unsigned($table, $field);
$field = new XMLDBField('sessdate');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'creator');
$result = $result && change_field_unsigned($table, $field);
$field = new XMLDBField('duration');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'sessdate');
$result = $result && add_field($table, $field);
$field = new XMLDBField('timetaken');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'takenby');
$result = $result && change_field_unsigned($table, $field);
$result = $result && rename_field($table, $field, 'lasttaken');
$field = new XMLDBField('takenby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lasttaken');
$result = $result && change_field_unsigned($table, $field);
$result = $result && rename_field($table, $field, 'lasttakenby');
$field = new XMLDBField('timemodified');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'lasttaken');
$result = $result && change_field_unsigned($table, $field);
$table = new XMLDBTable('attendance_log');
$field = new XMLDBField('attsid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field);
$field = new XMLDBField('studentid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'attsid');
$result = $result && change_field_unsigned($table, $field);
$field = new XMLDBField('statusid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'status');
$result = $result && add_field($table, $field);
$field = new XMLDBField('statusset');
$field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'statusid');
$result = $result && add_field($table, $field);
$field = new XMLDBField('timetaken');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'statusid');
$result = $result && add_field($table, $field);
$field = new XMLDBField('takenby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timetaken');
$result = $result && add_field($table, $field);
//Indexes
$index = new XMLDBIndex('statusid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
$result = $result && add_index($table, $index);
$index = new XMLDBIndex('attsid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
$result = $result && drop_index($table, $index);
$field = new XMLDBField('attsid');
//Rename field
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && rename_field($table, $field, 'sessionid');
$index = new XMLDBIndex('sessionid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
$result = $result && add_index($table, $index);
$table = new XMLDBTable('attendance_settings');
$field = new XMLDBField('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field);
$field = new XMLDBField('visible');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'grade');
$result = $result && add_field($table, $field);
$field = new XMLDBField('deleted');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible');
$result = $result && add_field($table, $field);
//Indexes
$index = new XMLDBIndex('visible');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
$result = $result && add_index($table, $index);
$index = new XMLDBIndex('deleted');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('deleted'));
//.........这里部分代码省略.........
示例6: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($col->max_length < 100) {
/// Changing precision of field lastname on table user to (100)
$table = new XMLDBTable('user');
$field = new XMLDBField('lastname');
$field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'firstname');
/// Launch change of precision for field lastname
$result = $result && change_field_precision($table, $field);
}
}
}
upgrade_main_savepoint($result, 2007012100);
}
if ($result && $oldversion < 2007012101) {
/// Changing precision of field lang on table course to (30)
$table = new XMLDBTable('course');
$field = new XMLDBField('lang');
$field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null, 'groupmodeforce');
/// Launch change of precision for field course->lang
$result = $result && change_field_precision($table, $field);
/// Changing precision of field lang on table user to (30)
$table = new XMLDBTable('user');
$field = new XMLDBField('lang');
$field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'country');
/// Launch change of precision for field user->lang
$result = $result && change_field_precision($table, $field);
upgrade_main_savepoint($result, 2007012101);
}
if ($result && $oldversion < 2007012400) {
/// Rename field access on table mnet_sso_access_control to accessctrl
$table = new XMLDBTable('mnet_sso_access_control');
$field = new XMLDBField('access');
$field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'allow', 'mnet_host_id');
/// Launch rename field accessctrl
$result = $result && rename_field($table, $field, 'accessctrl');
upgrade_main_savepoint($result, 2007012400);
}
if ($result && $oldversion < 2007012500) {
execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
upgrade_main_savepoint($result, 2007012500);
}
if ($result && $oldversion < 2007020400) {
/// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
/// Changing nullability of field ajax on table user to not null
$table = new XMLDBTable('user');
$field = new XMLDBField('ajax');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'htmleditor');
/// Launch change of nullability for field ajax
$result = $result && change_field_notnull($table, $field);
}
upgrade_main_savepoint($result, 2007020400);
}
if (!empty($CFG->rolesactive) && $result && $oldversion < 2007021401) {
/// create default logged in user role if not present - upgrade rom 1.7.x
if (empty($CFG->defaultuserroleid) or empty($CFG->guestroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
if (!get_records('role', 'shortname', 'user')) {
$userroleid = create_role(addslashes(get_string('authenticateduser')), 'user', addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
if ($userroleid) {
reset_role_capabilities($userroleid);
set_config('defaultuserroleid', $userroleid);
}
}
}
upgrade_main_savepoint($result, 2007021401);
}
if ($result && $oldversion < 2007021501) {
示例7: upgrade_18_broken_groups
/**
* Try to fix broken groups from 1.8 - at least partially
*/
function upgrade_18_broken_groups()
{
global $db;
/// Undo password -> enrolmentkey
$table = new XMLDBTable('groups');
$field = new XMLDBField('enrolmentkey');
$field->setAttributes(XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null, 'description');
rename_field($table, $field, 'password');
/// Readd courseid field
$table = new XMLDBTable('groups');
$field = new XMLDBField('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
add_field($table, $field);
/// and courseid key
$table = new XMLDBTable('groups');
$key = new XMLDBKey('courseid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
add_key($table, $key);
}
示例8: xmldb_stampcoll_upgrade
function xmldb_stampcoll_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2008021900) {
/// CONTRIB-288 Drop field "publish" from the table "stampcoll" and controll the access by capabilities
if ($collections = get_records('stampcoll', 'publish', '0')) {
// collections with publish set to STAMPCOLL_PUBLISH_NONE - prevent displaying from legacy:students
foreach ($collections as $collection) {
if ($cm = get_coursemodule_from_instance('stampcoll', $collection->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// find all roles with legacy:student
if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
foreach ($studentroles as $studentrole) {
// prevent students from viewing own stamps
assign_capability('mod/stampcoll:viewownstamps', CAP_PREVENT, $studentrole->id, $context->id);
}
}
}
}
}
if ($collections = get_records('stampcoll', 'publish', '2')) {
// collections with publish set to STAMPCOLL_PUBLISH_ALL - allow legacy:students to view others' stamps
foreach ($collections as $collection) {
if ($cm = get_coursemodule_from_instance('stampcoll', $collection->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// find all roles with legacy:student
if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
foreach ($studentroles as $studentrole) {
// allow students to view others' stamps
assign_capability('mod/stampcoll:viewotherstamps', CAP_ALLOW, $studentrole->id, $context->id);
}
}
}
}
}
$table = new XMLDBTable('stampcoll');
$field = new XMLDBField('publish');
$result = $result && drop_field($table, $field);
/// CONTRIB-289 Drop field "teachercancollect" in the table "mdl_stampcoll"
if ($collections = get_records('stampcoll', 'teachercancollect', '1')) {
// collections which allow teachers to collect stamps
foreach ($collections as $collection) {
if ($cm = get_coursemodule_from_instance('stampcoll', $collection->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// find all roles with legacy:teacher and legacy:editingteacher
// and allow them to collect stamps
if ($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
foreach ($teacherroles as $teacherrole) {
assign_capability('mod/stampcoll:collectstamps', CAP_ALLOW, $teacherrole->id, $context->id);
}
}
if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) {
foreach ($teacherroles as $teacherrole) {
assign_capability('mod/stampcoll:collectstamps', CAP_ALLOW, $teacherrole->id, $context->id);
}
}
}
}
}
$table = new XMLDBTable('stampcoll');
$field = new XMLDBField('teachercancollect');
$result = $result && drop_field($table, $field);
}
if ($result && $oldversion < 2008022002) {
/// Define field anonymous to be added to stampcoll
$table = new XMLDBTable('stampcoll');
$field = new XMLDBField('anonymous');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'displayzero');
$result = $result && add_field($table, $field);
/// Rename field comment on table stampcoll_stamps to text
$table = new XMLDBTable('stampcoll_stamps');
$field = new XMLDBField('comment');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
$result = $result && rename_field($table, $field, 'text');
/// Define field giver to be added to stampcoll_stamps
$table = new XMLDBTable('stampcoll_stamps');
$field = new XMLDBField('giver');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'userid');
$result = $result && add_field($table, $field);
/// Define key mdl_stampcoll_id_idx (unique) to be dropped form stampcoll
$table = new XMLDBTable('stampcoll');
$key = new XMLDBKey('mdl_stampcoll_id_idx');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('id'));
$result = $result && drop_key($table, $key);
/// Define index mdl_stampcoll_course_idx (not unique) to be dropped form stampcoll
$table = new XMLDBTable('stampcoll');
$index = new XMLDBIndex('mdl_stampcoll_course_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
$result = $result && drop_index($table, $index);
/// Define index course (not unique) to be added to stampcoll
$table = new XMLDBTable('stampcoll');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
$result = $result && add_index($table, $index);
/// Define index mdl_stampcoll_stamps_userid_idx (not unique) to be dropped form stampcoll_stamps
$table = new XMLDBTable('stampcoll_stamps');
$index = new XMLDBIndex('mdl_stampcoll_stamps_userid_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
$result = $result && drop_index($table, $index);
//.........这里部分代码省略.........
示例9: xmldb_enrol_authorize_upgrade
function xmldb_enrol_authorize_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2006111700) {
$table = new XMLDBTable('enrol_authorize');
if (!field_exists($table, new XMLDBField('refundinfo'))) {
$field = new XMLDBField('cclastfour');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'paymentmethod');
$result = $result && rename_field($table, $field, 'refundinfo');
}
}
if ($result && $oldversion < 2006112900) {
if (isset($CFG->an_login)) {
if (empty($CFG->an_login)) {
unset_config('an_login');
} else {
$result = $result && set_config('an_login', rc4encrypt($CFG->an_login), 'enrol/authorize') && unset_config('an_login');
}
}
if (isset($CFG->an_tran_key)) {
if (empty($CFG->an_tran_key)) {
unset_config('an_tran_key');
} else {
$result = $result && set_config('an_tran_key', rc4encrypt($CFG->an_tran_key), 'enrol/authorize') && unset_config('an_tran_key');
}
}
if (isset($CFG->an_password)) {
if (empty($CFG->an_password)) {
unset_config('an_password');
} else {
$result = $result && set_config('an_password', rc4encrypt($CFG->an_password), 'enrol/authorize') && unset_config('an_password');
}
}
}
if ($result && $oldversion < 2006112903) {
/// enrol_authorize.transid
/// Define index transid (not unique) to be dropped form enrol_authorize
$table = new XMLDBTable('enrol_authorize');
$index = new XMLDBIndex('transid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('transid'));
drop_index($table, $index);
/// Changing precision of field transid on table enrol_authorize to (20)
$table = new XMLDBTable('enrol_authorize');
$field = new XMLDBField('transid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'userid');
change_field_precision($table, $field);
/// Launch add index transid again
$table = new XMLDBTable('enrol_authorize');
$index = new XMLDBIndex('transid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('transid'));
add_index($table, $index);
/// enrol_authorize_refunds.transid
/// Define index transid (not unique) to be dropped form enrol_authorize_refunds
$table = new XMLDBTable('enrol_authorize_refunds');
$index = new XMLDBIndex('transid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('transid'));
drop_index($table, $index);
/// Changing precision of field transid on table enrol_authorize_refunds to (20)
$table = new XMLDBTable('enrol_authorize_refunds');
$field = new XMLDBField('transid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, null, '0', 'amount');
change_field_precision($table, $field);
/// Launch add index transid again
$table = new XMLDBTable('enrol_authorize_refunds');
$index = new XMLDBIndex('transid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('transid'));
add_index($table, $index);
}
return $result;
}
示例10: xmldb_scorm_upgrade
//.........这里部分代码省略.........
$table->addKeyInfo('scorm_rulecond_ruleconditionsid', XMLDB_KEY_FOREIGN, array('ruleconditionsid'), 'scorm_seq_ruleconds', array('id'));
/// Launch create table for scorm_seq_rulecond
$result = $result && create_table($table);
/// Define table scorm_seq_rolluprule to be created
$table = new XMLDBTable('scorm_seq_rolluprule');
/// Adding fields to table scorm_seq_rolluprule
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('childactivityset', XMLDB_TYPE_CHAR, '15', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('minimumcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('minimumpercent', XMLDB_TYPE_FLOAT, '11, 4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0.0000');
$table->addFieldInfo('conditioncombination', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, null, null, 'all');
$table->addFieldInfo('action', XMLDB_TYPE_CHAR, '15', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table scorm_seq_rolluprule
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('scorm_rolluprule_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'id'));
$table->addKeyInfo('scorm_rolluprule_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
/// Launch create table for scorm_seq_rolluprule
$result = $result && create_table($table);
/// Define table scorm_seq_rolluprulecond to be created
$table = new XMLDBTable('scorm_seq_rolluprulecond');
/// Adding fields to table scorm_seq_rolluprulecond
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('rollupruleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('operator', XMLDB_TYPE_CHAR, '5', null, XMLDB_NOTNULL, null, null, null, 'noOp');
$table->addFieldInfo('cond', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table scorm_seq_rolluprulecond
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('scorm_rulluprulecond_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'rollupruleid', 'id'));
$table->addKeyInfo('scorm_rolluprulecond_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
$table->addKeyInfo('scorm_rolluprulecond_rolluprule', XMLDB_KEY_FOREIGN, array('rollupruleid'), 'scorm_seq_rolluprule', array('id'));
/// Launch create table for scorm_seq_rolluprulecond
$result = $result && create_table($table);
}
//Adding new field to table scorm
if ($result && $oldversion < 2007011800) {
/// Define field format to be added to data_comments
$table = new XMLDBTable('scorm');
$field = new XMLDBField('md5_result');
$field->setAttributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, null, null, null);
/// Launch add field format
$result = $result && add_field($table, $field);
$field = new XMLDBField('external');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007012400) {
/// Rename field external on table scorm to updatefreq
$table = new XMLDBTable('scorm');
$field = new XMLDBField('external');
if (field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'maxattempt');
/// Launch rename field updatefreq
$result = $result && rename_field($table, $field, 'updatefreq');
} else {
$field = new XMLDBField('updatefreq');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'maxattempt');
$result = $result && add_field($table, $field);
}
/// Rename field md5_result on table scorm to md5hash
$field = new XMLDBField('md5_result');
if (field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, null, 'updatefreq');
/// Launch rename field md5hash
$result = $result && rename_field($table, $field, 'md5hash');
} else {
$field = new XMLDBField('md5hash');
$field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, '', 'updatefreq');
$result = $result && add_field($table, $field);
}
}
if ($result && $oldversion < 2007031300) {
if ($scorms = get_records('scorm')) {
foreach ($scorms as $scorm) {
if ($scoes = get_records('scorm_scoes', 'scorm', $scorm->id)) {
foreach ($scoes as $sco) {
if ($tracks = get_records('scorm_scoes_track', 'scoid', $sco->id)) {
foreach ($tracks as $track) {
$element = preg_replace('/\\.N(\\d+)\\./', ".\$1.", $track->element);
if ($track->element != $element) {
$track->element = $element;
update_record('scorm_scoes_track', $track);
}
}
}
}
}
}
}
}
if ($result && $oldversion < 2007081001) {
require_once $CFG->dirroot . '/mod/scorm/lib.php';
// too much debug output
$db->debug = false;
scorm_update_grades();
$db->debug = true;
}
return $result;
}
示例11: invoke
//.........这里部分代码省略.........
/// 39th test. Renaming one index
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$index = new XMLDBIndex('anyname');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'course'));
$test->sql = $table->getRenameIndexSQL($CFG->dbtype, $CFG->prefix, $index, 'newnamefortheindex', true);
$test->status = rename_index($table, $index, 'newnamefortheindex', false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['rename index (experimental. DO NOT USE IT)'] = $test;
}
/// 40th test. Renaming one key
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('anyname');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
$test->sql = $table->getRenameKeySQL($CFG->dbtype, $CFG->prefix, $key, 'newnameforthekey', true);
$test->status = rename_key($table, $key, 'newnameforthekey', false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['rename key (experimental. DO NOT USE IT)'] = $test;
}
/// 41th test. Renaming one field
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$field = new XMLDBField('type');
$field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
$test->sql = $table->getRenameFieldSQL($CFG->dbtype, $CFG->prefix, $field, 'newnameforthefield', true);
$test->status = rename_field($table, $field, 'newnameforthefield', false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['rename field'] = $test;
}
/// 42th test. Renaming one table
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$test->sql = $table->getRenameTableSQL($CFG->dbtype, $CFG->prefix, 'newnameforthetable', true);
$test->status = rename_table($table, 'newnameforthetable', false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['rename table'] = $test;
}
/// 43th test. Add enum to field containing enum
if ($test->status) {
/// Add enum to field containing enum
$table->setName('newnameforthetable');
$field = new XMLDBField('newnameforthefield');
$field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
/// Get SQL code and execute it
$test = new stdClass();
$test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
$test->status = change_field_enum($table, $field, false, false);
/// Let's see if the constraint exists to alter results
if (check_constraint_exists($table, $field)) {
$test->sql = array('Nothing executed. Enum already exists. Correct.');
} else {
$test->status = false;
}
示例12: install_group_db
function install_group_db()
{
global $CFG, $db;
$group_version = '';
// Get code version
require "{$CFG->dirroot}/group/version.php";
print_heading('group');
$db->debug = true;
$result = true;
/// 1) Set groups->description to NULLable
/// Changing nullability of field description on table groups to null
$table = new XMLDBTable('groups');
$field = new XMLDBField('description');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'name');
/// Launch change of nullability for field description
$result = $result && change_field_notnull($table, $field);
/// 2) Rename the groups->password field to enrolmentkey
/// Rename field password on table groups to enrolmentkey.
$field = new XMLDBField('password');
$field->setAttributes(XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null, 'description');
/// Launch rename field password
$result = $result && rename_field($table, $field, 'enrolmentkey');
/// 3) Change the groups->lang from 10cc to 30cc
/// Changing precision of field lang on table groups to (30)
$field = new XMLDBField('lang');
$field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'enrolmentkey');
/// Launch change of precision for field lang
$result = $result && change_field_precision($table, $field);
/// 4) Change the groups->hidepicture from int(2) to int(1)
/// Changing precision of field hidepicture on table groups to (1)
$field = new XMLDBField('hidepicture');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'picture');
/// Launch change of precision for field hidepicture
$result = $result && change_field_precision($table, $field);
/// 5) Add one UNIQUE index on groups_members (groupid, userid)
// first remove duplicates
$sql = "SELECT cm1.id\n FROM {$CFG->prefix}groups_members cm1, {$CFG->prefix}groups_members cm2\n WHERE cm1.groupid = cm2.groupid AND cm1.userid = cm2.userid AND cm1.id <> cm2.id\n ORDER BY cm1.id DESC";
while ($duplicates = get_records_sql($sql, 0, 1)) {
$first = reset($duplicates);
delete_records('groups_members', 'id', $first->id);
}
/// Define index groupid-courseid (unique) to be added to groups_members
$table = new XMLDBTable('groups_members');
$index = new XMLDBIndex('groupid-courseid');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('groupid', 'userid'));
/// Launch add index groupid-courseid
$result = $result && add_index($table, $index);
/// 6) Add the whole groups_groupings table (as is in 1.8.2+)
/// Define table groups_groupings to be created
$table = new XMLDBTable('groups_groupings');
/// Adding fields to table groups_groupings
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('viewowngroup', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
$table->addFieldInfo('viewallgroupsmembers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('viewallgroupsactivities', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('teachersgroupmark', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('teachersgroupview', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('teachersoverride', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('teacherdeletable', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
/// Adding keys to table groups_groupings
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Launch create table for groups_groupings
$result = $result && create_table($table);
/// 7) Add the whole groups_courses_groups table (as is in 1.8.2+)
/// Define table groups_courses_groups to be created
$table = new XMLDBTable('groups_courses_groups');
/// Adding fields to table groups_courses_groups
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table groups_courses_groups
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
/// Adding indexes to table groups_courses_groups
$table->addIndexInfo('courseid-groupid', XMLDB_INDEX_UNIQUE, array('courseid', 'groupid'));
/// Launch create table for groups_courses_groups
$result = $result && create_table($table);
/// 8) Add the whole groups_courses_groupings table (as is in 1.8.2+)
/// Define table groups_courses_groupings to be created
$table = new XMLDBTable('groups_courses_groupings');
/// Adding fields to table groups_courses_groupings
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('groupingid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table groups_courses_groupings
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('groupingid', XMLDB_KEY_FOREIGN, array('groupingid'), 'groups_groupings', array('id'));
/// Adding indexes to table groups_courses_groupings
$table->addIndexInfo('courseid-groupingid', XMLDB_INDEX_UNIQUE, array('courseid', 'groupingid'));
/// Launch create table for groups_courses_groupings
$result = $result && create_table($table);
/// 9) Add the whole groups_groupings_groups table (as is in 1.8.2+)
/// Define table groups_groupings_groups to be created
$table = new XMLDBTable('groups_groupings_groups');
/// Adding fields to table groups_groupings_groups
//.........这里部分代码省略.........
示例13: xmldb_geogebra_upgrade
/**
* Execute geogebra upgrade from the given old version
*
* @param int $oldversion
* @return bool
*/
function xmldb_geogebra_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
// loads ddl manager and xmldb classes
if ($oldversion < 2012030100) {
//Add grade field
$table = new XMLDBTable('geogebra');
$field = new XMLDBField('grade');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'showsubmit');
$result = $result && add_field($table, $field);
//Add autograde field
$field = new XMLDBField('autograde');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'grade');
$result = $result && add_field($table, $field);
//Delete maxgrade field
$field = new XMLDBField('maxgrade');
$result = $result && drop_field($table, $field);
//Make maxattempts signed
$field = new XMLDBField('maxattempts');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, null, null, null, '-1', 'autograde');
$result = $result && change_field_unsigned($table, $field);
//Add gradecomment field
$table = new XMLDBTable('geogebra_attempts');
$field = new XMLDBField('gradecomment');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'vars');
$result = $result && add_field($table, $field);
}
if ($oldversion < 2012030101) {
$table = new XMLDBTable('geogebra_attempts');
$field = new XMLDBField('dateteacher');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'finished');
$result = $result && add_field($table, $field);
}
if ($oldversion < 2012082100) {
$table = new XMLDBTable('geogebra');
$field = new XMLDBField('url');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'intro');
$result = $result && change_field_precision($table, $field);
$table = new XMLDBTable('geogebra_attempts');
$field = new XMLDBField('gradecomment');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, false, null, null, null, null, 'vars');
$result = $result && change_field_notnull($table, $field);
$field = new XMLDBField('date');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$result = $result && rename_field($table, $field, 'datestudent');
}
if ($oldversion < 2011122902) {
/// Define field introformat to be added to geogebra
$table = new xmldb_table('geogebra');
$field = new xmldb_field('introformat');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
/// Launch add field introformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('geogebra', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat');
foreach ($rs as $f) {
$f->intro = text_to_html($f->intro, false, false, true);
$f->introformat = FORMAT_HTML;
$DB->update_record('geogebra', $f);
upgrade_set_timeout();
}
$rs->close();
}
/// geogebra savepoint reached
upgrade_mod_savepoint(true, 2011122902, 'geogebra');
}
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2012042700) {
require_once "{$CFG->dirroot}/mod/geogebra/db/upgradelib.php";
// Add upgrading code from 1.9 (+ new file storage system)
// @TODO: test it!!!!
geogebra_migrate_files();
// geogebra savepoint reached
upgrade_mod_savepoint(true, 2012042700, 'geogebra');
}
if ($oldversion < 2013050600) {
// @TODO: test it!!!!
//Add atrributes field
$table = new xmldb_table('geogebra');
$field = new xmldb_field('attributes');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'url');
$dbman->add_field($table, $field);
$rs = $DB->get_recordset('geogebra');
foreach ($rs as $f) {
parse_str($f->url, $parsedVarsURL);
if (array_key_exists('filename', $parsedVarsURL)) {
// From Moodle 2, URL field only contains information about the GGB file location
$f->url = $parsedVarsURL['filename'];
// Remove filename from parsedVarsURL array (to avoid save twice)
unset($parsedVarsURL['filename']);
//.........这里部分代码省略.........
示例14: xmldb_studynotes_upgrade
function xmldb_studynotes_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2009032400) {
error("Version too old to be upgraded. Please delete the module and re-install it.");
}
if ($result && $oldversion < 2009041603) {
/// Define table studynotes_uploads to be created
$table = new XMLDBTable('studynotes_uploads');
/// Adding fields to table studynotes_uploads
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('type', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('user_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('topic_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('modified', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null, null, '0');
/// Adding keys to table studynotes_uploads
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Launch create table for studynotes_uploads
$result = $result && create_table($table);
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_cards');
$field = new XMLDBField('user');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'user_id');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_cards');
$field = new XMLDBField('index');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
if ($CFG->dbfamily == "mysql" || $CFG->dbfamily == "mysqli") {
if (field_exists($table, $field)) {
$query = "ALTER TABLE {$CFG->prefix}studynotes_cards CHANGE `index` index_num BIGINT( 11 ) UNSIGNED NOT NULL";
$db->Execute($query);
}
} else {
/// Launch rename field
$result = $result && rename_field($table, $field, 'index_num');
}
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_cards');
$field = new XMLDBField('level');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'level_num');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_flashcards');
$field = new XMLDBField('user');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'user_id');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_flashcards');
$field = new XMLDBField('number');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'num');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_flashcards');
$field = new XMLDBField('level');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'level_num');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_groups');
$field = new XMLDBField('access');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'access_num');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_markers');
$field = new XMLDBField('user');
$field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, null, null, null, null, '0', null);
/// Launch rename field
$result = $result && rename_field($table, $field, 'user_id');
}
/// Rename field
if ($result && $oldversion < 2009042400) {
$table = new XMLDBTable('studynotes_markers');
$field = new XMLDBField('range');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
if ($CFG->dbfamily == "mysql" || $CFG->dbfamily == "mysqli") {
//.........这里部分代码省略.........
示例15: xmldb_certificate_upgrade
function xmldb_certificate_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2007102806) {
/// Add new fields to certificate table
$table = new XMLDBTable('certificate');
$field = new XMLDBField('printoutcome');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'gradefmt');
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007102800) {
/// Add new fields to certificate table
$table = new XMLDBTable('certificate');
$field = new XMLDBField('reportcert');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'savecert');
$result = $result && add_field($table, $field);
$table = new XMLDBTable('certificate_issues');
$field = new XMLDBField('reportgrade');
$field->setAttributes(XMLDB_TYPE_CHAR, '10', null, null, null, null, null, null, 'certdate');
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007061300) {
/// Add new fields to certificate table
$table = new XMLDBTable('certificate');
$field = new XMLDBField('emailothers');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'emailteachers');
$result = $result && add_field($table, $field);
$table = new XMLDBTable('certificate');
$field = new XMLDBField('printhours');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'gradefmt');
$result = $result && add_field($table, $field);
$table = new XMLDBTable('certificate');
$field = new XMLDBField('lockgrade');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'printhours');
$result = $result && add_field($table, $field);
$table = new XMLDBTable('certificate');
$field = new XMLDBField('requiredgrade');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lockgrade');
$result = $result && add_field($table, $field);
/// Rename field save to savecert
$field = new XMLDBField('save');
if (field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'emailothers');
/// Launch rename field savecert
$result = $result && rename_field($table, $field, 'savecert');
} else {
$field = new XMLDBField('savecert');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'emailothers');
$result = $result && add_field($table, $field);
}
}
if ($result && $oldversion < 2007061301) {
$table = new XMLDBTable('certificate_linked_modules');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
$table->addFieldInfo('certificate_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$table->addFieldInfo('linkid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'certificate_id');
$table->addFieldInfo('linkgrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'linkid');
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'linkgrade');
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('certificate_id', XMLDB_INDEX_NOTUNIQUE, array('certificate_id'));
$table->addIndexInfo('linkid', XMLDB_INDEX_NOTUNIQUE, array('linkid'));
$result = create_table($table);
if ($result) {
require_once $CFG->dirroot . '/mod/certificate/lib.php';
$result = certificate_upgrade_grading_info();
}
}
if ($result && $oldversion < 2007061302) {
$table = new XMLDBTable('certificate_linked_modules');
$field = new XMLDBField('linkid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'certificate_id');
$result = change_field_unsigned($table, $field);
}
if ($result && $oldversion < 2008080902) {
$table = new XMLDBTable('certificate');
$field = new XMLDBField('requiredcertification');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'printhours');
$result = add_field($table, $field);
}
if ($result && $oldversion < 2008080903) {
$table = new XMLDBTable('certificate');
$field = new XMLDBField('setcertification');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'printhours');
$result = add_field($table, $field);
}
if ($result && $oldversion < 2008080904) {
/// Add new fields to certificate table if they dont already exist
$table = new XMLDBTable('certificate');
$field = new XMLDBField('intro');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'name');
if (!field_exists($table, $field)) {
$result = $result && add_field($table, $field);
}
}
if ($result && $oldversion < 2008080905) {
$table = new XMLDBTable('certificate');
$field = new XMLDBField('setcertification');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'printhours');
$result = change_field_type($table, $field);
//.........这里部分代码省略.........