本文整理汇总了PHP中drop_key函数的典型用法代码示例。如果您正苦于以下问题:PHP drop_key函数的具体用法?PHP drop_key怎么用?PHP drop_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drop_key函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_artefact_file_upgrade
//.........这里部分代码省略.........
add_field($table, $field);
}
if ($oldversion < 2007042500) {
// migrate everything we had to change to make mysql happy
execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
}
if ($oldversion < 2008091100) {
$table = new XMLDBTable('artefact_file_files');
$field = new XMLDBField('fileid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
add_field($table, $field);
execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL");
}
if ($oldversion < 2008101602) {
$table = new XMLDBTable('artefact_file_files');
$field = new XMLDBField('filetype');
$field->setAttributes(XMLDB_TYPE_TEXT);
add_field($table, $field);
// Guess mime type for existing files
$fileartefacts = get_records_sql_array('
SELECT
a.artefacttype, f.artefact, f.oldextension, f.fileid
FROM
{artefact} a,
{artefact_file_files} f
WHERE
a.id = f.artefact
', array());
require_once get_config('libroot') . 'file.php';
if ($fileartefacts) {
foreach ($fileartefacts as $a) {
$type = null;
if ($a->artefacttype == 'image') {
$size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
$type = $size['mime'];
} else {
if ($a->artefacttype == 'profileicon') {
$size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid);
$type = $size['mime'];
} else {
if ($a->artefacttype == 'file') {
$type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
}
}
}
if ($type) {
set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact);
}
}
}
delete_records('config', 'field', 'pathtofile');
}
if ($oldversion < 2008101701) {
if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
$olddata = unserialize($data);
$newdata = array();
foreach ($olddata as $d) {
if ($d == 'mov') {
$newdata[] = 'quicktime';
} else {
if ($d == 'mp4') {
$newdata[] = 'mp4_video';
} else {
if ($d != 'mpg') {
$newdata[] = $d;
}
}
}
}
set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata));
}
}
if ($oldversion < 2009021200) {
$table = new XMLDBTable('artefact_file_mime_types');
$key = new XMLDBKey('artefilemimetype_des_fk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
drop_key($table, $key);
$table = new XMLDBTable('artefact_file_file_types');
drop_table($table);
PluginArtefactFile::resync_filetype_list();
}
if ($oldversion < 2009021301) {
// IE has been uploading jpegs with the image/pjpeg mimetype,
// which is not recognised as an image by the download script.
// Fix all existing jpegs in the db:
set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg');
// This won't happen again because we now read the contents of the
// uploaded file to detect image artefacts, and overwrite the mime
// type declared by the browser if we see an image.
}
if ($oldversion < 2009033000) {
if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
}
}
return $status;
}
示例2: upgrade_18_groups_drop_keys_indexes
/**
* Drop keys & indexes for groups upgrade from 1.8.*
*/
function upgrade_18_groups_drop_keys_indexes()
{
$result = true;
/// 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'));
$result = $result && drop_index($table, $index);
/// Define key courseid (foreign) to be added to groups_courses_groups
$table = new XMLDBTable('groups_courses_groups');
$key = new XMLDBKey('courseid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$result = $result && drop_key($table, $key);
/// Define key groupid (foreign) to be added to groups_courses_groups
$table = new XMLDBTable('groups_courses_groups');
$key = new XMLDBKey('groupid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
$result = $result && drop_key($table, $key);
/// Define index courseid-groupid (unique) to be added to groups_courses_groups
$table = new XMLDBTable('groups_courses_groups');
$index = new XMLDBIndex('courseid-groupid');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('courseid', 'groupid'));
$result = $result && drop_index($table, $index);
/// Define key courseid (foreign) to be added to groups_courses_groupings
$table = new XMLDBTable('groups_courses_groupings');
$key = new XMLDBKey('courseid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$result = $result && drop_key($table, $key);
/// Define key groupingid (foreign) to be added to groups_courses_groupings
$table = new XMLDBTable('groups_courses_groupings');
$key = new XMLDBKey('groupingid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('groupingid'), 'groups_groupings', array('id'));
$result = $result && drop_key($table, $key);
/// Define index courseid-groupingid (unique) to be added to groups_courses_groupings
$table = new XMLDBTable('groups_courses_groupings');
$index = new XMLDBIndex('courseid-groupingid');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('courseid', 'groupingid'));
$result = $result && drop_index($table, $index);
/// Define key groupingid (foreign) to be added to groups_groupings_groups
$table = new XMLDBTable('groups_groupings_groups');
$key = new XMLDBKey('groupingid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('groupingid'), 'groups_groupings', array('id'));
$result = $result && drop_key($table, $key);
/// Define key groupid (foreign) to be added to groups_groupings_groups
$table = new XMLDBTable('groups_groupings_groups');
$key = new XMLDBKey('groupid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
$result = $result && drop_key($table, $key);
/// Define index groupingid-groupid (unique) to be added to groups_groupings_groups
$table = new XMLDBTable('groups_groupings_groups');
$index = new XMLDBIndex('groupingid-groupid');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('groupingid', 'groupid'));
$result = $result && drop_index($table, $index);
return $result;
}
示例3: xmldb_core_upgrade
//.........这里部分代码省略.........
// Now insert a record for it in view_layout_rows_columns, to represent its one row
insert_record('view_layout_rows_columns', (object) array('viewlayout' => $layout->id, 'row' => 1, 'columns' => $colsid));
// And also it needs a record in usr_custom_layout saying it belongs to the root user
insert_record('usr_custom_layout', (object) array('usr' => 0, 'layout' => $layout->id));
}
log_debug('7. Drop the obsolete view_layout.columns and view_layout.widths fields');
$table = new XMLDBTable('view_layout');
$field = new XMLDBField('columns');
drop_field($table, $field);
$field = new XMLDBField('widths');
drop_field($table, $field);
log_debug('8. Update default values for tables view_layout, view_layout_columns and view_layout_rows_columns');
install_view_layout_defaults();
log_debug('9. Update the table "block_instance"');
$table = new XMLDBTable('block_instance');
$field = new XMLDBField('row');
$field->setAttributes(XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, null, null, 1);
// This one tends to take a while...
set_time_limit(30);
add_field($table, $field);
set_time_limit(30);
// Refactor the block_instance.viewcolumnorderuk key so it includes row.
$key = new XMLDBKey('viewcolumnorderuk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('view', 'column', 'order'));
// If this particular site has been around since before Mahara 1.2, this
// will actually have been created as a unique index rather than a unique
// key, so check for that first.
$indexname = find_index_name($table, $key);
if (preg_match('/uix$/', $indexname)) {
$index = new XMLDBIndex($indexname);
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('view', 'column', 'order'));
drop_index($table, $index);
} else {
drop_key($table, $key);
}
$key = new XMLDBKey('viewrowcolumnorderuk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('view', 'row', 'column', 'order'));
add_key($table, $key);
log_debug('10. Add a "numrows" column to the views table.');
// The default value of "1" will be correct
// for all existing views, because they're using the old one-row layout style
$table = new XMLDBTable('view');
$field = new XMLDBField('numrows');
$field->setAttributes(XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
log_debug('11. Update the table "view_rows_columns" for existing pages');
execute_sql('INSERT INTO {view_rows_columns} ("view", "row", "columns") SELECT v.id, 1, v.numcolumns FROM {view} v');
}
if ($oldversion < 2013091900) {
// Create skin table...
$table = new XMLDBTable('skin');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('title', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT);
$table->addFieldInfo('owner', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('type', XMLDB_TYPE_CHAR, 10, 'private', XMLDB_NOTNULL);
$table->addFieldInfo('viewskin', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('bodybgimg', XMLDB_TYPE_INTEGER, 10);
$table->addFieldInfo('viewbgimg', XMLDB_TYPE_INTEGER, 10);
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME);
$table->addFieldInfo('mtime', XMLDB_TYPE_DATETIME);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('ownerfk', XMLDB_KEY_FOREIGN, array('owner'), 'usr', array('id'));
create_table($table);
// Create skin_favorites table...
$table = new XMLDBTable('skin_favorites');
示例4: xmldb_main_upgrade
//.........这里部分代码省略.........
/// Launch add key tagid
$result = $result && add_key($table, $key);
upgrade_main_savepoint($result, 2007082800);
}
if ($result && $oldversion < 2007082801) {
/// Define table user_private_key to be created
$table = new XMLDBTable('user_private_key');
/// Adding fields to table user_private_key
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('script', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('value', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table user_private_key
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
/// Adding indexes to table user_private_key
$table->addIndexInfo('script-value', XMLDB_INDEX_NOTUNIQUE, array('script', 'value'));
/// Launch create table for user_private_key
$result = $result && create_table($table);
upgrade_main_savepoint($result, 2007082801);
}
/// Going to modify the applicationid from int(1) to int(10). Dropping and
/// re-creating the associated keys/indexes is mandatory to be cross-db. MDL-11042
if ($result && $oldversion < 2007082803) {
/// Define key applicationid (foreign) to be dropped form mnet_host
$table = new XMLDBTable('mnet_host');
$key = new XMLDBKey('applicationid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
/// Launch drop key applicationid
$result = $result && drop_key($table, $key);
/// Changing type of field applicationid on table mnet_host to int
$field = new XMLDBField('applicationid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'last_log_id');
/// Launch change of type for field applicationid
$result = $result && change_field_type($table, $field);
/// Define key applicationid (foreign) to be added to mnet_host
$key = new XMLDBKey('applicationid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
/// Launch add key applicationid
$result = $result && add_key($table, $key);
upgrade_main_savepoint($result, 2007082803);
}
if ($result && $oldversion < 2007090503) {
/// Define field aggregatesubcats to be added to grade_categories
$table = new XMLDBTable('grade_categories');
$field = new XMLDBField('aggregatesubcats');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'aggregateoutcomes');
if (!field_exists($table, $field)) {
/// Launch add field aggregateonlygraded
$result = $result && add_field($table, $field);
}
/// Define field aggregateonlygraded to be added to grade_categories
$table = new XMLDBTable('grade_categories');
$field = new XMLDBField('aggregateonlygraded');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
if (!field_exists($table, $field)) {
/// Launch add field aggregateonlygraded
$result = $result && add_field($table, $field);
}
/// Define field aggregatesubcats to be added to grade_categories_history
$table = new XMLDBTable('grade_categories_history');
$field = new XMLDBField('aggregatesubcats');
示例5: invoke
//.........这里部分代码省略.........
/// 31th test. Adding one unique key to the table
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('id-course-grade');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
$test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
$test->status = add_key($table, $key, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['add unique key'] = $test;
}
/// 32th test. Adding one foreign+unique key to the table
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
$test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
$test->status = add_key($table, $key, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['add foreign+unique key'] = $test;
}
/// 33th test. Drop one key
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
$test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
$test->status = drop_key($table, $key, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['drop foreign+unique key'] = $test;
}
/// 34th test. Adding one foreign key to the table
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
$test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
$test->status = add_key($table, $key, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['add foreign key'] = $test;
}
/// 35th test. Drop one foreign key
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
$test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
$test->status = drop_key($table, $key, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['drop foreign key'] = $test;
}
/// 36th test. Adding one complex enum field
示例6: uninstall_from_xmldb_file
/**
* This function will load one entire XMLDB file, generating all the needed
* SQL statements, specific for each RDBMS ($CFG->dbtype) and, finally, it
* will execute all those statements against the DB, to drop all tables.
*
* @param $file full path to the XML file to be used
* @return boolean (true on success, false on error)
*/
function uninstall_from_xmldb_file($file)
{
global $CFG, $db;
$status = true;
$xmldb_file = new XMLDBFile($file);
if (!$xmldb_file->fileExists()) {
throw new InstallationException($xmldb_file->path . " doesn't exist.");
}
$loaded = $xmldb_file->loadXMLStructure();
if (!$loaded || !$xmldb_file->isLoaded()) {
throw new InstallationException("Could not load " . $xmldb_file->path);
}
$structure = $xmldb_file->getStructure();
if ($tables = array_reverse($structure->getTables())) {
foreach ($tables as $table) {
// for MySQL, skip dropping indices and keys
// as they will be dropped when the table is dropped
if (!is_mysql() && ($indexes = $table->getIndexes())) {
foreach ($indexes as $index) {
if ($index->getName() == 'usernameuk' && is_postgres()) {
// this is a giant hack, but adodb cannot handle resolving
// the column for indexes that include lower() or something similar
// and i can't find a nice way to do it.
execute_sql('DROP INDEX {usr_use_uix}');
continue;
}
drop_index($table, $index);
}
}
if (!is_mysql() && ($keys = $table->getKeys())) {
$sortkeys = array();
foreach ($keys as $key) {
$sortkeys[] = $key->type;
}
array_multisort($sortkeys, SORT_DESC, $keys);
foreach ($keys as $key) {
if (!is_postgres() && $key->type != XMLDB_KEY_FOREIGN && $key->type != XMLDB_KEY_FOREIGN_UNIQUE) {
// Skip keys for MySQL because these will be
// dropped when the table is dropped
continue;
}
drop_key($table, $key);
}
}
drop_table($table);
}
}
return true;
}
示例7: xmldb_assignment_type_onlinejudge_upgrade
function xmldb_assignment_type_onlinejudge_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2010032700) {
/// Define field ratiope to be added to assignment_oj
$table = new XMLDBTable('assignment_oj');
$field = new XMLDBField('ratiope');
$field->setAttributes(XMLDB_TYPE_NUMBER, '20, 10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0.0', 'compileonly');
/// Launch add field ratiope
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2010040701) {
/// Define index judged (not unique) to be added to assignment_oj_submissions
$table = new XMLDBTable('assignment_oj_submissions');
$index = new XMLDBIndex('judged');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('judged'));
/// Launch add index judged
$result = $result && add_index($table, $index);
/// Define index judgetime (not unique) to be added to assignment_oj_results
$table = new XMLDBTable('assignment_oj_results');
$index = new XMLDBIndex('judgetime');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('judgetime'));
/// Launch add index judgetime
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2010042800) {
/// Define field duejudge to be dropped from assignment_oj
$table = new XMLDBTable('assignment_oj');
$field = new XMLDBField('duejudge');
/// Launch drop field duejudge
$result = $result && drop_field($table, $field);
/// Define key test (foreign) to be dropped form assignment_oj_results
$table = new XMLDBTable('assignment_oj_results');
$key = new XMLDBKey('test');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('test'), 'assignment_oj_tests', array('id'));
/// Launch drop key test
$result = $result && drop_key($table, $key);
/// Define field test to be dropped from assignment_oj_results
$field = new XMLDBField('test');
/// Launch drop field test
$result = $result && drop_field($table, $field);
}
if ($result && $oldversion < 2010070400) {
/// Define field usefile to be added to assignment_oj_tests
$table = new XMLDBTable('assignment_oj_tests');
$field = new XMLDBField('usefile');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'output');
/// Launch add field usefile
$result = $result && add_field($table, $field);
/// Define field inputfile to be added to assignment_oj_tests
$table = new XMLDBTable('assignment_oj_tests');
$field = new XMLDBField('inputfile');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'usefile');
/// Launch add field inputfile
$result = $result && add_field($table, $field);
/// Define field outputfile to be added to assignment_oj_tests
$table = new XMLDBTable('assignment_oj_tests');
$field = new XMLDBField('outputfile');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'inputfile');
/// Launch add field outputfile
$result = $result && add_field($table, $field);
/// Changing type of field subgrade on table assignment_oj_tests to number
$table = new XMLDBTable('assignment_oj_tests');
$field = new XMLDBField('subgrade');
$field->setAttributes(XMLDB_TYPE_NUMBER, '20, 10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'feedback');
/// Launch change of type for field subgrade
$result = $result && change_field_type($table, $field);
/// Upgrade the value in subgrade field
if ($result) {
$ojs = get_records('assignment_oj');
foreach ($ojs as $oj) {
$modgrade = get_field('assignment', 'grade', 'id', $oj->assignment);
if ($modgrade) {
$sql = 'UPDATE ' . $CFG->prefix . 'assignment_oj_tests ' . 'SET subgrade=subgrade/' . $modgrade . ' ' . 'WHERE assignment=' . $oj->assignment;
$result = $result && execute_sql($sql);
}
}
}
}
// Tell the daemon to exit
set_config('assignment_oj_daemon_pid', '0');
return $result;
}
示例8: xmldb_local_upgrade
function xmldb_local_upgrade($oldversion)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2008032500) {
/// Define table backup_guids to be created
$table = new XMLDBTable('backup_guids');
/// Adding fields to table backup_guids
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('guid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_table', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_field', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table backup_guids
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
// $table->addKeyInfo('backup_guids_uk', XMLDB_KEY_UNIQUE, array('src_table', 'src_field', 'src_value'));
/// Adding indexes to table backup_guids
$table->addIndexInfo('guid_idx', XMLDB_INDEX_UNIQUE, array('guid'));
/// Launch create table for backup_guids
$result = $result && create_table($table);
/// Define table restore_guids to be created
$table = new XMLDBTable('restore_guids');
/// Adding fields to table restore_guids
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('guid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_table', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_field', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('src_value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table restore_guids
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
// uncommenting this key - it doesn't work for mysql users.
// $table->addKeyInfo('backup_guids_uk', XMLDB_KEY_UNIQUE, array('src_table', 'src_field', 'src_value'));
/// Adding indexes to table restore_guids
$table->addIndexInfo('guid_idx', XMLDB_INDEX_UNIQUE, array('guid'));
/// Launch create table for restore_guids
$result = $result && create_table($table);
}
if ($result && $oldversion < 2008032501) {
/// Define field src_value to be dropped from backup_guids
$table = new XMLDBTable('backup_guids');
$field = new XMLDBField('courseid');
/// Launch drop field src_value
$result = $result && drop_field($table, $field);
}
if ($result && $oldversion < 2008032602) {
/// Define key backup_guids_uk (unique) to be dropped form restore_guids
$table = new XMLDBTable('restore_guids');
$key = new XMLDBKey('backup_guids_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('src_table', 'src_field', 'src_value', 'courseid'));
/// Launch drop key backup_guids_uk
$result = $result && drop_key($table, $key);
/// Define key backup_guids_uk (unique) to be added to restore_guids
// $table = new XMLDBTable('restore_guids');
// $key = new XMLDBKey('backup_guids_uk');
// $key->setAttributes(XMLDB_KEY_UNIQUE, array('src_table', 'src_field', 'src_value', 'courseid'));
/// Launch add key backup_guids_uk
// $result = $result && add_key($table, $key);
/// Define index guid_idx (not unique) to be dropped form restore_guids
$table = new XMLDBTable('restore_guids');
$index = new XMLDBIndex('guid_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('guid'));
/// Launch drop index guid_idx
$result = $result && drop_index($table, $index);
/// Define index guid_idx (not unique) to be added to restore_guids
$table = new XMLDBTable('restore_guids');
$index = new XMLDBIndex('guid_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('guid'));
/// Launch add index guid_idx
$result = $result && add_index($table, $index);
}
//new incremental_courses table.
if ($result && $oldversion < 2008041101) {
// new incremental table.
/// Define table to be created
$table = new XMLDBTable('incremental_courses');
/// Adding fields to table
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('laststarttime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('lastendtime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('laststatus', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('nextstarttime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Launch create table
$result = $result && create_table($table);
}
if ($result && $oldversion < 2008041102) {
//new incremental_instance table.
/// Define table
$table = new XMLDBTable('incremental_instance');
/// Adding fields to table
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', 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('hash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table
//.........这里部分代码省略.........
示例9: xmldb_wiki_upgrade
function xmldb_wiki_upgrade($oldversion = 0)
{
global $CFG, $db;
$result = true;
// Checks if the current version installed in the system is old wiki (ewiki) or is new wiki (nwiki)
// We can distinguish ewiki from nwiki checking wiki_synonymous table existence.
//Initialy we asume we aren't upgrading from old wiki
$fromoldwiki = false;
$table = new XMLDBTable('wiki_synonymous');
if (!table_exists($table)) {
//New wiki isn't installed yet
$fromoldwiki = true;
//We are upgrading from old wiki.
// Upgrading ewiki to last version using XMLDB functions.
require_once $CFG->dirroot . '/mod/wiki/wikimigrate/ewiki_upgrade.php';
$result = xmldb_ewiki_upgrade($oldversion);
// We have an upgraded ewiki at this point of process.
// Migration can start.
require_once $CFG->dirroot . '/mod/wiki/wikimigrate/ewiki_migrate.php';
wiki_migrate_ewiki();
$oldversion = 0;
}
if ($result && $oldversion < 2006042900) {
//Delete previous log_display records for wiki for safety
delete_records('log_display', 'module', 'wiki');
//Add new log_display_records
$record->module = 'wiki';
$record->action = 'add';
$record->mtable = 'wiki';
$record->field = 'name';
$result = insert_record('log_display', $record);
$record->action = 'update';
$result = $result && insert_record('log_display', $record);
$record->action = 'view';
$result = $result && insert_record('log_display', $record);
$record->action = 'view all';
$result = $result && insert_record('log_display', $record);
$record->mtable = 'wiki_pages';
$record->field = 'pagename';
$record->action = 'view page';
$result = $result && insert_record('log_display', $record);
$record->action = 'edit page';
$result = $result && insert_record('log_display', $record);
$record->action = 'save page';
$result = $result && insert_record('log_display', $record);
$record->action = 'info page';
$result = $result && insert_record('log_display', $record);
// OLD SENTENCES
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'add', 'wiki', 'name') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'update', 'wiki', 'name') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view', 'wiki', 'name') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view all', 'wiki', 'name') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view page', 'wiki_pages', 'pagename') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'edit page', 'wiki_pages', 'pagename') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'save page', 'wiki_pages', 'pagename') ");
// execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'info page', 'wiki_pages', 'pagename') ");
}
if ($result && $oldversion < 2006050301) {
$result = table_column('wiki_synonymous', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'groupid');
if (empty($fromoldwiki)) {
//Only if we aren't migrating from old wiki, because it creates these columns and fills them!
$result = $result && table_column('wiki', '', 'intro', 'text', '', '', '', 'not null', 'name');
$result = $result && table_column('wiki', '', 'introformat', 'tinyint', '2', 'unsigned', '0', 'not null', 'intro');
//add colums
$result = $result && table_column('wiki_pages', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'author');
$result = $result && table_column('wiki_synonymous', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'groupid');
//set userid via author values
$authors = get_records_select('wiki_pages', null, null, 'distinct author');
// OLD SENTENCE
// $authors = get_records_sql('SELECT DISTINCT author, author FROM '.$CFG->prefix.'wiki_pages');
foreach ($authors as $author) {
if ($user = get_record('user', 'username', $author->author)) {
$result = $result && set_field('wiki_pages', 'userid', $user->id, 'author', $author->author);
}
}
}
}
if ($result && $oldversion < 2006050500) {
//droping and regenerating some indexes to normalize everything
//(some of them could not exist, but for safety...)
$table = new XMLDBTable('wiki');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
$result = drop_index($table, $index);
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
$result = $result && add_index($table, $index);
$table = new XMLDBTable('wiki_pages');
$key = new XMLDBKey('dfwiki_pages_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid'));
$result = $result && drop_key($table, $key);
$key = new XMLDBKey('wiki_pages_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid'));
$result = $result && drop_key($table, $key);
$key = new XMLDBKey('wiki_pages_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid', 'ownerid'));
$result = $result && add_key($table, $key);
$table = new XMLDBTable('wiki_synonymous');
$key = new XMLDBKey('dfwiki_synonymous_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'userid'));
//.........这里部分代码省略.........
示例10: wiki_drop_wikipagestable_fields
/**
* Private function.
*
* This function drop useless fields of ewiki 'wiki_pages table'
* after migration.
*
* @return boolean. true for success and false in case of error
*/
function wiki_drop_wikipagestable_fields()
{
$table = new XMLDBTable('wiki_pages');
$field = new XMLDBField('flags');
$result = drop_field($table, $field);
$field = new XMLDBField('meta');
$result = $result && drop_field($table, $field);
// We have to drop this key before dropping wiki field
$key = new XMLDBKey('wiki');
$key->setAttributes(XMLDB_KEY_UNIQUE, array("pagename", "version", "wiki"));
$result = $result && drop_key($table, $key);
$field = new XMLDBField('wiki');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && drop_field($table, $field);
return $result;
}
示例11: 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);
//.........这里部分代码省略.........
示例12: xmldb_ouwiki_upgrade
function xmldb_ouwiki_upgrade($oldversion = 0)
{
global $CFG, $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 < 2007022300) {
error('Cannot upgrade OU wiki module - please delete it by going to <a href="modules.php">the modules section</a> then delete it. (Module is called Wiki.) Then let it install itself again.');
}
if ($result && $oldversion < 2007041006) {
// First fix some signed-ness, then upgrade database to support comment system
$tw = new transaction_wrapper();
/// Changing sign of field id on table ouwiki_subwikis to unsigned
$table = new XMLDBTable('ouwiki_subwikis');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
/// Launch change of sign for field id
$result = $result && change_field_unsigned($table, $field);
/// Changing sign of field id on table ouwiki_pages to unsigned
$table = new XMLDBTable('ouwiki_pages');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
/// Launch change of sign for field id
$result = $result && change_field_unsigned($table, $field);
/// Define key ouwiki_pages_fk_forumid (foreign) to be dropped form ouwiki_pages
$table = new XMLDBTable('ouwiki_pages');
$key = new XMLDBKey('ouwiki_pages_fk_forumid');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('forumid'), 'forum', array('id'));
/// Launch drop key ouwiki_pages_fk_forumid
$result = $result && drop_key($table, $key);
/// Define field forumid to be dropped from ouwiki_pages
$table = new XMLDBTable('ouwiki_pages');
$field = new XMLDBField('forumid');
/// Launch drop field forumid
$result = $result && drop_field($table, $field);
/// Changing sign of field id on table ouwiki_versions to unsigned
$table = new XMLDBTable('ouwiki_versions');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
/// Launch change of sign for field id
$result = $result && change_field_unsigned($table, $field);
/// Changing sign of field id on table ouwiki_links to unsigned
$table = new XMLDBTable('ouwiki_links');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
/// Launch change of sign for field id
$result = $result && change_field_unsigned($table, $field);
/// Changing sign of field id on table ouwiki_locks to unsigned
$table = new XMLDBTable('ouwiki_locks');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
/// Launch change of sign for field id
$result = $result && change_field_unsigned($table, $field);
// Due to a bug or issues with xmldb/postgres - MDL-9271 - it lost all the primary keys!
// If this part of the upgrade fails because the primary keys are still there then that's
// ok.
/* XMLDB doesn't let you add primary keys! MDL-9272. Otherwise the code would be as follows:
$table = new XMLDBTable('ouwiki_subwikis');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$result = $result && add_key($table, $key);
$table = new XMLDBTable('ouwiki_pages');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$result = $result && add_key($table, $key);
$table = new XMLDBTable('ouwiki_versions');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$result = $result && add_key($table, $key);
$table = new XMLDBTable('ouwiki_links');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$result = $result && add_key($table, $key);
$table = new XMLDBTable('ouwiki_locks');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$result = $result && add_key($table, $key);
*/
// This is Postgres-only
$result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_subwikis ADD CONSTRAINT {$CFG->prefix}ouwisubw_id_pk PRIMARY KEY(id)");
$result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_pages ADD CONSTRAINT {$CFG->prefix}ouwipage_id_pk PRIMARY KEY(id)");
$result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_versions ADD CONSTRAINT {$CFG->prefix}ouwivers_id_pk PRIMARY KEY(id)");
$result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_links ADD CONSTRAINT {$CFG->prefix}ouwilink_id_pk PRIMARY KEY(id)");
$result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_locks ADD CONSTRAINT {$CFG->prefix}ouwilock_id_pk PRIMARY KEY(id)");
/// Define table ouwiki_sections to be created
$table = new XMLDBTable('ouwiki_sections');
/// Adding fields to table ouwiki_sections
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('xhtmlid', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table ouwiki_sections
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('ouwiki_sections_fk_pageid', XMLDB_KEY_FOREIGN, array('pageid'), 'ouwiki_pages', array('id'));
/// Launch create table for ouwiki_sections
//.........这里部分代码省略.........
示例13: xmldb_block_curr_admin_upgrade
//.........这里部分代码省略.........
/// Adding defaulttrack column to table
$table = new XMLDBTable('crlm_track');
$field = new XMLDBField('defaulttrack');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'enddate');
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2009010119) {
/// Define field completed to be added to crlm_curriculum_assignment
$table = new XMLDBTable('crlm_curriculum_assignment');
$field = new XMLDBField('completed');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'curriculumid');
/// Launch add field completed
$result = $result && add_field($table, $field);
/// Define field completiontime to be added to crlm_curriculum_assignment
$field = new XMLDBField('timecompleted');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completed');
/// Launch add field completiontime
$result = $result && add_field($table, $field);
/// Define field credits to be added to crlm_curriculum_assignment
$field = new XMLDBField('credits');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecompleted');
/// Launch add field credits
$result = $result && add_field($table, $field);
/// Define field locked to be added to crlm_curriculum_assignment
$table = new XMLDBTable('crlm_curriculum_assignment');
$field = new XMLDBField('locked');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'credits');
/// Launch add field locked
$result = $result && add_field($table, $field);
/// Define key mdl_currcurrassi_usecur_uix (unique) to be dropped from crlm_curriculum_assignment
$key = new XMLDBKey('mdl_currcurrassi_usecur_uix');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('userid', 'curriculumid'));
/// Launch drop key mdl_currcurrassi_usecur_uix
$result = $result && drop_key($table, $key);
/// Define index mdl_currcurrassi_usecurcom_ix (not unique) to be added to crlm_curriculum_assignment
$index = new XMLDBIndex('mdl_currcurrassi_usecurcom_ix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid', 'curriculumid', 'completed'));
/// Launch add index mdl_currcurrassi_usecurcom_ix
$result = $result && add_index($table, $index);
/// Define index completed_ix (not unique) to be added to crlm_curriculum_assignment
$index = new XMLDBIndex('completed_ix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('completed'));
/// Launch add index completed_ix
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2009010120) {
/// Define field autoenrol to be added to crlm_cluster_assignments
$table = new XMLDBTable('crlm_cluster_assignments');
$field = new XMLDBField('autoenrol');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'plugin');
/// Launch add field autoenrol
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2009010121) {
if (!record_exists('mnet_application', 'name', 'java')) {
$application = new stdClass();
$application->name = 'java';
$application->display_name = 'Java servlet';
$application->xmlrpc_server_url = '/mnet/server';
$application->sso_land_url = '/mnet/land.jsp';
$result = $result && insert_record('mnet_application', $application, false);
}
}
if ($result && $oldversion < 2009010122) {
$table = new XMLDBTable('crlm_track_class');
$field = new XMLDBField('requried');