本文整理汇总了PHP中drop_index函数的典型用法代码示例。如果您正苦于以下问题:PHP drop_index函数的具体用法?PHP drop_index怎么用?PHP drop_index使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drop_index函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_clean_index
function add_clean_index($table, $index)
{
global $wpdb;
drop_index($table, $index);
$wpdb->query("ALTER TABLE `{$table}` ADD INDEX ( `{$index}` )");
return true;
}
示例2: xmldb_taoresource_upgrade
function xmldb_taoresource_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
//===== 1.9.0 upgrade line ======//
// change the remoteid key to be non-unique
if ($result && $oldversion < 2007101510) {
$table = new XMLDBTable('taoresource_entry');
$index = new XMLDBIndex('remoteid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('remoteid'));
if (index_exists($table, $index)) {
$result = $result && drop_index($table, $index);
}
$result = $result && add_index($table, $index);
}
// change the remoteid key to be non-unique
if ($result && $oldversion < 2007101511) {
$table = new XMLDBTable('taoresource_metadata');
$field = new XMLDBField('entry_id');
// change the field type from ext to int
if (field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
$result = $result && change_field_type($table, $field);
}
}
return $result;
}
示例3: xmldb_block_student_gradeviewer_upgrade
function xmldb_block_student_gradeviewer_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2010070912) {
/// Define field opt to be dropped from block_teacher_referral_opt
$table = new XMLDBTable('block_teacher_referral_opt');
// First let's drop the index
$index = new XMLDBIndex('bloc_tea_usesec_uix');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('usersid', 'sectionsid'));
$failing_field = new XMLDBField('failing');
$lagging_field = new XMLDBField('lagging');
$usersid_field = new XMLDBField('usersid');
/// Launch drop field opt
$result = $result && drop_index($table, $index) && drop_field($table, $usersid_field) && drop_field($table, $lagging_field) && drop_field($table, $failing_field);
// Add the following fields
$fields = array('sectionsid', 'primary_instructor', 'non_primary_instructor', 'student', 'non_primary_control');
foreach (range(1, count($fields) - 1) as $index) {
$field = new XMLDBField($fields[$index]);
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $fields[$index - 1]);
$result = $result && add_field($table, $field);
}
$index = new XMLDBIndex('bloc_tea_usesec_uix');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('sectionsid'));
$result = $result && add_index($table, $index);
}
return $result;
}
示例4: xmldb_elis_core_upgrade
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package elis
* @subpackage core
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
*/
function xmldb_elis_core_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2011030402) {
/***********************************************************************
* Replace plugintype and pluginname with plugin field
**********************************************************************/
/// Define field plugin to be added to elis_scheduled_tasks
$table = new XMLDBTable('elis_scheduled_tasks');
$field = new XMLDBField('plugin');
$field->setAttributes(XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch add field plugin
$result = $result && add_field($table, $field);
/// Define index plugin_idx (not unique) to be dropped form elis_scheduled_tasks
$index = new XMLDBIndex('plugin_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('plugintype', 'pluginname', 'taskname'));
/// Launch drop index plugin_idx
$result = $result && drop_index($table, $index);
/// Define index plugin_idx (not unique) to be added to elis_scheduled_tasks
$index = new XMLDBIndex('plugin_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('plugin', 'taskname'));
/// Launch add index plugin_idx
$result = $result && add_index($table, $index);
/// Define field plugin to be dropped from elis_scheduled_tasks
$field = new XMLDBField('plugintype');
/// Launch drop field plugin
$result = $result && drop_field($table, $field);
/// Define field plugin to be dropped from elis_scheduled_tasks
$field = new XMLDBField('pluginname');
/// Launch drop field plugin
$result = $result && drop_field($table, $field);
/***********************************************************************
* Change callfunction from text to char
**********************************************************************/
/// Changing type of field callfunction on table elis_scheduled_tasks to char
$field = new XMLDBField('callfunction');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'callfile');
/// Launch change of type for field callfunction
$result = $result && change_field_type($table, $field);
}
if ($result && $oldversion < 2011030403) {
/// Define field startdate to be added to elis_scheduled_tasks
$table = new XMLDBTable('elis_scheduled_tasks');
$field = new XMLDBField('startdate');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'runsremaining');
/// Launch add field startdate
$result = $result && add_field($table, $field);
}
return $result;
}
示例5: question_upgrade_context_etc
function question_upgrade_context_etc()
{
global $CFG;
$result = true;
$result = $result && question_delete_unused_random();
$question_categories = get_records('question_categories');
if ($question_categories) {
//prepare content for new db structure
$tofix = question_cwqpfs_to_update($question_categories);
foreach ($tofix as $catid => $publish) {
$question_categories[$catid]->publish = $publish;
}
foreach ($question_categories as $id => $question_category) {
$course = $question_categories[$id]->course;
unset($question_categories[$id]->course);
if ($question_categories[$id]->publish) {
$context = get_context_instance(CONTEXT_SYSTEM);
//new name with old course name in brackets
$coursename = get_field('course', 'shortname', 'id', $course);
$question_categories[$id]->name .= " ({$coursename})";
} else {
$context = get_context_instance(CONTEXT_COURSE, $course);
}
$question_categories[$id]->contextid = $context->id;
unset($question_categories[$id]->publish);
}
$question_categories = question_category_checking($question_categories);
}
/// Define index course (not unique) to be dropped form question_categories
$table = new XMLDBTable('question_categories');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
/// Launch drop index course
$result = $result && drop_index($table, $index);
/// Define field course to be dropped from question_categories
$field = new XMLDBField('course');
/// Launch drop field course
$result = $result && drop_field($table, $field);
/// Define field context to be added to question_categories
$field = new XMLDBField('contextid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'name');
$field->comment = 'context that this category is shared in';
/// Launch add field context
$result = $result && add_field($table, $field);
/// Define index context (not unique) to be added to question_categories
$index = new XMLDBIndex('contextid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid'));
$index->comment = 'links to context table';
/// Launch add index context
$result = $result && add_index($table, $index);
$field = new XMLDBField('publish');
/// Launch drop field publish
$result = $result && drop_field($table, $field);
/// update table contents with previously calculated new contents.
if ($question_categories) {
foreach ($question_categories as $question_category) {
$question_category->name = addslashes($question_category->name);
$question_category->info = addslashes($question_category->info);
if (!($result = update_record('question_categories', $question_category))) {
notify('Couldn\'t update question_categories "' . $question_category->name . '"!');
}
}
}
/// Define field timecreated to be added to question
$table = new XMLDBTable('question');
$field = new XMLDBField('timecreated');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'hidden');
/// Launch add field timecreated
$result = $result && add_field($table, $field);
/// Define field timemodified to be added to question
$table = new XMLDBTable('question');
$field = new XMLDBField('timemodified');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated');
/// Launch add field timemodified
$result = $result && add_field($table, $field);
/// Define field createdby to be added to question
$table = new XMLDBTable('question');
$field = new XMLDBField('createdby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'timemodified');
/// Launch add field createdby
$result = $result && add_field($table, $field);
/// Define field modifiedby to be added to question
$table = new XMLDBTable('question');
$field = new XMLDBField('modifiedby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'createdby');
/// Launch add field modifiedby
$result = $result && add_field($table, $field);
/// Define key createdby (foreign) to be added to question
$table = new XMLDBTable('question');
$key = new XMLDBKey('createdby');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('createdby'), 'user', array('id'));
/// Launch add key createdby
$result = $result && add_key($table, $key);
/// Define key modifiedby (foreign) to be added to question
$table = new XMLDBTable('question');
$key = new XMLDBKey('modifiedby');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('modifiedby'), 'user', array('id'));
/// Launch add key modifiedby
$result = $result && add_key($table, $key);
return $result;
//.........这里部分代码省略.........
示例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_crlm_user_activity_upgrade
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package elis
* @subpackage component
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
*/
function xmldb_crlm_user_activity_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2010071502) {
/// Define table etl_user_module_activity to be created
$table = new XMLDBTable('etl_user_module_activity');
/// Adding fields to table etl_user_module_activity
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('hour', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('duration', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table etl_user_module_activity
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table etl_user_module_activity
$table->addIndexInfo('user_cmid_hour_idx', XMLDB_INDEX_UNIQUE, array('userid', 'cmid', 'hour'));
$table->addIndexInfo('cm_idx', XMLDB_INDEX_NOTUNIQUE, array('cmid'));
$table->addIndexInfo('hour_idx', XMLDB_INDEX_NOTUNIQUE, array('hour'));
/// Launch create table for etl_user_module_activity
if (!table_exists($table)) {
$result = $result && create_table($table);
}
}
if ($result && $oldversion < 2010071503) {
// clear all records -- they may be incorrect, and we'll recalculate
// them all
delete_records_select('etl_user_activity', 'TRUE');
delete_records('crlm_config', 'name', 'user_activity_last_run');
/// Define index user_idx (not unique) to be dropped form etl_user_activity
$table = new XMLDBTable('etl_user_activity');
$index = new XMLDBIndex('user_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
/// Launch drop index user_idx
$result = $result && drop_index($table, $index);
/// Define index user_idx (not unique) to be added to etl_user_activity
$table = new XMLDBTable('etl_user_activity');
$index = new XMLDBIndex('user_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid', 'courseid', 'hour'));
/// Launch add index user_idx
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2010071505) {
$sql = "SELECT userid, courseid, hour, COUNT('x') count\n FROM {$CFG->prefix}etl_user_activity\n GROUP BY userid, courseid, hour\n HAVING COUNT('x') > 1";
if (record_exists_sql($sql)) {
$table = new XMLDBTable('etl_user_activity_temp');
// fields
$field = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$field = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
$field = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'userid');
$field = $table->addFieldInfo('hour', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'courseid');
$field = $table->addFieldInfo('duration', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'hour');
// Keys & indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('user_idx', XMLDB_INDEX_UNIQUE, array('userid', 'courseid', 'hour'));
$table->addIndexInfo('course_idx', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
$table->addIndexInfo('hour_idx', XMLDB_INDEX_NOTUNIQUE, array('hour'));
$result = $result && create_table($table);
if ($result) {
$sql = "INSERT INTO {$CFG->prefix}etl_user_activity_temp (userid, courseid, hour, duration)\n SELECT userid, courseid, hour, duration\n FROM {$CFG->prefix}etl_user_activity\n GROUP BY userid, courseid, hour\n ORDER BY id ASC";
$result = $result && execute_sql($sql);
if ($result) {
$oldtable = new XMLDBTable('etl_user_activity');
$result = $result && drop_table($oldtable);
if ($result) {
$result = $result && rename_table($table, 'etl_user_activity');
}
}
}
}
if ($result) {
$sql = "UPDATE {$CFG->prefix}etl_user_activity SET duration = 3600 WHERE duration > 3600";
execute_sql($sql);
}
}
//.........这里部分代码省略.........
示例8: step3
function step3()
{
global $wpdb;
do_action('import_start');
set_time_limit(0);
update_option('ljapi_step', 3);
echo '<div id="ljapi-status">';
echo '<h3>' . __('Threading Comments…') . '</h3>';
echo '<p>' . __('We are now re-building the threading of your comments (this can also take a while if you have lots of comments)...') . '</p>';
ob_flush();
flush();
// Only bother adding indexes if they have over 5000 comments (arbitrary number)
$imported_comments = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_type = 'livejournal'");
$added_indices = false;
if (5000 < $imported_comments) {
include_once ABSPATH . 'wp-admin/includes/upgrade.php';
$added_indices = true;
add_clean_index($wpdb->comments, 'comment_type');
add_clean_index($wpdb->comments, 'comment_karma');
add_clean_index($wpdb->comments, 'comment_agent');
}
// Get LJ comments, which haven't been threaded yet, 5000 at a time and thread them
while ($comments = $wpdb->get_results("SELECT comment_ID, comment_agent FROM {$wpdb->comments} WHERE comment_type = 'livejournal' AND comment_agent != '0' LIMIT 5000", OBJECT)) {
foreach ($comments as $comment) {
$wpdb->update($wpdb->comments, array('comment_parent' => $this->get_wp_comment_ID($comment->comment_agent), 'comment_type' => 'livejournal-done'), array('comment_ID' => $comment->comment_ID));
}
wp_cache_flush();
$wpdb->flush();
}
// Revert the comments table back to normal and optimize it to reclaim space
if ($added_indices) {
drop_index($wpdb->comments, 'comment_type');
drop_index($wpdb->comments, 'comment_karma');
drop_index($wpdb->comments, 'comment_agent');
$wpdb->query("OPTIMIZE TABLE {$wpdb->comments}");
}
// Clean up database and we're out
$this->cleanup();
do_action('import_done', 'livejournal');
if ($imported_comments > 1) {
echo '<p>' . sprintf(__("Successfully re-threaded %s comments."), number_format($imported_comments)) . '</p>';
}
echo '<h3>';
printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
echo '</h3>';
echo '</div>';
}
示例9: xmldb_studynotes_upgrade
//.........这里部分代码省略.........
$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 tables longer than 24 chars
if ($result && $oldversion < 2009043001) {
/// Define table studynotes_feed_msg_stat to be renamed
$table = new XMLDBTable('studynotes_feed_messages_status');
/// Launch rename table for studynotes_feed_msg_stat
$result = $result && rename_table($table, 'studynotes_feed_msg_stat');
}
// Rename tables longer than 24 chars
if ($result && $oldversion < 2009043001) {
/// Define table studynotes_feed_subscrib to be renamed
$table = new XMLDBTable('studynotes_feed_subscriptions');
/// Launch rename table for studynotes_feed_subscrib
$result = $result && rename_table($table, 'studynotes_feed_subscrib');
}
// Rename tables longer than 24 chars
if ($result && $oldversion < 2009043001) {
/// Define table studynotes_rel_questions to be renamed
$table = new XMLDBTable('studynotes_relation_questions');
/// Launch rename table for studynotes_rel_questions
$result = $result && rename_table($table, 'studynotes_rel_questions');
}
// Rename tables longer than 24 chars
if ($result && $oldversion < 2009043001) {
/// Define table studynotes_rel_questions to be renamed
$table = new XMLDBTable('studynotes_relation_translations');
/// Launch rename table for studynotes_rel_questions
$result = $result && rename_table($table, 'studynotes_rel_translations');
}
if ($result && $oldversion < 2009050301) {
$fields = array(array('studynotes_cards', 'created'), array('studynotes_cards', 'modified'), array('studynotes_cards', 'locked_time'), array('studynotes_feed_messages', 'created'), array('studynotes_feed_messages', 'modified'), array('studynotes_feed_msg_stat', 'created'), array('studynotes_feed_msg_stat', 'modified'), array('studynotes_feeds', 'created'), array('studynotes_feeds', 'modified'), array('studynotes_groups', 'created'), array('studynotes_groups', 'modified'), array('studynotes_markers', 'created'), array('studynotes_markers', 'modified'), array('studynotes_memberships', 'created'), array('studynotes_memberships', 'modified'), array('studynotes_relations', 'created'), array('studynotes_relations', 'modified'), array('studynotes_relation_answers', 'created'), array('studynotes_relation_answers', 'modified'), array('studynotes_relation_links', 'created'), array('studynotes_relation_links', 'modified'), array('studynotes_rel_questions', 'created'), array('studynotes_rel_questions', 'modified'), array('studynotes_topics', 'created'), array('studynotes_topics', 'modified'), array('studynotes_uploads', 'created'), array('studynotes_uploads', 'modified'), array('studynotes_users', 'created'), array('studynotes_users', 'last_login'));
foreach ($fields as $info) {
$table = new XMLDBTable($info[0]);
$tmpField = new XMLDBField($info[1] . "_cpy");
$tmpField->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $info[1]);
//add new integer field
$result = $result && add_field($table, $tmpField);
//get value
if ($records = get_records($info[0], '', '', '', 'id,' . $info[1])) {
//convert value
foreach ($records as $record) {
$record->{$info[1] . "_cpy"} = strtotime($record->{$info[1]});
unset($record->{$info[1]});
print_r($record);
$result = $result && update_record($info[0], $record);
}
}
//drop old field
$field = new XMLDBField($info[1]);
$result = $result && drop_field($table, $field);
//rename copy
$tmpField->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && change_field_default($table, $tmpField);
$result = $result && rename_field($table, $tmpField, $info[1]);
}
}
if ($result && $oldversion < 2009050301) {
/// Define table studynotes_rel_translations to be dropped
$table = new XMLDBTable('studynotes_rel_translations');
/// Launch drop table for studynotes_rel_translations
$result = $result && drop_table($table);
}
if ($result && $oldversion < 2009070300) {
/// Define index link (not unique) to be dropped form studynotes_relation_links
$table = new XMLDBTable('studynotes_relation_links');
$index = new XMLDBIndex('link');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('link'));
/// Launch drop index link
$result = $result && drop_index($table, $index);
}
if ($result && $oldversion < 2009070300) {
/// Changing type of field link on table studynotes_relation_links to text
$table = new XMLDBTable('studynotes_relation_links');
$field = new XMLDBField('link');
$field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch change of type for field link
$result = $result && change_field_type($table, $field);
}
if ($result && $oldversion < 2009070300) {
/// Changing type of field answer on table studynotes_relation_answers to text
$table = new XMLDBTable('studynotes_relation_answers');
$field = new XMLDBField('answer');
$field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'id');
/// Launch change of type for field answer
$result = $result && change_field_type($table, $field);
}
if ($result && $oldversion < 2009070300) {
/// Changing type of field question on table studynotes_rel_questions to text
$table = new XMLDBTable('studynotes_rel_questions');
$field = new XMLDBField('question');
$field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch change of type for field question
$result = $result && change_field_type($table, $field);
}
return $result;
}
示例10: invoke
//.........这里部分代码省略.........
$test = new stdClass();
$index = new XMLDBIndex('secondname');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
$test->sql = $table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $index, true);
$test->status = add_index($table, $index, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['add not unique index'] = $test;
}
/// 29th test. Re-add the same index than previous test. Check find_index_name() works.
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$index = new XMLDBIndex('secondname');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('name', 'course'));
if ($indexfound = find_index_name($table, $index)) {
$test->status = true;
$test->sql = array();
} else {
$test->status = true;
$test->error = 'Index not found!';
$test->sql = array();
}
$tests['check find_index_name()'] = $test;
}
/// 30th test. Dropping one index from the table
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass();
$index = new XMLDBIndex('name');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname'));
$test->sql = $table->getDropIndexSQL($CFG->dbtype, $CFG->prefix, $index, true);
$test->status = drop_index($table, $index, false, false);
if (!$test->status) {
$test->error = $db->ErrorMsg();
}
$tests['drop index'] = $test;
}
/// 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
示例11: xmldb_core_upgrade
//.........这里部分代码省略.........
add_field($table, $field);
$key = new XMLDBKey('categoryfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('category'), 'group_category', array('id'));
add_key($table, $key);
}
if ($oldversion < 2010071300) {
set_config('searchusernames', 1);
}
if ($oldversion < 2010071500) {
reload_html_filters();
}
if ($oldversion < 2010071600) {
if (is_postgres()) {
// change_field_enum should do this
execute_sql('ALTER TABLE {view_access} DROP CONSTRAINT {viewacce_acc_ck}');
}
$table = new XMLDBTable('view_access');
$field = new XMLDBField('accesstype');
$field->setAttributes(XMLDB_TYPE_CHAR, 16, null, null, null, XMLDB_ENUM, array('public', 'loggedin', 'friends', 'objectionable'));
change_field_enum($table, $field);
}
if ($oldversion < 2010071900) {
$table = new XMLDBTable('group');
$field = new XMLDBField('viewnotify');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
}
if ($oldversion < 2010081000) {
// new table collection
$table = new XMLDBTable('collection');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, 255, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('owner', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('mtime', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, null);
$table->addFieldInfo('navigation', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('owner'), 'usr', array('id'));
create_table($table);
// new table collection_view
$table = new XMLDBTable('collection_view');
$table->addFieldInfo('view', XMLDB_TYPE_INTEGER, 10, false, XMLDB_NOTNULL);
$table->addFieldInfo('collection', XMLDB_TYPE_INTEGER, 10, false, XMLDB_NOTNULL);
$table->addFieldInfo('displayorder', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('view'));
$table->addKeyInfo('viewfk', XMLDB_KEY_FOREIGN, array('view'), 'view', array('id'));
$table->addKeyInfo('collectionfk', XMLDB_KEY_FOREIGN, array('collection'), 'collection', array('id'));
create_table($table);
// Drop unique constraint on token column of view_access
$table = new XMLDBTable('view_access');
$index = new XMLDBIndex('tokenuk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('token'));
drop_index($table, $index);
$index = new XMLDBIndex('tokenix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('token'));
add_index($table, $index);
}
if ($oldversion < 2010081001) {
if ($data = check_upgrades('artefact.plans')) {
upgrade_plugin($data);
}
if ($data = check_upgrades('blocktype.plans/plans')) {
upgrade_plugin($data);
}
}
if ($oldversion < 2010081100) {
if ($data = check_upgrades('blocktype.navigation')) {
upgrade_plugin($data);
}
}
if ($oldversion < 2010082000) {
delete_records_select('config', "field IN ('usersrank', 'groupsrank', 'viewsrank')");
}
if ($oldversion < 2010091300) {
// Cron job missing from installs post 2010041900
if (!record_exists('cron', 'callfunction', 'cron_check_for_updates')) {
$cron = new StdClass();
$cron->callfunction = 'cron_check_for_updates';
$cron->minute = rand(0, 59);
$cron->hour = rand(0, 23);
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
}
if ($oldversion < 2010091500) {
// Previous version of 2010040800 upgrade created the submittedtime
// column not null (see bug #638550)
$table = new XMLDBTable('view');
$field = new XMLDBField('submittedtime');
$field->setAttributes(XMLDB_TYPE_DATETIME, null, null);
change_field_notnull($table, $field);
// Our crappy db is full of redundant data (submittedtime depends on
// submittedhost or submittedgroup) so it's easy to correct this.
execute_sql("\n UPDATE {view} SET submittedtime = NULL\n WHERE submittedtime IS NOT NULL AND submittedgroup IS NULL AND submittedhost IS NULL");
}
return $status;
}
示例12: 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'));
//.........这里部分代码省略.........
示例13: cp_upgrade_320
/**
* Execute changes made in ClassiPress 3.2.
*
* @since 3.2
*/
function cp_upgrade_320()
{
global $wpdb, $app_abbr;
if (get_option($app_abbr . '_admin_security') == 'install_themes') {
update_option($app_abbr . '_admin_security', 'manage_options');
}
// remove old table indexes
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
drop_index($wpdb->cp_ad_pop_daily, 'id');
drop_index($wpdb->cp_ad_pop_total, 'id');
update_option($app_abbr . '_db_version', '1320');
}
示例14: xmldb_main_upgrade
//.........这里部分代码省略.........
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
// Create the table
$result = $result && create_table($table);
//
// Prime MNET configuration entries -- will be needed later by auth/mnet
//
include_once $CFG->dirroot . '/mnet/lib.php';
$env = new mnet_environment();
$env->init();
unset($env);
// add mnethostid to user-
$table = new XMLDBTable('user');
$field = new XMLDBField('mnethostid');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setSequence(null);
$field->setEnum(null);
$field->setDefault('0');
$field->setPrevious("deleted");
$field->setNext("username");
$result = $result && add_field($table, $field);
// The default mnethostid is zero... we need to update this for all
// users of the local IdP service.
set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'mnethostid', '0');
$index = new XMLDBIndex('username');
$index->setUnique(true);
$index->setFields(array('username'));
drop_index($table, $index);
$index->setFields(array('mnethostid', 'username'));
if (!add_index($table, $index)) {
notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
}
unset($table, $field, $index);
/**
** auth/mnet tables
**/
$table = new XMLDBTable('mnet_session');
$table->comment = 'Store session data from users migrating to other sites';
// fields
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('token', XMLDB_INDEX_UNIQUE, array('token'));
// Create the table
$result = $result && create_table($table);
$table = new XMLDBTable('mnet_sso_access_control');
$table->comment = 'Users by host permitted (or not) to login from a remote provider';
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, NULL, null, null, 'allow');
// PK and indexes
示例15: 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);
//.........这里部分代码省略.........