本文整理汇总了PHP中add_index函数的典型用法代码示例。如果您正苦于以下问题:PHP add_index函数的具体用法?PHP add_index怎么用?PHP add_index使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_index函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: xmldb_search_elasticsearch_upgrade
function xmldb_search_elasticsearch_upgrade($oldversion = 0)
{
if ($oldversion < 2015012800) {
// Adding indices on the table search_elasticsearch_queue
$table = new XMLDBTable('search_elasticsearch_queue');
$index = new XMLDBIndex('itemidix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('itemid'));
add_index($table, $index);
}
if ($oldversion < 2015060900) {
log_debug('Add "status" and "lastprocessed" columns to search_elasticsearch_queue table');
$table = new XMLDBTable('search_elasticsearch_queue');
$field = new XMLDBField('status');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
$table = new XMLDBTable('search_elasticsearch_queue');
$field = new XMLDBField('lastprocessed');
$field->setAttributes(XMLDB_TYPE_DATETIME);
add_field($table, $field);
$table = new XMLDBTable('search_elasticsearch_queue');
$index = new XMLDBIndex('statusix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
add_index($table, $index);
}
if ($oldversion < 2015072700) {
log_debug('Adding ability to search by "Text" blocks in elasticsearch');
// Need to add the 'block_instance' to the default types to index for elasticsearch
// Note: the $cfg->plugin_search_elasticsearch_types can be overriding this
// We don't want to run the re-indexing now as that will take ages for large sites
// It should be run from the Extensions -> Elasticsearch -> Configuration page
if ($types = get_field('search_config', 'value', 'plugin', 'elasticsearch', 'field', 'types')) {
$types = explode(',', $types);
if (!in_array('block_instance', $types)) {
$types[] = 'block_instance';
}
$types = implode(',', $types);
update_record('search_config', array('value' => $types), array('plugin' => 'elasticsearch', 'field' => 'types'));
log_warn(get_string('newindextype', 'search.elasticsearch', 'block_instance'), true, false);
}
}
if ($oldversion < 2015100800) {
log_debug('Adding ability to search by collection in elasticsearch');
// The code for this existed since the beginning but 'collection' was not
// added to the $cfg->plugin_search_elasticsearch_types
// We don't want to run the re-indexing now as that will take ages for large sites
// It should be run from the Extensions -> Elasticsearch -> Configuration page
if ($types = get_field('search_config', 'value', 'plugin', 'elasticsearch', 'field', 'types')) {
$types = explode(',', $types);
if (!in_array('collection', $types)) {
$types[] = 'collection';
}
$types = implode(',', $types);
update_record('search_config', array('value' => $types), array('plugin' => 'elasticsearch', 'field' => 'types'));
log_warn(get_string('newindextype', 'search.elasticsearch', 'collection'), true, false);
}
}
return true;
}
示例4: xmldb_search_elasticsearch_upgrade
function xmldb_search_elasticsearch_upgrade($oldversion = 0)
{
if ($oldversion < 2015012800) {
// Adding indices on the table search_elasticsearch_queue
$table = new XMLDBTable('search_elasticsearch_queue');
$index = new XMLDBIndex('itemidix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('itemid'));
add_index($table, $index);
}
return true;
}
示例5: 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;
}
示例6: xmldb_quiz_upgrade
function xmldb_quiz_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 < 2007022800) {
/// Ensure that there are not existing duplicate entries in the database.
$duplicateunits = get_records_select('question_numerical_units', "id > (SELECT MIN(iqnu.id)\n FROM {$CFG->prefix}question_numerical_units iqnu\n WHERE iqnu.question = {$CFG->prefix}question_numerical_units.question AND\n iqnu.unit = {$CFG->prefix}question_numerical_units.unit)", '', 'id');
if ($duplicateunits) {
delete_records_select('question_numerical_units', 'id IN (' . implode(',', array_keys($duplicateunits)) . ')');
}
/// Define index question-unit (unique) to be added to question_numerical_units
$table = new XMLDBTable('question_numerical_units');
$index = new XMLDBIndex('question-unit');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('question', 'unit'));
/// Launch add index question-unit
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2007070200) {
/// Changing precision of field timelimit on table quiz to (10)
$table = new XMLDBTable('quiz');
$field = new XMLDBField('timelimit');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timemodified');
/// Launch change of precision for field timelimit
$result = $result && change_field_precision($table, $field);
}
if ($result && $oldversion < 2007072200) {
require_once $CFG->dirroot . '/mod/quiz/lib.php';
// too much debug output
$db->debug = false;
quiz_update_grades();
$db->debug = true;
}
// Separate control for when overall feedback is displayed, independant of the question feedback settings.
if ($result && $oldversion < 2007072600) {
// Adjust the quiz review options so that overall feedback is displayed whenever feedback is.
$result = $result && execute_sql('UPDATE ' . $CFG->prefix . 'quiz SET review = ' . sql_bitor(sql_bitand('review', sql_bitnot(QUIZ_REVIEW_OVERALLFEEDBACK)), sql_bitor(sql_bitand('review', QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY) . ' * 65536', sql_bitor(sql_bitand('review', QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN) . ' * 16384', sql_bitand('review', QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED) . ' * 4096'))));
// Same adjustment to the defaults for new quizzes.
$result = $result && set_config('quiz_review', $CFG->quiz_review & ~QUIZ_REVIEW_OVERALLFEEDBACK | ($CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY) << 16 | ($CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN) << 14 | ($CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED) << 12);
}
//===== 1.9.0 upgrade line ======//
return $result;
}
示例7: postinst
public static function postinst($prevversion)
{
if ($prevversion == 0) {
if (is_postgres()) {
$table = new XMLDBTable('blocktype_externalfeed_data');
$index = new XMLDBIndex('urlautautix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('url', 'authuser', 'authpassword'));
add_index($table, $index);
} else {
if (is_mysql()) {
// MySQL needs size limits when indexing text fields
execute_sql('ALTER TABLE {blocktype_externalfeed_data} ADD INDEX
{blocextedata_urlautaut_ix} (url(255), authuser(255), authpassword(255))');
}
}
}
}
示例8: xmldb_local_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 curriculummanagement
* @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_local_upgrade($oldversion)
{
global $CFG, $db;
$result = true;
if ($result && $oldversion < 2010110800) {
$table = new XMLDBTable('user_info_data');
$index = new XMLDBIndex('useridx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
$result = $result && add_index($table, $index);
$index = new XMLDBIndex('fieldidx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('fieldid'));
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2011033100) {
// Changing size of field 'name' on 'user_preferences' from 50 to 255
$table = new XMLDBTable('user_preferences');
$field = new XMLDBField('name');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
// Launch change of precision for field name
$result = $result && change_field_precision($table, $field);
}
return $result;
}
示例9: xmldb_block_php_report_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 php_reports
* @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_block_php_report_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2011040600) {
/// Define table php_report_schedule to be created
$table = new XMLDBTable('php_report_schedule');
/// Adding fields to table php_report_schedule
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('report', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('config', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table php_report_schedule
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table php_report_schedule
$table->addIndexInfo('report_idx', XMLDB_INDEX_NOTUNIQUE, array('report'));
/// Launch create table for php_report_schedule
$result = $result && create_table($table);
/// Define field userid to be added to php_report_schedule
$table = new XMLDBTable('php_report_schedule');
$field = new XMLDBField('userid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch add field userid
$result = $result && add_field($table, $field);
/// Define index userid_idx (not unique) to be added to php_report_schedule
$table = new XMLDBTable('php_report_schedule');
$index = new XMLDBIndex('userid_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
/// Launch add index userid_idx
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2011042900) {
$query = "name " . sql_ilike() . " 'php_report%'";
$result = $result && delete_records_select('user_preferences', $query);
}
return $result;
}
示例10: xmldb_blocktype_externalfeed_upgrade
function xmldb_blocktype_externalfeed_upgrade($oldversion = 0)
{
if ($oldversion < 2008042101) {
// We hit the 255 character limit for feed URLs
if (is_postgres()) {
execute_sql('ALTER TABLE {blocktype_externalfeed_data} ALTER COLUMN url TYPE TEXT');
} else {
if (is_mysql()) {
// If 2 URLs > 255 chars have the same first 255 characters then mahara will error - this is a MySQL issue though, their unique key length limit is to blame
execute_sql('ALTER TABLE {blocktype_externalfeed_data} DROP KEY {blocextedata_url_uix}');
// We have to remove then add the constraint again else the change will make MySQL cry
execute_sql('ALTER TABLE {blocktype_externalfeed_data} MODIFY COLUMN "url" text');
execute_sql('ALTER TABLE {blocktype_externalfeed_data} add unique {blocextedata_url_uix} (url(255))');
}
}
}
if ($oldversion < 2009121600) {
if (is_mysql()) {
// Make content column wider (TEXT is only 65kb in mysql)
$table = new XMLDBTable('blocktype_externalfeed_data');
$field = new XMLDBField('content');
$field->setAttributes(XMLDB_TYPE_TEXT, "big", null, null);
change_field_precision($table, $field);
}
}
if ($oldversion < 2010073000) {
execute_sql('
UPDATE {blocktype_cron}
SET minute = ?
WHERE minute = ? AND hour = ? AND plugin = ? AND callfunction = ?', array('30', '0', '3', 'externalfeed', 'cleanup_feeds'));
}
if ($oldversion < 2011091400) {
// Add columns for HTTP basic auth
$table = new XMLDBTable('blocktype_externalfeed_data');
$field1 = new XMLDBField('authuser');
$field1->setAttributes(XMLDB_TYPE_TEXT);
$field2 = new XMLDBField('authpassword');
$field2->setAttributes(XMLDB_TYPE_TEXT);
add_field($table, $field1);
add_field($table, $field2);
// Change unique constraint that's no longer valid
$table = new XMLDBTable('blocktype_externalfeed_data');
$index = new XMLDBIndex('url_uix');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('url'));
drop_index($table, $index);
if (is_postgres()) {
$index = new XMLDBIndex('urlautautix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('url', 'authuser', 'authpassword'));
add_index($table, $index);
} else {
if (is_mysql()) {
// MySQL needs size limits when indexing text fields
execute_sql('ALTER TABLE {blocktype_externalfeed_data} ADD INDEX
{blocextedata_urlautaut_ix} (url(255), authuser(255), authpassword(255))');
}
}
}
if ($oldversion < 2011091401) {
// Add columns for insecure SSL mode
$table = new XMLDBTable('blocktype_externalfeed_data');
$field = new XMLDBField('insecuresslmode');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
if ($oldversion < 2012090700) {
// Reset all feeds to reset themselves
set_field('blocktype_externalfeed_data', 'lastupdate', db_format_timestamp('0'));
safe_require('blocktype', 'externalfeed');
call_static_method('PluginBlocktypeExternalfeed', 'refresh_feeds');
}
if ($oldversion < 2014041500) {
log_debug('Cleaning up duplicate feeds in the externalfeed blocktype');
log_debug('1. Find the duplicate feed urls');
// Setting these to be empty strings instead of NULL will make our SQL a lot simpler in the next section
execute_sql("update {blocktype_externalfeed_data} set authuser='' where authuser is null");
execute_sql("update {blocktype_externalfeed_data} set authpassword='' where authpassword is null");
if ($duplicatefeeds = get_records_sql_array("SELECT COUNT(url), url, authuser, authpassword FROM {blocktype_externalfeed_data} GROUP BY url, authuser, authpassword HAVING COUNT(url) > 1 ORDER BY url, authuser, authpassword", array())) {
log_debug('2. Get all feed ids for the duplicated feed urls');
// Use the 1st one found to be the feed id for the block instances that need updating
$feedstoupdate = array();
foreach ($duplicatefeeds as $feed) {
$feedids = get_column('blocktype_externalfeed_data', 'id', 'url', $feed->url, 'authuser', $feed->authuser, 'authpassword', $feed->authpassword);
$feedstoupdate[$feed->url] = $feedids;
}
log_debug('3. Updating blocks to use correct feed id');
// Find the block instances using external feeds. Check to see if they are not using the 'true' id and update them accordingly
require_once get_config('docroot') . 'blocktype/lib.php';
$blockids = get_records_array('block_instance', 'blocktype', 'externalfeed', 'id ASC', 'id');
foreach ($blockids as $blockid) {
$blockinstance = new BlockInstance($blockid->id);
$configdata = $blockinstance->get('configdata');
if (!empty($configdata['feedid'])) {
foreach ($feedstoupdate as $url => $ids) {
foreach ($ids as $key => $id) {
if ($id == $configdata['feedid'] && $key != '0') {
$configdata['feedid'] = $ids[0];
$blockinstance->set('configdata', $configdata);
$blockinstance->set('dirty', true);
$blockinstance->commit();
break;
//.........这里部分代码省略.........
示例11: xmldb_data_upgrade
function xmldb_data_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2006121300) {
/// Define field format to be added to data_comments
$table = new XMLDBTable('data_comments');
$field = new XMLDBField('format');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'content');
/// Launch add field format
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007022600) {
/// Define field asearchtemplate to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
/// Launch add field asearchtemplate
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007072200) {
require_once $CFG->dirroot . '/mod/data/lib.php';
// too much debug output
$db->debug = false;
data_update_grades();
$db->debug = true;
}
if ($result && $oldversion < 2007081400) {
/// Define field notification to be added to data
$table = new XMLDBTable('data');
$field = new XMLDBField('notification');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null, 'editany');
/// Launch add field notification
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2007081402) {
/// Define index type-dataid (not unique) to be added to data_fields
$table = new XMLDBTable('data_fields');
$index = new XMLDBIndex('type-dataid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('type', 'dataid'));
/// Launch add index type-dataid
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
/// Define index course (not unique) to be added to data
$table = new XMLDBTable('data');
$index = new XMLDBIndex('course');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
/// Launch add index course
if (!index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
}
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007101512) {
/// Launch add field asearchtemplate again if does not exists yet - reported on several sites
$table = new XMLDBTable('data');
$field = new XMLDBField('asearchtemplate');
$field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
if (!field_exists($table, $field)) {
$result = $result && add_field($table, $field);
}
}
return $result;
}
示例12: upgrade_18_letters
/**
* Migrates the grade_letter data to grade_letters
*/
function upgrade_18_letters()
{
global $CFG;
$table = new XMLDBTable('grade_letters');
if (table_exists($table)) {
// already converted or development site
return true;
}
$result = true;
/// Rename field grade_low on table grade_letter to lowerboundary
$table = new XMLDBTable('grade_letter');
$field = new XMLDBField('grade_low');
$field->setAttributes(XMLDB_TYPE_NUMBER, '5, 2', null, XMLDB_NOTNULL, null, null, null, '0.00', 'grade_high');
/// Launch rename field grade_low
$result = $result && rename_field($table, $field, 'lowerboundary');
/// Define field grade_high to be dropped from grade_letter
$table = new XMLDBTable('grade_letter');
$field = new XMLDBField('grade_high');
/// Launch drop field grade_high
$result = $result && drop_field($table, $field);
/// Define index courseid (not unique) to be dropped form grade_letter
$table = new XMLDBTable('grade_letter');
$index = new XMLDBIndex('courseid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('courseid'));
/// Launch drop index courseid
$result = $result && drop_index($table, $index);
/// Rename field courseid on table grade_letter to contextid
$table = new XMLDBTable('grade_letter');
$field = new XMLDBField('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
/// Launch rename field courseid
$result = $result && rename_field($table, $field, 'contextid');
$sql = "UPDATE {$CFG->prefix}grade_letter\n SET contextid=COALESCE((SELECT c.id\n FROM {$CFG->prefix}context c\n WHERE c.instanceid={$CFG->prefix}grade_letter.contextid AND c.contextlevel=" . CONTEXT_COURSE . "), 0)";
execute_sql($sql);
/// remove broken records
execute_sql("DELETE FROM {$CFG->prefix}grade_letter WHERE contextid=0");
/// Define table grade_letter to be renamed to grade_letters
$table = new XMLDBTable('grade_letter');
/// Launch rename table for grade_letter
$result = $result && rename_table($table, 'grade_letters');
/// Changing type of field lowerboundary on table grade_letters to number
$table = new XMLDBTable('grade_letters');
$field = new XMLDBField('lowerboundary');
$field->setAttributes(XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, null, 'contextid');
/// Launch change of type for field lowerboundary
$result = $result && change_field_precision($table, $field);
$result = $result && change_field_default($table, $field);
/// Changing the default of field letter on table grade_letters to drop it
$table = new XMLDBTable('grade_letters');
$field = new XMLDBField('letter');
$field->setAttributes(XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'lowerboundary');
/// Launch change of default for field letter
$result = $result && change_field_precision($table, $field);
$result = $result && change_field_default($table, $field);
/// Define index contextidlowerboundary (not unique) to be added to grade_letters
$table = new XMLDBTable('grade_letters');
$index = new XMLDBIndex('contextid-lowerboundary');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
/// Launch add index contextidlowerboundary
$result = $result && add_index($table, $index);
return $result;
}
示例13: xmldb_interaction_forum_upgrade
function xmldb_interaction_forum_upgrade($oldversion = 0)
{
if ($oldversion < 2009062300) {
foreach (array('topic', 'forum') as $type) {
log_debug("Subscription upgrade for {$type}s");
// Add missing primary key to the subscription tables
// Step 1: remove duplicates
if ($dupes = get_records_sql_array('
SELECT "user", ' . $type . ', COUNT(*)
FROM {interaction_forum_subscription_' . $type . '}
GROUP BY "user", ' . $type . '
HAVING COUNT(*) > 1', array())) {
// We found duplicate subscriptions to a topic/forum
foreach ($dupes as $dupe) {
log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}");
delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type});
insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type}));
}
}
// Step 2: add the actual key
$table = new XMLDBTable('interaction_forum_subscription_' . $type);
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type));
add_key($table, $key);
// Add a 'key' column, used for unsubscriptions
$field = new XMLDBField('key');
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null);
add_field($table, $field);
$key = new XMLDBKey('keyuk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('key'));
add_key($table, $key);
// Populate the key column
if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) {
foreach ($records as $where) {
$new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand()));
update_record('interaction_forum_subscription_' . $type, $new, $where);
}
}
// Now make the key column not null
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
change_field_notnull($table, $field);
}
}
if ($oldversion < 2009081700) {
if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) {
insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30));
}
}
if ($oldversion < 2009081800) {
$subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum');
ensure_record_exists('interaction_event_subscription', $subscription, $subscription);
}
if ($oldversion < 2012071100) {
// Add new column 'path' to table interaction_forum_post used for diplaying posts by threads
$table = new XMLDBTable('interaction_forum_post');
$field = new XMLDBField('path');
$field->setAttributes(XMLDB_TYPE_CHAR, 2048, null, null);
add_field($table, $field);
$index = new XMLDBIndex('pathix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('path'));
add_index($table, $index);
// Update the column 'path' for all posts in the old database
$done = 0;
$lastid = 0;
$pwcount = count_records('interaction_forum_post');
if (is_mysql()) {
$mp = mysql_get_variable('max_allowed_packet');
$limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100;
} else {
$limit = 2000;
}
while ($posts = get_records_select_array('interaction_forum_post', 'id > ?', array($lastid), 'id', 'id, parent', 0, $limit)) {
foreach ($posts as $post) {
// Update the column 'path'
$path = sprintf('%010d', $post->id);
$parentid = $post->parent;
while (!empty($parentid)) {
if ($p = get_record_select('interaction_forum_post', 'id = ?', array($parentid), 'parent, path')) {
if (!empty($p->path)) {
$path = $p->path . '/' . $path;
break;
}
$path = sprintf('%010d', $parentid) . '/' . $path;
$parentid = $p->parent;
} else {
throw new SQLException("Can't find the post with id = '{$parentid}'");
}
}
$post->path = $path;
update_record('interaction_forum_post', $post);
$lastid = $post->id;
}
$done += count($posts);
log_debug("Updating posts' path: {$done}/{$pwcount}");
set_time_limit(50);
}
}
if ($oldversion < 2014050800) {
// Subscribe admins to new activity.
$adminusers = get_column('usr', 'id', 'admin', 1, 'deleted', 0);
//.........这里部分代码省略.........
示例14: xmldb_block_email_list_upgrade
function xmldb_block_email_list_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 < 2007062205) {
$fields = array('mod/email:viewmail', 'mod/email:addmail', 'mod/email:reply', 'mod/email:replyall', 'mod/email:forward', 'mod/email:addsubfolder', 'mod/email:updatesubfolder', 'mod/email:removesubfolder');
/// Remove no more used fields
$table = new XMLDBTable('capabilities');
foreach ($fields as $name) {
$field = new XMLDBField($name);
$result = $result && drop_field($table, $field);
}
// Active cron block of email_list
if ($result) {
if ($email_list = get_record('block', 'name', 'email_list')) {
$email_list->cron = 1;
update_record('block', $email_list);
}
}
}
// force
$result = true;
if ($result && $oldversion < 2007072003) {
// Add marriedfolder2courses flag on email_preferences
$table = new XMLDBTable('email_preference');
$field = new XMLDBField('marriedfolders2courses');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
// Add course ID on email_folder
$table = new XMLDBTable('email_folder');
$field = new XMLDBField('course');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
// Add index
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
$result = $result && add_key($table, $key);
}
if ($result && $oldversion < 2008061400) {
// Add reply and forwarded info field on email_mail.
$table = new XMLDBTable('email_send');
$field = new XMLDBField('answered');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
}
// Solve old problems
if ($result && $oldversion < 2008061600) {
$table = new XMLDBTable('email_preference');
$field = new XMLDBField('marriedfolders2courses');
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
}
$table = new XMLDBTable('email_folder');
$field = new XMLDBField('course');
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
$result = $result && add_field($table, $field);
// Add index
$key = new XMLDBKey('course');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
$result = $result && add_key($table, $key);
}
}
// Add new index
if ($result and $oldversion < 2008081600) {
// Add combine key on foldermail
$table = new XMLDBTable('email_foldermail');
$index = new XMLDBIndex('folderid-mailid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('folderid', 'mailid'));
if (!index_exists($table, $index)) {
/// Launch add index
$result = $result && add_index($table, $index);
}
}
return $result;
}
示例15: xmldb_core_upgrade
//.........这里部分代码省略.........
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null);
add_field($table, $field);
$field = new XMLDBField('role');
$field->setAttributes(XMLDB_TYPE_CHAR, 255, null, null);
add_field($table, $field);
$field = new XMLDBField('usr');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null);
add_field($table, $field);
$field = new XMLDBField('token');
$field->setAttributes(XMLDB_TYPE_CHAR, 100, null, null);
add_field($table, $field);
$field = new XMLDBField('visible');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
// Copy data to view_access
execute_sql('
INSERT INTO {view_access} (view, accesstype, "group", role, startdate, stopdate)
SELECT view, NULL, "group", role, startdate, stopdate FROM {view_access_group}');
execute_sql('
INSERT INTO {view_access} (view, accesstype, usr, startdate, stopdate)
SELECT view, NULL, usr, startdate, stopdate FROM {view_access_usr}');
execute_sql('
INSERT INTO {view_access} (view, accesstype, token, visible, startdate, stopdate)
SELECT view, NULL, token, visible, startdate, stopdate FROM {view_access_token}');
// Add foreign keys
$key = new XMLDBKey('groupfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('group'), 'group', array('id'));
add_key($table, $key);
$key = new XMLDBKey('usrfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
add_key($table, $key);
$index = new XMLDBIndex('tokenuk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('token'));
add_index($table, $index);
// Exactly one of accesstype, group, usr, token must be not null
execute_sql('ALTER TABLE {view_access} ADD CHECK (
(accesstype IS NOT NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NOT NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NOT NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NOT NULL)
)');
// Drop old tables
$table = new XMLDBTable('view_access_group');
drop_table($table);
$table = new XMLDBTable('view_access_usr');
drop_table($table);
$table = new XMLDBTable('view_access_token');
drop_table($table);
// Insert explicit tutor access records for submitted views
if (!($submittedviews = get_records_sql_array('
SELECT v.id, v.submittedgroup, g.grouptype
FROM {view} v JOIN {group} g ON (v.submittedgroup = g.id AND g.deleted = 0)', array()))) {
$submittedviews = array();
}
$roles = array();
foreach ($submittedviews as $v) {
if (!isset($roles[$v->grouptype])) {
$rs = get_column('grouptype_roles', 'role', 'grouptype', $v->grouptype, 'see_submitted_views', 1);
$roles[$v->grouptype] = empty($rs) ? array() : $rs;
}
foreach ($roles[$v->grouptype] as $role) {
$accessrecord = (object) array('view' => $v->id, 'group' => $v->submittedgroup, 'role' => $role, 'visible' => 0, 'allowcomments' => 1, 'approvecomments' => 0);
ensure_record_exists('view_access', $accessrecord, $accessrecord);
}
}
}