コード例 #1
0
ファイル: upgrade.php プロジェクト: amsibsam/moodle3
/**
 * Campus theme with the underlying Bootstrap theme.
 *
 * @package    theme
 * @subpackage campus
 * @copyright  © 2014-onwards G J Barnard in respect to modifications of the Clean theme.
 * @copyright  © 2014-onwards Work undertaken for David Bogner of Edulabs.org.
 * @author     G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
 * @author     Based on code originally written by Mary Evans, Bas Brands, Stuart Lamour and David Scotson.
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function xmldb_theme_campus_upgrade($oldversion = 0)
{
    // Automatic 'Purge all caches'....
    if ($oldversion < 2114121700) {
        purge_all_caches();
    }
    return true;
}
コード例 #2
0
ファイル: locallib.php プロジェクト: kevin-bruton/marsupial
function set_marsupial_state($enable)
{
    global $DB;
    $DB->set_field('modules', 'visible', $enable, array('name' => 'rcontent'));
    $DB->set_field('block', 'visible', $enable, array('name' => 'my_books'));
    $DB->set_field('block', 'visible', $enable, array('name' => 'rgrade'));
    set_config('enabled', $enable, 'rcommon');
    purge_all_caches();
}
コード例 #3
0
function xmldb_block_course_message_upgrade($oldversion = 0)
{
    global $DB;
    $dbman = $DB->get_manager();
    $result = true;
    // July 7, 2014 version added the carbon copy field.
    if ($oldversion < 2014070700) {
        $table = new xmldb_table('course_message_mails');
        $field = new xmldb_field('carboncopy', XMLDB_TYPE_TEXT, 'big', null, null, null, 'attachment');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Force cache purge.
        purge_all_caches();
        // Update savepoint.
        upgrade_block_savepoint(true, 2014062600, 'course_message');
    }
    return $result;
}
コード例 #4
0
ファイル: behat_hooks.php プロジェクト: rwijaya/moodle
    /**
     * Resets the test environment.
     *
     * @throws coding_exception If here we are not using the test database it should be because of a coding error
     * @BeforeScenario
     */
    public function before_scenario($event) {
        global $DB, $SESSION, $CFG;

        // As many checks as we can.
        if (!defined('BEHAT_TEST') ||
               !defined('BEHAT_SITE_RUNNING') ||
               php_sapi_name() != 'cli' ||
               !behat_util::is_test_mode_enabled() ||
               !behat_util::is_test_site()) {
            throw new coding_exception('Behat only can modify the test database and the test dataroot!');
        }

        $moreinfo = 'More info in ' . behat_command::DOCS_URL . '#Running_tests';
        $driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo;
        try {
            $session = $this->getSession();
        } catch (CurlExec $e) {
            // Exception thrown by WebDriver, so only @javascript tests will be caugth; in
            // behat_util::is_server_running() we already checked that the server is running.
            throw new Exception($driverexceptionmsg);
        } catch (DriverException $e) {
            throw new Exception($driverexceptionmsg);
        } catch (UnknownError $e) {
            // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions.
            $this->throw_unknown_exception($e);
        }


        // We need the Mink session to do it and we do it only before the first scenario.
        if (self::is_first_scenario()) {
            behat_selectors::register_moodle_selectors($session);
        }

        // Reset $SESSION.
        $_SESSION = array();
        $SESSION = new stdClass();
        $_SESSION['SESSION'] =& $SESSION;

        behat_util::reset_database();
        behat_util::reset_dataroot();

        purge_all_caches();
        accesslib_clear_all_caches(true);

        // Reset the nasty strings list used during the last test.
        nasty_strings::reset_used_strings();

        // Assign valid data to admin user (some generator-related code needs a valid user).
        $user = $DB->get_record('user', array('username' => 'admin'));
        \core\session\manager::set_user($user);

        // Reset the browser if specified in config.php.
        if (!empty($CFG->behat_restart_browser_after) && $this->running_javascript()) {
            $now = time();
            if (self::$lastbrowsersessionstart + $CFG->behat_restart_browser_after < $now) {
                $session->restart();
                self::$lastbrowsersessionstart = $now;
            }
        }

        // Start always in the the homepage.
        try {
            // Let's be conservative as we never know when new upstream issues will affect us.
            $session->visit($this->locate_path('/'));
        } catch (UnknownError $e) {
            $this->throw_unknown_exception($e);
        }


        // Checking that the root path is a Moodle test site.
        if (self::is_first_scenario()) {
            $notestsiteexception = new Exception('The base URL (' . $CFG->wwwroot . ') is not a behat test site, ' .
                'ensure you started the built-in web server in the correct directory or your web server is correctly started and set up');
            $this->find("xpath", "//head/child::title[normalize-space(.)='" . behat_util::BEHATSITENAME . "']", $notestsiteexception);

            self::$initprocessesfinished = true;
        }

    }
コード例 #5
0
/**
 * Automatically clean-up all plugin data and remove the plugin DB tables
 *
 * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc.
 * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc.
 * @uses global $OUTPUT to produce notices and other messages
 * @return void
 */
