示例#1
0
 /**
  * Test disabling the cache stores.
  */
 public function test_disable_stores()
 {
     $instance = cache_config_phpunittest::instance();
     $instance->phpunit_add_definition('phpunit/disabletest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'disabletest'));
     $cache = cache::make('phpunit', 'disabletest');
     $this->assertInstanceOf('cache_phpunit_application', $cache);
     $this->assertEquals('cachestore_file', $cache->phpunit_get_store_class());
     $this->assertFalse($cache->get('test'));
     $this->assertTrue($cache->set('test', 'test'));
     $this->assertEquals('test', $cache->get('test'));
     cache_factory::disable_stores();
     $cache = cache::make('phpunit', 'disabletest');
     $this->assertInstanceOf('cache_phpunit_application', $cache);
     $this->assertEquals('cachestore_dummy', $cache->phpunit_get_store_class());
     $this->assertFalse($cache->get('test'));
     $this->assertTrue($cache->set('test', 'test'));
     $this->assertEquals('test', $cache->get('test'));
 }
示例#2
0
 /**
  * Test disabling the cache stores.
  */
 public function test_disable_stores()
 {
     $instance = cache_config_testing::instance();
     $instance->phpunit_add_definition('phpunit/disabletest1', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'disabletest1'));
     $instance->phpunit_add_definition('phpunit/disabletest2', array('mode' => cache_store::MODE_SESSION, 'component' => 'phpunit', 'area' => 'disabletest2'));
     $instance->phpunit_add_definition('phpunit/disabletest3', array('mode' => cache_store::MODE_REQUEST, 'component' => 'phpunit', 'area' => 'disabletest3'));
     $caches = array('disabletest1' => cache::make('phpunit', 'disabletest1'), 'disabletest2' => cache::make('phpunit', 'disabletest2'), 'disabletest3' => cache::make('phpunit', 'disabletest3'));
     $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']);
     $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']);
     $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']);
     $this->assertEquals('cachestore_file', $caches['disabletest1']->phpunit_get_store_class());
     $this->assertEquals('cachestore_session', $caches['disabletest2']->phpunit_get_store_class());
     $this->assertEquals('cachestore_static', $caches['disabletest3']->phpunit_get_store_class());
     foreach ($caches as $cache) {
         $this->assertFalse($cache->get('test'));
         $this->assertTrue($cache->set('test', 'test'));
         $this->assertEquals('test', $cache->get('test'));
     }
     cache_factory::disable_stores();
     $caches = array('disabletest1' => cache::make('phpunit', 'disabletest1'), 'disabletest2' => cache::make('phpunit', 'disabletest2'), 'disabletest3' => cache::make('phpunit', 'disabletest3'));
     $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']);
     $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']);
     $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']);
     $this->assertEquals('cachestore_dummy', $caches['disabletest1']->phpunit_get_store_class());
     $this->assertEquals('cachestore_dummy', $caches['disabletest2']->phpunit_get_store_class());
     $this->assertEquals('cachestore_dummy', $caches['disabletest3']->phpunit_get_store_class());
     foreach ($caches as $cache) {
         $this->assertFalse($cache->get('test'));
         $this->assertTrue($cache->set('test', 'test'));
         $this->assertEquals('test', $cache->get('test'));
     }
 }
示例#3
0
/**
 * 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 {
        // Disable the use of cache stores here.
        // We don't reset this, the site can live without proper caching for life of this request.
        cache_factory::disable_stores();

        $plugintypes = 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();
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
示例#4
0
/**
 * Get configuration values from the global config table
 * or the config_plugins table.
 *
 * If called with one parameter, it will load all the config
 * variables for one plugin, and return them as an object.
 *
 * If called with 2 parameters it will return a string single
 * value or false if the value is not found.
 *
 * @static $siteidentifier The site identifier is not cached. We use this static cache so
 *     that we need only fetch it once per request.
 * @param string $plugin full component name
 * @param string $name default NULL
 * @return mixed hash-like object or single value, return false no config found
 */
function get_config($plugin, $name = NULL)
{
    global $CFG, $DB;
    static $siteidentifier = null;
    if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) {
        $forced =& $CFG->config_php_settings;
        $iscore = true;
        $plugin = 'core';
    } else {
        if (array_key_exists($plugin, $CFG->forced_plugin_settings)) {
            $forced =& $CFG->forced_plugin_settings[$plugin];
        } else {
            $forced = array();
        }
        $iscore = false;
    }
    if ($siteidentifier === null) {
        try {
            // This may fail during installation.
            // If you have a look at {@link initialise_cfg()} you will see that this is how we detect the need to
            // install the database.
            $siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
        } catch (dml_exception $ex) {
            // It's failed. We'll use this opportunity to disable cache stores so that we don't inadvertingly start using
            // old caches. People should delete their moodledata dirs when reinstalling the database... but they don't.
            cache_factory::disable_stores();
            // Set siteidentifier to false. We don't want to trip this continually.
            $siteidentifier = false;
            throw $ex;
        }
    }
    if (!empty($name)) {
        if (array_key_exists($name, $forced)) {
            return (string) $forced[$name];
        } else {
            if ($name === 'siteidentifier' && $plugin == 'core') {
                return $siteidentifier;
            }
        }
    }
    $cache = cache::make('core', 'config');
    $result = $cache->get($plugin);
    if (!$result) {
        // the user is after a recordset
        $result = new stdClass();
        if (!$iscore) {
            $result = $DB->get_records_menu('config_plugins', array('plugin' => $plugin), '', 'name,value');
        } else {
            // this part is not really used any more, but anyway...
            $result = $DB->get_records_menu('config', array(), '', 'name,value');
        }
        $cache->set($plugin, $result);
    }
    if (!empty($name)) {
        if (array_key_exists($name, $result)) {
            return $result[$name];
        }
        return false;
    }
    if ($plugin === 'core') {
        $result['siteidentifier'] = $siteidentifier;
    }
    foreach ($forced as $key => $value) {
        if (is_null($value) or is_array($value) or is_object($value)) {
            // we do not want any extra mess here, just real settings that could be saved in db
            unset($result[$key]);
        } else {
            //convert to string as if it went through the DB
            $result[$key] = (string) $value;
        }
    }
    return (object) $result;
}
示例#5
0
/**
 * 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 {
        // 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();
        $plugintypes = 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();
        // Reset the cache system to a normal state.
        cache_factory::reset();
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}