function setUp()
 {
     // Set db prefix for testing
     global $CFG, $USER;
     $this->beforeprefix = $CFG->prefix;
     $this->beforeuser = $USER;
     $CFG->prefix = self::TESTPREFIX;
     // Delete existing tables
     $this->delete_tables();
     // Install new wiki tables and core user table
     ob_start();
     install_from_xmldb_file(dirname(__FILE__) . '/../db/install.xml');
     ob_end_clean();
     load_test_table(self::TESTPREFIX . 'user', array(array('id', 'username', 'firstname', 'lastname'), array(1, 'u1', 'user', 'one'), array(2, 'u2', 'user', 'two'), array(3, 'u3', 'user', 'three')));
     $USER = get_record('user', 'id', 1);
 }
Пример #2
0
function xmldb_block_tao_certification_path_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    if ($result && $oldversion < 2008111204) {
        //New version in version.php
        $table = new XMLDBTable('tao_user_certification_status');
        if (!table_exists($table)) {
            //this table doesn't exist so create it!
            $result = install_from_xmldb_file("{$CFG->dirroot}/blocks/tao_certification_path/db/install.xml");
        }
    }
    return $result;
}
Пример #3
0
function upgrade_blocks_plugins($continueto)
{
    global $CFG, $db;
    $blocktitles = array();
    $invalidblocks = array();
    $validblocks = array();
    $notices = array();
    //Count the number of blocks in db
    $blockcount = count_records('block');
    //If there isn't records. This is the first install, so I remember it
    if ($blockcount == 0) {
        $first_install = true;
    } else {
        $first_install = false;
    }
    $site = get_site();
    if (!($blocks = get_list_of_plugins('blocks', 'db'))) {
        error('No blocks installed!');
    }
    include_once $CFG->dirroot . '/blocks/moodleblock.class.php';
    if (!class_exists('block_base')) {
        error('Class block_base is not defined or file not found for /blocks/moodleblock.class.php');
    }
    foreach ($blocks as $blockname) {
        if ($blockname == 'NEWBLOCK') {
            // Someone has unzipped the template, ignore it
            continue;
        }
        if (!block_is_compatible($blockname)) {
            // This is an old-style block
            //$notices[] = 'Block '. $blockname .' is not compatible with the current version of Mooodle and needs to be updated by a programmer.';
            $invalidblocks[] = $blockname;
            continue;
        }
        $fullblock = $CFG->dirroot . '/blocks/' . $blockname;
        if (is_readable($fullblock . '/block_' . $blockname . '.php')) {
            include_once $fullblock . '/block_' . $blockname . '.php';
        } else {
            $notices[] = 'Block ' . $blockname . ': ' . $fullblock . '/block_' . $blockname . '.php was not readable';
            continue;
        }
        $oldupgrade = false;
        $newupgrade = false;
        if (@is_dir($fullblock . '/db/')) {
            if (@is_readable($fullblock . '/db/' . $CFG->dbtype . '.php')) {
                include_once $fullblock . '/db/' . $CFG->dbtype . '.php';
                // defines old upgrading function
                $oldupgrade = true;
            }
            if (@is_readable($fullblock . '/db/upgrade.php')) {
                include_once $fullblock . '/db/upgrade.php';
                // defines new upgrading function
                $newupgrade = true;
            }
        }
        $classname = 'block_' . $blockname;
        if (!class_exists($classname)) {
            $notices[] = 'Block ' . $blockname . ': ' . $classname . ' not implemented';
            continue;
        }
        // Here is the place to see if the block implements a constructor (old style),
        // an init() function (new style) or nothing at all (error time).
        $constructor = get_class_constructor($classname);
        if (empty($constructor)) {
            // No constructor
            $notices[] = 'Block ' . $blockname . ': class does not have a constructor';
            $invalidblocks[] = $blockname;
            continue;
        }
        $block = new stdClass();
        // This may be used to update the db below
        $blockobj = new $classname();
        // This is what we 'll be testing
        // Inherits from block_base?
        if (!is_subclass_of($blockobj, 'block_base')) {
            $notices[] = 'Block ' . $blockname . ': class does not inherit from block_base';
            continue;
        }
        // OK, it's as we all hoped. For further tests, the object will do them itself.
        if (!$blockobj->_self_test()) {
            $notices[] = 'Block ' . $blockname . ': self test failed';
            continue;
        }
        $block->version = $blockobj->get_version();
        if (!isset($block->version)) {
            $notices[] = 'Block ' . $blockname . ': has no version support. It must be updated by a programmer.';
            continue;
        }
        $block->name = $blockname;
        // The name MUST match the directory
        $blocktitle = $blockobj->get_title();
        if ($currblock = get_record('block', 'name', $block->name)) {
            if ($currblock->version == $block->version) {
                // do nothing
            } else {
                if ($currblock->version < $block->version) {
                    if (empty($updated_blocks)) {
                        $strblocksetup = get_string('blocksetup');
                        print_header($strblocksetup, $strblocksetup, build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
                    }
                    $updated_blocks = true;
                    upgrade_log_start();
                    print_heading('New version of ' . $blocktitle . ' (' . $block->name . ') exists');
                    @set_time_limit(0);
                    // To allow slow databases to complete the long SQL
                    /// Run de old and new upgrade functions for the module
                    $oldupgrade_function = $block->name . '_upgrade';
                    $newupgrade_function = 'xmldb_block_' . $block->name . '_upgrade';
                    /// First, the old function if exists
                    $oldupgrade_status = true;
                    if ($oldupgrade && function_exists($oldupgrade_function)) {
                        $db->debug = true;
                        $oldupgrade_status = $oldupgrade_function($currblock->version, $block);
                    } else {
                        if ($oldupgrade) {
                            notify('Upgrade function ' . $oldupgrade_function . ' was not available in ' . $fullblock . '/db/' . $CFG->dbtype . '.php');
                        }
                    }
                    /// Then, the new function if exists and the old one was ok
                    $newupgrade_status = true;
                    if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
                        $db->debug = true;
                        $newupgrade_status = $newupgrade_function($currblock->version, $block);
                    } else {
                        if ($newupgrade) {
                            notify('Upgrade function ' . $newupgrade_function . ' was not available in ' . $fullblock . '/db/upgrade.php');
                        }
                    }
                    $db->debug = false;
                    /// Now analyze upgrade results
                    if ($oldupgrade_status && $newupgrade_status) {
                        // No upgrading failed
                        // Set the block cron on upgrade
                        $block->cron = !empty($blockobj->cron) ? $blockobj->cron : 0;
                        // OK so far, now update the block record
                        $block->id = $currblock->id;
                        if (!update_record('block', $block)) {
                            error('Could not update block ' . $block->name . ' record in block table!');
                        }
                        $component = 'block/' . $block->name;
                        if (!update_capabilities($component)) {
                            error('Could not update ' . $block->name . ' capabilities!');
                        }
                        events_update_definition($component);
                        notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
                    } else {
                        notify('Upgrading block ' . $block->name . ' from ' . $currblock->version . ' to ' . $block->version . ' FAILED!');
                    }
                    echo '<hr />';
                } else {
                    upgrade_log_start();
                    error('Version mismatch: block ' . $block->name . ' can\'t downgrade ' . $currblock->version . ' -> ' . $block->version . '!');
                }
            }
        } else {
            // block not installed yet, so install it
            // If it allows multiples, start with it enabled
            if ($blockobj->instance_allow_multiple()) {
                $block->multiple = 1;
            }
            // Set the block cron on install
            $block->cron = !empty($blockobj->cron) ? $blockobj->cron : 0;
            // [pj] Normally this would be inline in the if, but we need to
            //      check for NULL (necessary for 4.0.5 <= PHP < 4.2.0)
            $conflictblock = array_search($blocktitle, $blocktitles);
            if ($conflictblock !== false && $conflictblock !== NULL) {
                // Duplicate block titles are not allowed, they confuse people
                // AND PHP's associative arrays ;)
                error('<strong>Naming conflict</strong>: block <strong>' . $block->name . '</strong> has the same title with an existing block, <strong>' . $conflictblock . '</strong>!');
            }
            if (empty($updated_blocks)) {
                $strblocksetup = get_string('blocksetup');
                print_header($strblocksetup, $strblocksetup, build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
            }
            $updated_blocks = true;
            upgrade_log_start();
            print_heading($block->name);
            $db->debug = true;
            @set_time_limit(0);
            // To allow slow databases to complete the long SQL
            /// Both old .sql files and new install.xml are supported
            /// but we priorize install.xml (XMLDB) if present
            $status = false;
            if (file_exists($fullblock . '/db/install.xml')) {
                $status = install_from_xmldb_file($fullblock . '/db/install.xml');
                //New method
            } else {
                if (file_exists($fullblock . '/db/' . $CFG->dbtype . '.sql')) {
                    $status = modify_database($fullblock . '/db/' . $CFG->dbtype . '.sql');
                    //Old method
                } else {
                    $status = true;
                }
            }
            $db->debug = false;
            if ($status) {
                if ($block->id = insert_record('block', $block)) {
                    $blockobj->after_install();
                    $component = 'block/' . $block->name;
                    if (!update_capabilities($component)) {
                        notify('Could not set up ' . $block->name . ' capabilities!');
                    }
                    events_update_definition($component);
                    notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
                    echo '<hr />';
                } else {
                    error($block->name . ' block could not be added to the block list!');
                }
            } else {
                error('Block ' . $block->name . ' tables could NOT be set up successfully!');
            }
        }
        $blocktitles[$block->name] = $blocktitle;
    }
    if (!empty($notices)) {
        upgrade_log_start();
        foreach ($notices as $notice) {
            notify($notice);
        }
    }
    // Finally, if we are in the first_install of BLOCKS (this means that we are
    // upgrading from Moodle < 1.3), put blocks in all existing courses.
    if ($first_install) {
        upgrade_log_start();
        //Iterate over each course
        if ($courses = get_records('course')) {
            foreach ($courses as $course) {
                $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
                blocks_repopulate_page($page);
            }
        }
    }
    if (!empty($CFG->siteblocksadded)) {
        /// This is a once-off hack to make a proper upgrade
        upgrade_log_start();
        $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
        blocks_repopulate_page($page);
        delete_records('config', 'name', 'siteblocksadded');
    }
    upgrade_log_finish();
    if (!empty($updated_blocks)) {
        print_continue($continueto);
        print_footer('none');
        die;
    }
}
Пример #4
0
/**
 * Upgrades the plugin to a new version
 *
 * @param object $upgrade   Information about the plugin to upgrade
 * @return bool             Whether the upgrade succeeded or not
 * @throws SQLException     If the upgrade failed due to a database error
 */
function upgrade_plugin($upgrade)
{
    global $db;
    $plugintype = '';
    $pluginname = '';
    list($plugintype, $pluginname) = explode('.', $upgrade->name);
    if ($plugintype == 'blocktype' && strpos($pluginname, '/') !== false) {
        list($artefactplugin, $blocktypename) = explode('/', $pluginname);
    }
    $location = get_config('docroot') . $plugintype . '/' . $pluginname . '/db/';
    db_begin();
    if (!empty($upgrade->install)) {
        if (is_readable($location . 'install.xml')) {
            install_from_xmldb_file($location . 'install.xml');
        }
    } else {
        if (is_readable($location . 'upgrade.php')) {
            require_once $location . 'upgrade.php';
            $function = 'xmldb_' . $plugintype . '_' . $pluginname . '_upgrade';
            if (!$function($upgrade->from)) {
                throw new InstallationException("Failed to run " . $function . " (check logs for errors)");
            }
        }
    }
    $installed = new StdClass();
    $installed->name = $pluginname;
    $installed->version = $upgrade->to;
    $installed->release = $upgrade->torelease;
    if ($plugintype == 'blocktype') {
        if (!empty($blocktypename)) {
            $installed->name = $blocktypename;
        }
        if (!empty($artefactplugin)) {
            // blocks come from artefactplugins.
            $installed->artefactplugin = $artefactplugin;
        }
    }
    if (property_exists($upgrade, 'requires_config')) {
        $installed->requires_config = $upgrade->requires_config;
    }
    if (property_exists($upgrade, 'requires_parent')) {
        $installed->requires_parent = $upgrade->requires_parent;
    }
    $installtable = $plugintype . '_installed';
    if (!empty($upgrade->install)) {
        insert_record($installtable, $installed);
    } else {
        update_record($installtable, $installed, 'name');
    }
    // postinst stuff...
    safe_require($plugintype, $pluginname);
    $pcname = generate_class_name($plugintype, $installed->name);
    if ($crons = call_static_method($pcname, 'get_cron')) {
        foreach ($crons as $cron) {
            $cron = (object) $cron;
            if (empty($cron->callfunction)) {
                throw new InstallationException("cron for {$pcname} didn't supply function name");
            }
            if (!is_callable(array($pcname, $cron->callfunction))) {
                throw new InstallationException("cron {$cron->callfunction} for {$pcname} supplied but wasn't callable");
            }
            $new = false;
            $table = $plugintype . '_cron';
            if (!empty($upgrade->install)) {
                $new = true;
            } else {
                if (!record_exists($table, 'plugin', $pluginname, 'callfunction', $cron->callfunction)) {
                    $new = true;
                }
            }
            $cron->plugin = $pluginname;
            if (!empty($new)) {
                insert_record($table, $cron);
            } else {
                update_record($table, $cron, array('plugin', 'callfunction'));
            }
        }
    }
    if ($events = call_static_method($pcname, 'get_event_subscriptions')) {
        foreach ($events as $event) {
            $event = (object) $event;
            if (!record_exists('event_type', 'name', $event->event)) {
                throw new InstallationException("event {$event->event} for {$pcname} doesn't exist!");
            }
            if (empty($event->callfunction)) {
                throw new InstallationException("event {$event->event} for {$pcname} didn't supply function name");
            }
            if (!is_callable(array($pcname, $event->callfunction))) {
                throw new InstallationException("event {$event->event} with function {$event->callfunction} for {$pcname} supplied but wasn't callable");
            }
            $exists = false;
            $table = $plugintype . '_event_subscription';
            $block = blocktype_namespaced_to_single($pluginname);
            if (empty($upgrade->install)) {
                $exists = get_record($table, 'plugin', $block, 'event', $event->event);
            }
            $event->plugin = $block;
            if (empty($exists)) {
                insert_record($table, $event);
            } else {
                update_record($table, $event, array('id' => $exists->id));
            }
        }
    }
    if ($activities = call_static_method($pcname, 'get_activity_types')) {
        foreach ($activities as $activity) {
            $classname = 'ActivityType' . ucfirst($plugintype) . ucfirst($pluginname) . ucfirst($activity->name);
            if (!class_exists($classname)) {
                throw new InstallationException(get_string('classmissing', 'error', $classname, $pluginname, $plugintype));
            }
            $activity->plugintype = $plugintype;
            $activity->pluginname = $pluginname;
            $where = $activity;
            unset($where->admin);
            unset($where->delay);
            // Work around the fact that insert_record cached the columns that
            // _were_ in the activity_type table before it was upgraded
            global $INSERTRECORD_NOCACHE;
            $INSERTRECORD_NOCACHE = true;
            ensure_record_exists('activity_type', $where, $activity);
            unset($INSERTRECORD_NOCACHE);
        }
    }
    // install artefact types
    if ($plugintype == 'artefact') {
        if (!is_callable(array($pcname, 'get_artefact_types'))) {
            throw new InstallationException("Artefact plugin {$pcname} must implement get_artefact_types and doesn't");
        }
        $types = call_static_method($pcname, 'get_artefact_types');
        $ph = array();
        if (is_array($types)) {
            foreach ($types as $type) {
                $ph[] = '?';
                if (!record_exists('artefact_installed_type', 'plugin', $pluginname, 'name', $type)) {
                    $t = new StdClass();
                    $t->name = $type;
                    $t->plugin = $pluginname;
                    insert_record('artefact_installed_type', $t);
                }
            }
            $select = '(plugin = ? AND name NOT IN (' . implode(',', $ph) . '))';
            delete_records_select('artefact_installed_type', $select, array_merge(array($pluginname), $types));
        }
    }
    // install blocktype categories.
    if ($plugintype == 'blocktype' && get_config('installed')) {
        install_blocktype_categories_for_plugin($pluginname);
        install_blocktype_viewtypes_for_plugin($pluginname);
    }
    $prevversion = empty($upgrade->install) ? $upgrade->from : 0;
    call_static_method($pcname, 'postinst', $prevversion);
    db_commit();
    return true;
}
Пример #5
0
 /// return to original debugging level
 $CFG->debug = $origdebug;
 error_reporting($CFG->debug);
 upgrade_log_start();
 $db->debug = true;
 /// Both old .sql files and new install.xml are supported
 /// But we prioritise install.xml (XMLDB) if present
 change_db_encoding();
 // first try to change db encoding to utf8
 if (!setup_is_unicodedb()) {
     // If could not convert successfully, throw error, and prevent installation
     print_error('unicoderequired', 'admin');
 }
 $status = false;
 if (file_exists("{$CFG->libdir}/db/install.xml")) {
     $status = install_from_xmldb_file("{$CFG->libdir}/db/install.xml");
     //New method
 } else {
     if (file_exists("{$CFG->libdir}/db/{$CFG->dbtype}.sql")) {
         $status = modify_database("{$CFG->libdir}/db/{$CFG->dbtype}.sql");
         //Old method
     } else {
         error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by Moodle or install.xml is not present.  See the lib/db directory.");
     }
 }
 // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
 set_config('unicodedb', 1);
 /// Continue with the instalation
 $db->debug = false;
 if ($status) {
     /// Groups install is now in core above.
Пример #6
0
/**
 * Find and check all modules and load them up or upgrade them if necessary
 *
 * @uses $db
 * @uses $CFG
 * @param string $return The url to prompt the user to continue to
 * @todo Finish documenting this function
 */
function upgrade_activity_modules($return)
{
    global $CFG, $db;
    if (!($mods = get_list_of_plugins('mod'))) {
        error('No modules installed!');
    }
    $updated_modules = false;
    $strmodulesetup = get_string('modulesetup');
    foreach ($mods as $mod) {
        if ($mod == 'NEWMODULE') {
            // Someone has unzipped the template, ignore it
            continue;
        }
        $fullmod = $CFG->dirroot . '/mod/' . $mod;
        unset($module);
        if (is_readable($fullmod . '/version.php')) {
            include_once $fullmod . '/version.php';
            // defines $module with version etc
        } else {
            notify('Module ' . $mod . ': ' . $fullmod . '/version.php was not readable');
            continue;
        }
        $oldupgrade = false;
        $newupgrade = false;
        if (is_readable($fullmod . '/db/' . $CFG->dbtype . '.php')) {
            include_once $fullmod . '/db/' . $CFG->dbtype . '.php';
            // defines old upgrading function
            $oldupgrade = true;
        }
        if (is_readable($fullmod . '/db/upgrade.php')) {
            include_once $fullmod . '/db/upgrade.php';
            // defines new upgrading function
            $newupgrade = true;
        }
        if (!isset($module)) {
            continue;
        }
        if (!empty($module->requires)) {
            if ($module->requires > $CFG->version) {
                $info = new object();
                $info->modulename = $mod;
                $info->moduleversion = $module->version;
                $info->currentmoodle = $CFG->version;
                $info->requiremoodle = $module->requires;
                if (!$updated_modules) {
                    print_header($strmodulesetup, $strmodulesetup, build_navigation(array(array('name' => $strmodulesetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
                }
                upgrade_log_start();
                notify(get_string('modulerequirementsnotmet', 'error', $info));
                $updated_modules = true;
                continue;
            }
        }
        $module->name = $mod;
        // The name MUST match the directory
        include_once $fullmod . '/lib.php';
        // defines upgrading and/or installing functions
        if ($currmodule = get_record('modules', 'name', $module->name)) {
            if ($currmodule->version == $module->version) {
                // do nothing
            } else {
                if ($currmodule->version < $module->version) {
                    /// If versions say that we need to upgrade but no upgrade files are available, notify and continue
                    if (!$oldupgrade && !$newupgrade) {
                        notify('Upgrade files ' . $mod . ': ' . $fullmod . '/db/' . $CFG->dbtype . '.php or ' . $fullmod . '/db/upgrade.php were not readable');
                        continue;
                    }
                    if (!$updated_modules) {
                        print_header($strmodulesetup, $strmodulesetup, build_navigation(array(array('name' => $strmodulesetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
                    }
                    upgrade_log_start();
                    print_heading($module->name . ' module needs upgrading');
                    /// Run de old and new upgrade functions for the module
                    $oldupgrade_function = $module->name . '_upgrade';
                    $newupgrade_function = 'xmldb_' . $module->name . '_upgrade';
                    /// First, the old function if exists
                    $oldupgrade_status = true;
                    if ($oldupgrade && function_exists($oldupgrade_function)) {
                        $db->debug = true;
                        $oldupgrade_status = $oldupgrade_function($currmodule->version, $module);
                        if (!$oldupgrade_status) {
                            notify('Upgrade function ' . $oldupgrade_function . ' did not complete successfully.');
                        }
                    } else {
                        if ($oldupgrade) {
                            notify('Upgrade function ' . $oldupgrade_function . ' was not available in ' . $mod . ': ' . $fullmod . '/db/' . $CFG->dbtype . '.php');
                        }
                    }
                    /// Then, the new function if exists and the old one was ok
                    $newupgrade_status = true;
                    if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
                        $db->debug = true;
                        $newupgrade_status = $newupgrade_function($currmodule->version, $module);
                    } else {
                        if ($newupgrade && $oldupgrade_status) {
                            notify('Upgrade function ' . $newupgrade_function . ' was not available in ' . $mod . ': ' . $fullmod . '/db/upgrade.php');
                        }
                    }
                    $db->debug = false;
                    /// Now analyze upgrade results
                    if ($oldupgrade_status && $newupgrade_status) {
                        // No upgrading failed
                        // OK so far, now update the modules record
                        $module->id = $currmodule->id;
                        if (!update_record('modules', $module)) {
                            error('Could not update ' . $module->name . ' record in modules table!');
                        }
                        remove_dir($CFG->dataroot . '/cache', true);
                        // flush cache
                        notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
                        echo '<hr />';
                    } else {
                        notify('Upgrading ' . $module->name . ' from ' . $currmodule->version . ' to ' . $module->version . ' FAILED!');
                    }
                    /// Update the capabilities table?
                    if (!update_capabilities('mod/' . $module->name)) {
                        error('Could not update ' . $module->name . ' capabilities!');
                    }
                    events_update_definition('mod/' . $module->name);
                    $updated_modules = true;
                } else {
                    upgrade_log_start();
                    error('Version mismatch: ' . $module->name . ' can\'t downgrade ' . $currmodule->version . ' -> ' . $module->version . ' !');
                }
            }
        } else {
            // module not installed yet, so install it
            if (!$updated_modules) {
                print_header($strmodulesetup, $strmodulesetup, build_navigation(array(array('name' => $strmodulesetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
            }
            upgrade_log_start();
            print_heading($module->name);
            $updated_modules = true;
            $db->debug = true;
            @set_time_limit(0);
            // To allow slow databases to complete the long SQL
            /// Both old .sql files and new install.xml are supported
            /// but we priorize install.xml (XMLDB) if present
            if (file_exists($fullmod . '/db/install.xml')) {
                $status = install_from_xmldb_file($fullmod . '/db/install.xml');
                //New method
            } else {
                $status = modify_database($fullmod . '/db/' . $CFG->dbtype . '.sql');
                //Old method
            }
            $db->debug = false;
            /// Continue with the installation, roles and other stuff
            if ($status) {
                if ($module->id = insert_record('modules', $module)) {
                    /// Capabilities
                    if (!update_capabilities('mod/' . $module->name)) {
                        error('Could not set up the capabilities for ' . $module->name . '!');
                    }
                    /// Events
                    events_update_definition('mod/' . $module->name);
                    /// Run local install function if there is one
                    $installfunction = $module->name . '_install';
                    if (function_exists($installfunction)) {
                        if (!$installfunction()) {
                            notify('Encountered a problem running install function for ' . $module->name . '!');
                        }
                    }
                    notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
                    echo '<hr />';
                } else {
                    error($module->name . ' module could not be added to the module list!');
                }
            } else {
                error($module->name . ' tables could NOT be set up successfully!');
            }
        }
        /// Check submodules of this module if necessary
        $submoduleupgrade = $module->name . '_upgrade_submodules';
        if (function_exists($submoduleupgrade)) {
            $submoduleupgrade();
        }
        /// Run any defaults or final code that is necessary for this module
        if (is_readable($fullmod . '/defaults.php')) {
            // Insert default values for any important configuration variables
            unset($defaults);
            include $fullmod . '/defaults.php';
            // include here means execute, not library include
            if (!empty($defaults)) {
                foreach ($defaults as $name => $value) {
                    if (!isset($CFG->{$name})) {
                        set_config($name, $value);
                    }
                }
            }
        }
    }
    upgrade_log_finish();
    // finish logging if started
    if ($updated_modules) {
        print_continue($return);
        print_footer('none');
        die;
    }
}
Пример #7
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2009 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 File system
 * @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_repository_alfresco_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2007011900) {
        $result = install_from_xmldb_file($CFG->dirroot . '/repository/alfresco/db/install.xml');
    }
    if ($result && $oldversion < 2010030901) {
        $table = new XMLDBTable('alfresco_course_store');
        $table->comment = 'Stores course storage UUID values';
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('uuid', XMLDB_TYPE_CHAR, '36', null, false, null, null, null, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
        $table->addIndexInfo('courseid-uuid', XMLDB_INDEX_UNIQUE, array('courseid', 'uuid'));
        $result = $result && create_table($table);
        // Only proceed here if the Alfresco plug-in is actually enabled.
        if (isset($CFG->repository_plugins_enabled) && strstr($CFG->repository_plugins_enabled, 'alfresco')) {
            // Handle upgrading some things on the Alfresco repository.
            require_once $CFG->dirroot . '/file/repository/repository.class.php';
            if (!($repo = repository_factory::factory('alfresco'))) {
                debugging(get_string('couldnotcreaterepositoryobject', 'repository'), DEBUG_DEVELOPER);
                $result = false;
            }
            // Turn off "Inherit parent space permissions" for the special Moodle storage directories.
            $result = $result && $repo->node_inherit($repo->muuid, false);
            $result = $result && $repo->node_inherit($repo->suuid, false);
            $result = $result && $repo->node_inherit($repo->cuuid, false);
            // Make sure that all of the individual course directories are set to not interhit parent space permissions.
            $dir = $repo->read_dir($repo->cuuid);
            if (!empty($dir->folders)) {
                foreach ($dir->folders as $folder) {
                    if ((int) $folder->title != $folder->title || (int) $folder->title <= 1 || !($course = get_record('course', 'id', $folder->title, '', '', '', '', 'id,shortname'))) {
                        continue;
                    }
                    // Check if we need to add this node to the course store table.
                    if ($result && !record_exists('alfresco_course_store', 'courseid', $course->id)) {
                        $coursestore = new stdClass();
                        $coursestore->courseid = $course->id;
                        $coursestore->uuid = $folder->uuid;
                        $coursestore->id = insert_record('alfresco_course_store', $coursestore);
                        $result = !empty($coursestore->id);
                    }
                    $result = $result && $repo->node_inherit($folder->uuid, false);
                    $result = $result && alfresco_node_rename($folder->uuid, $course->shortname);
                }
            }
        }
    }
    if ($result && $oldversion < 2010032900) {
        // Only proceed here if the Alfresco plug-in is actually enabled.
        if (isset($CFG->repository_plugins_enabled) && strstr($CFG->repository_plugins_enabled, 'alfresco')) {
            // Handle upgrading some things on the Alfresco repository.
            require_once $CFG->dirroot . '/file/repository/repository.class.php';
            if (!($repo = repository_factory::factory('alfresco'))) {
                debugging(get_string('couldnotcreaterepositoryobject', 'repository'), DEBUG_DEVELOPER);
                $result = false;
            }
            $root = $repo->get_root();
            if (!empty($root->uuid)) {
                $dir = $repo->read_dir($root->uuid, true);
                if (!empty($dir->folders)) {
                    foreach ($dir->folders as $folder) {
                        // Process each of these directories to make sure that any non-privileged user cannot directly
                        // access them.
                        if ($folder->title == 'Data Dictionary' || $folder->title == 'Guest Home' || $folder->title == 'Sites') {
                            $a = new stdClass();
                            $a->uuid = $folder->uuid;
                            $a->name = $folder->title;
                            echo '<p>' . get_string('lockingdownpermissionson', 'repository_alfresco', $a) . '</p>';
                            if ($permissions = alfresco_get_permissions($folder->uuid, 'GROUP_EVERYONE')) {
                                foreach ($permissions as $permission) {
                                    // Make sure the node isn't inheriting parent node permissions.
                                    $repo->node_inherit($folder->uuid, false);
                                    // Construct the post data
                                    $postdata = array('username' => 'GROUP_EVERYONE', 'name' => $permission, 'capability' => ALFRESCO_CAPABILITY_DENIED);
                                    // We're not going to examine the response (we assume it worked).
                                    $response = alfresco_send('/moodle/setpermissions/' . $folder->uuid, $postdata, 'POST');
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($result && $oldversion < 2010090300) {
        // Add the mapping table for organization shared spaces.
        $table = new XMLDBTable('alfresco_organization_store');
        $table->comment = 'Stores organization shared storage UUID values';
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('organizationid', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('uuid', XMLDB_TYPE_CHAR, '36', null, false, null, null, null, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('organizationid', XMLDB_KEY_FOREIGN, array('organizationid'), 'crlm_cluster', array('id'));
        $table->addIndexInfo('organization-uuid', XMLDB_INDEX_UNIQUE, array('organizationid', 'uuid'));
        $result = $result && create_table($table);
    }
    return $result;
}
Пример #8
0
function upgrade_backup_db($continueto)
{
    /// This function upgrades the backup tables, if necessary
    /// It's called from admin/index.php, also backup.php and restore.php
    global $CFG, $db;
    require_once "{$CFG->dirroot}/backup/version.php";
    // Get code versions
    if (empty($CFG->backup_version)) {
        // Backup has never been installed.
        $strdatabaseupgrades = get_string("databaseupgrades");
        $navlinks = array();
        $navlinks[] = array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc');
        $navigation = build_navigation($navlinks);
        print_header($strdatabaseupgrades, $strdatabaseupgrades, $navigation, "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
        upgrade_log_start();
        print_heading('backup');
        $db->debug = true;
        /// Both old .sql files and new install.xml are supported
        /// but we priorize install.xml (XMLDB) if present
        $status = false;
        if (file_exists($CFG->dirroot . '/backup/db/install.xml')) {
            $status = install_from_xmldb_file($CFG->dirroot . '/backup/db/install.xml');
            //New method
        } else {
            if (file_exists($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql')) {
                $status = modify_database($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql');
                //Old method
            }
        }
        $db->debug = false;
        if ($status) {
            if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
                //initialize default backup settings now
                $adminroot = admin_get_root();
                apply_default_settings($adminroot->locate('backups'));
                notify(get_string("databasesuccess"), "green");
                notify(get_string("databaseupgradebackups", "", $backup_version), "green");
                print_continue($continueto);
                print_footer('none');
                exit;
            } else {
                error("Upgrade of backup system failed! (Could not update version in config table)");
            }
        } else {
            error("Backup tables could NOT be set up successfully!");
        }
    }
    /// Upgrading code starts here
    $oldupgrade = false;
    $newupgrade = false;
    if (is_readable($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.php')) {
        include_once $CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.php';
        // defines old upgrading function
        $oldupgrade = true;
    }
    if (is_readable($CFG->dirroot . '/backup/db/upgrade.php')) {
        include_once $CFG->dirroot . '/backup/db/upgrade.php';
        // defines new upgrading function
        $newupgrade = true;
    }
    if ($backup_version > $CFG->backup_version) {
        // Upgrade tables
        $strdatabaseupgrades = get_string("databaseupgrades");
        $navigation = array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'));
        print_header($strdatabaseupgrades, $strdatabaseupgrades, build_navigation($navigation), '', upgrade_get_javascript());
        upgrade_log_start();
        print_heading('backup');
        /// Run de old and new upgrade functions for the module
        $oldupgrade_function = 'backup_upgrade';
        $newupgrade_function = 'xmldb_backup_upgrade';
        /// First, the old function if exists
        $oldupgrade_status = true;
        if ($oldupgrade && function_exists($oldupgrade_function)) {
            $db->debug = true;
            $oldupgrade_status = $oldupgrade_function($CFG->backup_version);
        } else {
            if ($oldupgrade) {
                notify('Upgrade function ' . $oldupgrade_function . ' was not available in ' . '/backup/db/' . $CFG->dbtype . '.php');
            }
        }
        /// Then, the new function if exists and the old one was ok
        $newupgrade_status = true;
        if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
            $db->debug = true;
            $newupgrade_status = $newupgrade_function($CFG->backup_version);
        } else {
            if ($newupgrade) {
                notify('Upgrade function ' . $newupgrade_function . ' was not available in ' . '/backup/db/upgrade.php');
            }
        }
        $db->debug = false;
        /// Now analyze upgrade results
        if ($oldupgrade_status && $newupgrade_status) {
            // No upgrading failed
            if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
                notify(get_string("databasesuccess"), "green");
                notify(get_string("databaseupgradebackups", "", $backup_version), "green");
                print_continue($continueto);
                print_footer('none');
                exit;
            } else {
                error("Upgrade of backup system failed! (Could not update version in config table)");
            }
        } else {
            error("Upgrade failed!  See backup/version.php");
        }
    } else {
        if ($backup_version < $CFG->backup_version) {
            upgrade_log_start();
            notify("WARNING!!!  The code you are using is OLDER than the version that made these databases!");
        }
    }
    upgrade_log_finish();
}
function xmldb_block_exabis_eportfolio_upgrade($oldversion = 0, $tmp)
{
    global $CFG, $db;
    $result = true;
    //     if (empty($db)) {
    //         return false;
    //     }
    if ($oldversion < 2008090100 && !empty($db)) {
        // old tables
        $tables = array('block_exabeporpers', 'block_exabeporexte', 'block_exabeporcate', 'block_exabeporbooklink', 'block_exabeporcommlink', 'block_exabeporsharlink', 'block_exabeporbookfile', 'block_exabeporcommfile', 'block_exabeporsharfile', 'block_exabepornote', 'block_exabeporcommnote', 'block_exabeporsharnote');
        $tableNames = array();
        // rename tables to old_*
        foreach ($tables as $table) {
            $tableNames[$table] = 'old_' . $oldversion . '_' . $table;
            $xmltable = new XMLDBTable($table);
            rename_table($xmltable, $tableNames[$table]);
        }
        // add new tables
        install_from_xmldb_file(dirname(__FILE__) . '/install.xml');
        // import data from old tables
        $insert_type = 'REPLACE';
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporuser (id, user_id, persinfo_timemodified, description, user_hash)' . ' SELECT u.id, u.userid, u.timemodified, u.description, e.user_hash FROM ' . $CFG->prefix . $tableNames['block_exabeporpers'] . ' AS u LEFT JOIN ' . $CFG->prefix . $tableNames['block_exabeporexte'] . ' AS e ON u.userid = e.user_id');
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporcate (id, pid, userid, name, timemodified, courseid)' . ' SELECT id, pid, userid, name, timemodified, course FROM ' . $CFG->prefix . $tableNames['block_exabeporcate']);
        $file_id_start = 0;
        $note_id_start = get_field_select($tableNames['block_exabepornote'], 'MAX(id)', null) + 100;
        $link_id_start = get_field_select($tableNames['block_exabeporbooklink'], 'MAX(id)', null) + $note_id_start + 100;
        // combine item table
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitem' . ' (id, userid, type, categoryid, name, url, intro, attachment, timemodified, courseid, shareall, externaccess, externcomment)' . ' SELECT id+' . $file_id_start . ', userid, "file", category, name, url, intro, attachment, timemodified, course, shareall, externaccess, externcomment' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporbookfile']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitem' . ' (id, userid, type, categoryid, name, url, intro, attachment, timemodified, courseid, shareall, externaccess, externcomment)' . ' SELECT id+' . $note_id_start . ', userid, "note", category, name, url, intro, attachment, timemodified, course, shareall, externaccess, externcomment' . ' FROM ' . $CFG->prefix . $tableNames['block_exabepornote']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitem' . ' (id, userid, type, categoryid, name, url, intro, attachment, timemodified, courseid, shareall, externaccess, externcomment)' . ' SELECT id+' . $link_id_start . ', userid, "link", category, name, url, intro, attachment, timemodified, course, shareall, externaccess, externcomment' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporbooklink']);
        // combine comment table
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemcomm' . ' (id, itemid, userid, entry, timemodified)' . ' SELECT id, bookmarkid+' . $file_id_start . ', userid, entry, timemodified' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporcommfile']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemcomm' . ' (id, itemid, userid, entry, timemodified)' . ' SELECT id, bookmarkid+' . $note_id_start . ', userid, entry, timemodified' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporcommnote']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemcomm' . ' (id, itemid, userid, entry, timemodified)' . ' SELECT id, bookmarkid+' . $link_id_start . ', userid, entry, timemodified' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporcommlink']);
        // combine share table
        $ret = $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemshar' . ' (id, itemid, userid, original, courseid)' . ' SELECT id, bookid+' . $file_id_start . ', userid, original, course' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporsharfile']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemshar' . ' (id, itemid, userid, original, courseid)' . ' SELECT id, bookid+' . $note_id_start . ', userid, original, course' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporsharnote']);
        $db->Execute($insert_type . ' INTO ' . $CFG->prefix . 'block_exabeporitemshar' . ' (id, itemid, userid, original, courseid)' . ' SELECT id, bookid+' . $link_id_start . ', userid, original, course' . ' FROM ' . $CFG->prefix . $tableNames['block_exabeporsharlink']);
        $result = true;
    }
    if ($result && $oldversion < 2009010104) {
        // Add THEME support (nadavkav)
        //$result = execute_sql("ALTER TABLE `{$CFG->prefix}_block_exabeporview` ADD `theme` TEXT NULL DEFAULT NULL AFTER `description`");
        $table = new XMLDBTable('block_exabeporview');
        /// Adding fields to table block_exabeporview
        //$table->addFieldInfo('theme', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
        $field = new XMLDBField('theme');
        $field->setAttributes(XMLDB_TYPE_CHAR, '25', null, null, null, null, null, null, 'description');
        /// Launch update table for block_exabeporview
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2009010105) {
        // Add THEME support (nadavkav)
        //$result = execute_sql("ALTER TABLE `{$CFG->prefix}_block_exabeporuser` ADD `emailnotification` TEXT NULL DEFAULT NULL AFTER `description`");
        $table = new XMLDBTable('block_exabeporuser');
        /// Adding fields to table block_exabeporview
        //$table->addFieldInfo('theme', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
        $field = new XMLDBField('emailnotification');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'user_hash');
        /// Launch update table for block_exabeporview
        $result = $result && add_field($table, $field);
    }
    return $result;
}
Пример #10
0
/**
 * Database upgrade code.
 *
 * @version $Id: upgrade.php,v 1.6 2009-06-05 20:12:38 jfilip Exp $
 * @author Justin Filip <*****@*****.**>
 * @author Remote Learner - http://www.remote-learner.net/
 */
function xmldb_elluminate_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $DB;
    $dbman = $DB->get_manager();
    /// loads ddl manager and xmldb classes
    //  We don't need this anymore. As per Moodle.org to upgrade to 2.0 having 1.9 is a requirement, so checks on old versions can be removed for this version (Moodle Integration 2.0.2)
    //	which is a compatibility release for Moodle 2.2.2.
    ///if ($oldversion < 2006062102) {
    /// This should not be necessary but it's included just in case.
    //    $result = install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/install.xml');
    //}
    if ($result && $oldversion < 2009090801) {
        //updates to the elluminate table
        $elluminate_table = new xmldb_table('elluminate');
        $field = new xmldb_field('meetinginit');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'meetingid');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('groupmode');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'meetinginit');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('groupid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'groupmode');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('groupparentid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'groupid');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('sessionname');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, false, '0', 'groupparentid');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('customname');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, false, '0', 'sessionname');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('customdescription');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, false, '0', 'customname');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('timestart');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'customdescription');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('timeend');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'timestart');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('recordingmode');
        $field->set_attributes(XMLDB_TYPE_CHAR, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'timeend');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('boundarytime');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'recordingmode');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('boundarytimedisplay');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'boundarytime');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('chairlist');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, false, null, 'boundarytimedisplay');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        $field = new xmldb_field('nonchairlist');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'big', XMLDB_UNSIGNED, null, false, null, 'chairlist');
        $result = $result && $dbman->add_field($elluminate_table, $field);
        //Updates to the recordings table
        $recordings_table = new xmldb_table('elluminate_recordings');
        $field = new xmldb_field('description');
        $field->set_attributes(XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, null, false, '0', 'recordingid');
        $result = $result && $dbman->add_field($recordings_table, $field);
        $field = new xmldb_field('visible');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'description');
        $result = $result && $dbman->add_field($recordings_table, $field);
        $field = new xmldb_field('groupvisible');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'visible');
        $result = $result && $dbman->add_field($recordings_table, $field);
        $table = new xmldb_table('elluminate_session');
        if ($dbman->table_exists($table)) {
            $status = $dbman->drop_table($table, true, false);
        }
        $table = new xmldb_table('elluminate_users');
        if ($dbman->table_exists($table)) {
            $status = $dbman->drop_table($table, true, false);
        }
        $table = new xmldb_table('elluminate_preloads');
        if ($dbman->table_exists($table)) {
            $status = $dbman->drop_table($table, true, false);
        }
        install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/upgrade.xml');
        $meetings = $DB->get_records('elluminate');
        /// Modify all of the existing meetings, if any.
        if ($result && !empty($meetings)) {
            $timenow = time();
            foreach ($meetings as $meeting) {
                /// Update the meeting by storing values from the ELM server in the local DB.
                if (!($elmmeeting = elluminate_get_meeting_full_response($meeting->meetingid))) {
                    continue;
                }
                $meeting->meetinginit = 2;
                $meeting->groupmode = 0;
                $meeting->groupid = 0;
                $meeting->groupparentid = 0;
                $meeting->sessionname = addslashes($meeting->name);
                $meeting->timestart = substr($elmmeeting->startTime, 0, -3);
                $meeting->timeend = substr($elmmeeting->endTime, 0, -3);
                $meeting->chairlist = $elmmeeting->chairList;
                $meeting->nonchairlist = $elmmeeting->nonChairList;
                $meeting->recordingmode = $elmmeeting->recordingModeType;
                $meeting->boundarytime = $elmmeeting->boundaryTime;
                $meeting->boundarytimedisplay = 1;
                $meeting->customname = 0;
                $meeting->customdescription = 0;
                $DB->update_record('elluminate', $meeting);
            }
        }
        $recordings = $DB->get_records('elluminate_recordings');
        if (!empty($recordings)) {
            foreach ($recordings as $recording) {
                $urecording = new stdClass();
                $recording->description = '';
                $recording->visible = '1';
                $recording->groupvisible = '0';
                $DB->update_record('elluminate_recordings', $urecording);
            }
        }
        upgrade_mod_savepoint(true, 2009090801, 'elluminate');
    }
    if ($oldversion < 2010062500) {
        /*
         * This is put in place to account for Elluminate Sessions that were created using
         * the 1.0 and 1.1 bridge which do not contain group sessions, however if the course
         * has either seperate or visible groups set as it's default the 1.6 adapter will attempt
         * to convert it to a group session which is bad.  We have to force the
         * group mode of the course_module to be zero which means no groups.
         */
        if ($oldversion <= 2009020501) {
            $module = $DB->get_record('modules', array('name' => 'elluminate'));
            $course_modules = $DB->get_records('course_modules', array('module' => $module->id));
            foreach ($course_modules as $course_module) {
                $course_module->groupmode = 0;
                $DB->update_record('course_modules', $course_module);
            }
            upgrade_mod_savepoint(true, 2009020501, 'elluminate');
        }
        $table = new xmldb_table('elluminate');
        $field = new xmldb_field('sessiontype');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', 'creator');
        $result = $result && $dbman->add_field($table, $field);
        $field = new xmldb_field('groupingid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', 'sessiontype');
        $result = $result && $dbman->add_field($table, $field);
        $meetings = $DB->get_records('elluminate');
        foreach ($meetings as $meeting) {
            $meeting->groupingid = 0;
            if ($meeting->private == true) {
                $meeting->sessiontype = 1;
            }
            if ($meeting->groupmode > 0) {
                $meeting->sessiontype = 2;
            }
            $DB->update_record('elluminate', $meeting);
        }
        $field = new xmldb_field('private');
        $dbman->drop_field($table, $field);
        $recordings_table = new xmldb_table('elluminate_recordings');
        $size_field = new xmldb_field('recordingsize');
        $size_field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, '0', 'description');
        $result = $result && $dbman->add_field($recordings_table, $size_field);
        $recordings = $DB->get_records('elluminate_recordings');
        foreach ($recordings as $recording) {
            $full_recordings = elluminate_list_recordings($recording->meetingid);
            foreach ($full_recordings as $full_recording) {
                if ($full_recording->recordingid == $recording->recordingid) {
                    $recording->recordingsize = $full_recording->size;
                    $DB->update_record('elluminate_recordings', $recording);
                }
            }
        }
        upgrade_mod_savepoint(true, 2010062500, 'elluminate');
    }
    if ($result && $oldversion < 2012050211) {
        $table = new xmldb_table('elluminate');
        $max_talkers_field = new xmldb_field('maxtalkers');
        $max_talkers_field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'boundarytimedisplay');
        if (!$dbman->field_exists($table, $max_talkers_field)) {
            $dbman->add_field($table, $max_talkers_field);
        }
        upgrade_mod_savepoint(true, 2012050211, 'elluminate');
    }
    return true;
}
Пример #11
0
function xmldb_artefact_blog_upgrade($oldversion = 0)
{
    // There was no database prior to this version.
    if ($oldversion < 2006120501) {
        install_from_xmldb_file(get_config('docroot') . 'artefact/blog/db/install.xml');
    }
    if ($oldversion < 2006121501) {
        $table = new XMLDBTable('artefact_blog_blogpost_file_pending');
        $table->addFieldInfo('file', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('when', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
        $table->addKeyInfo('blogpost_file_pending_pk', XMLDB_KEY_PRIMARY, array('file'));
        $table->addKeyInfo('filefk', XMLDB_KEY_FOREIGN, array('file'), 'artefact', array('id'));
        if (!create_table($table)) {
            throw new SQLException($table . " could not be created, check log for errors.");
        }
    }
    if ($oldversion < 2008012200) {
        // From 0.9, some files were not having their temporary download paths
        // translated to proper artefact/file/download.php paths. This upgrade
        // attempts to fix them. It should work in the vast majority of cases,
        // the largest assumption made is that artefacts were inserted in
        // ascending ID order when the post was created, which is a pretty safe
        // bet.
        if ($blogfiles = get_records_array('artefact_blog_blogpost_file', '', '', 'blogpost ASC, file ASC')) {
            $blogpostids = join(', ', array_map(create_function('$a', 'return $a->blogpost;'), $blogfiles));
            // Find all blogposts that have attached files
            if ($blogposts = get_records_select_array('artefact', 'id IN(' . $blogpostids . ')', null, 'id ASC')) {
                foreach ($blogposts as $post) {
                    log_debug("Checking post {$post->id}");
                    // Only doublecheck posts that are likely to have a broken URL in them
                    if (false !== strpos($post->description, 'createid')) {
                        log_debug(" * Looks like post " . $post->id . " has a createid in it");
                        $i = 0;
                        $body = $post->description;
                        foreach ($blogfiles as $file) {
                            if ($file->blogpost == $post->id) {
                                // This file is connected to this post, so likely it is to be displayed
                                $i++;
                                log_debug('* Replace uploadnumber = ' . $i . ' with artefact id ' . $file->file);
                                $regexps = array('/<img([^>]+)src="([^>]+)downloadtemp.php\\?uploadnumber=' . $i . '&amp;createid=\\d+/', '/alt="uploaded:' . $i . '"/');
                                $subs = array('<img$1src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->file, 'alt="artefact:' . $file->file . '"');
                                $body = preg_replace($regexps, $subs, $body);
                            }
                        }
                        // Update the post if necessary
                        if ($body != $post->description) {
                            $postobj = new ArtefactTypeBlogPost($post->id, null);
                            $postobj->set('description', $body);
                            $postobj->commit();
                        }
                    }
                }
            }
        }
    }
    if ($oldversion < 2008020700) {
        $table = new XMLDBTable('artefact_blog_blog');
        drop_table($table);
        if (is_mysql()) {
            execute_sql('DROP INDEX {arteblogblog_blo2_ix} ON {artefact_blog_blogpost}');
            execute_sql('CREATE INDEX {arteblogblog_blo_ix} ON {artefact_blog_blogpost} (blogpost)');
            execute_sql('ALTER TABLE {artefact_blog_blogpost} DROP FOREIGN KEY {arteblogblog_blo2_fk}');
            // I can't quite get mysql to name this key correctly, so there
            // will be a difference in the database if you upgrade from 0.9
            // compared with installing from 1.0
            execute_sql('ALTER TABLE {artefact_blog_blogpost} ADD FOREIGN KEY (blogpost) REFERENCES {artefact} (id)');
        } else {
            // Rename indexes to keep things the same regardless of whether the
            // user installed or upgraded to this release
            execute_sql('DROP INDEX {arteblogblog_blo2_ix}');
            execute_sql('CREATE INDEX {arteblogblog_blo_ix} ON {artefact_blog_blogpost} USING btree (blogpost)');
            execute_sql('ALTER TABLE {artefact_blog_blogpost} DROP CONSTRAINT {arteblogblog_blo2_fk}');
            execute_sql('ALTER TABLE {artefact_blog_blogpost} ADD CONSTRAINT {arteblogblog_blo_fk} FOREIGN KEY (blogpost) REFERENCES {artefact}(id)');
        }
    }
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_blog_blogpost_file_pending');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('oldextension', XMLDB_TYPE_TEXT, null);
        $table->addFieldInfo('filetype', XMLDB_TYPE_TEXT, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        create_table($table);
    }
    if ($oldversion < 2009033100) {
        $bloguploadbase = get_config('dataroot') . 'artefact/blog/uploads/';
        if (is_dir($bloguploadbase)) {
            if ($basedir = opendir($bloguploadbase)) {
                while (false !== ($sessionupload = readdir($basedir))) {
                    if ($sessionupload != "." && $sessionupload != "..") {
                        $sessionupload = $bloguploadbase . $sessionupload;
                        $subdir = opendir($sessionupload);
                        while (false !== ($uploadfile = readdir($subdir))) {
                            if ($uploadfile != "." && $uploadfile != "..") {
                                $uploadfile = $sessionupload . '/' . $uploadfile;
                                unlink($uploadfile);
                            }
                        }
                        closedir($subdir);
                        rmdir($sessionupload);
                    }
                }
            }
            @rmdir($bloguploadbase);
        }
    }
    if ($oldversion < 2009081800) {
        $subscription = (object) array('plugin' => 'blog', 'event' => 'createuser', 'callfunction' => 'create_default_blog');
        ensure_record_exists('artefact_event_subscription', $subscription, $subscription);
    }
    return true;
}
Пример #12
0
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;
}
/**
 * Database upgrade code.
 *
 * @version $Id: upgrade.php,v 1.6 2009-06-05 20:12:38 jfilip Exp $
 * @author Justin Filip <*****@*****.**>
 * @author Remote Learner - http://www.remote-learner.net/
 */
function xmldb_elluminate_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($oldversion < 2006062102) {
        /// This should not be necessary but it's included just in case.
        $result = install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/install.xml');
    }
    if ($result && $oldversion < 2009090801) {
        $meetings = get_records('elluminate');
        $table = new XMLDBTable('elluminate');
        if (table_exists($table)) {
            $status = drop_table($table, true, false);
        }
        $table = new XMLDBTable('elluminate_recordings');
        if (table_exists($table)) {
            $status = drop_table($table, true, false);
        }
        $table = new XMLDBTable('elluminate_session');
        if (table_exists($table)) {
            $status = drop_table($table, true, false);
        }
        $table = new XMLDBTable('elluminate_users');
        if (table_exists($table)) {
            $status = drop_table($table, true, false);
        }
        $table = new XMLDBTable('elluminate_preloads');
        if (table_exists($table)) {
            $status = drop_table($table, true, false);
        }
        install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/upgrade.xml');
        /// Modify all of the existing meetings, if any.
        if ($result && !empty($meetings)) {
            $timenow = time();
            foreach ($meetings as $meeting) {
                /// Update the meeting by storing values from the ELM server in the local DB.
                if (!($elmmeeting = elluminate_get_meeting_full_response($meeting->meetingid))) {
                    continue;
                }
                //$mparams = elluminate_get_meeting_parameters($meeting->meetingid);
                $sparams = elluminate_get_server_parameters($meeting->meetingid);
                $umeeting = new stdClass();
                //$umeeting->id          = $meeting->id;
                $umeeting->meetingid = $meeting->meetingid;
                $umeeting->meetinginit = 2;
                $umeeting->course = $meeting->course;
                $umeeting->creator = $elmmeeting->creatorId;
                $umeeting->groupmode = '0';
                $umeeting->groupid = '0';
                $umeeting->sessionname = addslashes($meeting->name);
                $umeeting->timestart = substr($elmmeeting->startTime, 0, -3);
                $umeeting->timeend = substr($elmmeeting->endTime, 0, -3);
                $umeeting->nonchairlist = $elmmeeting->nonChairList;
                $umeeting->chairlist = $elmmeeting->chairList;
                $umeeting->recordingmode = $elmmeeting->recordingModeType;
                $umeeting->name = $meeting->name;
                $umeeting->description = addslashes($meeting->description);
                $umeeting->boundarytime = $elmmeeting->boundaryTime;
                $umeeting->boundarytimedisplay = 1;
                $umeeting->seats = $meeting->seats;
                $umeeting->private = $meeting->private;
                $umeeting->grade = $meeting->grade;
                $umeeting->timemodified = $meeting->timemodified;
                insert_record('elluminate', $umeeting);
                $newmeeting = get_record('elluminate', 'meetingid', $meeting->meetingid);
                $attendancerecords = get_records('elluminate_attendance', 'elluminateid', $meeting->id);
                if (!empty($attendancerecords)) {
                    foreach ($attendancerecords as $attendee) {
                        $attendee->ellumianteid = $newmeeting->id;
                        update_record('elluminate_attendance', $attendee);
                    }
                }
                $recordings = elluminate_list_recordings($meeting->meetingid);
                if ($result && !empty($recordings)) {
                    $timenow = time();
                    foreach ($recordings as $recording) {
                        $urecording = new stdClass();
                        $urecording->meetingid = $recording->meetingid;
                        $urecording->recordingid = $recording->recordingid;
                        $urecording->description = $recording->roomname;
                        $urecording->visible = '1';
                        $urecording->groupvisible = '0';
                        $urecording->created = $recording->created;
                        insert_record('elluminate_recordings', $urecording);
                    }
                }
            }
        }
        $timenow = time();
        $sysctx = get_context_instance(CONTEXT_SYSTEM);
        $adminrid = get_field('role', 'id', 'shortname', 'admin');
        $coursecreatorrid = get_field('role', 'id', 'shortname', 'coursecreator');
        $editingteacherrid = get_field('role', 'id', 'shortname', 'editingteacher');
        $teacherrid = get_field('role', 'id', 'shortname', 'teacher');
        /// Fully setup the Elluminate Moderator role.
        if ($result && !($mrole = get_record('role', 'shortname', 'elluminatemoderator'))) {
            if ($rid = create_role(get_string('elluminatemoderator', 'elluminatelive'), 'elluminatemoderator', get_string('elluminatemoderatordescription', 'elluminatelive'))) {
                $mrole = get_record('role', 'id', $rid);
                $result = $result && assign_capability('mod/elluminatelive:moderatemeeting', CAP_ALLOW, $mrole->id, $sysctx->id);
            } else {
                $result = false;
            }
        }
        if (!count_records('role_allow_assign', 'allowassign', $mrole->id)) {
            $result = $result && allow_assign($adminrid, $mrole->id);
            $result = $result && allow_assign($coursecreatorrid, $mrole->id);
            $result = $result && allow_assign($editingteacherrid, $mrole->id);
            $result = $result && allow_assign($teacherrid, $mrole->id);
        }
        /// Fully setup the Elluminate Participant role.
        if ($result && !($prole = get_record('role', 'shortname', 'elluminateparticipant'))) {
            if ($rid = create_role(get_string('elluminateparticipant', 'elluminatelive'), 'elluminateparticipant', get_string('elluminateparticipantdescription', 'elluminatelive'))) {
                $prole = get_record('role', 'id', $rid);
                $result = $result && assign_capability('mod/elluminatelive:joinmeeting', CAP_ALLOW, $prole->id, $sysctx->id);
            } else {
                $result = false;
            }
        }
        if (!count_records('role_allow_assign', 'allowassign', $prole->id)) {
            $result = $result && allow_assign($adminrid, $prole->id);
            $result = $result && allow_assign($coursecreatorrid, $prole->id);
            $result = $result && allow_assign($editingteacherrid, $prole->id);
            $result = $result && allow_assign($teacherrid, $prole->id);
        }
    }
    if ($result && $oldversion == 2010021600) {
        $table = new XMLDBTable('elluminate');
        $field = new XMLDBField('sessiontype');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, false, false, '0', 'creator');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('groupingid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, false, false, '0', 'sessiontype');
        $result = $result && add_field($table, $field);
        $meetings = get_records('elluminate');
        foreach ($meetings as $meeting) {
            $meeting->groupingid = 0;
            if ($meeting->private == true) {
                $meeting->sessiontype = 1;
            }
            if ($meeting->groupmode > 0) {
                $meeting->sessiontype = 2;
            }
            update_record('elluminate', $meeting);
        }
        $field = new XMLDBField('private');
        drop_field($table, $field);
        $recordings_table = new XMLDBTable('elluminate_recordings');
        $size_field = new XMLDBField('recordingsize');
        $size_field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, false, false, '0', 'description');
        $result = $result && add_field($recordings_table, $size_field);
        $recordings = get_records('elluminate_recordings');
        foreach ($recordings as $recording) {
            $full_recordings = elluminate_list_recordings($recording->meetingid);
            foreach ($full_recordings as $full_recording) {
                if ($full_recording->recordingid == $recording->recordingid) {
                    $recording->recordingsize = $full_recording->size;
                    update_record('elluminate_recordings', $recording);
                }
            }
        }
    }
    return $result;
}