Skip to content

Commit

Permalink
MDL-61307 core: Remove deletion_criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 13, 2018
1 parent 15a4560 commit cf9ef32
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 149 deletions.
6 changes: 3 additions & 3 deletions comment/classes/privacy/provider.php
Expand Up @@ -102,11 +102,11 @@ public static function export_comments($context, $component, $commentarea, $item
/**
* Deletes all comments for a specified context.
*
* @param \core_privacy\local\request\deletion_criteria $criteria Details about which context to delete comments for.
* @param \context $context Details about which context to delete comments for.
*/
public static function delete_comments_for_context(\core_privacy\local\request\deletion_criteria $criteria) {
public static function delete_comments_for_context(\context $context) {
global $DB;
$DB->delete_records('comments', ['contextid' => $criteria->get_context()->id]);
$DB->delete_records('comments', ['contextid' => $context->id]);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions comment/tests/privacy_test.php
Expand Up @@ -115,8 +115,7 @@ public function test_delete_comments_for_context() {
$comment2->add('First comment for user 2 on comment 2');

// Delete only for the first context. All records in the comments table for this context should be removed.
$deletioncriteria = new \core_privacy\local\request\deletion_criteria($coursecontext1);
\core_comment\privacy\provider::delete_comments_for_context($deletioncriteria);
\core_comment\privacy\provider::delete_comments_for_context($coursecontext1);
// No records left here.
$this->assertCount(0, $comment1->get_comments());
// All of the records are left intact here.
Expand Down
9 changes: 4 additions & 5 deletions privacy/classes/local/legacy_polyfill.php
Expand Up @@ -26,7 +26,6 @@
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\approved_contextlist;
use \core_privacy\local\request\deletion_criteria;

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

Expand Down Expand Up @@ -87,12 +86,12 @@ public static function export_user_data(approved_contextlist $contextlist) {
}

/**
* Delete all use data which matches the specified deletion_criteria.
* Delete all use data which matches the specified deletion criteria.
*
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(deletion_criteria $criteria) {
return static::_delete_for_context($criteria);
public static function delete_for_context(\context $context) {
return static::_delete_for_context($context);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions privacy/classes/local/request/core_user_data_provider.php
Expand Up @@ -54,11 +54,11 @@ public static function get_contexts_for_userid(int $userid) : contextlist;
public static function export_user_data(approved_contextlist $contextlist);

/**
* Delete all use data which matches the specified deletion_criteria.
* Delete all use data which matches the specified deletion criteria.
*
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(deletion_criteria $criteria);
public static function delete_for_context(\context $context);

/**
* Delete all user data for the specified user, in the specified contexts.
Expand Down
58 changes: 0 additions & 58 deletions privacy/classes/local/request/deletion_criteria.php

This file was deleted.

8 changes: 4 additions & 4 deletions privacy/classes/local/request/helper.php
Expand Up @@ -86,13 +86,13 @@ public static function export_data_for_null_provider(approved_contextlist $conte
*
* This will handle deletion for things such as activity completion.
*
* @param string $component The component being deleted for.
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
* @param string $component The component being deleted for.
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(string $component, deletion_criteria $criteria) {
public static function delete_for_context(string $component, \context $context) {
if (strpos($component, 'mod_') === 0) {
// Activity modules support data stored by core about them - for example, activity completion.
static::delete_for_context_course_module($component, $criteria->get_context());
static::delete_for_context_course_module($component, $context);
}
}

Expand Down
11 changes: 5 additions & 6 deletions privacy/classes/manager.php
Expand Up @@ -24,7 +24,6 @@
namespace core_privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\contextlist_collection;
use core_privacy\local\request\deletion_criteria;

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

Expand Down Expand Up @@ -252,20 +251,20 @@ public function delete_user_data(contextlist_collection $contextlistcollection)
}

/**
* Delete user data for all users using the specified deletion_criteria.
* Delete all use data which matches the specified deletion criteria.
*
* @param deletion_criteria $criteria the criteria object dictating what contexts will be deleted.
* @param context $context The specific context to delete data for.
*/
public function delete_for_context(deletion_criteria $criteria) {
public function delete_for_context(\context $context) {
foreach ($this->get_component_list() as $component) {
if ($this->component_implements($component, \core_privacy\local\request\core_user_data_provider::class)) {
// This component knows about specific data that it owns.
// Have it delete all of that user data for the context.
$this->get_provider_classname($component)::delete_for_context($criteria);
$this->get_provider_classname($component)::delete_for_context($context);
}

// Delete any shared user data it doesn't know about.
local\request\helper::delete_for_context($component, $criteria);
local\request\helper::delete_for_context($component, $context);
}
}

Expand Down
56 changes: 0 additions & 56 deletions privacy/tests/deletion_criteria_test.php

This file was deleted.

7 changes: 3 additions & 4 deletions privacy/tests/fixtures/mock_provider.php
Expand Up @@ -27,7 +27,6 @@
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\deletion_criteria;

/**
* Mock core_user_data_provider for unit tests.
Expand Down Expand Up @@ -67,11 +66,11 @@ public static function export_user_data(approved_contextlist $contextlist) {
}

/**
* Delete all use data which matches the specified deletion_criteria.
* Delete all use data which matches the specified deletion criteria.
*
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
* @param context $context The specific context to delete data for.
*/
public static function delete_for_context(deletion_criteria $criteria) {
public static function delete_for_context(\context $context) {
// This does nothing. We only want to confirm this can be called via the \core_privacy\manager.
}

Expand Down
13 changes: 5 additions & 8 deletions privacy/tests/legacy_polyfill_test.php
Expand Up @@ -29,7 +29,6 @@

use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\deletion_criteria;
use \core_privacy\local\request\approved_contextlist;

/**
Expand Down Expand Up @@ -114,15 +113,13 @@ public function test_export_user_data() {
* _delete_for_context can be successfully called.
*/
public function test_delete_for_context() {
$criteria = new deletion_criteria(\context_system::instance());

$mock = $this->createMock(test_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_delete_for_context', [$criteria]);
->with('_delete_for_context', [\context_system::instance()]);

test_legacy_polyfill_request_provider::$mock = $mock;
test_legacy_polyfill_request_provider::delete_for_context($criteria);
test_legacy_polyfill_request_provider::delete_for_context(\context_system::instance());
}

/**
Expand Down Expand Up @@ -242,11 +239,11 @@ protected static function _export_user_data(approved_contextlist $contextlist) {


/**
* Delete all use data which matches the specified deletion_criteria.
* Delete all use data which matches the specified deletion criteria.
*
* @param deletion_criteria $criteria An object containing specific deletion criteria to delete for.
* @param context $context The specific context to delete data for.
*/
public static function _delete_for_context(deletion_criteria $criteria) {
public static function _delete_for_context(\context $context) {
return static::$mock->get_return_value(__FUNCTION__, func_get_args());
}

Expand Down

0 comments on commit cf9ef32

Please sign in to comment.