当前位置: 首页>>代码示例>>PHP>>正文


PHP add_key函数代码示例

本文整理汇总了PHP中add_key函数的典型用法代码示例。如果您正苦于以下问题:PHP add_key函数的具体用法?PHP add_key怎么用?PHP add_key使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_key函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
    }
    return true;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:54,代码来源:upgrade.php

示例2: xmldb_auth_internal_upgrade

/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
 *
 * 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    mahara
 * @subpackage auth-internal
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
function xmldb_auth_internal_upgrade($oldversion = 0)
{
    if ($oldversion < 2007062900) {
        $auth_instance = new stdClass();
        $auth_instance->instancename = 'internal';
        $auth_instance->priority = '1';
        $auth_instance->institution = 'mahara';
        $auth_instance->authname = 'internal';
        $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
        if (empty($auth_instance->id)) {
            return false;
        }
        $table = new XMLDBTable('usr');
        $key = new XMLDBKey("authinstancefk");
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('authinstance'), 'auth_instance', array('id'));
        add_key($table, $key);
        return true;
    }
    return true;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:45,代码来源:upgrade.php

示例3: 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;
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:upgrade.php

示例4: xmldb_dialogue_upgrade


//.........这里部分代码省略.........
        /// Define field lastrecipientid to be added to dialogue_conversations
        $table = new XMLDBTable('dialogue_conversations');
        $field = new XMLDBField('lastrecipientid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'lastid');
        /// Launch add field lastrecipientid
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2007100400) {
        /// Define field attachment to be added to dialogue_entries
        $table = new XMLDBTable('dialogue_entries');
        $field = new XMLDBField('attachment');
        $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'text');
        /// Launch add field attachment
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2007100800) {
        /// Define field edittime to be added to dialogue
        $table = new XMLDBTable('dialogue');
        $field = new XMLDBField('edittime');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro');
        /// Launch add field edittime
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2007110700) {
        /// Define field groupid to be added to dialogue_conversations
        $table = new XMLDBTable('dialogue_conversations');
        $field = new XMLDBField('groupid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'subject');
        /// Launch add field groupid
        $result = $result && add_field($table, $field);
        /// Define index dialogue_conversations_groupid_idx (not unique) to be added to dialogue_conversations
        $index = new XMLDBIndex('dialogue_conversations_groupid_idx');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('groupid'));
        /// Launch add index dialogue_conversations_groupid_idx
        $result = $result && add_index($table, $index);
    }
    if ($result && $oldversion < 2007110800) {
        /// Define field grouping to be added to dialogue_conversations
        $table = new XMLDBTable('dialogue_conversations');
        $field = new XMLDBField('grouping');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, '0', 'groupid');
        /// Launch add field grouping
        $result = $result && add_field($table, $field);
        /// Define index dialogue_conversations_grouping_idx (not unique) to be added to dialogue_conversations
        $table = new XMLDBTable('dialogue_conversations');
        $index = new XMLDBIndex('dialogue_conversations_grouping_idx');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('grouping'));
        /// Launch add index dialogue_conversations_grouping_idx
        $result = $result && add_index($table, $index);
    }
    if ($result && $oldversion < 2007111401) {
        /// Define field timemodified to be added to dialogue_entries
        $table = new XMLDBTable('dialogue_entries');
        $field = new XMLDBField('timemodified');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, '0', 'timecreated');
        /// Launch add field timemodified
        $result = $result && add_field($table, $field);
        $result = $result && ($result = execute_sql('UPDATE ' . $CFG->prefix . 'dialogue_entries SET timemodified = timecreated'));
    }
    if ($result && $oldversion < 2007112200) {
        /// Define table dialogue_read to be created
        $table = new XMLDBTable('dialogue_read');
        /// Adding fields to table dialogue_read
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('entryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('firstread', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('lastread', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table dialogue_read
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('dialogueread_entryid_userid_uk', XMLDB_KEY_UNIQUE, array('entryid', 'userid'));
        /// Launch create table for dialogue_read
        $result = $result && create_table($table);
    }
    if ($result && $oldversion < 2007112201) {
        /// Define field conversationid to be added to dialogue_read
        $table = new XMLDBTable('dialogue_read');
        $field = new XMLDBField('conversationid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null, 'lastread');
        /// Launch add field conversationid
        $result = $result && add_field($table, $field);
        /// Define key dialogueread_conversation_fk (foreign) to be added to dialogue_read
        $table = new XMLDBTable('dialogue_read');
        $key = new XMLDBKey('dialogueread_conversation_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('conversationid'), 'dialogue_conversations', array('id'));
        /// Launch add key dialogueread_conversation_fk
        $result = $result && add_key($table, $key);
    }
    if ($result && $oldversion < 2007121701) {
        $logdisplay = new stdClass();
        $logdisplay->module = 'assignment';
        $logdisplay->mtable = 'assignment';
        $logdisplay->field = 'name';
        $logdisplay->action = 'delete';
        $result = $result && insert_record('log_display', $logdisplay);
        $logdisplay->action = 'view receipt';
        $result = $result && insert_record('log_display', $logdisplay);
    }
    return $result;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php

示例5: 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);
//.........这里部分代码省略.........
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:101,代码来源:upgrade.php

示例6: xmldb_core_upgrade


//.........这里部分代码省略.........
        execute_sql('ALTER TABLE {artefact} ADD CONSTRAINT {arte_gro_fk} FOREIGN KEY ("group") REFERENCES {group}(id)');
        // New artefact permissions for use with group-owned artefacts
        execute_sql('CREATE TABLE {artefact_access_role} (
            role VARCHAR(255) NOT NULL,
            artefact INTEGER NOT NULL REFERENCES {artefact}(id),
            can_view SMALLINT NOT NULL,
            can_edit SMALLINT NOT NULL,
            can_republish SMALLINT NOT NULL
        )' . $INNODB);
        execute_sql('CREATE TABLE {artefact_access_usr} (
            usr INTEGER NOT NULL REFERENCES {usr}(id),
            artefact INTEGER NOT NULL REFERENCES {artefact}(id),
            can_republish SMALLINT
        )' . $INNODB);
        // grouptype tables
        execute_sql("CREATE TABLE {grouptype} (\n            name VARCHAR(20) PRIMARY KEY,\n            submittableto SMALLINT NOT NULL,\n            defaultrole VARCHAR(255) NOT NULL DEFAULT 'member'\n        )" . $INNODB);
        execute_sql("INSERT INTO {grouptype} (name,submittableto) VALUES ('standard',0)");
        execute_sql("INSERT INTO {grouptype} (name,submittableto) VALUES ('course',1)");
        execute_sql('CREATE TABLE {grouptype_roles} (
            grouptype VARCHAR(20) NOT NULL REFERENCES {grouptype}(name),
            edit_views SMALLINT NOT NULL DEFAULT 1,
            see_submitted_views SMALLINT NOT NULL DEFAULT 0,
            role VARCHAR(255) NOT NULL
        )' . $INNODB);
        execute_sql("INSERT INTO {grouptype_roles} (grouptype,edit_views,see_submitted_views,role) VALUES ('standard',1,0,'admin')");
        execute_sql("INSERT INTO {grouptype_roles} (grouptype,edit_views,see_submitted_views,role) VALUES ('standard',1,0,'member')");
        execute_sql("INSERT INTO {grouptype_roles} (grouptype,edit_views,see_submitted_views,role) VALUES ('course',1,0,'admin')");
        execute_sql("INSERT INTO {grouptype_roles} (grouptype,edit_views,see_submitted_views,role) VALUES ('course',1,1,'tutor')");
        execute_sql("INSERT INTO {grouptype_roles} (grouptype,edit_views,see_submitted_views,role) VALUES ('course',0,0,'member')");
        if (is_postgres()) {
            $table = new XMLDBTable('group');
            $key = new XMLDBKey('grouptypefk');
            $key->setAttributes(XMLDB_KEY_FOREIGN, array('grouptype'), 'grouptype', array('name'));
            add_key($table, $key);
        } else {
            if (is_mysql()) {
                // Seems to refuse to create foreign key, not sure why yet
                execute_sql("ALTER TABLE {group} ADD INDEX {grou_gro_ix} (grouptype);");
                // execute_sql("ALTER TABLE {group} ADD CONSTRAINT {grou_gro_fk} FOREIGN KEY (grouptype) REFERENCES {grouptype} (name);");
            }
        }
        // Group views
        execute_sql('ALTER TABLE {view} ADD COLUMN "group" BIGINT');
        execute_sql('ALTER TABLE {view} ADD CONSTRAINT {view_gro_fk} FOREIGN KEY ("group") REFERENCES {group}(id)');
        if (is_postgres()) {
            execute_sql('ALTER TABLE {view} ALTER COLUMN owner DROP NOT NULL');
            execute_sql('ALTER TABLE {view} ALTER COLUMN ownerformat DROP NOT NULL');
        } else {
            if (is_mysql()) {
                execute_sql('ALTER TABLE {view} MODIFY owner BIGINT(10) NULL');
                execute_sql('ALTER TABLE {view} MODIFY ownerformat TEXT NULL');
            }
        }
        execute_sql('ALTER TABLE {view_access_group} ADD COLUMN role VARCHAR(255)');
        execute_sql("UPDATE {view_access_group} SET role = 'tutor' WHERE tutoronly = 1");
        execute_sql('ALTER TABLE {view_access_group} DROP COLUMN tutoronly');
        // grouptype plugin tables
        $table = new XMLDBTable('grouptype_installed');
        $table->addFieldInfo('name', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
        $table->addFieldInfo('version', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
        $table->addFieldInfo('release', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL);
        $table->addFieldInfo('active', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('name'));
        create_table($table);
        $table = new XMLDBTable('grouptype_cron');
        $table->addFieldInfo('plugin', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
开发者ID:Br3nda,项目名称:mahara,代码行数:67,代码来源:upgrade.php

示例7: xmldb_oublog_upgrade

function xmldb_oublog_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2008022600) {
        /// Define field views to be added to oublog_instances
        $table = new XMLDBTable('oublog_instances');
        $field = new XMLDBField('views');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'accesstoken');
        /// Launch add field views
        $result = $result && add_field($table, $field);
        $table = new XMLDBTable('oublog');
        $field = new XMLDBField('views');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'global');
        /// Launch add field views
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008022700) {
        /// Define field oublogid to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('oublogid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
        /// Launch add field oublogid
        $result = $result && add_field($table, $field);
        /// Define key oublog_links_oublog_fk (foreign) to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $key = new XMLDBKey('oublog_links_oublog_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('oublogid'), 'oublog', array('id'));
        /// Launch add key oublog_links_oublog_fk
        $result = $result && add_key($table, $key);
        /// Changing nullability of field oubloginstancesid on table oublog_links to null
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('oubloginstancesid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'oublogid');
        /// Launch change of nullability for field oubloginstancesid
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2008022701) {
        /// Define field sortorder to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('sortorder');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'url');
        /// Launch add field sortorder
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008030704) {
        /// Add search data
        require_once dirname(__FILE__) . '/../locallib.php';
        require_once dirname(__FILE__) . '/../lib.php';
        if (oublog_search_installed()) {
            global $db;
            $olddebug = $db->debug;
            $db->debug = false;
            print '<ul>';
            oublog_ousearch_update_all(true);
            print '</ul>';
            $db->debug = $olddebug;
        }
    }
    if ($result && $oldversion < 2008030707) {
        /// Define field lasteditedby to be added to oublog_posts
        $table = new XMLDBTable('oublog_posts');
        $field = new XMLDBField('lasteditedby');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'visibility');
        /// Launch add field lasteditedby
        $result = $result && add_field($table, $field);
        /// Transfer edit data to lasteditedby
        $result = $result && execute_sql("\r\nUPDATE {$CFG->prefix}oublog_posts SET lasteditedby=(\r\n    SELECT userid FROM {$CFG->prefix}oublog_edits WHERE {$CFG->prefix}oublog_posts.id=postid ORDER BY id DESC LIMIT 1 \r\n) WHERE editsummary IS NOT NULL\r\n        ");
        /// Define field editsummary to be dropped from oublog_posts
        $table = new XMLDBTable('oublog_posts');
        $field = new XMLDBField('editsummary');
        /// Launch drop field editsummary
        $result = $result && drop_field($table, $field);
    }
    if ($result && $oldversion < 2008073000) {
        /// Define field completionposts to be added to oublog
        $table = new XMLDBTable('oublog');
        $field = new XMLDBField('completionposts');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'views');
        /// Launch add field completionposts
        $result = $result && add_field($table, $field);
        /// Define field completioncomments to be added to oublog
        $field = new XMLDBField('completioncomments');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionposts');
        /// Launch add field completioncomments
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008121100) {
        // remove oublog:view from legacy:user roles
        $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
        foreach ($roles as $role) {
            $result = $result && unassign_capability('mod/oublog:view', $role->id);
        }
    }
    if ($result && $oldversion < 2009012600) {
        // Remove oublog:post and oublog:comment from legacy:user roles (if present)
        $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
        // Also from default user role if not already included
        if (!array_key_exists($CFG->defaultuserroleid, $roles)) {
            $roles[] = get_record('role', 'id', $CFG->defaultuserroleid);
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php

示例8: xmldb_core_upgrade


//.........这里部分代码省略.........
        }
        set_config('spamhaus', 0);
        set_config('surbl', 0);
    }
    if ($oldversion < 2010040800) {
        $table = new XMLDBTable('view');
        $field = new XMLDBField('submittedtime');
        $field->setAttributes(XMLDB_TYPE_DATETIME, null, null);
        add_field($table, $field);
    }
    if ($oldversion < 2010041200) {
        delete_records('config', 'field', 'captchaoncontactform');
        delete_records('config', 'field', 'captchaonregisterform');
    }
    if ($oldversion < 2010041201) {
        $sql = "\n            SELECT u.id\n            FROM {usr} u\n            LEFT JOIN {artefact} a\n                ON (a.owner = u.id AND a.artefacttype = 'blog')\n            WHERE u.id > 0\n            GROUP BY u.id\n            HAVING COUNT(a.id) != 1";
        $manyblogusers = get_records_sql_array($sql, array());
        if ($manyblogusers) {
            foreach ($manyblogusers as $u) {
                $where = (object) array('usr' => $u->id, 'field' => 'multipleblogs');
                $data = (object) array('usr' => $u->id, 'field' => 'multipleblogs', 'value' => 1);
                ensure_record_exists('usr_account_preference', $where, $data);
            }
        }
    }
    if ($oldversion < 2010041600 && table_exists(new XMLDBTable('view_feedback'))) {
        // Add author, authorname to artefact table
        $table = new XMLDBTable('artefact');
        $field = new XMLDBField('author');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10');
        add_field($table, $field);
        $key = new XMLDBKey('authorfk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('author'), 'usr', array('id'));
        add_key($table, $key);
        table_column('artefact', null, 'authorname', 'text', null, null, null, '');
        if (is_postgres()) {
            execute_sql("ALTER TABLE {artefact} ALTER COLUMN authorname DROP DEFAULT");
            set_field('artefact', 'authorname', null);
            execute_sql('UPDATE {artefact} SET authorname = g.name FROM {group} g WHERE "group" = g.id');
            execute_sql("UPDATE {artefact} SET authorname = CASE WHEN institution = 'mahara' THEN ? ELSE i.displayname END FROM {institution} i WHERE institution = i.name", array(get_config('sitename')));
        } else {
            execute_sql("UPDATE {artefact} a, {group} g SET a.authorname = g.name WHERE a.group = g.id");
            execute_sql("UPDATE {artefact} a, {institution} i SET a.authorname = CASE WHEN a.institution = 'mahara' THEN ? ELSE i.displayname END WHERE a.institution = i.name", array(get_config('sitename')));
        }
        execute_sql('UPDATE {artefact} SET author = owner WHERE owner IS NOT NULL');
        execute_sql('ALTER TABLE {artefact} ADD CHECK (
            (author IS NOT NULL AND authorname IS NULL    ) OR
            (author IS NULL     AND authorname IS NOT NULL)
        )');
        // Move feedback activity type to artefact plugin
        execute_sql("\n            UPDATE {activity_type}\n            SET plugintype = 'artefact', pluginname = 'comment'\n            WHERE name = 'feedback'\n        ");
        // Install the comment artefact
        if ($data = check_upgrades('artefact.comment')) {
            upgrade_plugin($data);
        }
        // Flag all views & artefacts to enable/disable comments
        table_column('artefact', null, 'allowcomments', 'integer', 1);
        table_column('view', null, 'allowcomments', 'integer', 1, null, 1);
        // Initially allow comments on blogposts, images, files
        set_field_select('artefact', 'allowcomments', 1, 'artefacttype IN (?,?,?)', array('blogpost', 'image', 'file'));
        // Convert old feedback to comment artefacts
        if ($viewfeedback = get_records_sql_array('
            SELECT f.*, v.id AS viewid, v.owner, v.group, v.institution
            FROM {view_feedback} f JOIN {view} v ON f.view = v.id', array())) {
            foreach ($viewfeedback as &$f) {
                if ($f->author > 0) {
开发者ID:patkira,项目名称:mahara,代码行数:67,代码来源:upgrade.php

示例9: invoke


//.........这里部分代码省略.........
         $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
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new XMLDBKey('course');
         $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
         $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
         $test->status = drop_key($table, $key, false, false);
         if (!$test->status) {
             $test->error = $db->ErrorMsg();
         }
         $tests['drop foreign+unique key'] = $test;
     }
     /// 34th test. Adding one foreign key to the table
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:67,代码来源:test.class.php

示例10: xmldb_stampcoll_upgrade


//.........这里部分代码省略.........
                    }
                }
            }
        }
        $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);
        /// Define index mdl_stampcoll_stamps_stampcollid_idx (not unique) to be dropped form stampcoll_stamps
        $table = new XMLDBTable('stampcoll_stamps');
        $index = new XMLDBIndex('mdl_stampcoll_stamps_stampcollid_idx');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('stampcollid'));
        $result = $result && drop_index($table, $index);
        /// Define index userid (not unique) to be added to stampcoll_stamps
        $table = new XMLDBTable('stampcoll_stamps');
        $index = new XMLDBIndex('userid');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
        /// Launch add index userid
        $result = $result && add_index($table, $index);
        /// Define index giver (not unique) to be added to stampcoll_stamps
        $table = new XMLDBTable('stampcoll_stamps');
        $index = new XMLDBIndex('giver');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('giver'));
        /// Launch add index giver
        $result = $result && add_index($table, $index);
        /// Define key mdl_stampcoll_stamps_id_idx (unique) to be dropped form stampcoll_stamps
        $table = new XMLDBTable('stampcoll_stamps');
        $key = new XMLDBKey('mdl_stampcoll_stamps_id_idx');
        $key->setAttributes(XMLDB_KEY_UNIQUE, array('id'));
        /// Launch drop key mdl_stampcoll_stamps_id_idx
        $result = $result && drop_key($table, $key);
        /// Define key stampcollid (foreign) to be added to stampcoll_stamps
        $table = new XMLDBTable('stampcoll_stamps');
        $key = new XMLDBKey('stampcollid');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('stampcollid'), 'stampcoll', array('id'));
        /// Launch add key stampcollid
        $result = $result && add_key($table, $key);
    }
    return $result;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php

