/** * Creates the default configuration and saves it. * * This function calls config_save, however it is safe to continue using it afterwards as this function should only ever * be called when there is no configuration file already. * * @param bool $forcesave If set to true then we will forcefully save the default configuration file. * @return true|array Returns true if the default configuration was successfully created. * Returns a configuration array if it could not be saved. This is a bad situation. Check your error logs. */ public static function create_default_configuration($forcesave = false) { global $CFG; // HACK ALERT. // We probably need to come up with a better way to create the default stores, or at least ensure 100% that the // default store plugins are protected from deletion. $writer = new self(); $writer->configstores = self::get_default_stores(); $writer->configdefinitions = self::locate_definitions(); $defaultapplication = 'default_application'; $appdefine = defined('TEST_CACHE_USING_APPLICATION_STORE') ? TEST_CACHE_USING_APPLICATION_STORE : false; if ($appdefine !== false && preg_match('/^[a-zA-Z][a-zA-Z0-9_]+$/', $appdefine)) { $expectedstore = $appdefine; $expecteddefine = 'TEST_CACHESTORE_' . strtoupper($expectedstore) . '_TESTSERVERS'; $file = $CFG->dirroot . '/cache/stores/' . $appdefine . '/lib.php'; $class = 'cachestore_' . $appdefine; if (file_exists($file)) { require_once $file; } if (defined($expecteddefine) && class_exists($class)) { /** @var cache_store $class */ $writer->configstores['test_application'] = array('use_test_store' => true, 'name' => 'test_application', 'plugin' => $expectedstore, 'alt' => $writer->configstores[$defaultapplication], 'modes' => $class::get_supported_modes(), 'features' => $class::get_supported_features()); $defaultapplication = 'test_application'; } } $writer->configmodemappings = array(array('mode' => cache_store::MODE_APPLICATION, 'store' => $defaultapplication, 'sort' => -1), array('mode' => cache_store::MODE_SESSION, 'store' => 'default_session', 'sort' => -1), array('mode' => cache_store::MODE_REQUEST, 'store' => 'default_request', 'sort' => -1)); $writer->configlocks = array('default_file_lock' => array('name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true)); $factory = cache_factory::instance(); // We expect the cache to be initialising presently. If its not then something has gone wrong and likely // we are now in a loop. if (!$forcesave && $factory->get_state() !== cache_factory::STATE_INITIALISING) { return $writer->generate_configuration_array(); } $factory->set_state(cache_factory::STATE_SAVING); $writer->config_save(); return true; }
/** * Creates the default configuration and saves it. * * This function calls config_save, however it is safe to continue using it afterwards as this function should only ever * be called when there is no configuration file already. * * @param bool $forcesave If set to true then we will forcefully save the default configuration file. * @return true|array Returns true if the default configuration was successfully created. * Returns a configuration array if it could not be saved. This is a bad situation. Check your error logs. */ public static function create_default_configuration($forcesave = false) { // HACK ALERT. // We probably need to come up with a better way to create the default stores, or at least ensure 100% that the // default store plugins are protected from deletion. $writer = new self(); $writer->configstores = self::get_default_stores(); $writer->configdefinitions = self::locate_definitions(); $writer->configmodemappings = array(array('mode' => cache_store::MODE_APPLICATION, 'store' => 'default_application', 'sort' => -1), array('mode' => cache_store::MODE_SESSION, 'store' => 'default_session', 'sort' => -1), array('mode' => cache_store::MODE_REQUEST, 'store' => 'default_request', 'sort' => -1)); $writer->configlocks = array('default_file_lock' => array('name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true)); $factory = cache_factory::instance(); // We expect the cache to be initialising presently. If its not then something has gone wrong and likely // we are now in a loop. if (!$forcesave && $factory->get_state() !== cache_factory::STATE_INITIALISING) { return $writer->generate_configuration_array(); } $factory->set_state(cache_factory::STATE_SAVING); $writer->config_save(); return true; }
/** * Creates the default configuration and saves it. * * @param bool $forcesave Ignored because we are disabled! * @return array */ public static function create_default_configuration($forcesave = false) { global $CFG; // HACK ALERT. // We probably need to come up with a better way to create the default stores, or at least ensure 100% that the // default store plugins are protected from deletion. require_once $CFG->dirroot . '/cache/stores/file/lib.php'; require_once $CFG->dirroot . '/cache/stores/session/lib.php'; require_once $CFG->dirroot . '/cache/stores/static/lib.php'; $writer = new self(); $writer->configstores = array('default_application' => array('name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cache_store::MODE_APPLICATION, 'default' => true), 'default_session' => array('name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cache_store::MODE_SESSION, 'default' => true), 'default_request' => array('name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cache_store::MODE_REQUEST, 'default' => true)); $writer->configdefinitions = array(); $writer->configmodemappings = array(array('mode' => cache_store::MODE_APPLICATION, 'store' => 'default_application', 'sort' => -1), array('mode' => cache_store::MODE_SESSION, 'store' => 'default_session', 'sort' => -1), array('mode' => cache_store::MODE_REQUEST, 'store' => 'default_request', 'sort' => -1)); $writer->configlocks = array('default_file_lock' => array('name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true)); return $writer->generate_configuration_array(); }