Skip to content

Commit

Permalink
MDL-62560 tool_dataprivacy: Add a purpose override cache
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and David Monllao committed Oct 22, 2018
1 parent 9fc1390 commit 05b441c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
48 changes: 46 additions & 2 deletions admin/tool/dataprivacy/classes/purpose_override.php
Expand Up @@ -89,11 +89,55 @@ protected static function define_properties() {
* @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'));
}
}
7 changes: 7 additions & 0 deletions admin/tool/dataprivacy/db/caches.php
Expand Up @@ -33,6 +33,13 @@
'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,
Expand Down
1 change: 1 addition & 0 deletions admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
Expand Up @@ -35,6 +35,7 @@
$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?';
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2018051411;
$plugin->version = 2018051412;
$plugin->requires = 2018050800; // Moodle 3.5dev (Build 2018031600) and upwards.
$plugin->component = 'tool_dataprivacy';

0 comments on commit 05b441c

Please sign in to comment.