Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions classes/cache_administration_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_forcedcache_cache_administration_helper extends core_cache\administration_helper {

/**
* Empty constructor so cache_helper::__construct isn't called.
*/
Expand All @@ -40,11 +39,11 @@ public function __construct() {
*/
public function get_store_instance_actions(string $name, array $storedetails): array {
global $OUTPUT;
$actions = array();
$actions = [];
if (has_capability('moodle/site:config', context_system::instance())) {
$baseurl = new moodle_url('/cache/admin.php', array('store' => $name, 'sesskey' => sesskey()));
$baseurl = new moodle_url('/cache/admin.php', ['store' => $name, 'sesskey' => sesskey()]);
Comment thread
Peterburnett marked this conversation as resolved.
$actions[] = $OUTPUT->action_link(
new moodle_url($baseurl, array('action' => 'purgestore')),
new moodle_url($baseurl, ['action' => 'purgestore']),
get_string('purge', 'cache')
);
}
Expand All @@ -60,11 +59,11 @@ public function get_store_instance_actions(string $name, array $storedetails): a
*/
public function get_definition_actions(context $context, array $definitionsummary): array {
global $OUTPUT;
$actions = array();
$actions = [];
if (has_capability('moodle/site:config', $context)) {
$actions[] = $OUTPUT->action_link(
new moodle_url('/cache/admin.php', array('action' => 'purgedefinition',
'definition' => $definitionsummary['id'], 'sesskey' => sesskey())),
new moodle_url('/cache/admin.php', ['action' => 'purgedefinition',
'definition' => $definitionsummary['id'], 'sesskey' => sesskey()]),
get_string('purge', 'cache')
);
}
Expand Down Expand Up @@ -107,7 +106,7 @@ public function get_ruleset_output(): string {
if (!empty($CFG->tool_forcedcache_config_path)) {
$path = $CFG->tool_forcedcache_config_path;
} else {
$path = __DIR__.'/../config.json';
$path = __DIR__ . '/../config.json';
}
// We dont need safety here, if we reach this point,
// Its already been included and working.
Expand Down Expand Up @@ -143,10 +142,10 @@ private function generate_store_table(string $name, array $config): string {
$table = new html_table();
$table->id = $name . '_def_table';
$table->attributes['class'] = 'generaltable table table-bordered table-sm w-auto';
$table->head = array (
$table->head = [
get_string('store_config', 'tool_forcedcache'),
get_string('store_value', 'tool_forcedcache'),
);
];
$table->data = [];
foreach ($config['config'] as $key => $value) {
$table->data[] = [s($key), s($value)];
Expand Down Expand Up @@ -174,10 +173,10 @@ private function generate_override_table(array $overrides): string {
$table = new html_table();
$table->id = 'def_override_table';
$table->attributes['class'] = 'generaltable table table-bordered table-sm w-auto';
$table->head = array (
$table->head = [
get_string('definition_name', 'tool_forcedcache'),
get_string('definition_overrides', 'tool_forcedcache'),
);
];
$table->data = [];
foreach ($overrides as $definition => $items) {
$itemstring = '';
Expand Down Expand Up @@ -222,11 +221,11 @@ private function generate_mode_table(int $mode, array $config): string {
$table = new html_table();
$table->id = $mode . '_rule_table';
$table->attributes['class'] = 'generaltable table table-bordered table-sm w-auto';
$table->head = array (
$table->head = [
get_string('rule_priority', 'tool_forcedcache'),
get_string('rule_ruleset', 'tool_forcedcache'),
get_string('mappings', 'cache')
);
get_string('mappings', 'cache'),
];

$counter = 1;
$defaultrulestr = get_string('rule_default_rule', 'tool_forcedcache');
Expand All @@ -242,11 +241,11 @@ private function generate_mode_table(int $mode, array $config): string {
$conditions = $defaultrulestr;
}

$table->data[] = array(
$table->data[] = [
$counter,
$conditions,
s(implode(',', $ruleset['stores'])),
);
];
$counter++;
}

Expand All @@ -256,17 +255,17 @@ private function generate_mode_table(int $mode, array $config): string {
if (empty($table->data) || end($table->data)[1] !== $defaultrulestr) {
// Append a default entry to the table.
$defaultmodemappings = tool_forcedcache_cache_config::get_default_mode_mappings();
$defaultstoreformode = array_filter($defaultmodemappings, function($modemapping) use ($mode) {
$defaultstoreformode = array_filter($defaultmodemappings, function ($modemapping) use ($mode) {
return $modemapping['mode'] === $mode;
});
$defaultstore = reset($defaultstoreformode)['store'];
$conditions = $defaultrulestr;

$table->data[] = array(
$table->data[] = [
$counter,
$conditions,
implode(',', (array) $defaultstore),
);
];
}

// Now output a header and the table.
Expand All @@ -276,7 +275,8 @@ private function generate_mode_table(int $mode, array $config): string {
if (count($rules[$ruletype]) === 0) {
$html .= $OUTPUT->notification(
get_string('rule_no_rulesets', 'tool_forcedcache', $defaultstore),
\core\output\notification::NOTIFY_WARNING);
\core\output\notification::NOTIFY_WARNING
);
$html .= html_writer::table($table);
} else {
$html .= html_writer::table($table);
Expand Down
76 changes: 39 additions & 37 deletions classes/cache_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_forcedcache_cache_config extends cache_config {

/**
* Array to track errors thrown during store instantiation.
*
Expand Down Expand Up @@ -70,8 +69,10 @@ protected function include_configuration() {
}

// If plugin is supposed to be active, rethrow exception, can't continue with broken config.
if (!empty($CFG->alternative_cache_factory_class)
&& $CFG->alternative_cache_factory_class === 'tool_forcedcache_cache_factory') {
if (
!empty($CFG->alternative_cache_factory_class)
&& $CFG->alternative_cache_factory_class === 'tool_forcedcache_cache_factory'
) {
throw $e;
}
}
Expand All @@ -98,8 +99,10 @@ private function generate_config_array(): array {
$modemappings = $this->generate_mode_mapping($config['rules']);

// Get the definitions.
$definitions = $this->apply_definition_overrides(tool_forcedcache_cache_config_writer::locate_definitions(),
$config['definitionoverrides']);
$definitions = $this->apply_definition_overrides(
tool_forcedcache_cache_config_writer::locate_definitions(),
$config['definitionoverrides']
);

// Generate definition mappings from rulesets.
$definitionmappings = $this->generate_definition_mappings_from_rules($config['rules'], $definitions);
Expand All @@ -118,7 +121,7 @@ private function generate_config_array(): array {
'modemappings' => $modemappings,
'definitions' => $definitions,
'definitionmappings' => $definitionmappings,
'locks' => $locks
'locks' => $locks,
];

// Get the siteidentifier. Copies pattern from cache_config.
Expand All @@ -129,7 +132,6 @@ private function generate_config_array(): array {
}

return $config;

}

/**
Expand Down Expand Up @@ -161,7 +163,6 @@ public static function read_config_file(): array {

// Return config array.
return $array;

} else if ($pathexists) {
// Else decide on the path, then try to load it.
$path = realpath($CFG->tool_forcedcache_config_path);
Expand All @@ -172,7 +173,7 @@ public static function read_config_file(): array {
if (!empty($path) && strpos($path, $CFG->dirroot) !== false) {
throw new cache_exception(get_string('config_json_path_invalid', 'tool_forcedcache', [
'path' => $path,
'dirroot' => $CFG->dirroot
'dirroot' => $CFG->dirroot,
]));
}

Expand Down Expand Up @@ -204,21 +205,22 @@ public static function read_config_file(): array {
* @throws cache_exception
*/
private function generate_store_instance_config(array $stores): array {
$storesarr = array();
$storesarr = [];
foreach ($stores as $name => $store) {

// First check that all the required fields are present in the store.
if (!(array_key_exists('type', $store) &&
array_key_exists('config', $store))) {
if (
!(array_key_exists('type', $store) &&
array_key_exists('config', $store))
) {
throw new cache_exception(get_string('store_missing_fields', 'tool_forcedcache', $name));
}

$storearr = array();
$storearr = [];
$storearr['name'] = $name;
$storearr['plugin'] = $store['type'];
// Assume all configuration is correct.
$storearr['configuration'] = $store['config'];
$classname = 'cachestore_'.$store['type'];
$classname = 'cachestore_' . $store['type'];
$storearr['class'] = $classname;

// Now for the derived config from the store information provided.
Expand All @@ -233,7 +235,7 @@ private function generate_store_instance_config(array $stores): array {
!file_exists($cachepath)
) {
throw new cache_exception(
get_string('store_bad_type','tool_forcedcache', $store['type'])
get_string('store_bad_type', 'tool_forcedcache', $store['type'])
);
}
require_once($cachepath);
Expand Down Expand Up @@ -271,25 +273,25 @@ private function generate_store_instance_config(array $stores): array {
*
* @return array the generated default mode mappings.
*/
public static function get_default_mode_mappings() : array {
public static function get_default_mode_mappings(): array {
// Use the defaults from core.
$modemappings = array(
array(
$modemappings = [
[
'mode' => cache_store::MODE_APPLICATION,
'store' => 'default_application',
'sort' => -1
),
array(
'sort' => -1,
],
[
'mode' => cache_store::MODE_SESSION,
'store' => 'default_session',
'sort' => -1
),
array(
'sort' => -1,
],
[
'mode' => cache_store::MODE_REQUEST,
'store' => 'default_request',
'sort' => -1
)
);
'sort' => -1,
],
];

return $modemappings;
}
Expand Down Expand Up @@ -337,7 +339,7 @@ private function generate_mode_mapping(array $rules): array {
* @return array an array of ordered mappings for every definition to its ruleset.
*/
private function generate_definition_mappings_from_rules(array $rules, array $definitions): array {
$defmappings = array();
$defmappings = [];
$num = 1;
foreach ($definitions as $defname => $definition) {
// Find the mode of the definition to discover the mappings.
Expand All @@ -364,7 +366,7 @@ private function generate_definition_mappings_from_rules(array $rules, array $de
}

// Now decide on the ruleset that matches.
$stores = array();
$stores = [];
foreach ($ruleset as $rule) {
if (array_key_exists('conditions', $rule)) {
foreach ($rule['conditions'] as $condition => $value) {
Expand All @@ -390,7 +392,7 @@ private function generate_definition_mappings_from_rules(array $rules, array $de
$sort = count($stores);
foreach ($stores as $store) {
// Create the mapping for the definition -> store and add to the master list.
$mappingarr = array();
$mappingarr = [];
$mappingarr['store'] = $store;
$mappingarr['definition'] = $defname;
$mappingarr['sort'] = $sort;
Expand Down Expand Up @@ -438,15 +440,15 @@ private function generate_definition_mappings_from_rules(array $rules, array $de
*
* @return array array of locks to use.
*/
private function generate_locks() : array {
return array(
'default_file_lock' => array(
private function generate_locks(): array {
return [
'default_file_lock' => [
'name' => 'cachelock_file_default',
'type' => 'cachelock_file',
'dir' => 'filelocks',
'default' => true
)
);
'default' => true,
],
];
}

/**
Expand Down
3 changes: 0 additions & 3 deletions classes/cache_config_writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

defined('MOODLE_INTERNAL') || die();

/**
* This config_writer is readonly, and provides public access to some protected methods.
*
Expand All @@ -25,7 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_forcedcache_cache_config_writer extends cache_config_writer {

/**
* Overriding this means nothing gets Written.
* This must still work if we fallback to core caching.
Expand Down
Loading
Loading