MDL-62560 tool_dataprivacy: Add a purpose override cache

This commit is contained in:
Andrew Nicols 2018-10-18 14:16:57 +08:00 committed by David Monllao
parent b519dab3bd
commit 9e217d8441
4 changed files with 55 additions and 3 deletions

View File

@ -89,11 +89,55 @@ class purpose_override extends \core\persistent {
* @return array
*/
public static function get_overrides_for_purpose(purpose $purpose) : array {
$cache = \cache::make('tool_dataprivacy', 'purpose_overrides');
$overrides = [];
foreach (self::get_records(['purposeid' => $purpose->get('id')]) as $override) {
$overrides[$override->get('roleid')] = $override;
$alldata = $cache->get($purpose->get('id'));
if (false === $alldata) {
$tocache = [];
foreach (self::get_records(['purposeid' => $purpose->get('id')]) as $override) {
$tocache[] = $override->to_record();
$overrides[$override->get('roleid')] = $override;
}
$cache->set($purpose->get('id'), $tocache);
} else {
foreach ($alldata as $data) {
$override = new self(0, $data);
$overrides[$override->get('roleid')] = $override;
}
}
return $overrides;
}
/**
* Adds the new record to the cache.
*
* @return null
*/
protected function after_create() {
$cache = \cache::make('tool_dataprivacy', 'purpose_overrides');
$cache->delete($this->get('purposeid'));
}
/**
* Updates the cache record.
*
* @param bool $result
* @return null
*/
protected function after_update($result) {
$cache = \cache::make('tool_dataprivacy', 'purpose_overrides');
$cache->delete($this->get('purposeid'));
}
/**
* Removes unnecessary stuff from db.
*
* @return null
*/
protected function before_delete() {
$cache = \cache::make('tool_dataprivacy', 'purpose_overrides');
$cache->delete($this->get('purposeid'));
}
}

View File

@ -33,6 +33,13 @@ $definitions = array(
'staticacceleration' => true,
'staticaccelerationsize' => 30,
),
'purpose_overrides' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => false,
'staticacceleration' => true,
'staticaccelerationsize' => 50,
),
'contextlevel' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,

View File

@ -35,6 +35,7 @@ $string['approverequest'] = 'Approve request';
$string['bulkapproverequests'] = 'Approve requests';
$string['bulkdenyrequests'] = 'Deny requests';
$string['cachedef_purpose'] = 'Data purposes';
$string['cachedef_purpose_overrides'] = 'Purpose overrides in the Data Privacy tool';
$string['cachedef_contextlevel'] = 'Context levels purpose and category';
$string['cancelrequest'] = 'Cancel request';
$string['cancelrequestconfirmation'] = 'Do you really want cancel this data request?';

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2018100401;
$plugin->version = 2018100403;
$plugin->requires = 2018050800; // Moodle 3.5dev (Build 2018031600) and upwards.
$plugin->component = 'tool_dataprivacy';