function uninstall_plugin($type, $name)
{
    global $CFG, $DB, $OUTPUT;
    // This may take a long time.
    @set_time_limit(0);
    // recursively uninstall all module/editor subplugins first
    if ($type === 'mod' || $type === 'editor') {
        $base = get_component_directory($type . '_' . $name);
        if (file_exists("{$base}/db/subplugins.php")) {
            $subplugins = array();
            include "{$base}/db/subplugins.php";
            foreach ($subplugins as $subplugintype => $dir) {
                $instances = get_plugin_list($subplugintype);
                foreach ($instances as $subpluginname => $notusedpluginpath) {
                    uninstall_plugin($subplugintype, $subpluginname);
                }
            }
        }
    }
    $component = $type . '_' . $name;
    // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
    if ($type === 'mod') {
        $pluginname = $name;
        // eg. 'forum'
        if (get_string_manager()->string_exists('modulename', $component)) {
            $strpluginname = get_string('modulename', $component);
        } else {
            $strpluginname = $component;
        }
    } else {
        $pluginname = $component;
        if (get_string_manager()->string_exists('pluginname', $component)) {
            $strpluginname = get_string('pluginname', $component);
        } else {
            $strpluginname = $component;
        }
    }
    echo $OUTPUT->heading($pluginname);
    $plugindirectory = get_plugin_directory($type, $name);
    $uninstalllib = $plugindirectory . '/db/uninstall.php';
    if (file_exists($uninstalllib)) {
        require_once $uninstalllib;
        $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall';
        // eg. 'xmldb_workshop_uninstall()'
        if (function_exists($uninstallfunction)) {
            if (!$uninstallfunction()) {
                echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $pluginname);
            }
        }
    }
    if ($type === 'mod') {
        // perform cleanup tasks specific for activity modules
        if (!($module = $DB->get_record('modules', array('name' => $name)))) {
            print_error('moduledoesnotexist', 'error');
        }
        // delete all the relevant instances from all course sections
        if ($coursemods = $DB->get_records('course_modules', array('module' => $module->id))) {
            foreach ($coursemods as $coursemod) {
                if (!delete_mod_from_section($coursemod->id, $coursemod->section)) {
                    echo $OUTPUT->notification("Could not delete the {$strpluginname} with id = {$coursemod->id} from section {$coursemod->section}");
                }
            }
        }
        // clear course.modinfo for courses that used this module
        $sql = "UPDATE {course}\n                   SET modinfo=''\n                 WHERE id IN (SELECT DISTINCT course\n                                FROM {course_modules}\n                               WHERE module=?)";
        $DB->execute($sql, array($module->id));
        // delete all the course module records
        $DB->delete_records('course_modules', array('module' => $module->id));
        // delete module contexts
        if ($coursemods) {
            foreach ($coursemods as $coursemod) {
                if (!delete_context(CONTEXT_MODULE, $coursemod->id)) {
                    echo $OUTPUT->notification("Could not delete the context for {$strpluginname} with id = {$coursemod->id}");
                }
            }
        }
        // delete the module entry itself
        $DB->delete_records('modules', array('name' => $module->name));
        // cleanup the gradebook
        require_once $CFG->libdir . '/gradelib.php';
        grade_uninstalled_module($module->name);
        // Perform any custom uninstall tasks
        if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
            require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php';
            $uninstallfunction = $module->name . '_uninstall';
            if (function_exists($uninstallfunction)) {
                debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
                if (!$uninstallfunction()) {
                    echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!');
                }
            }
        }
    } else {
        if ($type === 'enrol') {
            // NOTE: this is a bit brute force way - it will not trigger events and hooks properly
            // nuke all role assignments
            role_unassign_all(array('component' => $component));
            // purge participants
            $DB->delete_records_select('user_enrolments', "enrolid IN (SELECT id FROM {enrol} WHERE enrol = ?)", array($name));
            // purge enrol instances
            $DB->delete_records('enrol', array('enrol' => $name));
            // tweak enrol settings
            if (!empty($CFG->enrol_plugins_enabled)) {
                $enabledenrols = explode(',', $CFG->enrol_plugins_enabled);
                $enabledenrols = array_unique($enabledenrols);
                $enabledenrols = array_flip($enabledenrols);
                unset($enabledenrols[$name]);
                $enabledenrols = array_flip($enabledenrols);
                if (is_array($enabledenrols)) {
                    set_config('enrol_plugins_enabled', implode(',', $enabledenrols));
                }
            }
        } else {
            if ($type === 'block') {
                if ($block = $DB->get_record('block', array('name' => $name))) {
                    // Inform block it's about to be deleted
                    if (file_exists("{$CFG->dirroot}/blocks/{$block->name}/block_{$block->name}.php")) {
                        $blockobject = block_instance($block->name);
                        if ($blockobject) {
                            $blockobject->before_delete();
                            //only if we can create instance, block might have been already removed
                        }
                    }
                    // First delete instances and related contexts
                    $instances = $DB->get_records('block_instances', array('blockname' => $block->name));
                    foreach ($instances as $instance) {
                        blocks_delete_instance($instance);
                    }
                    // Delete block
                    $DB->delete_records('block', array('id' => $block->id));
                }
            } else {
                if ($type === 'format') {
                    if (($defaultformat = get_config('moodlecourse', 'format')) && $defaultformat !== $name) {
                        $courses = $DB->get_records('course', array('format' => $name), 'id');
                        $data = (object) array('id' => null, 'format' => $defaultformat);
                        foreach ($courses as $record) {
                            $data->id = $record->id;
                            update_course($data);
                        }
                    }
                    $DB->delete_records('course_format_options', array('format' => $name));
                }
            }
        }
    }
    // perform clean-up task common for all the plugin/subplugin types
    //delete the web service functions and pre-built services
    require_once $CFG->dirroot . '/lib/externallib.php';
    external_delete_descriptions($component);
    // delete calendar events
    $DB->delete_records('event', array('modulename' => $pluginname));
    // delete all the logs
    $DB->delete_records('log', array('module' => $pluginname));
    // delete log_display information
    $DB->delete_records('log_display', array('component' => $component));
    // delete the module configuration records
    unset_all_config_for_plugin($pluginname);
    // delete message provider
    message_provider_uninstall($component);
    // delete message processor
    if ($type === 'message') {
        message_processor_uninstall($name);
    }
    // delete the plugin tables
    $xmldbfilepath = $plugindirectory . '/db/install.xml';
    drop_plugin_tables($component, $xmldbfilepath, false);
    if ($type === 'mod' or $type === 'block') {
        // non-frankenstyle table prefixes
        drop_plugin_tables($name, $xmldbfilepath, false);
    }
    // delete the capabilities that were defined by this module
    capabilities_cleanup($component);
    // remove event handlers and dequeue pending events
    events_uninstall($component);
    // Delete all remaining files in the filepool owned by the component.
    $fs = get_file_storage();
    $fs->delete_component_files($component);
    // Finally purge all caches.
    purge_all_caches();
    echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
コード例 #6
0
ファイル: behat_hooks.php プロジェクト: Jtgadbois/Pedadida
    /**
     * Resets the test environment.
     *
     * @throws coding_exception If here we are not using the test database it should be because of a coding error
     * @BeforeScenario
     */
    public function before_scenario($event) {
        global $DB, $SESSION, $CFG;

        // As many checks as we can.
        if (!defined('BEHAT_TEST') ||
               !defined('BEHAT_SITE_RUNNING') ||
               php_sapi_name() != 'cli' ||
               !behat_util::is_test_mode_enabled() ||
               !behat_util::is_test_site()) {
            throw new coding_exception('Behat only can modify the test database and the test dataroot!');
        }

        // Avoid some notices / warnings.
        $SESSION = new stdClass();

        behat_util::reset_database();
        behat_util::reset_dataroot();

        purge_all_caches();
        accesslib_clear_all_caches(true);

        // Reset the nasty strings list used during the last test.
        nasty_strings::reset_used_strings();

        // Assing valid data to admin user (some generator-related code needs a valid user).
        $user = $DB->get_record('user', array('username' => 'admin'));
        session_set_user($user);

        // Start always in the the homepage.
        $this->getSession()->visit($this->locate_path('/'));
    }
コード例 #7
0
ファイル: adminlib.php プロジェクト: Alexbado/moodle2
/**
 * Moved from admin/replace.php so that we can use this in cron
 *
 * @param string $search string to look for
 * @param string $replace string to replace
 * @return bool success or fail
 */