示例11: xmldb_block_email_list_upgrade

function xmldb_block_email_list_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $DB;
    $result = true;
    // If is set upgrade_blocks_savepoint function
    $existfunction = false;
    if (!function_exists('upgrade_blocks_savepoint')) {
        $existfunction = 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);
            }
        }
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2007062205, '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 ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2007072003, 'email_list');
        }
    }
    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);
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2008061400, 'email_list');
        }
    }
    // 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);
        }
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2008061600, 'email_list');
        }
    }
    // Add new index
    if ($result and $oldversion < 2008081602) {
        // 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);
        }
        if ($existfunction) {
//.........这里部分代码省略.........
开发者ID:henriquecrang,项目名称:e-UNI,代码行数:101,代码来源:upgrade.php

示例12: make_depaths

function make_depaths(&$result, &$depaths, &$parts, $lang = NULL)
{
    foreach ($depaths as $key => &$depath) {
        $duo = [[], []];
        # Add keys to populate the depath via duo[]
        foreach ($depath as $_) {
            if (is_scalar($_)) {
                add_key($duo, $_, $parts, $result);
            } else {
                copy_onto($duo[0], reduced_values($_, $parts, $duo[1])[0]);
            }
        }
        # link depath into result, update caller's record of the depaths
        $depath = $result[$key] = DEPATH($duo[0], $duo[1], "{$lang}/{$key}");
    }
    return $result;
}
开发者ID:NasalMusician,项目名称:Pantheum,代码行数:17,代码来源:db_depaths.php

示例13: xmldb_group_upgrade

function xmldb_group_upgrade($oldversion = 0)
{
    global $CFG;
    $result = true;
    if ($result && $oldversion < 2007012000) {
        /// Changing nullability of field description on table groups to null
        $table = new XMLDBTable('groups');
        $field = new XMLDBField('description');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'name');
        /// Launch change of nullability for field description
        $result = $result && change_field_notnull($table, $field);
        /// Changing nullability of field description on table groups_groupings to null
        $table = new XMLDBTable('groups_groupings');
        $field = new XMLDBField('description');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'name');
        /// Launch change of nullability for field description
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2007012100) {
        /// Changing precision of field lang on table groups to (30)
        $table = new XMLDBTable('groups');
        $field = new XMLDBField('lang');
        $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'enrolmentkey');
        /// Launch change of precision for field lang
        $result = $result && change_field_precision($table, $field);
    }
    /// Adding all the missing FK + Unique indexes (XMLDB will create the underlying indexes)
    if ($result && $oldversion < 2007012200) {
        /// Define index groupid-courseid (unique) to be added to groups_members
        $table = new XMLDBTable('groups_members');
        $index = new XMLDBIndex('groupid-courseid');
        $index->setAttributes(XMLDB_INDEX_UNIQUE, array('groupid', 'userid'));
        /// Launch add index groupid-courseid
        $result = $result && add_index($table, $index);
        /// 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'));
        /// Launch add key courseid
        $result = $result && add_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'));
        /// Launch add key groupid
        $result = $result && add_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'));
        /// Launch add index courseid-groupid
        $result = $result && add_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'));
        /// Launch add key courseid
        $result = $result && add_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'));
        /// Launch add key groupingid
        $result = $result && add_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'));
        /// Launch add index courseid-groupingid
        $result = $result && add_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'));
        /// Launch add key groupingid
        $result = $result && add_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'));
        /// Launch add key groupid
        $result = $result && add_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'));
        /// Launch add index groupingid-groupid
        $result = $result && add_index($table, $index);
    }
    if ($result && $oldversion < 2007012400) {
        if (table_exists(new XMLDBTable('groups_temp')) && file_exists($CFG->dirroot . '/group/db/install.xml')) {
            /// Need to drop foreign keys/indexes added in last upgrade, drop 'new' tables, then start again!!
            $result = $result && groups_drop_keys_indexes_db();
            $result = $result && groups_revert_db($renametemp = false);
            $result = $result && install_from_xmldb_file($CFG->dirroot . '/group/db/install.xml');
            $result = $result && groups_transfer_db();
        }
    }
    return $result;
}
开发者ID:veritech,项目名称:pare-project,代码行数:100,代码来源:upgrade.php

