1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_cache;
|
|
|
18 |
|
|
|
19 |
use core\exception\coding_exception;
|
|
|
20 |
use core_cache\exception\cache_exception;
|
|
|
21 |
use cachestore_static;
|
|
|
22 |
use cachestore_session;
|
|
|
23 |
use cachestore_file;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* The cache config class used when the Cache has been disabled.
|
|
|
27 |
*
|
|
|
28 |
* @package core_cache
|
|
|
29 |
* @copyright 2012 Sam Hemelryk
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class disabled_config extends config_writer {
|
|
|
33 |
/**
|
|
|
34 |
* Returns an instance of the configuration writer.
|
|
|
35 |
*
|
|
|
36 |
* @return disabled_config
|
|
|
37 |
*/
|
|
|
38 |
public static function instance() {
|
|
|
39 |
$factory = factory::instance();
|
|
|
40 |
return $factory->create_config_instance(true);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Saves the current configuration.
|
|
|
45 |
*/
|
|
|
46 |
protected function config_save() {
|
|
|
47 |
// Nothing to do here.
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Generates a configuration array suitable to be written to the config file.
|
|
|
52 |
*
|
|
|
53 |
* @return array
|
|
|
54 |
*/
|
|
|
55 |
protected function generate_configuration_array() {
|
|
|
56 |
$configuration = [];
|
|
|
57 |
$configuration['stores'] = $this->configstores;
|
|
|
58 |
$configuration['modemappings'] = $this->configmodemappings;
|
|
|
59 |
$configuration['definitions'] = $this->configdefinitions;
|
|
|
60 |
$configuration['definitionmappings'] = $this->configdefinitionmappings;
|
|
|
61 |
$configuration['locks'] = $this->configlocks;
|
|
|
62 |
return $configuration;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Adds a plugin instance.
|
|
|
67 |
*
|
|
|
68 |
* @param string $name Unused.
|
|
|
69 |
* @param string $plugin Unused.
|
|
|
70 |
* @param array $configuration Unused.
|
|
|
71 |
* @return bool
|
|
|
72 |
* @throws cache_exception
|
|
|
73 |
*/
|
|
|
74 |
public function add_store_instance($name, $plugin, array $configuration = []) {
|
|
|
75 |
return false;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Sets the mode mappings.
|
|
|
80 |
*
|
|
|
81 |
* @param array $modemappings Unused.
|
|
|
82 |
* @return bool
|
|
|
83 |
* @throws cache_exception
|
|
|
84 |
*/
|
|
|
85 |
public function set_mode_mappings(array $modemappings) {
|
|
|
86 |
return false;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Edits a give plugin instance.
|
|
|
91 |
*
|
|
|
92 |
* @param string $name Unused.
|
|
|
93 |
* @param string $plugin Unused.
|
|
|
94 |
* @param array $configuration Unused.
|
|
|
95 |
* @return bool
|
|
|
96 |
* @throws cache_exception
|
|
|
97 |
*/
|
|
|
98 |
public function edit_store_instance($name, $plugin, $configuration) {
|
|
|
99 |
return false;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* Deletes a store instance.
|
|
|
104 |
*
|
|
|
105 |
* @param string $name Unused.
|
|
|
106 |
* @return bool
|
|
|
107 |
* @throws cache_exception
|
|
|
108 |
*/
|
|
|
109 |
public function delete_store_instance($name) {
|
|
|
110 |
return false;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Creates the default configuration and saves it.
|
|
|
115 |
*
|
|
|
116 |
* @param bool $forcesave Ignored because we are disabled!
|
|
|
117 |
* @return array
|
|
|
118 |
*/
|
|
|
119 |
public static function create_default_configuration($forcesave = false) {
|
|
|
120 |
global $CFG;
|
|
|
121 |
|
|
|
122 |
// HACK ALERT.
|
|
|
123 |
// We probably need to come up with a better way to create the default stores, or at least ensure 100% that the
|
|
|
124 |
// default store plugins are protected from deletion.
|
|
|
125 |
require_once($CFG->dirroot . '/cache/stores/file/lib.php');
|
|
|
126 |
require_once($CFG->dirroot . '/cache/stores/session/lib.php');
|
|
|
127 |
require_once($CFG->dirroot . '/cache/stores/static/lib.php');
|
|
|
128 |
|
|
|
129 |
$writer = new self();
|
|
|
130 |
$writer->configstores = [
|
|
|
131 |
'default_application' => [
|
|
|
132 |
'name' => 'default_application',
|
|
|
133 |
'plugin' => 'file',
|
|
|
134 |
'configuration' => [],
|
|
|
135 |
'features' => cachestore_file::get_supported_features(),
|
|
|
136 |
'modes' => store::MODE_APPLICATION,
|
|
|
137 |
'default' => true,
|
|
|
138 |
],
|
|
|
139 |
'default_session' => [
|
|
|
140 |
'name' => 'default_session',
|
|
|
141 |
'plugin' => 'session',
|
|
|
142 |
'configuration' => [],
|
|
|
143 |
'features' => cachestore_session::get_supported_features(),
|
|
|
144 |
'modes' => store::MODE_SESSION,
|
|
|
145 |
'default' => true,
|
|
|
146 |
],
|
|
|
147 |
'default_request' => [
|
|
|
148 |
'name' => 'default_request',
|
|
|
149 |
'plugin' => 'static',
|
|
|
150 |
'configuration' => [],
|
|
|
151 |
'features' => cachestore_static::get_supported_features(),
|
|
|
152 |
'modes' => store::MODE_REQUEST,
|
|
|
153 |
'default' => true,
|
|
|
154 |
],
|
|
|
155 |
];
|
|
|
156 |
$writer->configdefinitions = [];
|
|
|
157 |
$writer->configmodemappings = [
|
|
|
158 |
[
|
|
|
159 |
'mode' => store::MODE_APPLICATION,
|
|
|
160 |
'store' => 'default_application',
|
|
|
161 |
'sort' => -1,
|
|
|
162 |
],
|
|
|
163 |
[
|
|
|
164 |
'mode' => store::MODE_SESSION,
|
|
|
165 |
'store' => 'default_session',
|
|
|
166 |
'sort' => -1,
|
|
|
167 |
],
|
|
|
168 |
[
|
|
|
169 |
'mode' => store::MODE_REQUEST,
|
|
|
170 |
'store' => 'default_request',
|
|
|
171 |
'sort' => -1,
|
|
|
172 |
],
|
|
|
173 |
];
|
|
|
174 |
$writer->configlocks = [
|
|
|
175 |
'default_file_lock' => [
|
|
|
176 |
'name' => 'cachelock_file_default',
|
|
|
177 |
'type' => 'cachelock_file',
|
|
|
178 |
'dir' => 'filelocks',
|
|
|
179 |
'default' => true,
|
|
|
180 |
],
|
|
|
181 |
];
|
|
|
182 |
|
|
|
183 |
return $writer->generate_configuration_array();
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
* Updates the definition in the configuration from those found in the cache files.
|
|
|
188 |
*
|
|
|
189 |
* @param bool $coreonly Unused.
|
|
|
190 |
*/
|
|
|
191 |
public static function update_definitions($coreonly = false) {
|
|
|
192 |
// Nothing to do here.
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* Locates all of the definition files.
|
|
|
197 |
*
|
|
|
198 |
* @param bool $coreonly Unused.
|
|
|
199 |
* @return array
|
|
|
200 |
*/
|
|
|
201 |
protected static function locate_definitions($coreonly = false) {
|
|
|
202 |
return [];
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
* Sets the mappings for a given definition.
|
|
|
207 |
*
|
|
|
208 |
* @param string $definition Unused.
|
|
|
209 |
* @param array $mappings Unused.
|
|
|
210 |
* @throws coding_exception
|
|
|
211 |
*/
|
|
|
212 |
public function set_definition_mappings($definition, $mappings) {
|
|
|
213 |
// Nothing to do here.
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
// Alias this class to the old name.
|
|
|
218 |
// This file will be autoloaded by the legacyclasses autoload system.
|
|
|
219 |
// In future all uses of this class will be corrected and the legacy references will be removed.
|
|
|
220 |
class_alias(disabled_config::class, \cache_config_disabled::class);
|