function db_replace($search, $replace)
{
    global $DB, $CFG, $OUTPUT;
    // TODO: this is horrible hack, we should do whitelisting and each plugin should be responsible for proper replacing...
    $skiptables = array('config', 'config_plugins', 'config_log', 'upgrade_log', 'log', 'filter_config', 'sessions', 'events_queue', 'repository_instance_config', 'block_instances', '');
    // Turn off time limits, sometimes upgrades can be slow.
    core_php_time_limit::raise();
    if (!($tables = $DB->get_tables())) {
        // No tables yet at all.
        return false;
    }
    foreach ($tables as $table) {
        if (in_array($table, $skiptables)) {
            // Don't process these
            continue;
        }
        if ($columns = $DB->get_columns($table)) {
            $DB->set_debug(true);
            foreach ($columns as $column) {
                $DB->replace_all_text($table, $column, $search, $replace);
            }
            $DB->set_debug(false);
        }
    }
    // delete modinfo caches
    rebuild_course_cache(0, true);
    // TODO: we should ask all plugins to do the search&replace, for now let's do only blocks...
    $blocks = core_component::get_plugin_list('block');
    foreach ($blocks as $blockname => $fullblock) {
        if ($blockname === 'NEWBLOCK') {
            // Someone has unzipped the template, ignore it
            continue;
        }
        if (!is_readable($fullblock . '/lib.php')) {
            continue;
        }
        $function = 'block_' . $blockname . '_global_db_replace';
        include_once $fullblock . '/lib.php';
        if (!function_exists($function)) {
            continue;
        }
        echo $OUTPUT->notification("Replacing in {$blockname} blocks...", 'notifysuccess');
        $function($search, $replace);
        echo $OUTPUT->notification("...finished", 'notifysuccess');
    }
    purge_all_caches();
    return true;
}
コード例 #8
0
 public function test_matching_cacherev()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $this->setAdminUser();
     $cache = cache::make('core', 'coursemodinfo');
     // Generate the course and pre-requisite module.
     $course = $this->getDataGenerator()->create_course(array('format' => 'topics', 'numsections' => 3), array('createsections' => true));
     // Make sure the cacherev is set.
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan(0, $cacherev);
     $prevcacherev = $cacherev;
     // Reset course cache and make sure cacherev is bumped up but cache is empty.
     rebuild_course_cache($course->id, true);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
     $prevcacherev = $cacherev;
     // Build course cache. Cacherev should not change but cache is now not empty. Make sure cacherev is the same everywhere.
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertEquals($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Little trick to check that cache is not rebuilt druing the next step - substitute the value in MUC and later check that it is still there.
     $cache->set($course->id, (object) array_merge((array) $cachedvalue, array('secretfield' => 1)));
     // Clear static cache and call get_fast_modinfo() again (pretend we are in another request). Cache should not be rebuilt.
     course_modinfo::clear_instance_cache();
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertEquals($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertNotEmpty($cachedvalue->secretfield);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Rebuild course cache. Cacherev must be incremented everywhere.
     rebuild_course_cache($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $modinfo = get_fast_modinfo($course->id);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Update cacherev in DB and make sure the cache will be rebuilt on the next call to get_fast_modinfo().
     increment_revision_number('course', 'cacherev', 'id = ?', array($course->id));
     // We need to clear static cache for course_modinfo instances too.
     course_modinfo::clear_instance_cache();
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Reset cache for all courses and make sure this course cache is reset.
     rebuild_course_cache(0, true);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
     // Rebuild again.
     $modinfo = get_fast_modinfo($course->id);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Purge all caches and make sure cacherev is increased and data from MUC erased.
     purge_all_caches();
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
 }
コード例 #9
0
 /**
  * Make sure that when internal file is updated all references to it are
  * updated immediately. When it is deleted, the references are converted
  * to true copies.
  */
 public function test_update_reference_internal()
 {
     purge_all_caches();
     $this->resetAfterTest(true);
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $repo = reset($repos);
     // Create two aliases linking the same original.
     $areafiles = array_values($fs->get_area_files($user->ctxid, 'user', 'private', false, 'filename', false));
     $originalfile = $areafiles[0];
     $this->assertInstanceOf('stored_file', $originalfile);
     $contenthash = $originalfile->get_contenthash();
     $filesize = $originalfile->get_filesize();
     $substitutefile = $areafiles[1];
     $this->assertInstanceOf('stored_file', $substitutefile);
     $newcontenthash = $substitutefile->get_contenthash();
     $newfilesize = $substitutefile->get_filesize();
     $originalrecord = array('contextid' => $originalfile->get_contextid(), 'component' => $originalfile->get_component(), 'filearea' => $originalfile->get_filearea(), 'itemid' => $originalfile->get_itemid(), 'filepath' => $originalfile->get_filepath(), 'filename' => $originalfile->get_filename());
     $aliasrecord = $this->generate_file_record();
     $aliasrecord->filepath = '/A/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $symlink1 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // Make sure created alias is a reference and has the same size and contenthash as source.
     $this->assertEquals($contenthash, $symlink1->get_contenthash());
     $this->assertEquals($filesize, $symlink1->get_filesize());
     $this->assertEquals($repo->id, $symlink1->get_repository_id());
     $this->assertNotEmpty($symlink1->get_referencefileid());
     $referenceid = $symlink1->get_referencefileid();
     $aliasrecord->filepath = '/B/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $symlink2 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // Make sure created alias is a reference and has the same size and contenthash as source.
     $this->assertEquals($contenthash, $symlink2->get_contenthash());
     $this->assertEquals($filesize, $symlink2->get_filesize());
     $this->assertEquals($repo->id, $symlink2->get_repository_id());
     // Make sure both aliases have the same reference id.
     $this->assertEquals($referenceid, $symlink2->get_referencefileid());
     // Overwrite ofiginal file.
     $originalfile->replace_file_with($substitutefile);
     $this->assertEquals($newcontenthash, $originalfile->get_contenthash());
     $this->assertEquals($newfilesize, $originalfile->get_filesize());
     // References to the internal files must be synchronised immediately.
     // Refetch A/symlink.txt file.
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertTrue($symlink1->is_external_file());
     $this->assertEquals($newcontenthash, $symlink1->get_contenthash());
     $this->assertEquals($newfilesize, $symlink1->get_filesize());
     $this->assertEquals($repo->id, $symlink1->get_repository_id());
     $this->assertEquals($referenceid, $symlink1->get_referencefileid());
     // Refetch B/symlink.txt file.
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertTrue($symlink2->is_external_file());
     $this->assertEquals($newcontenthash, $symlink2->get_contenthash());
     $this->assertEquals($newfilesize, $symlink2->get_filesize());
     $this->assertEquals($repo->id, $symlink2->get_repository_id());
     $this->assertEquals($referenceid, $symlink2->get_referencefileid());
     // Remove original file.
     $originalfile->delete();
     // References must be converted to independend files.
     // Refetch A/symlink.txt file.
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertFalse($symlink1->is_external_file());
     $this->assertEquals($newcontenthash, $symlink1->get_contenthash());
     $this->assertEquals($newfilesize, $symlink1->get_filesize());
     $this->assertNull($symlink1->get_repository_id());
     $this->assertNull($symlink1->get_referencefileid());
     // Refetch B/symlink.txt file.
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertFalse($symlink2->is_external_file());
     $this->assertEquals($newcontenthash, $symlink2->get_contenthash());
     $this->assertEquals($newfilesize, $symlink2->get_filesize());
     $this->assertNull($symlink2->get_repository_id());
     $this->assertNull($symlink2->get_referencefileid());
 }
コード例 #10
0
ファイル: upgradelib.php プロジェクト: nicusX/moodle
/**
 * Upgrade moodle core
 * @param float $version target version
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_core($version, $verbose) {
    global $CFG;

    raise_memory_limit(MEMORY_EXTRA);

    require_once($CFG->libdir.'/db/upgrade.php');    // Defines upgrades

    try {
        // Reset caches before any output
        purge_all_caches();

        // Upgrade current language pack if we can
        upgrade_language_pack();

        print_upgrade_part_start('moodle', false, $verbose);

        // one time special local migration pre 2.0 upgrade script
        if ($CFG->version < 2007101600) {
            $pre20upgradefile = "$CFG->dirroot/local/upgrade_pre20.php";
            if (file_exists($pre20upgradefile)) {
                set_time_limit(0);
                require($pre20upgradefile);
                // reset upgrade timeout to default
                upgrade_set_timeout();
            }
        }

        $result = xmldb_main_upgrade($CFG->version);
        if ($version > $CFG->version) {
            // store version if not already there
            upgrade_main_savepoint($result, $version, false);
        }

        // perform all other component upgrade routines
        update_capabilities('moodle');
        log_update_descriptions('moodle');
        external_update_descriptions('moodle');
        events_update_definition('moodle');
        message_update_providers('moodle');

        // Reset caches again, just to be sure
        purge_all_caches();

        // Clean up contexts - more and more stuff depends on existence of paths and contexts
        context_helper::cleanup_instances();
        context_helper::create_instances(null, false);
        context_helper::build_all_paths(false);
        $syscontext = context_system::instance();
        $syscontext->mark_dirty();

        print_upgrade_part_end('moodle', false, $verbose);
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
コード例 #11
0
ファイル: UserMod.php プロジェクト: dariogs/moosh
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     unset($CFG->passwordpolicy);
     $options = $this->expandedOptions;
     if ($options['all']) {
         //run on the whole mdl_user table
         $sql = "UPDATE {user} SET ";
         $sqlFragment = array();
         $parameters = array();
         //we want to use the options that were actually provided on the commandline
         if ($this->parsedOptions->has('password')) {
             $sqlFragment[] = 'password = ?';
             $parameters['password'] = md5($this->parsedOptions['password']->value);
         }
         if ($this->parsedOptions->has('email')) {
             $sqlFragment[] = 'email = ?';
             $parameters['email'] = $this->parsedOptions['email']->value;
         }
         if ($this->parsedOptions->has('auth')) {
             $sqlFragment[] = 'auth = ?';
             $parameters['auth'] = $this->parsedOptions['auth']->value;
         }
         if (count($sqlFragment) == 0) {
             cli_error('You need to provide at least one option for updating a profile field (password or email)');
         }
         $sql .= implode(' , ', $sqlFragment);
         $DB->execute($sql, $parameters);
         exit(0);
     }
     foreach ($this->arguments as $argument) {
         if ($options['id']) {
             $user = $DB->get_record('user', array('id' => $argument));
         } else {
             $user = $DB->get_record('user', array('username' => $argument));
         }
         if (!$user) {
             cli_problem("User '{$argument}' not found'");
             continue;
         }
         if ($this->parsedOptions->has('password')) {
             $user->password = md5($this->parsedOptions['password']->value);
         }
         if ($this->parsedOptions->has('email')) {
             $user->email = $this->parsedOptions['email']->value;
         }
         if ($this->parsedOptions->has('auth')) {
             $user->auth = $this->parsedOptions['auth']->value;
         }
         if ($this->parsedOptions->has('global')) {
             foreach (explode(',', $CFG->siteadmins) as $admin) {
                 $admin = (int) $admin;
                 if ($admin) {
                     $admins[$admin] = $admin;
                 }
             }
             if (!isset($admins[$user->id])) {
                 $admins[$user->id] = $user->id;
             }
             set_config('siteadmins', implode(',', $admins));
             purge_all_caches();
         }
         echo $DB->update_record('user', $user) . "\n";
     }
 }
コード例 #12
0
/**
 * Upgrade moodle core
 * @param float $version target version
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_core($version, $verbose)
{
    global $CFG, $SITE, $DB, $COURSE;
    raise_memory_limit(MEMORY_EXTRA);
    require_once $CFG->libdir . '/db/upgrade.php';
    // Defines upgrades
    try {
        // Reset caches before any output
        purge_all_caches();
        cache_helper::purge_all(true);
        // Upgrade current language pack if we can
        upgrade_language_pack();
        print_upgrade_part_start('moodle', false, $verbose);
        // Pre-upgrade scripts for local hack workarounds.
        $preupgradefile = "{$CFG->dirroot}/local/preupgrade.php";
        if (file_exists($preupgradefile)) {
            set_time_limit(0);
            require $preupgradefile;
            // Reset upgrade timeout to default.
            upgrade_set_timeout();
        }
        $result = xmldb_main_upgrade($CFG->version);
        if ($version > $CFG->version) {
            // store version if not already there
            upgrade_main_savepoint($result, $version, false);
        }
        // In case structure of 'course' table has been changed and we forgot to update $SITE, re-read it from db.
        $SITE = $DB->get_record('course', array('id' => $SITE->id));
        $COURSE = clone $SITE;
        // perform all other component upgrade routines
        update_capabilities('moodle');
        log_update_descriptions('moodle');
        external_update_descriptions('moodle');
        events_update_definition('moodle');
        message_update_providers('moodle');
        // Update core definitions.
        cache_helper::update_definitions(true);
        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        purge_all_caches();
        cache_helper::purge_all(true);
        // Clean up contexts - more and more stuff depends on existence of paths and contexts
        context_helper::cleanup_instances();
        context_helper::create_instances(null, false);
        context_helper::build_all_paths(false);
        $syscontext = context_system::instance();
        $syscontext->mark_dirty();
        print_upgrade_part_end('moodle', false, $verbose);
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
コード例 #13
0
ファイル: upgradelib.php プロジェクト: vinoth4891/clinique
/**
 * Upgrade moodle core
 * @param float $version target version
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_core($version, $verbose)
{
    global $CFG;
    raise_memory_limit(MEMORY_EXTRA);
    require_once $CFG->libdir . '/db/upgrade.php';
    // Defines upgrades
    try {
        // Reset caches before any output
        purge_all_caches();
        // Disable the use of cache stores here. We will reset the factory after we've performed the installation.
        // This ensures that we don't permanently cache anything during installation.
        cache_factory::disable_stores();
        // Upgrade current language pack if we can
        upgrade_language_pack();
        print_upgrade_part_start('moodle', false, $verbose);
        // one time special local migration pre 2.0 upgrade script
        if ($CFG->version < 2007101600) {
            $pre20upgradefile = "{$CFG->dirroot}/local/upgrade_pre20.php";
            if (file_exists($pre20upgradefile)) {
                set_time_limit(0);
                require $pre20upgradefile;
                // reset upgrade timeout to default
                upgrade_set_timeout();
            }
        }
        $result = xmldb_main_upgrade($CFG->version);
        if ($version > $CFG->version) {
            // store version if not already there
            upgrade_main_savepoint($result, $version, false);
        }
        // perform all other component upgrade routines
        update_capabilities('moodle');
        log_update_descriptions('moodle');
        external_update_descriptions('moodle');
        events_update_definition('moodle');
        message_update_providers('moodle');
        // Update core definitions.
        cache_helper::update_definitions(true);
        // Reset the cache, this returns it to a normal operation state.
        cache_factory::reset();
        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        purge_all_caches();
        // Clean up contexts - more and more stuff depends on existence of paths and contexts
        context_helper::cleanup_instances();
        context_helper::create_instances(null, false);
        context_helper::build_all_paths(false);
        $syscontext = context_system::instance();
        $syscontext->mark_dirty();
        print_upgrade_part_end('moodle', false, $verbose);
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
コード例 #14
0
ファイル: upgrade.php プロジェクト: Keneth1212/moodle
function xmldb_format_grid_upgrade($oldversion = 0)
{
    global $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2011041802) {
        // Define table course_grid_summary to be created.
        $table = new xmldb_table('course_grid_summary');
        // Adding fields to table course_grid_summary.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
        $table->add_field('show_summary', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', null);
        $table->add_field('course_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
        // Adding keys to table course_grid_summary.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Launch create table for course_grid_summary.
        $dbman->create_table($table);
        upgrade_plugin_savepoint(true, '2011041802', 'format', 'grid');
    }
    if ($oldversion < 2012011701) {
        // Rename the tables.
        if ($dbman->table_exists('course_grid_icon')) {
            $table = new xmldb_table('course_grid_icon');
            if (!$dbman->table_exists('format_grid_icon')) {
                $dbman->rename_table($table, 'format_grid_icon');
            } else {
                // May as well tidy up the db.
                $dbman->drop_table($table);
            }
        }
        if ($dbman->table_exists('course_grid_summary')) {
            $table = new xmldb_table('course_grid_summary');
            if (!$dbman->table_exists('format_grid_summary')) {
                $dbman->rename_table($table, 'format_grid_summary');
            } else {
                // May as well tidy up the db.
                $dbman->drop_table($table);
            }
        }
        upgrade_plugin_savepoint(true, '2012011701', 'format', 'grid');
    }
    if ($oldversion < 2012071500) {
        $table = new xmldb_table('format_grid_summary');
        $field = new xmldb_field('course_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        // Rename course_id.
        $dbman->rename_field($table, $field, 'courseid');
        $field = new xmldb_field('show_summary', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
        // Rename show_summary.
        $dbman->rename_field($table, $field, 'showsummary');
        // Add fields and change to unsigned.
        $table = new xmldb_table('format_grid_icon');
        $field = new xmldb_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'sectionid');
        // Conditionally launch add field courseid.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_plugin_savepoint(true, '2012071500', 'format', 'grid');
    }
    if ($oldversion < 2013110400) {
        $table = new xmldb_table('format_grid_icon');
        $field = new xmldb_field('imagepath', XMLDB_TYPE_TEXT, null, null, null, null, null);
        // Rename imagepath.
        $dbman->rename_field($table, $field, 'image');
        $field = new xmldb_field('displayedimageindex', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        // Conditionally launch add field displayediconpath.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_plugin_savepoint(true, '2013110400', 'format', 'grid');
    }
    // Automatic 'Purge all caches'....
    if ($oldversion < 2114052000) {
        purge_all_caches();
    }
    return true;
}
コード例 #15
0
 /**
  * Flavours deployment
  *
  * Executes the deployment delegating to the specific ingredient types managers, it
  * opens the flavour compressed file to extract the data and cleans the flavour temp
  * directory when finishes
  */
 public function deployment_execute()
 {
     global $CFG;
     $outputs = array();
     // Deployment results
     $errorredirect = $this->url . '?action=deployment_upload&sesskey=' . sesskey();
     $form = new flavours_deployment_form($this->url);
     if (!($formdata = $form->get_data())) {
         $this->unlink($flavourpath);
         redirect($errorredirect, get_string('reselect', 'local_flavours'), 2);
     }
     // Flavour contents
     $flavourpath = $CFG->dataroot . '/temp/' . $formdata->flavourhash;
     $flavourfilename = $flavourpath . '/flavour.zip';
     // Getting the ingredients to deploy
     if (!($flavouringredients = $this->get_ingredients_from_form())) {
         $this->unlink($flavourpath);
         redirect($errorredirect, get_string('reselect', 'local_flavours'), 2);
     }
     // Getting zip contents
     if (!unzip_file($flavourfilename, $flavourpath, false)) {
         print_error('errorcantunzip', 'local_flavours');
     }
     $flavourzip = new ZipArchive();
     if (!$flavourzip->open($flavourfilename, 0)) {
         $this->unlink($flavourpath);
         redirect($errorredirect, get_string('errordeployflavour', 'local_flavours'), 4);
     }
     // Getting the flavour xml which describes the flavour contents
     $xml = $this->get_flavour_xml($flavourzip);
     // Deploying ingredients when possible
     foreach ($flavouringredients as $type => $ingredientstodeploy) {
         $this->ingredients[$type] = $this->instance_ingredient_type($type);
         // Ingredient type filesystem
         $ingredienttypepath = $flavourpath . '/flavour/' . $type;
         if (!file_exists($ingredienttypepath)) {
             $ingredienttypepath = false;
         }
         // Deploying ingredients and storing the problems encountered to give feedback
         $xmldata = $xml->ingredient[0]->{$type};
         $outputs[$type] = $this->ingredients[$type]->deploy_ingredients($ingredientstodeploy, $ingredienttypepath, $xmldata);
         // Prepare to display deployment results
         foreach ($ingredientstodeploy as $ingredientname => $ingredientdata) {
             // Then success
             if (empty($outputs[$type][$ingredientname])) {
                 $outputs[$type][$ingredientname] = true;
             }
         }
     }
     // Output results
     $table = new html_table();
     $table->attributes['class'] = 'generaltable boxaligncenter';
     $table->align = array('left', 'left', 'center');
     $table->head = array(get_string('ingredienttype', 'local_flavours'), get_string('ingredient', 'local_flavours'), get_string('deploymentresult', 'local_flavours'));
     // Fill the table
     foreach ($outputs as $type => $ingredients) {
         foreach ($ingredients as $ingredientname => $outputs) {
             // Success
             if (is_bool($outputs)) {
                 $feedback = get_string('success');
                 $classname = 'notifysuccess';
             } else {
                 $feedback = $this->get_restrictions_string($outputs);
                 $classname = 'notifyproblem';
             }
             $feedback = '<span class="' . $classname . '">' . $feedback . '</span>';
             $table->data[] = array($this->ingredients[$type]->name, $ingredientname, $feedback);
         }
     }
     // Will be printed on the renderer
     $this->renderable = new flavours_renderable_deployment_execute($table);
     // Finishing
     $this->unlink($flavourpath);
     purge_all_caches();
 }
コード例 #16
0
/**
 * Purge internally all caches.
 * @param object $user The calling user, containing mnethostroot reference and hostroot reference.
 */
function mnetadmin_rpc_purge_caches($user, $json_response = true)
{
    global $CFG, $USER;
    debug_trace('RPC ' . json_encode($user));
    if ($auth_response = invoke_local_user((array) $user)) {
        if ($json_response) {
            return $auth_response;
        } else {
            return json_decode($auth_response);
        }
    }
    // Creating response.
    $response = new stdClass();
    $response->status = RPC_SUCCESS;
    purge_all_caches();
    debug_trace('RPC Bind : Sending response');
    // Returns response (success or failure).
    return json_encode($response);
}
コード例 #17
0
ファイル: upgradelib.php プロジェクト: dg711/moodle
/**
 * Upgrade/install other parts of moodle
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_noncore($verbose)
{
    global $CFG;
    raise_memory_limit(MEMORY_EXTRA);
    // upgrade all plugins types
    try {
        // Reset caches before any output.
        cache_helper::purge_all(true);
        purge_all_caches();
        $plugintypes = core_component::get_plugin_types();
        foreach ($plugintypes as $type => $location) {
            upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
        }
        // Upgrade services.
        // This function gives plugins and subsystems a chance to add functions to existing built-in services.
        external_update_services();
        // Update cache definitions. Involves scanning each plugin for any changes.
        cache_helper::update_definitions();
        // Mark the site as upgraded.
        set_config('allversionshash', core_component::get_all_versions_hash());
        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        cache_helper::purge_all(true);
        purge_all_caches();
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    } catch (Throwable $ex) {
        // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
        upgrade_handle_exception($ex);
    }
}
コード例 #18
0
 public function clearCache()
 {
     purge_all_caches();
 }
コード例 #19
0
/**
 * Automatically clean-up all plugin data and remove the plugin DB tables
 *
 * NOTE: do not call directly, use new /admin/plugins.php?uninstall=component instead!
 *
 * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc.
 * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc.
 * @uses global $OUTPUT to produce notices and other messages
 * @return void
 */
function uninstall_plugin($type, $name)
{
    global $CFG, $DB, $OUTPUT;
    // This may take a long time.
    @set_time_limit(0);
    // Recursively uninstall all subplugins first.
    $subplugintypes = core_component::get_plugin_types_with_subplugins();
    if (isset($subplugintypes[$type])) {
        $base = core_component::get_plugin_directory($type, $name);
        if (file_exists("{$base}/db/subplugins.php")) {
            $subplugins = array();
            include "{$base}/db/subplugins.php";
            foreach ($subplugins as $subplugintype => $dir) {
                $instances = core_component::get_plugin_list($subplugintype);
                foreach ($instances as $subpluginname => $notusedpluginpath) {
                    uninstall_plugin($subplugintype, $subpluginname);
                }
            }
        }
    }
    $component = $type . '_' . $name;
    // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
    if ($type === 'mod') {
        $pluginname = $name;
        // eg. 'forum'
        if (get_string_manager()->string_exists('modulename', $component)) {
            $strpluginname = get_string('modulename', $component);
        } else {
            $strpluginname = $component;
        }
    } else {
        $pluginname = $component;
        if (get_string_manager()->string_exists('pluginname', $component)) {
            $strpluginname = get_string('pluginname', $component);
        } else {
            $strpluginname = $component;
        }
    }
    echo $OUTPUT->heading($pluginname);
    // Custom plugin uninstall.
    $plugindirectory = core_component::get_plugin_directory($type, $name);
    $uninstalllib = $plugindirectory . '/db/uninstall.php';
    if (file_exists($uninstalllib)) {
        require_once $uninstalllib;
        $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall';
        // eg. 'xmldb_workshop_uninstall()'
        if (function_exists($uninstallfunction)) {
            // Do not verify result, let plugin complain if necessary.
            $uninstallfunction();
        }
    }
    // Specific plugin type cleanup.
    $plugininfo = core_plugin_manager::instance()->get_plugin_info($component);
    if ($plugininfo) {
        $plugininfo->uninstall_cleanup();
        core_plugin_manager::reset_caches();
    }
    $plugininfo = null;
    // perform clean-up task common for all the plugin/subplugin types
    //delete the web service functions and pre-built services
    require_once $CFG->dirroot . '/lib/externallib.php';
    external_delete_descriptions($component);
    // delete calendar events
    $DB->delete_records('event', array('modulename' => $pluginname));
    // delete all the logs
    $DB->delete_records('log', array('module' => $pluginname));
    // delete log_display information
    $DB->delete_records('log_display', array('component' => $component));
    // delete the module configuration records
    unset_all_config_for_plugin($component);
    if ($type === 'mod') {
        unset_all_config_for_plugin($pluginname);
    }
    // delete message provider
    message_provider_uninstall($component);
    // delete the plugin tables
    $xmldbfilepath = $plugindirectory . '/db/install.xml';
    drop_plugin_tables($component, $xmldbfilepath, false);
    if ($type === 'mod' or $type === 'block') {
        // non-frankenstyle table prefixes
        drop_plugin_tables($name, $xmldbfilepath, false);
    }
    // delete the capabilities that were defined by this module
    capabilities_cleanup($component);
    // remove event handlers and dequeue pending events
    events_uninstall($component);
    // Delete all remaining files in the filepool owned by the component.
    $fs = get_file_storage();
    $fs->delete_component_files($component);
    // Finally purge all caches.
    purge_all_caches();
    // Invalidate the hash used for upgrade detections.
    set_config('allversionshash', '');
    echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
コード例 #20
0
function xmldb_format_collblct_upgrade($oldversion = 0)
{
    global $DB;
    $dbman = $DB->get_manager();
    $result = true;
    /* From Moodle 2.2 bit, this places the right defaults in the 'format_collblct_settings' table so they can be read by the 2.3
       update code even though the table is then dropped.... */
    if ($result && $oldversion < 2012070300) {
        // Rename table format_collblct_layout if it exists.
        $table = new xmldb_table('format_collblct_layout');
        // Rename the table...
        if ($dbman->table_exists($table)) {
            $dbman->rename_table($table, 'format_collblct_settings');
        }
        $table = new xmldb_table('format_collblct_settings');
        // Use the new table.
        // If the table does not exist, create it along with its fields.
        if (!$dbman->table_exists($table)) {
            // Adding fields.
            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
            $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
            $table->add_field('layoutelement', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null);
            $table->add_field('layoutstructure', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null);
            // Adding key.
            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
            // Create table.
            $dbman->create_table($table);
        }
        // Moodle 2.3 uses signed integers.
        // Changing sign of field id on table format_collblct_settings to signed - mysql only,
        // see 'upgrade_mysql_fix_unsigned_columns()' in '/lib/db/upgradelib.php'.
        if ($DB->get_dbfamily() == 'mysql') {
            $field = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
            // Launch change of sign for field id.
            $dbman->change_field_unsigned($table, $field);
            // Changing sign of field courseid on table format_collblct_settings to signed.
            $field = new xmldb_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id');
            // Launch change of sign for field courseid.
            $dbman->change_field_unsigned($table, $field);
            // Changing sign of field layoutelement on table format_collblct_settings to signed.
            $field = new xmldb_field('layoutelement', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1', 'courseid');
            // Launch change of sign for field layoutelement.
            $dbman->change_field_unsigned($table, $field);
            // Changing sign of field layoutstructure on table format_collblct_settings to signed.
            $field = new xmldb_field('layoutstructure', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'layoutelement');
            // Launch change of sign for field layoutstructure.
            $dbman->change_field_unsigned($table, $field);
        }
        // Define field tgfgcolour to be added to format_collblct_settings.
        $field = new xmldb_field('tgfgcolour', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, '000000', 'layoutstructure');
        // Conditionally launch add field tgfgcolour.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field tgbgcolour to be added to format_collblct_settings.
        $field = new xmldb_field('tgbgcolour', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, 'e2e2f2', 'tgfgcolour');
        // Conditionally launch add field tgbgcolour.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Define field tgbghvrcolour to be added to format_collblct_settings.
        $field = new xmldb_field('tgbghvrcolour', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, 'eeeeff', 'tgbgcolour');
        // Conditionally launch add field tgbghvrcolour.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // New field layoutcolumns on table format_collblct_settings.  This is not the same place as install.xml
        // because of altering previous field issue but will work.
        $field = new xmldb_field('layoutcolumns', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'tgbghvrcolour');
        // Conditionally launch add field layoutcolumns.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Drop table format_collblct_cookie_cnsnt if it exists - this may not work, please check db to see that
        // the table has really gone.
        $table = new xmldb_table('format_collblct_cookie_cnsnt');
        // Drop the table...
        if ($dbman->table_exists($table)) {
            $dbman->drop_table($table);
        }
    }
    // DB tables were first added with Oct. 30th version [Craig's DB].
    if ($oldversion < 2012103001) {
        $table = new xmldb_table('collblct');
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_field('foregroundcolor', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
        $table->add_field('backgroundcolor', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint(true, 2012110100, 'format', 'collblct');
    }
    // The "enable" table was added on Nov. 26th [Craig's DB].
    if ($oldversion < 2012112600) {
        $table = new xmldb_table('collblct_enable');
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_field('sectionid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_field('status', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint(true, 2012112600, 'format', 'collblct');
    }
    // From Moodle 2.3 bit....
    if ($result && $oldversion < 2012120100) {
        // Note to self, Moodle 2.3 version cannot now be greater than this.
        $table = new xmldb_table('format_collblct_settings');
        if ($dbman->table_exists($table) == true) {
            // Extract data out of table and put in course settings table for 2.4.
            $records = $DB->get_records($table->getName());
            foreach ($records as $record) {
                // Check that the course still exists - CONTRIB-4065...
                if ($DB->record_exists('course', array('id' => $record->courseid))) {
                    $courseformat = course_get_format($record->courseid);
                    // In '/course/format/lib.php'.
                    // Only update if the current format is 'collblct' as we must have an instance of 'format_collblct' (in 'lib.php')
                    // returned by the above.  Thanks to Marina Glancy for this :).
                    // If there are entries that existed for courses that were originally collblct, then they will be lost.  However
                    // the code copes with this through the employment of defaults and I dont think the underlying
                    // code desires entries in the course_format_settings table for courses of a format that belong
                    // to another format.
                    if ($courseformat->get_format() == 'collblct') {
                        $courseformat->restore_collblct_setting($record->courseid, $record->layoutelement, $record->layoutstructure, $record->layoutcolumns, $record->tgfgcolour, $record->tgbgcolour, $record->tgbghvrcolour);
                        // In '/course/format/collblct/lib.php'.
                    }
                }
            }
            // Farewell old settings table.
            $dbman->drop_table($table);
        }
        // ...else Nothing to do as settings put in DB on first use.
    }
    // Automatic 'Purge all caches'....
    if ($oldversion < 2114052000) {
        purge_all_caches();
    }
    return $result;
}
コード例 #21
0
ファイル: upgradelib.php プロジェクト: jtibbetts/moodle
/**
 * Upgrade/install other parts of moodle
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_noncore($verbose) {
    global $CFG;

    raise_memory_limit(MEMORY_EXTRA);

    // upgrade all plugins types
    try {
        // Reset caches before any output.
        cache_helper::purge_all(true);
        purge_all_caches();

        $plugintypes = core_component::get_plugin_types();
        foreach ($plugintypes as $type=>$location) {
            upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
        }
        // Update cache definitions. Involves scanning each plugin for any changes.
        cache_helper::update_definitions();
        // Mark the site as upgraded.
        set_config('allversionshash', core_component::get_all_versions_hash());

        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        cache_helper::purge_all(true);
        purge_all_caches();

    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
コード例 #22
0
/**
 * Find and check all submodules and load them up or upgrade them if necessary
 *
 * @global object
 * @global object
 */
function vmoodle_upgrade_subplugins_modules($startcallback, $endcallback, $verbose = true)
{
    global $CFG, $DB;
    include $CFG->dirroot . '/local/vmoodle/db/subplugins.php';
    foreach ($subplugins as $type => $subpluginpath) {
        $plugindirs = glob($CFG->dirroot . '/' . $subpluginpath . '/*');
        foreach ($plugindirs as $dir) {
            $plug = basename($dir);
            $fullplug = $dir;
            if ($plug === 'CVS') {
                // Someone has unzipped the template, ignore it.
                continue;
            }
            if ($plug === 'NEWMODULE') {
                // Someone has unzipped the template, ignore it.
                continue;
            }
            // Reset time so that it works when installing a large number of plugins.
            set_time_limit(600);
            $component = clean_param($type . '_' . $plug, PARAM_COMPONENT);
            // standardised plugin name
            // Check plugin dir is valid name.
            if (empty($component)) {
                throw new plugin_defective_exception($type . '_' . $plug, 'Invalid plugin directory name.');
            }
            if (!is_readable($fullplug . '/version.php')) {
                continue;
            }
            $plugin = new stdClass();
            require $fullplug . '/version.php';
            // Defines $plugin with version etc.
            // If plugin tells us it's full name we may check the location.
            if (isset($plugin->component)) {
                if ($plugin->component !== $component) {
                    throw new plugin_defective_exception($component, 'Plugin installed in wrong folder.');
                }
            }
            if (empty($plugin->version)) {
                throw new plugin_defective_exception($component, 'Missing version value in version.php');
            }
            $plugin->name = $plug;
            $plugin->fullname = $component;
            if (!empty($plugin->requires)) {
                if ($plugin->requires > $CFG->version) {
                    throw new upgrade_requires_exception($component, $plugin->version, $CFG->version, $plugin->requires);
                } else {
                    if ($plugin->requires < 2010000000) {
                        throw new plugin_defective_exception($component, 'Plugin is not compatible with Moodle 2.x or later.');
                    }
                }
            }
            // Try to recover from interrupted install.php if needed.
            if (file_exists($fullplug . '/db/install.php')) {
                if (get_config($plugin->fullname, 'installrunning')) {
                    require_once $fullplug . '/db/install.php';
                    $recover_install_function = 'xmldb_' . $plugin->fullname . '_install_recovery';
                    if (function_exists($recover_install_function)) {
                        $startcallback($component, true, $verbose);
                        $recover_install_function();
                        unset_config('installrunning', $plugin->fullname);
                        update_capabilities($component);
                        log_update_descriptions($component);
                        external_update_descriptions($component);
                        events_update_definition($component);
                        message_update_providers($component);
                        if ($type === 'message') {
                            message_update_processors($plug);
                        }
                        vmoodle_upgrade_plugin_mnet_functions($component, $fullplug);
                        // Fix wrongly twicked paths.
                        if ($rpc_shifted_defines = $DB->get_records_select('mnet_rpc', " xmlrpcpath LIKE 'vmoodleadminset' ", array())) {
                            foreach ($rpc_shifted_defines as $rpc) {
                                $rpc->xmlrpcpath = str_replace('vmoocleadminset', 'local/vmoodle/plugins');
                                $DB->update_record('mnet_rpc', $rpc);
                            }
                        }
                        $endcallback($component, true, $verbose);
                    }
                }
            }
            $installedversion = get_config($plugin->fullname, 'version');
            if (empty($installedversion)) {
                // New installation.
                $startcallback($component, true, $verbose);
                // Install tables if defined.
                if (file_exists($fullplug . '/db/install.xml')) {
                    $DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml');
                }
                // Store version.
                upgrade_plugin_savepoint(true, $plugin->version, $type, $plug, false);
                // Execute post install file.
                if (file_exists($fullplug . '/db/install.php')) {
                    require_once $fullplug . '/db/install.php';
                    set_config('installrunning', 1, $plugin->fullname);
                    $post_install_function = 'xmldb_' . $plugin->fullname . '_install';
                    $post_install_function();
                    unset_config('installrunning', $plugin->fullname);
                }
                // Install various components.
                update_capabilities($component);
                log_update_descriptions($component);
                external_update_descriptions($component);
                events_update_definition($component);
                message_update_providers($component);
                if ($type === 'message') {
                    message_update_processors($plug);
                }
                vmoodle_upgrade_plugin_mnet_functions($component, $fullplug);
                // Fix wrongly twicked paths.
                if ($rpc_shifted_defines = $DB->get_records_select('mnet_rpc', " xmlrpcpath LIKE 'vmoodleadminset' ", array())) {
                    foreach ($rpc_shifted_defines as $rpc) {
                        $rpc->xmlrpcpath = str_replace('vmoocleadminset', 'local/vmoodle/plugins');
                        $DB->update_record('mnet_rpc', $rpc);
                    }
                }
                purge_all_caches();
                $endcallback($component, true, $verbose);
            } else {
                if ($installedversion < $plugin->version) {
                    // Upgrade
                    // Run the upgrade function for the plugin.
                    $startcallback($component, false, $verbose);
                    if (is_readable($fullplug . '/db/upgrade.php')) {
                        require_once $fullplug . '/db/upgrade.php';
                        // Defines upgrading function
                        $newupgrade_function = 'xmldb_' . $plugin->fullname . '_upgrade';
                        $result = $newupgrade_function($installedversion);
                    } else {
                        $result = true;
                    }
                    $installedversion = get_config($plugin->fullname, 'version');
                    if ($installedversion < $plugin->version) {
                        // store version if not already there.
                        upgrade_plugin_savepoint($result, $plugin->version, $type, $plug, false);
                    }
                    // Upgrade various components.
                    update_capabilities($component);
                    log_update_descriptions($component);
                    external_update_descriptions($component);
                    events_update_definition($component);
                    message_update_providers($component);
                    if ($type === 'message') {
                        message_update_processors($plug);
                    }
                    vmoodle_upgrade_plugin_mnet_functions($component, $fullplug);
                    purge_all_caches();
                    $endcallback($component, false, $verbose);
                } else {
                    if ($installedversion > $plugin->version) {
                        throw new downgrade_exception($component, $installedversion, $plugin->version);
                    }
                }
            }
        }
    }
}
コード例 #23
0
 public function test_localcachedir()
 {
     global $CFG;
     $this->resetAfterTest(true);
     // Test default location - can not be modified in phpunit tests because we override everything in config.php.
     $this->assertSame("{$CFG->dataroot}/localcache", $CFG->localcachedir);
     $this->setCurrentTimeStart();
     $timestampfile = "{$CFG->localcachedir}/.lastpurged";
     // Delete existing localcache directory, as this is testing first call
     // to make_localcache_directory.
     remove_dir($CFG->localcachedir, true);
     $dir = make_localcache_directory('', false);
     $this->assertSame($CFG->localcachedir, $dir);
     $this->assertFileNotExists("{$CFG->localcachedir}/.htaccess");
     $this->assertFileExists($timestampfile);
     $this->assertTimeCurrent(filemtime($timestampfile));
     $dir = make_localcache_directory('test/test', false);
     $this->assertSame("{$CFG->localcachedir}/test/test", $dir);
     // Test custom location.
     $CFG->localcachedir = "{$CFG->dataroot}/testlocalcache";
     $this->setCurrentTimeStart();
     $timestampfile = "{$CFG->localcachedir}/.lastpurged";
     $this->assertFileNotExists($timestampfile);
     $dir = make_localcache_directory('', false);
     $this->assertSame($CFG->localcachedir, $dir);
     $this->assertFileExists("{$CFG->localcachedir}/.htaccess");
     $this->assertFileExists($timestampfile);
     $this->assertTimeCurrent(filemtime($timestampfile));
     $dir = make_localcache_directory('test', false);
     $this->assertSame("{$CFG->localcachedir}/test", $dir);
     $prevtime = filemtime($timestampfile);
     $dir = make_localcache_directory('pokus', false);
     $this->assertSame("{$CFG->localcachedir}/pokus", $dir);
     $this->assertSame($prevtime, filemtime($timestampfile));
     // Test purging.
     $testfile = "{$CFG->localcachedir}/test/test.txt";
     $this->assertTrue(touch($testfile));
     $now = $this->setCurrentTimeStart();
     set_config('localcachedirpurged', $now - 2);
     purge_all_caches();
     $this->assertFileNotExists($testfile);
     $this->assertFileNotExists(dirname($testfile));
     $this->assertFileExists($timestampfile);
     $this->assertTimeCurrent(filemtime($timestampfile));
     $this->assertTimeCurrent($CFG->localcachedirpurged);
     // Simulates purge_all_caches() on another server node.
     make_localcache_directory('test', false);
     $this->assertTrue(touch($testfile));
     set_config('localcachedirpurged', $now - 1);
     $this->assertTrue(touch($timestampfile, $now - 2));
     clearstatcache();
     $this->assertSame($now - 2, filemtime($timestampfile));
     $this->setCurrentTimeStart();
     $dir = make_localcache_directory('', false);
     $this->assertSame("{$CFG->localcachedir}", $dir);
     $this->assertFileNotExists($testfile);
     $this->assertFileNotExists(dirname($testfile));
     $this->assertFileExists($timestampfile);
     $this->assertTimeCurrent(filemtime($timestampfile));
 }
コード例 #24
0
ファイル: CacheClear.php プロジェクト: dariogs/moosh
 public function execute()
 {
     purge_all_caches();
 }
コード例 #25
0
ファイル: purgecaches.php プロジェクト: vuchannguyen/web
 *
 * @package    core
 * @copyright  2010 Petr Skoda {@link http://skodak.org}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
require_once $CFG->libdir . '/adminlib.php';
$confirm = optional_param('confirm', 0, PARAM_BOOL);
admin_externalpage_setup('purgecaches');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
if ($confirm) {
    require_sesskey();
    // Valid request. Purge, and redisplay the form so it is easy to purge again
    // in the near future.
    purge_all_caches();
    redirect(new moodle_url('/admin/purgecaches.php'), get_string('purgecachesfinished', 'admin'));
} else {
    // Show a confirm form.
    echo $OUTPUT->header();
    echo $OUTPUT->heading(get_string('purgecaches', 'admin'));
    $url = new moodle_url('/admin/purgecaches.php', array('sesskey' => sesskey(), 'confirm' => 1));
    $button = new single_button($url, get_string('purgecaches', 'admin'), 'post');
    // Cancel button takes them back to the page the were on, if possible,
    // otherwise to the site home page.
    $return = new moodle_url('/');
    if (isset($_SERVER['HTTP_REFERER']) and !empty($_SERVER['HTTP_REFERER'])) {
        if ($_SERVER['HTTP_REFERER'] !== "{$CFG->wwwroot}/{$CFG->admin}/purgecaches.php") {
            $return = $_SERVER['HTTP_REFERER'];
        }
    }
コード例 #26
0
ファイル: lib.php プロジェクト: nickread/moodle
 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  *
  * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
  *
  * @static
  */
 public static function reset_all_data()
 {
     global $DB, $CFG;
     $data = self::get_tabledata();
     $trans = $DB->start_delegated_transaction();
     // faster and safer
     foreach ($data as $table => $records) {
         $DB->delete_records($table, array());
         $resetseq = null;
         foreach ($records as $record) {
             if (is_null($resetseq)) {
                 $resetseq = property_exists($record, 'id');
             }
             $DB->import_record($table, $record, false, true);
         }
         if ($resetseq === true) {
             $DB->get_manager()->reset_sequence($table, true);
         }
     }
     $trans->allow_commit();
     purge_all_caches();
     $user = new stdClass();
     $user->id = 0;
     $user->mnet = 0;
     $user->mnethostid = $CFG->mnet_localhost_id;
     session_set_user($user);
     accesslib_clear_all_caches_for_unit_testing();
 }