/** * 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. * * @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() { 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 = 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 ($factory->get_state() !== cache_factory::STATE_INITIALISING) { return $writer->generate_configuration_array(); } $factory->set_state(cache_factory::STATE_SAVING); $writer->config_save(); return true; }
/** * Returns an array of default stores for use. * * @return array */ protected static function get_default_stores() { global $CFG; 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'; return array('default_application' => array('name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cachestore_file::get_supported_modes(), 'default' => true), 'default_session' => array('name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cachestore_session::get_supported_modes(), 'default' => true), 'default_request' => array('name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cachestore_static::get_supported_modes(), 'default' => 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(); }