本文整理汇总了PHP中XMLDBIndex类的典型用法代码示例。如果您正苦于以下问题:PHP XMLDBIndex类的具体用法?PHP XMLDBIndex怎么用?PHP XMLDBIndex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLDBIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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_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: invoke
/**
* Invoke method, every class will have its own
* returns true/false on completion, setting both
* errormsg and output as necessary
*/
function invoke()
{
parent::invoke();
$result = true;
/// Set own core attributes
$this->does_generate = ACTION_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
$tableparam = required_param('table', PARAM_CLEAN);
$table =& $structure->getTable($tableparam);
/// If the changeme index exists, just get it and continue
$changeme_exists = false;
if ($indexes =& $table->getIndexes()) {
if ($index =& $table->getIndex('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
/// Lets create the Index
$index = new XMLDBIndex('changeme');
$index->setComment('Default comment for the index, please edit me');
$table->addIndex($index);
/// We have one new key, so the structure has changed
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
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_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;
}
示例9: 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;
}
示例10: 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;
}
示例11: getDbTables
private static function getDbTables()
{
$tables = array();
// globalmessages table
$table = new XMLDBTable('local_globalmessages');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('summary', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('created', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('modified', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('status', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$table->addFieldInfo('design', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$index = new XMLDBIndex('design');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('design'));
$table->addIndex($index);
$index = new XMLDBIndex('modified');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('modified'));
$table->addIndex($index);
$tables[] = $table;
// globalmessages_designs table
$table = new XMLDBTable('local_globalmessages_designs');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 400);
$table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 400);
$table->addFieldInfo('bgcolor', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
$table->addFieldInfo('bgimage', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('bgimageposition', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('bgimagerepeat', XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null);
$table->addFieldInfo('bordersize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$table->addFieldInfo('bordercolor', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
$table->addFieldInfo('bordershape', XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null);
$table->addFieldInfo('padding', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('innerpadding', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$tables[] = $table;
// globalmessages_rules table
$table = new XMLDBTable('local_globalmessages_rules');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('construct', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('leftside', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('operator', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('rightside', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('message', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$index = new XMLDBIndex('message');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('message'));
$table->addIndex($index);
$tables[] = $table;
return $tables;
}
示例12: 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;
//.........这里部分代码省略.........
示例13: 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;
}
示例14: 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;
//.........这里部分代码省略.........
示例15: xmldb_turnitintool_upgrade
/**
* @package turnitintool
* @copyright 2012 Turnitin
*/
function xmldb_turnitintool_upgrade($oldversion)
{
global $CFG, $THEME, $DB, $OUTPUT;
$result = true;
// Do necessary DB upgrades here
//function add_field($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null)
// Newer DB Man ($name, $type=null, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null)
if ($result && $oldversion < 2009071501) {
if (is_callable(array($DB, 'get_manager'))) {
$dbman = $DB->get_manager();
$table = new xmldb_table('turnitintool_submissions');
$field = new xmldb_field('submission_gmimaged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'submission_grade');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
} else {
$table = new XMLDBTable('turnitintool_submissions');
$field = new XMLDBField('submission_gmimaged');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'submission_grade');
$result = $result && add_field($table, $field);
}
}
if ($result && $oldversion < 2009091401) {
if (is_callable(array($DB, 'get_manager'))) {
$dbman = $DB->get_manager();
$table = new xmldb_table('turnitintool');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', 'intro');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
} else {
$table = new XMLDBTable('turnitintool');
$field = new XMLDBField('introformat');
$field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', 'intro');
$result = $result && add_field($table, $field);
}
}
if ($result && $oldversion < 2009092901) {
if (is_callable(array($DB, 'get_manager'))) {
$dbman = $DB->get_manager();
$table1 = new xmldb_table('turnitintool');
$field1 = new xmldb_field('resubmit', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '0', 'defaultdtpost');
if ($dbman->field_exists($table1, $field1)) {
$dbman->rename_field($table1, $field1, 'anon');
}
$table2 = new xmldb_table('turnitintool_submissions');
$field2 = new xmldb_field('submission_unanon', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, NULL, null, null, null, '0', 'submission_nmlastname');
$field3 = new xmldb_field('submission_unanonreason', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'submission_unanon');
$field4 = new xmldb_field('submission_nmuserid', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
if (!$dbman->field_exists($table2, $field2)) {
$dbman->add_field($table2, $field2);
}
if (!$dbman->field_exists($table2, $field3)) {
$dbman->add_field($table2, $field3);
}
$dbman->change_field_type($table2, $field4);
} else {
$table1 = new XMLDBTable('turnitintool');
$field1 = new XMLDBField('resubmit');
$field1->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '0', 'defaultdtpost');
$result = $result && rename_field($table1, $field1, 'anon');
$table2 = new XMLDBTable('turnitintool_submissions');
$field2 = new XMLDBField('submission_unanon');
$field3 = new XMLDBField('submission_unanonreason');
$field4 = new XMLDBField('submission_nmuserid');
$field2->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '0', 'submission_nmlastname');
$result = $result && add_field($table2, $field2);
$field3->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'submission_unanon');
$result = $result && add_field($table2, $field3);
$field4->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
$result = $result && change_field_type($table2, $field4);
}
}
if ($result && $oldversion < 2009120501) {
if (is_callable(array($DB, 'get_manager'))) {
$dbman = $DB->get_manager();
// Launch add index userid
$table = new xmldb_table('turnitintool_submissions');
$index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Launch add index turnitintoolid
$table = new xmldb_table('turnitintool_submissions');
$index = new xmldb_index('turnitintoolid', XMLDB_INDEX_NOTUNIQUE, array('turnitintoolid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
} else {
$table = new XMLDBTable('turnitintool_submissions');
// Launch add index userid
$index = new XMLDBIndex('userid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
if (index_exists($table, $index)) {
$result = $result && add_index($table, $index);
}
//.........这里部分代码省略.........