mirror of
https://github.com/moodle/moodle.git
synced 2025-03-23 17:10:20 +01:00
MDL-66230 tool_usertours: account for deleted tours in privacy export.
This commit is contained in:
parent
f622ee97e3
commit
a1ab8ec216
@ -77,18 +77,22 @@ class provider implements
|
||||
}
|
||||
|
||||
if ($descriptionidentifier !== null) {
|
||||
$time = transform::datetime($value);
|
||||
$tour = \tool_usertours\tour::instance($tourid);
|
||||
try {
|
||||
$tour = \tool_usertours\tour::instance($tourid);
|
||||
$time = transform::datetime($value);
|
||||
|
||||
writer::export_user_preference(
|
||||
'tool_usertours',
|
||||
$name,
|
||||
$time,
|
||||
get_string($descriptionidentifier, 'tool_usertours', (object) [
|
||||
'name' => $tour->get_name(),
|
||||
'time' => $time,
|
||||
])
|
||||
);
|
||||
writer::export_user_preference(
|
||||
'tool_usertours',
|
||||
$name,
|
||||
$time,
|
||||
get_string($descriptionidentifier, 'tool_usertours', (object) [
|
||||
'name' => $tour->get_name(),
|
||||
'time' => $time,
|
||||
])
|
||||
);
|
||||
} catch (\dml_missing_record_exception $ex) {
|
||||
// The tour related to this user preference no longer exists.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,4 +112,37 @@ class tool_usertours_privacy_testcase extends \core_privacy\tests\provider_testc
|
||||
|
||||
$this->assertCount(2, (array) $prefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that export_user_preferences excludes deleted tours.
|
||||
*/
|
||||
public function test_export_user_preferences_deleted_tour() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$user = \core_user::get_user_by_username('admin');
|
||||
|
||||
$alltours = $DB->get_records('tool_usertours_tours');
|
||||
|
||||
$tour1 = tour::instance(array_shift($alltours)->id);
|
||||
$tour1->mark_user_completed();
|
||||
|
||||
$tour2 = tour::instance(array_shift($alltours)->id);
|
||||
$tour2->mark_user_completed();
|
||||
$tour2->remove();
|
||||
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertTrue($writer->has_any_data());
|
||||
|
||||
// We should have one preference.
|
||||
$prefs = $writer->get_user_preferences('tool_usertours');
|
||||
$this->assertCount(1, (array) $prefs);
|
||||
|
||||
// The preference should be related to the first tour.
|
||||
$this->assertContains($tour1->get_name(), reset($prefs)->description);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user