Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 18... Línea 18...
18
 * Cache display administration helper.
18
 * Cache display administration helper.
19
 *
19
 *
20
 * This file is part of Moodle's cache API, affectionately called MUC.
20
 * This file is part of Moodle's cache API, affectionately called MUC.
21
 * It contains the components that are requried in order to use caching.
21
 * It contains the components that are requried in order to use caching.
22
 *
22
 *
23
 * @package    core
23
 * @package    core_cache
24
 * @category   cache
24
 * @category   cache
25
 * @author     Peter Burnett <peterburnett@catalyst-au.net>
25
 * @author     Peter Burnett <peterburnett@catalyst-au.net>
26
 * @copyright  2020 Catalyst IT
26
 * @copyright  2020 Catalyst IT
27
 * @copyright  2012 Sam Hemelryk
27
 * @copyright  2012 Sam Hemelryk
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
29
 */
Línea 30... Línea 30...
30
 
30
 
Línea -... Línea 31...
-
 
31
namespace core_cache\local;
-
 
32
 
-
 
33
use core_cache\cache;
-
 
34
use core_cache\config;
-
 
35
use core_cache\config_writer;
-
 
36
use core_cache\configurable_cache_interface;
-
 
37
use core_cache\exception\cache_exception;
-
 
38
use core_cache\factory;
-
 
39
use core_cache\form\cache_lock_form;
31
namespace core_cache\local;
40
use core_cache\form\cache_mode_mappings_form;
-
 
41
use core_cache\form\cache_definition_sharing_form;
-
 
42
use core_cache\form\cache_definition_mappings_form;
-
 
43
use core_cache\form\cachestore_addinstance_form;
-
 
44
use core_cache\helper as cache_helper;
-
 
45
use core_cache\lockable_cache_interface;
-
 
46
use core_cache\store;
-
 
47
use core_component;
-
 
48
use core\context;
-
 
49
use core\context\system as context_system;
32
 
50
use core\exception\coding_exception;
-
 
51
use core\exception\moodle_exception;
-
 
52
use core\output\notification;
-
 
53
use core\output\single_button;
-
 
54
use core\url;
Línea 33... Línea 55...
33
use cache_store, cache_factory, cache_config_writer, cache_helper;
55
use html_writer;
34
use core\output\notification;
56
use stdClass;
35
 
57
 
36
/**
58
/**
37
 * A cache helper for administration tasks
59
 * A cache helper for administration tasks
38
 *
60
 *
39
 * @package    core
61
 * @package    core
40
 * @category   cache
62
 * @category   cache
41
 * @copyright  2020 Peter Burnett <peterburnett@catalyst-au.net>
63
 * @copyright  2020 Peter Burnett <peterburnett@catalyst-au.net>
42
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
43
 */