示例14: xmldb_ouwiki_upgrade

function xmldb_ouwiki_upgrade($oldversion = 0)
{
    global $CFG, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    if ($result && $oldversion < 2007022300) {
        error('Cannot upgrade OU wiki module - please delete it by going to <a href="modules.php">the modules section</a> then delete it. (Module is called Wiki.) Then let it install itself again.');
    }
    if ($result && $oldversion < 2007041006) {
        // First fix some signed-ness, then upgrade database to support comment system
        $tw = new transaction_wrapper();
        /// Changing sign of field id on table ouwiki_subwikis to unsigned
        $table = new XMLDBTable('ouwiki_subwikis');
        $field = new XMLDBField('id');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        /// Launch change of sign for field id
        $result = $result && change_field_unsigned($table, $field);
        /// Changing sign of field id on table ouwiki_pages to unsigned
        $table = new XMLDBTable('ouwiki_pages');
        $field = new XMLDBField('id');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        /// Launch change of sign for field id
        $result = $result && change_field_unsigned($table, $field);
        /// Define key ouwiki_pages_fk_forumid (foreign) to be dropped form ouwiki_pages
        $table = new XMLDBTable('ouwiki_pages');
        $key = new XMLDBKey('ouwiki_pages_fk_forumid');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('forumid'), 'forum', array('id'));
        /// Launch drop key ouwiki_pages_fk_forumid
        $result = $result && drop_key($table, $key);
        /// Define field forumid to be dropped from ouwiki_pages
        $table = new XMLDBTable('ouwiki_pages');
        $field = new XMLDBField('forumid');
        /// Launch drop field forumid
        $result = $result && drop_field($table, $field);
        /// Changing sign of field id on table ouwiki_versions to unsigned
        $table = new XMLDBTable('ouwiki_versions');
        $field = new XMLDBField('id');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        /// Launch change of sign for field id
        $result = $result && change_field_unsigned($table, $field);
        /// Changing sign of field id on table ouwiki_links to unsigned
        $table = new XMLDBTable('ouwiki_links');
        $field = new XMLDBField('id');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        /// Launch change of sign for field id
        $result = $result && change_field_unsigned($table, $field);
        /// Changing sign of field id on table ouwiki_locks to unsigned
        $table = new XMLDBTable('ouwiki_locks');
        $field = new XMLDBField('id');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        /// Launch change of sign for field id
        $result = $result && change_field_unsigned($table, $field);
        // Due to a bug or issues with xmldb/postgres - MDL-9271 - it lost all the primary keys!
        // If this part of the upgrade fails because the primary keys are still there then that's
        // ok.
        /* XMLDB doesn't let you add primary keys! MDL-9272. Otherwise the code would be as follows:
           $table = new XMLDBTable('ouwiki_subwikis');
           $key = new XMLDBKey('primary');
           $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
           $result = $result && add_key($table, $key);
           $table = new XMLDBTable('ouwiki_pages');
           $key = new XMLDBKey('primary');
           $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
           $result = $result && add_key($table, $key);
           $table = new XMLDBTable('ouwiki_versions');
           $key = new XMLDBKey('primary');
           $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
           $result = $result && add_key($table, $key);
           $table = new XMLDBTable('ouwiki_links');
           $key = new XMLDBKey('primary');
           $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
           $result = $result && add_key($table, $key);
           $table = new XMLDBTable('ouwiki_locks');
           $key = new XMLDBKey('primary');
           $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
           $result = $result && add_key($table, $key);
           */
        // This is Postgres-only
        $result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_subwikis ADD CONSTRAINT {$CFG->prefix}ouwisubw_id_pk PRIMARY KEY(id)");
        $result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_pages ADD CONSTRAINT {$CFG->prefix}ouwipage_id_pk PRIMARY KEY(id)");
        $result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_versions ADD CONSTRAINT {$CFG->prefix}ouwivers_id_pk PRIMARY KEY(id)");
        $result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_links ADD CONSTRAINT {$CFG->prefix}ouwilink_id_pk PRIMARY KEY(id)");
        $result &= execute_sql("ALTER TABLE {$CFG->prefix}ouwiki_locks ADD CONSTRAINT {$CFG->prefix}ouwilock_id_pk PRIMARY KEY(id)");
        /// Define table ouwiki_sections to be created
        $table = new XMLDBTable('ouwiki_sections');
        /// Adding fields to table ouwiki_sections
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('xhtmlid', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
        $table->addFieldInfo('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table ouwiki_sections
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('ouwiki_sections_fk_pageid', XMLDB_KEY_FOREIGN, array('pageid'), 'ouwiki_pages', array('id'));
        /// Launch create table for ouwiki_sections
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php

示例15: xmldb_forumng_upgrade


//.........这里部分代码省略.........
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'forumid');
        /// Launch change of default for field subscribed
        $result = $result && change_field_default($table, $field);
    }
    if ($result && $oldversion < 2009111001) {
        /// Define field reportingemail to be added to forumng
        $table = new XMLDBTable('forumng');
        $field = new XMLDBField('reportingemail');
        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'attachmentmaxbytes');
        /// Launch add field reportingemail
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2009111002) {
        /// Define table forumng_flags to be created
        $table = new XMLDBTable('forumng_flags');
        /// Adding fields to table forumng_flags
        $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('postid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('flagged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table forumng_flags
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        $table->addKeyInfo('postid', XMLDB_KEY_FOREIGN, array('postid'), 'forumng_posts', array('id'));
        /// Launch create table for forumng_flags
        $result = $result && create_table($table);
    }
    if ($result && $oldversion < 2009120200) {
        // For OU version only, rebuild course cache - it is missing some of
        // the completion information
        if (class_exists('ouflags')) {
            rebuild_course_cache(0, true);
        }
    }
    if ($result && $oldversion < 2010020200) {
        /// Define field discussionid to be added to forumng_subscriptions
        $table = new XMLDBTable('forumng_subscriptions');
        $field = new XMLDBField('discussionid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'subscribed');
        /// Launch add field discussionid
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2010051300) {
        /// Define field removeafter to be added to forumng
        $table = new XMLDBTable('forumng');
        $field = new XMLDBField('removeafter');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionposts');
        /// Launch add field removeafter
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('removeto');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'removeafter');
        /// Launch add field removeto
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2010071900) {
        /// Define field shared to be added to forumng
        $table = new XMLDBTable('forumng');
        $field = new XMLDBField('shared');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'removeto');
        /// Launch add field shared
        $result = $result && add_field($table, $field);
        /// Define field originalcmid to be added to forumng
        $field = new XMLDBField('originalcmid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'shared');
        /// Launch add field originalcmid
        $result = $result && add_field($table, $field);
        /// Define key originalcmid (foreign) to be added to forumng
        $key = new XMLDBKey('originalcmid');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('originalcmid'), 'course_modules', array('id'));
        /// Launch add key originalcmid
        $result = $result && add_key($table, $key);
    }
    if ($result && $oldversion < 2010072100) {
        /// Define field clonecmid to be added to forumng_subscriptions
        $table = new XMLDBTable('forumng_subscriptions');
        $field = new XMLDBField('clonecmid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'discussionid');
        /// Launch add field clonecmid
        $result = $result && add_field($table, $field);
        /// Define key clonecmid (foreign) to be added to forumng_subscriptions
        $key = new XMLDBKey('clonecmid');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('clonecmid'), 'course_modules', array('id'));
        /// Launch add key clonecmid
        $result = $result && add_key($table, $key);
    }
    if ($result && $oldversion < 2010073000) {
        /// Define field groupid to be added to forumng_subscriptions
        $table = new XMLDBTable('forumng_subscriptions');
        $field = new XMLDBField('groupid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'clonecmid');
        /// Launch add field groupid
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2010073001) {
        $db->debug = false;
        forum::group_subscription_update(true);
        $db->debug = true;
    }
    return $result;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php


注:本文中的add_key函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。