64
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
class administration_display_helper extends \core_cache\administration_helper {
65
 */
45
 
66
class administration_display_helper extends \core_cache\administration_helper {
46
    /**
67
    /**
47
     * Please do not call constructor directly. Use cache_factory::get_administration_display_helper() instead.
68
     * Please do not call constructor directly. Use factory::get_administration_display_helper() instead.
48
     */
69
     */
Línea 57... Línea 78...
57
     * @param array $definitionsummary information about this cache, from the array returned by
78
     * @param array $definitionsummary information about this cache, from the array returned by
58
     *      core_cache\administration_helper::get_definition_summaries(). Currently only 'sharingoptions'
79
     *      core_cache\administration_helper::get_definition_summaries(). Currently only 'sharingoptions'
59
     *      element is used.
80
     *      element is used.
60
     * @return array of actions. Each action is an action_url.
81
     * @return array of actions. Each action is an action_url.
61
     */
82
     */
62
    public function get_definition_actions(\context $context, array $definitionsummary): array {
83
    public function get_definition_actions(context $context, array $definitionsummary): array {
63
        global $OUTPUT;
84
        global $OUTPUT;
64
        if (has_capability('moodle/site:config', $context)) {
85
        if (has_capability('moodle/site:config', $context)) {
65
            $actions = array();
86
            $actions = [];
66
            // Edit mappings.
87
            // Edit mappings.
67
            $actions[] = $OUTPUT->action_link(
88
            $actions[] = $OUTPUT->action_link(
68
                new \moodle_url('/cache/admin.php', array('action' => 'editdefinitionmapping',
89
                new url('/cache/admin.php', ['action' => 'editdefinitionmapping',
69
                    'definition' => $definitionsummary['id'])),
90
                    'definition' => $definitionsummary['id'], ]),
70
                get_string('editmappings', 'cache')
91
                get_string('editmappings', 'cache')
71
            );
92
            );
72
            // Edit sharing.
93
            // Edit sharing.
73
            if (count($definitionsummary['sharingoptions']) > 1) {
94
            if (count($definitionsummary['sharingoptions']) > 1) {
74
                $actions[] = $OUTPUT->action_link(
95
                $actions[] = $OUTPUT->action_link(
75
                    new \moodle_url('/cache/admin.php', array('action' => 'editdefinitionsharing',
96
                    new url('/cache/admin.php', ['action' => 'editdefinitionsharing',
76
                        'definition' => $definitionsummary['id'])),
97
                        'definition' => $definitionsummary['id'], ]),
77
                    get_string('editsharing', 'cache')
98
                    get_string('editsharing', 'cache')
78
                );
99
                );
79
            }
100
            }
80
            // Purge.
101
            // Purge.
81
            $actions[] = $OUTPUT->action_link(
102
            $actions[] = $OUTPUT->action_link(
82
                new \moodle_url('/cache/admin.php', array('action' => 'purgedefinition',
103
                new url('/cache/admin.php', ['action' => 'purgedefinition',
83
                    'definition' => $definitionsummary['id'], 'sesskey' => sesskey())),
104
                    'definition' => $definitionsummary['id'], 'sesskey' => sesskey(), ]),
84
                get_string('purge', 'cache')
105
                get_string('purge', 'cache')
85
            );
106
            );
86
            return $actions;
107
            return $actions;
87
        }
108
        }
88
        return array();
109
        return [];
89
    }
110
    }
Línea 90... Línea 111...
90
 
111
 
91
    /**
112
    /**
92
     * Returns all of the actions that can be performed on a store.
113
     * Returns all of the actions that can be performed on a store.
Línea 96... Línea 117...
96
     *      core_cache\administration_helper::get_store_instance_summaries().
117
     *      core_cache\administration_helper::get_store_instance_summaries().
97
     * @return array of actions. Each action is an action_url.
118
     * @return array of actions. Each action is an action_url.
98
     */
119
     */
99
    public function get_store_instance_actions(string $name, array $storedetails): array {
120
    public function get_store_instance_actions(string $name, array $storedetails): array {
100
        global $OUTPUT;
121
        global $OUTPUT;
101
        $actions = array();
122
        $actions = [];
102
        if (has_capability('moodle/site:config', \context_system::instance())) {
123
        if (has_capability('moodle/site:config', context_system::instance())) {
103
            $baseurl = new \moodle_url('/cache/admin.php', array('store' => $name));
124
            $baseurl = new url('/cache/admin.php', ['store' => $name]);
104
            if (empty($storedetails['default'])) {
125
            if (empty($storedetails['default'])) {
105
                // Edit store.
126
                // Edit store.
106
                $actions[] = $OUTPUT->action_link(
127
                $actions[] = $OUTPUT->action_link(
107
                    new \moodle_url($baseurl, array('action' => 'editstore', 'plugin' => $storedetails['plugin'])),
128
                    new url($baseurl, ['action' => 'editstore', 'plugin' => $storedetails['plugin']]),
108
                    get_string('editstore', 'cache')
129
                    get_string('editstore', 'cache')
109
                );
130
                );
110
                // Delete store.
131
                // Delete store.
111
                $actions[] = $OUTPUT->action_link(
132
                $actions[] = $OUTPUT->action_link(
112
                    new \moodle_url($baseurl, array('action' => 'deletestore')),
133
                    new url($baseurl, ['action' => 'deletestore']),
113
                    get_string('deletestore', 'cache')
134
                    get_string('deletestore', 'cache')
114
                );
135
                );
115
            }
136
            }
116
            // Purge store.
137
            // Purge store.
117
            $actions[] = $OUTPUT->action_link(
138
            $actions[] = $OUTPUT->action_link(
118
                new \moodle_url($baseurl, array('action' => 'purgestore', 'sesskey' => sesskey())),
139
                new url($baseurl, ['action' => 'purgestore', 'sesskey' => sesskey()]),
119
                get_string('purge', 'cache')
140
                get_string('purge', 'cache')
120
            );
141
            );
121
        }
142
        }
122
        return $actions;
143
        return $actions;
123
    }
144
    }
Línea 130... Línea 151...
130
     *      core_cache\administration_helper::get_store_plugin_summaries().
151
     *      core_cache\administration_helper::get_store_plugin_summaries().
131
     * @return array of actions. Each action is an action_url.
152
     * @return array of actions. Each action is an action_url.
132
     */
153
     */
133
    public function get_store_plugin_actions(string $name, array $plugindetails): array {
154
    public function get_store_plugin_actions(string $name, array $plugindetails): array {
134
        global $OUTPUT;
155
        global $OUTPUT;
135
        $actions = array();
156
        $actions = [];
136
        if (has_capability('moodle/site:config', \context_system::instance())) {
157
        if (has_capability('moodle/site:config', context_system::instance())) {
137
            if (!empty($plugindetails['canaddinstance'])) {
158
            if (!empty($plugindetails['canaddinstance'])) {
-
 
159
                $url = new url(
138
                $url = new \moodle_url('/cache/admin.php',
160
                    '/cache/admin.php',
139
                    array('action' => 'addstore', 'plugin' => $name));
161
                    ['action' => 'addstore', 'plugin' => $name]
-
 
162
                );
140
                $actions[] = $OUTPUT->action_link(
163
                $actions[] = $OUTPUT->action_link(
141
                    $url,
164
                    $url,
142
                    get_string('addinstance', 'cache')
165
                    get_string('addinstance', 'cache')
143
                );
166
                );
144
            }
167
            }
Línea 151... Línea 174...
151
     *
174
     *
152
     * @param string $plugin The plugin to add an instance of
175
     * @param string $plugin The plugin to add an instance of
153
     * @return cachestore_addinstance_form
176
     * @return cachestore_addinstance_form
154
     * @throws coding_exception
177
     * @throws coding_exception
155
     */
178
     */
156
    public function get_add_store_form(string $plugin): \cachestore_addinstance_form {
179
    public function get_add_store_form(string $plugin): cachestore_addinstance_form {
157
        global $CFG; // Needed for includes.
180
        global $CFG; // Needed for includes.
158
        $plugins = \core_component::get_plugin_list('cachestore');
181
        $plugins = core_component::get_plugin_list('cachestore');
159
        if (!array_key_exists($plugin, $plugins)) {
182
        if (!array_key_exists($plugin, $plugins)) {
160
            throw new \coding_exception('Invalid cache plugin used when trying to create an edit form.');
183
            throw new coding_exception('Invalid cache plugin used when trying to create an edit form.');
161
        }
184
        }
162
        $plugindir = $plugins[$plugin];
185
        $plugindir = $plugins[$plugin];
163
        $class = 'cachestore_addinstance_form';
186
        $class = 'cachestore_addinstance_form';
164
        if (file_exists($plugindir.'/addinstanceform.php')) {
187
        if (file_exists($plugindir . '/addinstanceform.php')) {
165
            require_once($plugindir.'/addinstanceform.php');
188
            require_once($plugindir . '/addinstanceform.php');
166
            if (class_exists('cachestore_'.$plugin.'_addinstance_form')) {
189
            if (class_exists('cachestore_' . $plugin . '_addinstance_form')) {
167
                $class = 'cachestore_'.$plugin.'_addinstance_form';
190
                $class = 'cachestore_' . $plugin . '_addinstance_form';
168
                if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) {
191
                if (!array_key_exists(cachestore_addinstance_form::class, class_parents($class))) {
169
                    throw new \coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form');
192
                    throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form');
170
                }
193
                }
171
            }
194
            }
172
        }
195
        }
Línea 173... Línea 196...
173
 
196
 
Línea 174... Línea 197...
174
        $locks = $this->get_possible_locks_for_stores($plugindir, $plugin);
197
        $locks = $this->get_possible_locks_for_stores($plugindir, $plugin);
175
 
198
 
176
        $url = new \moodle_url('/cache/admin.php', array('action' => 'addstore'));
199
        $url = new url('/cache/admin.php', ['action' => 'addstore']);
Línea 177... Línea 200...
177
        return new $class($url, array('plugin' => $plugin, 'store' => null, 'locks' => $locks));
200
        return new $class($url, ['plugin' => $plugin, 'store' => null, 'locks' => $locks]);
178
    }
201
    }
179
 
202
 
180
    /**
203
    /**
181
     * Returns a form that can be used to edit a store instance.
204
     * Returns a form that can be used to edit a store instance.
182
     *
205
     *
183
     * @param string $plugin
206
     * @param string $plugin
184
     * @param string $store
207
     * @param string $store
185
     * @return cachestore_addinstance_form
208
     * @return cachestore_addinstance_form
186
     * @throws coding_exception
209
     * @throws coding_exception
187
     */
210
     */
188
    public function get_edit_store_form(string $plugin, string $store): \cachestore_addinstance_form {
211
    public function get_edit_store_form(string $plugin, string $store): cachestore_addinstance_form {
189
        global $CFG; // Needed for includes.
212
        global $CFG; // Needed for includes.
190
        $plugins = \core_component::get_plugin_list('cachestore');
213
        $plugins = core_component::get_plugin_list('cachestore');
191
        if (!array_key_exists($plugin, $plugins)) {
214
        if (!array_key_exists($plugin, $plugins)) {
192
            throw new \coding_exception('Invalid cache plugin used when trying to create an edit form.');
215
            throw new coding_exception('Invalid cache plugin used when trying to create an edit form.');
193
        }
216
        }
194
        $factory = \cache_factory::instance();
217
        $factory = factory::instance();
195
        $config = $factory->create_config_instance();
218
        $config = $factory->create_config_instance();
196
        $stores = $config->get_all_stores();
219
        $stores = $config->get_all_stores();
197
        if (!array_key_exists($store, $stores)) {
220
        if (!array_key_exists($store, $stores)) {
198
            throw new \coding_exception('Invalid store name given when trying to create an edit form.');
221
            throw new coding_exception('Invalid store name given when trying to create an edit form.');
199
        }
222
        }
200
        $plugindir = $plugins[$plugin];
223
        $plugindir = $plugins[$plugin];
201
        $class = 'cachestore_addinstance_form';
224
        $class = 'cachestore_addinstance_form';
202
        if (file_exists($plugindir.'/addinstanceform.php')) {
225
        if (file_exists($plugindir . '/addinstanceform.php')) {
203
            require_once($plugindir.'/addinstanceform.php');
226
            require_once($plugindir . '/addinstanceform.php');
204
            if (class_exists('cachestore_'.$plugin.'_addinstance_form')) {
227
            if (class_exists('cachestore_' . $plugin . '_addinstance_form')) {
205
                $class = 'cachestore_'.$plugin.'_addinstance_form';
228
                $class = 'cachestore_' . $plugin . '_addinstance_form';
206
                if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) {
229
                if (!array_key_exists(cachestore_addinstance_form::class, class_parents($class))) {
207
                    throw new \coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form');
230
                    throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form');
Línea 208... Línea 231...
208
                }
231
                }
Línea 209... Línea 232...
209
            }
232
            }
210
        }
233
        }
211
 
234
 
212
        $locks = $this->get_possible_locks_for_stores($plugindir, $plugin);
235
        $locks = $this->get_possible_locks_for_stores($plugindir, $plugin);
213
 
236
 
214
        $url = new \moodle_url('/cache/admin.php', array('action' => 'editstore', 'plugin' => $plugin, 'store' => $store));
237
        $url = new url('/cache/admin.php', ['action' => 'editstore', 'plugin' => $plugin, 'store' => $store]);
215
        $editform = new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks));
238
        $editform = new $class($url, ['plugin' => $plugin, 'store' => $store, 'locks' => $locks]);
216
        if (isset($stores[$store]['lock'])) {
239
        if (isset($stores[$store]['lock'])) {
217
            $editform->set_data(array('lock' => $stores[$store]['lock']));
240
            $editform->set_data(['lock' => $stores[$store]['lock']]);
-
 
241
        }
218
        }
242
        // See if the cachestore is going to want to load data for the form.
219
        // See if the cachestore is going to want to load data for the form.
243
        // If it has a customised add instance form then it is going to want to.
-
 
244
        $storeclass = 'cachestore_' . $plugin;
220
        // If it has a customised add instance form then it is going to want to.
245
        $storedata = $stores[$store];
221
        $storeclass = 'cachestore_'.$plugin;
246
        if (
222
        $storedata = $stores[$store];
247
            array_key_exists('configuration', $storedata) &&
223
        if (array_key_exists('configuration', $storedata) &&
248
            array_key_exists(configurable_cache_interface::class, class_implements($storeclass))
Línea 235... Línea 260...
235
     * @return array|false
260
     * @return array|false
236
     */
261
     */
237
    protected function get_possible_locks_for_stores(string $plugindir, string $plugin) {
262
    protected function get_possible_locks_for_stores(string $plugindir, string $plugin) {
238
        global $CFG; // Needed for includes.
263
        global $CFG; // Needed for includes.
239
        $supportsnativelocking = false;
264
        $supportsnativelocking = false;
240
        if (file_exists($plugindir.'/lib.php')) {
265
        if (file_exists($plugindir . '/lib.php')) {
241
            require_once($plugindir.'/lib.php');
266
            require_once($plugindir . '/lib.php');
242
            $pluginclass = 'cachestore_'.$plugin;
267
            $pluginclass = 'cachestore_' . $plugin;
243
            if (class_exists($pluginclass)) {
268
            if (class_exists($pluginclass)) {
244
                $supportsnativelocking = array_key_exists('cache_is_lockable', class_implements($pluginclass));
269
                $supportsnativelocking = array_key_exists(lockable_cache_interface::class, class_implements($pluginclass));
245
            }
270
            }
246
        }
271
        }
Línea 247... Línea 272...
247
 
272
 
248
        if (!$supportsnativelocking) {
273
        if (!$supportsnativelocking) {
249
            $config = \cache_config::instance();
274
            $config = config::instance();
250
            $locks = array();
275
            $locks = [];
251
            foreach ($config->get_locks() as $lock => $conf) {
276
            foreach ($config->get_locks() as $lock => $conf) {
252
                if (!empty($conf['default'])) {
277
                if (!empty($conf['default'])) {
253
                    $name = get_string($lock, 'cache');
278
                    $name = get_string($lock, 'cache');
254
                } else {
279
                } else {
Línea 269... Línea 294...
269
     *
294
     *
270
     * @param stdClass $data The mform data.
295
     * @param stdClass $data The mform data.
271
     * @return array
296
     * @return array
272
     * @throws coding_exception
297
     * @throws coding_exception
273
     */
298
     */
274
    public function get_store_configuration_from_data(\stdClass $data): array {
299
    public function get_store_configuration_from_data(stdClass $data): array {
275
        global $CFG;
300
        global $CFG;
276
        $file = $CFG->dirroot.'/cache/stores/'.$data->plugin.'/lib.php';
301
        $file = $CFG->dirroot . '/cache/stores/' . $data->plugin . '/lib.php';
277
        if (!file_exists($file)) {
302
        if (!file_exists($file)) {
278
            throw new \coding_exception('Invalid cache plugin provided. '.$file);
303
            throw new coding_exception('Invalid cache plugin provided. ' . $file);
279
        }
304
        }
280
        require_once($file);
305
        require_once($file);
281
        $class = 'cachestore_'.$data->plugin;
306
        $class = 'cachestore_' . $data->plugin;
282
        if (!class_exists($class)) {
307
        if (!class_exists($class)) {
283
            throw new \coding_exception('Invalid cache plugin provided.');
308
            throw new coding_exception('Invalid cache plugin provided.');
284
        }
309
        }
285
        if (array_key_exists('cache_is_configurable', class_implements($class))) {
310
        if (array_key_exists(configurable_cache_interface::class, class_implements($class))) {
286
            return $class::config_get_configuration_array($data);
311
            return $class::config_get_configuration_array($data);
287
        }
312
        }
288
        return array();
313
        return [];
289
    }
314
    }
Línea 290... Línea 315...
290
 
315
 
291
    /**
316
    /**
292
     * Returns an array of lock plugins for which we can add an instance.
317
     * Returns an array of lock plugins for which we can add an instance.
293
     *
318
     *
294
     * Suitable for use within an mform select element.
319
     * Suitable for use within an mform select element.
295
     *
320
     *
296
     * @return array
321
     * @return array
297
     */
322
     */
298
    public function get_addable_lock_options(): array {
323
    public function get_addable_lock_options(): array {
299
        $plugins = \core_component::get_plugin_list_with_class('cachelock', '', 'lib.php');
324
        $plugins = core_component::get_plugin_list_with_class('cachelock', '', 'lib.php');
300
        $options = array();
325
        $options = [];
301
        $len = strlen('cachelock_');
326
        $len = strlen('cachelock_');
302
        foreach ($plugins as $plugin => $class) {
327
        foreach ($plugins as $plugin => $class) {
303
            $method = "$class::can_add_instance";
328
            $method = "$class::can_add_instance";
304
            if (is_callable($method) && !call_user_func($method)) {
329
            if (is_callable($method) && !call_user_func($method)) {
Línea 312... Línea 337...
312
 
337
 
313
    /**
338
    /**
314
     * Gets the form to use when adding a lock instance.
339
     * Gets the form to use when adding a lock instance.
315
     *
340
     *
316
     * @param string $plugin
341
     * @param string $plugin
317
     * @param array $lockplugin
342
     * @param array|null $lockplugin
318
     * @return cache_lock_form
343
     * @return cache_lock_form
319
     * @throws coding_exception
344
     * @throws coding_exception
320
     */
345
     */
321
    public function get_add_lock_form(string $plugin, array $lockplugin = null): \cache_lock_form {
346
    public function get_add_lock_form(string $plugin, ?array $lockplugin = null): cache_lock_form {
322
        global $CFG; // Needed for includes.
347
        global $CFG; // Needed for includes.
323
        $plugins = \core_component::get_plugin_list('cachelock');
348
        $plugins = core_component::get_plugin_list('cachelock');
324
        if (!array_key_exists($plugin, $plugins)) {
349
        if (!array_key_exists($plugin, $plugins)) {
325
            throw new \coding_exception('Invalid cache lock plugin requested when trying to create a form.');
350
            throw new coding_exception('Invalid cache lock plugin requested when trying to create a form.');
326
        }
351
        }
327
        $plugindir = $plugins[$plugin];
352
        $plugindir = $plugins[$plugin];
-
 
353
        $class = cache_lock_form::class;
328
        $class = 'cache_lock_form';
354
        $hasaddinstanceform = file_exists($plugindir . '/addinstanceform.php');
-
 
355
        $hasaddinstanceform = $hasaddinstanceform && in_array(configurable_cache_interface::class, class_implements($class));
329
        if (file_exists($plugindir.'/addinstanceform.php') && in_array('cache_is_configurable', class_implements($class))) {
356
        if ($hasaddinstanceform) {
330
            require_once($plugindir.'/addinstanceform.php');
357
            require_once($plugindir . '/addinstanceform.php');
331
            if (class_exists('cachelock_'.$plugin.'_addinstance_form')) {
358
            if (class_exists('cachelock_' . $plugin . '_addinstance_form')) {
332
                $class = 'cachelock_'.$plugin.'_addinstance_form';
359
                $class = 'cachelock_' . $plugin . '_addinstance_form';
333
                if (!array_key_exists('cache_lock_form', class_parents($class))) {
360
                if (!is_a($class, cache_lock_form::class, true)) {
334
                    throw new \coding_exception('Cache lock plugin add instance forms must extend cache_lock_form');
361
                    throw new coding_exception('Cache lock plugin add instance forms must extend cache_lock_form');
335
                }
362
                }
336
            }
363
            }
337
        }
364
        }
338
        return new $class(null, array('lock' => $plugin));
365
        return new $class(null, ['lock' => $plugin]);
Línea 339... Línea 366...
339
    }
366
    }
340
 
367
 
341
    /**
368
    /**
342
     * Gets configuration data from a new lock instance form.
369
     * Gets configuration data from a new lock instance form.
343
     *
370
     *
344
     * @param string $plugin
371
     * @param string $plugin
345
     * @param stdClass $data
372
     * @param stdClass $data
346
     * @return array
373
     * @return array
347
     * @throws coding_exception
374
     * @throws coding_exception
348
     */
375
     */
349
    public function get_lock_configuration_from_data(string $plugin, \stdClass $data): array {
376
    public function get_lock_configuration_from_data(string $plugin, stdClass $data): array {
350
        global $CFG;
377
        global $CFG;
351
        $file = $CFG->dirroot.'/cache/locks/'.$plugin.'/lib.php';
378
        $file = $CFG->dirroot . '/cache/locks/' . $plugin . '/lib.php';
352
        if (!file_exists($file)) {
379
        if (!file_exists($file)) {
353
            throw new \coding_exception('Invalid cache plugin provided. '.$file);
380
            throw new coding_exception('Invalid cache plugin provided. ' . $file);
354
        }
381
        }
355
        require_once($file);
382
        require_once($file);
356
        $class = 'cachelock_'.$plugin;
383
        $class = 'cachelock_' . $plugin;
357
        if (!class_exists($class)) {
384
        if (!class_exists($class)) {
358
            throw new \coding_exception('Invalid cache plugin provided.');
385
            throw new coding_exception('Invalid cache plugin provided.');
359
        }
386
        }
360
        if (array_key_exists('cache_is_configurable', class_implements($class))) {
387
        if (array_key_exists(configurable_cache_interface::class, class_implements($class))) {
361
            return $class::config_get_configuration_array($data);
388
            return $class::config_get_configuration_array($data);
362
        }
389
        }
Línea 363... Línea 390...
363
        return array();
390
        return [];
364
    }
391
    }
365
 
392
 
Línea 370... Línea 397...
370
     * @param array $forminfo an empty array to be overridden and set.
397
     * @param array $forminfo an empty array to be overridden and set.
371
     * @return array the empty or overridden forminfo array.
398
     * @return array the empty or overridden forminfo array.
372
     */
399
     */
373
    public function perform_cache_actions(string $action, array $forminfo): array {
400
    public function perform_cache_actions(string $action, array $forminfo): array {
374
        switch ($action) {
401
        switch ($action) {
375
            case 'rescandefinitions' : // Rescan definitions.
402
            case 'rescandefinitions': // Rescan definitions.
376
                $this->action_rescan_definition();
403
                $this->action_rescan_definition();
377
                break;
404
                break;
Línea 378... Línea 405...
378
 
405
 
379
            case 'addstore' : // Add the requested store.
406
            case 'addstore': // Add the requested store.
380
                $forminfo = $this->action_addstore();
407
                $forminfo = $this->action_addstore();
Línea 381... Línea 408...
381
                break;
408
                break;
382
 
409
 
383
            case 'editstore' : // Edit the requested store.
410
            case 'editstore': // Edit the requested store.
Línea 384... Línea 411...
384
                $forminfo = $this->action_editstore();
411
                $forminfo = $this->action_editstore();
385
                break;
412
                break;
386
 
413
 
Línea 387... Línea 414...
387
            case 'deletestore' : // Delete a given store.
414
            case 'deletestore': // Delete a given store.
388
                $this->action_deletestore($action);
415
                $this->action_deletestore($action);
389
                break;
416
                break;
Línea 390... Línea 417...
390
 
417
 
391
            case 'editdefinitionmapping' : // Edit definition mappings.
418
            case 'editdefinitionmapping': // Edit definition mappings.
392
                $forminfo = $this->action_editdefinitionmapping();
419
                $forminfo = $this->action_editdefinitionmapping();
Línea 393... Línea 420...
393
                break;
420
                break;
394
 
421
 
Línea 429... Línea 456...
429
     */
456
     */
430
    public function action_rescan_definition() {
457
    public function action_rescan_definition() {
431
        global $PAGE;
458
        global $PAGE;
Línea 432... Línea 459...
432
 
459
 
433
        require_sesskey();
460
        require_sesskey();
434
        \cache_config_writer::update_definitions();
461
        config_writer::update_definitions();
435
        redirect($PAGE->url);
462
        redirect($PAGE->url);
Línea 436... Línea 463...
436
    }
463
    }
437
 
464
 
Línea 444... Línea 471...
444
        global $PAGE;
471
        global $PAGE;
445
        $storepluginsummaries = $this->get_store_plugin_summaries();
472
        $storepluginsummaries = $this->get_store_plugin_summaries();
Línea 446... Línea 473...
446
 
473
 
447
        $plugin = required_param('plugin', PARAM_PLUGIN);
474
        $plugin = required_param('plugin', PARAM_PLUGIN);
448
        if (!$storepluginsummaries[$plugin]['canaddinstance']) {
475
        if (!$storepluginsummaries[$plugin]['canaddinstance']) {
449
            throw new \moodle_exception('ex_unmetstorerequirements', 'cache');
476
            throw new moodle_exception('ex_unmetstorerequirements', 'cache');
450
        }
477
        }
451
        $mform = $this->get_add_store_form($plugin);
478
        $mform = $this->get_add_store_form($plugin);
452
        $title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
479
        $title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
453
        if ($mform->is_cancelled()) {
480
        if ($mform->is_cancelled()) {
454
            redirect($PAGE->url);
481
            redirect($PAGE->url);
455
        } else if ($data = $mform->get_data()) {
482
        } else if ($data = $mform->get_data()) {
456
            $config = $this->get_store_configuration_from_data($data);
483
            $config = $this->get_store_configuration_from_data($data);
457
            $writer = \cache_config_writer::instance();
484
            $writer = config_writer::instance();
458
            unset($config['lock']);
485
            unset($config['lock']);
459
            foreach ($writer->get_locks() as $lock => $lockconfig) {
486
            foreach ($writer->get_locks() as $lock => $lockconfig) {
460
                if ($lock == $data->lock) {
487
                if ($lock == $data->lock) {
461
                    $config['lock'] = $data->lock;
488
                    $config['lock'] = $data->lock;
Línea 464... Línea 491...
464
            $writer->add_store_instance($data->name, $data->plugin, $config);
491
            $writer->add_store_instance($data->name, $data->plugin, $config);
465
            redirect($PAGE->url, get_string('addstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
492
            redirect($PAGE->url, get_string('addstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
466
        }
493
        }
Línea 467... Línea 494...
467
 
494
 
468
        $PAGE->navbar->add(get_string('addstore', 'cache', 'cache'), $PAGE->url);
495
        $PAGE->navbar->add(get_string('addstore', 'cache', 'cache'), $PAGE->url);
469
        return array('form' => $mform, 'title' => $title);
496
        return ['form' => $mform, 'title' => $title];
Línea 470... Línea 497...
470
    }
497
    }
471
 
498
 
472
    /**
499
    /**
Línea 484... Línea 511...
484
        $title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
511
        $title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
485
        if ($mform->is_cancelled()) {
512
        if ($mform->is_cancelled()) {
486
            redirect($PAGE->url);
513
            redirect($PAGE->url);
487
        } else if ($data = $mform->get_data()) {
514
        } else if ($data = $mform->get_data()) {
488
            $config = $this->get_store_configuration_from_data($data);
515
            $config = $this->get_store_configuration_from_data($data);
489
            $writer = \cache_config_writer::instance();
516
            $writer = config_writer::instance();
Línea 490... Línea 517...
490
 
517
 
491
            unset($config['lock']);
518
            unset($config['lock']);
492
            foreach ($writer->get_locks() as $lock => $lockconfig) {
519
            foreach ($writer->get_locks() as $lock => $lockconfig) {
493
                if ($lock == $data->lock) {
520
                if ($lock == $data->lock) {
Línea 496... Línea 523...
496
            }
523
            }
497
            $writer->edit_store_instance($data->name, $data->plugin, $config);
524
            $writer->edit_store_instance($data->name, $data->plugin, $config);
498
            redirect($PAGE->url, get_string('editstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
525
            redirect($PAGE->url, get_string('editstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
499
        }
526
        }
Línea 500... Línea 527...
500
 
527
 
501
        return array('form' => $mform, 'title' => $title);
528
        return ['form' => $mform, 'title' => $title];
Línea 502... Línea 529...
502
    }
529
    }
503
 
530
 
504
    /**
531
    /**
Línea 523... Línea 550...
523
        }
550
        }
Línea 524... Línea 551...
524
 
551
 
525
        if ($notifysuccess) {
552
        if ($notifysuccess) {
526
            if (!$confirm) {
553
            if (!$confirm) {
527
                $title = get_string('confirmstoredeletion', 'cache');
554
                $title = get_string('confirmstoredeletion', 'cache');
528
                $params = array('store' => $store, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey());
555
                $params = ['store' => $store, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey()];
529
                $url = new \moodle_url($PAGE->url, $params);
556
                $url = new url($PAGE->url, $params);
Línea 530... Línea 557...
530
                $button = new \single_button($url, get_string('deletestore', 'cache'));
557
                $button = new single_button($url, get_string('deletestore', 'cache'));
531
 
558
 
532
                $PAGE->set_title($title);
559
                $PAGE->set_title($title);
533
                $PAGE->set_heading($SITE->fullname);
560
                $PAGE->set_heading($SITE->fullname);
Línea 537... Línea 564...
537
                echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
564
                echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
538
                echo $OUTPUT->footer();
565
                echo $OUTPUT->footer();
539
                exit;
566
                exit;
540
            } else {
567
            } else {
541
                require_sesskey();
568
                require_sesskey();
542
                $writer = \cache_config_writer::instance();
569
                $writer = config_writer::instance();
543
                $writer->delete_store_instance($store);
570
                $writer->delete_store_instance($store);
544
                redirect($PAGE->url, get_string('deletestoresuccess', 'cache'), 5);
571
                redirect($PAGE->url, get_string('deletestoresuccess', 'cache'), 5);
545
            }
572
            }
546
        } else {
573
        } else {
547
            redirect($PAGE->url, $notification, null, notification::NOTIFY_ERROR);
574
            redirect($PAGE->url, $notification, null, notification::NOTIFY_ERROR);
Línea 558... Línea 585...
558
        global $PAGE;
585
        global $PAGE;
559
        $definitionsummaries = $this->get_definition_summaries();
586
        $definitionsummaries = $this->get_definition_summaries();
Línea 560... Línea 587...
560
 
587
 
561
        $definition = required_param('definition', PARAM_SAFEPATH);
588
        $definition = required_param('definition', PARAM_SAFEPATH);
562
        if (!array_key_exists($definition, $definitionsummaries)) {
589
        if (!array_key_exists($definition, $definitionsummaries)) {
563
            throw new \cache_exception('Invalid cache definition requested');
590
            throw new cache_exception('Invalid cache definition requested');
564
        }
591
        }
565
        $title = get_string('editdefinitionmappings', 'cache', $definition);
592
        $title = get_string('editdefinitionmappings', 'cache', $definition);
566
        $mform = new \cache_definition_mappings_form($PAGE->url, array('definition' => $definition));
593
        $mform = new cache_definition_mappings_form($PAGE->url, ['definition' => $definition]);
567
        if ($mform->is_cancelled()) {
594
        if ($mform->is_cancelled()) {
568
            redirect($PAGE->url);
595
            redirect($PAGE->url);
569
        } else if ($data = $mform->get_data()) {
596
        } else if ($data = $mform->get_data()) {
570
            $writer = \cache_config_writer::instance();
597
            $writer = config_writer::instance();
571
            $mappings = array();
598
            $mappings = [];
572
            foreach ($data->mappings as $mapping) {
599
            foreach ($data->mappings as $mapping) {
573
                if (!empty($mapping)) {
600
                if (!empty($mapping)) {
574
                    $mappings[] = $mapping;
601
                    $mappings[] = $mapping;
575
                }
602
                }
576
            }
603
            }
577
            $writer->set_definition_mappings($definition, $mappings);
604
            $writer->set_definition_mappings($definition, $mappings);
578
            redirect($PAGE->url);
605
            redirect($PAGE->url);
Línea 579... Línea 606...
579
        }
606
        }
580
 
607
 
581
        $PAGE->navbar->add(get_string('updatedefinitionmapping', 'cache'), $PAGE->url);
608
        $PAGE->navbar->add(get_string('updatedefinitionmapping', 'cache'), $PAGE->url);
Línea 582... Línea 609...
582
        return array('form' => $mform, 'title' => $title);
609
        return ['form' => $mform, 'title' => $title];
583
    }
610
    }
584
 
611
 
Línea 591... Línea 618...
591
        global $PAGE;
618
        global $PAGE;
592
        $definitionsummaries = $this->get_definition_summaries();
619
        $definitionsummaries = $this->get_definition_summaries();
Línea 593... Línea 620...
593
 
620
 
594
        $definition = required_param('definition', PARAM_SAFEPATH);
621
        $definition = required_param('definition', PARAM_SAFEPATH);
595
        if (!array_key_exists($definition, $definitionsummaries)) {
622
        if (!array_key_exists($definition, $definitionsummaries)) {
596
            throw new \cache_exception('Invalid cache definition requested');
623
            throw new cache_exception('Invalid cache definition requested');
597
        }
624
        }
598
        $title = get_string('editdefinitionsharing', 'cache', $definition);
625
        $title = get_string('editdefinitionsharing', 'cache', $definition);
599
        $sharingoptions = $definitionsummaries[$definition]['sharingoptions'];
626
        $sharingoptions = $definitionsummaries[$definition]['sharingoptions'];
600
        $customdata = array('definition' => $definition, 'sharingoptions' => $sharingoptions);
627
        $customdata = ['definition' => $definition, 'sharingoptions' => $sharingoptions];
601
        $mform = new \cache_definition_sharing_form($PAGE->url, $customdata);
628
        $mform = new cache_definition_sharing_form($PAGE->url, $customdata);
602
        $mform->set_data(array(
629
        $mform->set_data([
603
            'sharing' => $definitionsummaries[$definition]['selectedsharingoption'],
630
            'sharing' => $definitionsummaries[$definition]['selectedsharingoption'],
604
            'userinputsharingkey' => $definitionsummaries[$definition]['userinputsharingkey']
631
            'userinputsharingkey' => $definitionsummaries[$definition]['userinputsharingkey'],
605
        ));
632
        ]);
606
        if ($mform->is_cancelled()) {
633
        if ($mform->is_cancelled()) {
607
            redirect($PAGE->url);
634
            redirect($PAGE->url);
608
        } else if ($data = $mform->get_data()) {
635
        } else if ($data = $mform->get_data()) {
609
            $component = $definitionsummaries[$definition]['component'];
636
            $component = $definitionsummaries[$definition]['component'];
610
            $area = $definitionsummaries[$definition]['area'];
637
            $area = $definitionsummaries[$definition]['area'];
611
            // Purge the stores removing stale data before we alter the sharing option.
638
            // Purge the stores removing stale data before we alter the sharing option.
612
            \cache_helper::purge_stores_used_by_definition($component, $area);
639
            cache_helper::purge_stores_used_by_definition($component, $area);
613
            $writer = \cache_config_writer::instance();
640
            $writer = config_writer::instance();
614
            $sharing = array_sum(array_keys($data->sharing));
641
            $sharing = array_sum(array_keys($data->sharing));
615
            $userinputsharingkey = $data->userinputsharingkey;
642
            $userinputsharingkey = $data->userinputsharingkey;
616
            $writer->set_definition_sharing($definition, $sharing, $userinputsharingkey);
643
            $writer->set_definition_sharing($definition, $sharing, $userinputsharingkey);
617
            redirect($PAGE->url);
644
            redirect($PAGE->url);
Línea 618... Línea 645...
618
        }
645
        }
619
 
646
 
620
        $PAGE->navbar->add(get_string('updatedefinitionsharing', 'cache'), $PAGE->url);
647
        $PAGE->navbar->add(get_string('updatedefinitionsharing', 'cache'), $PAGE->url);
Línea 621... Línea 648...
621
        return array('form' => $mform, 'title' => $title);
648
        return ['form' => $mform, 'title' => $title];
622
    }
649
    }
623
 
650
 
Línea 629... Línea 656...
629
    public function action_editmodemappings(): array {
656
    public function action_editmodemappings(): array {
630
        global $PAGE;
657
        global $PAGE;
631
        $storeinstancesummaries = $this->get_store_instance_summaries();
658
        $storeinstancesummaries = $this->get_store_instance_summaries();
632
        $defaultmodestores = $this->get_default_mode_stores();
659
        $defaultmodestores = $this->get_default_mode_stores();
Línea 633... Línea 660...
633
 
660
 
634
        $mform = new \cache_mode_mappings_form(null, $storeinstancesummaries);
661
        $mform = new cache_mode_mappings_form(null, $storeinstancesummaries);
635
        $mform->set_data(array(
662
        $mform->set_data([
636
            'mode_'.cache_store::MODE_APPLICATION => key($defaultmodestores[cache_store::MODE_APPLICATION]),
663
            'mode_' . store::MODE_APPLICATION => key($defaultmodestores[store::MODE_APPLICATION]),
637
            'mode_'.cache_store::MODE_SESSION => key($defaultmodestores[cache_store::MODE_SESSION]),
664
            'mode_' . store::MODE_SESSION => key($defaultmodestores[store::MODE_SESSION]),
638
            'mode_'.cache_store::MODE_REQUEST => key($defaultmodestores[cache_store::MODE_REQUEST]),
665
            'mode_' . store::MODE_REQUEST => key($defaultmodestores[store::MODE_REQUEST]),
639
        ));
666
        ]);
640
        if ($mform->is_cancelled()) {
667
        if ($mform->is_cancelled()) {
641
            redirect($PAGE->url);
668
            redirect($PAGE->url);
642
        } else if ($data = $mform->get_data()) {
669
        } else if ($data = $mform->get_data()) {
643
            $mappings = array(
670
            $mappings = [
644
                cache_store::MODE_APPLICATION => array($data->{'mode_'.cache_store::MODE_APPLICATION}),
671
                store::MODE_APPLICATION => [$data->{'mode_' . store::MODE_APPLICATION}],
645
                cache_store::MODE_SESSION => array($data->{'mode_'.cache_store::MODE_SESSION}),
672
                store::MODE_SESSION => [$data->{'mode_' . store::MODE_SESSION}],
646
                cache_store::MODE_REQUEST => array($data->{'mode_'.cache_store::MODE_REQUEST}),
673
                store::MODE_REQUEST => [$data->{'mode_' . store::MODE_REQUEST}],
647
            );
674
            ];
648
            $writer = cache_config_writer::instance();
675
            $writer = config_writer::instance();
649
            $writer->set_mode_mappings($mappings);
676
            $writer->set_mode_mappings($mappings);
650
            redirect($PAGE->url);
677
            redirect($PAGE->url);
Línea 651... Línea 678...
651
        }
678
        }
652
 
679
 
Línea 653... Línea 680...
653
        return array('form' => $mform);
680
        return ['form' => $mform];
654
    }
681
    }
655
 
682
 
Línea 661... Línea 688...
661
    public function action_purgedefinition() {
688
    public function action_purgedefinition() {
662
        global $PAGE;
689
        global $PAGE;
Línea 663... Línea 690...
663
 
690
 
664
        require_sesskey();
691
        require_sesskey();
665
        $id = required_param('definition', PARAM_SAFEPATH);
692
        $id = required_param('definition', PARAM_SAFEPATH);
666
        list($component, $area) = explode('/', $id, 2);
693
        [$component, $area] = explode('/', $id, 2);
667
        $factory = cache_factory::instance();
694
        $factory = factory::instance();
668
        $definition = $factory->create_definition($component, $area);
695
        $definition = $factory->create_definition($component, $area);
669
        if ($definition->has_required_identifiers()) {
696
        if ($definition->has_required_identifiers()) {
670
            // We will have to purge the stores used by this definition.
697
            // We will have to purge the stores used by this definition.
671
            cache_helper::purge_stores_used_by_definition($component, $area);
698
            cache_helper::purge_stores_used_by_definition($component, $area);
Línea 677... Línea 704...
677
        $message = get_string('purgexdefinitionsuccess', 'cache', [
704
        $message = get_string('purgexdefinitionsuccess', 'cache', [
678
                    'name' => $definition->get_name(),
705
                    'name' => $definition->get_name(),
679
                    'component' => $component,
706
                    'component' => $component,
680
                    'area' => $area,
707
                    'area' => $area,
681
                ]);
708
                ]);
682
        $purgeagainlink = \html_writer::link(new \moodle_url('/cache/admin.php', [
709
        $purgeagainlink = html_writer::link(
-
 
710
            new url('/cache/admin.php', [
683
                'action' => 'purgedefinition', 'sesskey' => sesskey(), 'definition' => $id]),
711
                'action' => 'purgedefinition', 'sesskey' => sesskey(), 'definition' => $id, ]),
684
                get_string('purgeagain', 'cache'));
712
            get_string('purgeagain', 'cache')
-
 
713
        );
685
        redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
714
        redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
686
    }
715
    }
Línea 687... Línea 716...
687
 
716
 
688
    /**
717
    /**
Línea 695... Línea 724...
695
 
724
 
696
        require_sesskey();
725
        require_sesskey();
697
        $store = required_param('store', PARAM_TEXT);
726
        $store = required_param('store', PARAM_TEXT);
698
        cache_helper::purge_store($store);
727
        cache_helper::purge_store($store);
699
        $message = get_string('purgexstoresuccess', 'cache', ['store' => $store]);
728
        $message = get_string('purgexstoresuccess', 'cache', ['store' => $store]);
-
 
729
        $purgeagainlink = html_writer::link(
700
        $purgeagainlink = \html_writer::link(new \moodle_url('/cache/admin.php', [
730
            new url('/cache/admin.php', [
701
                'action' => 'purgestore', 'sesskey' => sesskey(), 'store' => $store]),
731
                'action' => 'purgestore', 'sesskey' => sesskey(), 'store' => $store, ]),
-
 
732
            get_string('purgeagain', 'cache')
702
                get_string('purgeagain', 'cache'));
733
        );
703
        redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
734
        redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
Línea 704... Línea 735...
704
    }
735
    }
705
 
736
 
Línea 715... Línea 746...
715
        $lock = required_param('lock', PARAM_ALPHANUMEXT);
746
        $lock = required_param('lock', PARAM_ALPHANUMEXT);
716
        $mform = $this->get_add_lock_form($lock);
747
        $mform = $this->get_add_lock_form($lock);
717
        if ($mform->is_cancelled()) {
748
        if ($mform->is_cancelled()) {
718
            redirect($PAGE->url);
749
            redirect($PAGE->url);
719
        } else if ($data = $mform->get_data()) {
750
        } else if ($data = $mform->get_data()) {
720
            $factory = cache_factory::instance();
751
            $factory = factory::instance();
721
            $config = $factory->create_config_instance(true);
752
            $config = $factory->create_config_instance(true);
722
            $name = $data->name;
753
            $name = $data->name;
723
            $data = $this->get_lock_configuration_from_data($lock, $data);
754
            $data = $this->get_lock_configuration_from_data($lock, $data);
724
            $config->add_lock_instance($name, $lock, $data);
755
            $config->add_lock_instance($name, $lock, $data);
725
            redirect($PAGE->url, get_string('addlocksuccess', 'cache', $name), 5);
756
            redirect($PAGE->url, get_string('addlocksuccess', 'cache', $name), 5);
726
        }
757
        }
Línea 727... Línea 758...
727
 
758
 
728
        return array('form' => $mform);
759
        return ['form' => $mform];
Línea 729... Línea 760...
729
    }
760
    }
730
 
761
 
731
    /**
762
    /**
Línea 748... Línea 779...
748
            $notification = get_string('deletelockhasuses', 'cache');
779
            $notification = get_string('deletelockhasuses', 'cache');
749
        }
780
        }
750
        if ($notifysuccess) {
781
        if ($notifysuccess) {
751
            if (!$confirm) {
782
            if (!$confirm) {
752
                $title = get_string('confirmlockdeletion', 'cache');
783
                $title = get_string('confirmlockdeletion', 'cache');
753
                $params = array('lock' => $lock, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey());
784
                $params = ['lock' => $lock, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey()];
754
                $url = new \moodle_url($PAGE->url, $params);
785
                $url = new url($PAGE->url, $params);
755
                $button = new \single_button($url, get_string('deletelock', 'cache'));
786
                $button = new single_button($url, get_string('deletelock', 'cache'));
Línea 756... Línea 787...
756
 
787
 
757
                $PAGE->set_title($title);
788
                $PAGE->set_title($title);
758
                $PAGE->set_heading($SITE->fullname);
789
                $PAGE->set_heading($SITE->fullname);
759
                echo $OUTPUT->header();
790
                echo $OUTPUT->header();
Línea 762... Línea 793...
762
                echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
793
                echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
763
                echo $OUTPUT->footer();
794
                echo $OUTPUT->footer();
764
                exit;
795
                exit;
765
            } else {
796
            } else {
766
                require_sesskey();
797
                require_sesskey();
767
                $writer = cache_config_writer::instance();
798
                $writer = config_writer::instance();
768
                $writer->delete_lock_instance($lock);
799
                $writer->delete_lock_instance($lock);
769
                redirect($PAGE->url, get_string('deletelocksuccess', 'cache'), 5);
800
                redirect($PAGE->url, get_string('deletelocksuccess', 'cache'), 5);
770
            }
801
            }
771
        } else {
802
        } else {
772
            redirect($PAGE->url, $notification, null, notification::NOTIFY_ERROR);
803
            redirect($PAGE->url, $notification, null, notification::NOTIFY_ERROR);
Línea 778... Línea 809...
778
     *
809
     *
779
     * @param \core_cache\output\renderer $renderer the renderer to use to generate the page.
810
     * @param \core_cache\output\renderer $renderer the renderer to use to generate the page.
780
     * @return string the HTML for the admin page.
811
     * @return string the HTML for the admin page.
781
     */
812
     */
782
    public function generate_admin_page(\core_cache\output\renderer $renderer): string {
813
    public function generate_admin_page(\core_cache\output\renderer $renderer): string {
783
        $context = \context_system::instance();
814
        $context = context_system::instance();
784
        $html = '';
815
        $html = '';
Línea 785... Línea 816...
785
 
816
 
786
        $storepluginsummaries = $this->get_store_plugin_summaries();
817
        $storepluginsummaries = $this->get_store_plugin_summaries();
787
        $storeinstancesummaries = $this->get_store_instance_summaries();
818
        $storeinstancesummaries = $this->get_store_instance_summaries();
Línea 793... Línea 824...
793
        $html .= $renderer->store_instance_summariers($storeinstancesummaries, $storepluginsummaries);
824
        $html .= $renderer->store_instance_summariers($storeinstancesummaries, $storepluginsummaries);
794
        $html .= $renderer->definition_summaries($definitionsummaries, $context);
825
        $html .= $renderer->definition_summaries($definitionsummaries, $context);
795
        $html .= $renderer->lock_summaries($locks);
826
        $html .= $renderer->lock_summaries($locks);
796
        $html .= $renderer->additional_lock_actions();
827
        $html .= $renderer->additional_lock_actions();
Línea 797... Línea 828...
797
 
828
 
798
        $applicationstore = join(', ', $defaultmodestores[cache_store::MODE_APPLICATION]);
829
        $applicationstore = join(', ', $defaultmodestores[store::MODE_APPLICATION]);
799
        $sessionstore = join(', ', $defaultmodestores[cache_store::MODE_SESSION]);
830
        $sessionstore = join(', ', $defaultmodestores[store::MODE_SESSION]);
800
        $requeststore = join(', ', $defaultmodestores[cache_store::MODE_REQUEST]);
831
        $requeststore = join(', ', $defaultmodestores[store::MODE_REQUEST]);
801
        $editurl = new \moodle_url('/cache/admin.php', array('action' => 'editmodemappings'));
832
        $editurl = new url('/cache/admin.php', ['action' => 'editmodemappings']);
Línea 802... Línea 833...
802
        $html .= $renderer->mode_mappings($applicationstore, $sessionstore, $requeststore, $editurl);
833
        $html .= $renderer->mode_mappings($applicationstore, $sessionstore, $requeststore, $editurl);
803
 
834
 
Línea 827... Línea 858...
827
     * @return array Details of cache usage
858
     * @return array Details of cache usage
828
     */
859
     */
829
    public function get_usage(int $samplekeys): array {
860
    public function get_usage(int $samplekeys): array {
830
        $results = [];
861
        $results = [];
Línea 831... Línea 862...
831
 
862
 
Línea 832... Línea 863...
832
        $factory = cache_factory::instance();
863
        $factory = factory::instance();
833
 
864
 
834
        // Check the caches we already have an instance of, so we don't make another one...
865
        // Check the caches we already have an instance of, so we don't make another one...
835
        $got = $factory->get_caches_in_use();
866
        $got = $factory->get_caches_in_use();
Línea 847... Línea 878...
847
        foreach ($config->get_definitions() as $configdetails) {
878
        foreach ($config->get_definitions() as $configdetails) {
848
            if (!array_key_exists($configdetails['component'] . '/' .  $configdetails['area'], $gotid)) {
879
            if (!array_key_exists($configdetails['component'] . '/' .  $configdetails['area'], $gotid)) {
849
                // Where possible (if it doesn't need identifiers), make an instance of the cache, otherwise
880
                // Where possible (if it doesn't need identifiers), make an instance of the cache, otherwise
850
                // we can't get the store instances for it (and it won't show up in the list).
881
                // we can't get the store instances for it (and it won't show up in the list).
851
                if (empty($configdetails['requireidentifiers'])) {
882
                if (empty($configdetails['requireidentifiers'])) {
852
                    \cache::make($configdetails['component'], $configdetails['area']);
883
                    cache::make($configdetails['component'], $configdetails['area']);
853
                }
884
                }
854
            }
885
            }
855
            $definition = $factory->create_definition($configdetails['component'], $configdetails['area']);
886
            $definition = $factory->create_definition($configdetails['component'], $configdetails['area']);
856
            $stores = $factory->get_store_instances_in_use($definition);
887
            $stores = $factory->get_store_instances_in_use($definition);
Línea 857... Línea 888...
857
 
888
 
858
            // Create object for results about this cache definition.
889
            // Create object for results about this cache definition.
859
            $currentresult = (object)['cacheid' => $definition->get_id(), 'stores' => []];
890
            $currentresult = (object)['cacheid' => $definition->get_id(), 'stores' => []];
Línea 860... Línea 891...
860
            $results[$currentresult->cacheid] = $currentresult;
891
            $results[$currentresult->cacheid] = $currentresult;
861
 
892
 
862
            /** @var cache_store $store */
893
            /** @var store $store */
863
            foreach ($stores as $store) {
894
            foreach ($stores as $store) {
864
                // Skip static cache.
895
                // Skip static cache.
865
                if ($store instanceof \cachestore_static) {
896
                if ($store instanceof \cachestore_static) {