mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-56789 core: Recycle bin warn only if a grade item is being deleted
This commit is contained in:
parent
6cdf0207ff
commit
36272110ba
@ -1289,16 +1289,36 @@ function course_module_flag_for_async_deletion($cmid) {
|
||||
* Checks whether the given course has any course modules scheduled for adhoc deletion.
|
||||
*
|
||||
* @param int $courseid the id of the course.
|
||||
* @param bool $onlygradable whether to check only gradable modules or all modules.
|
||||
* @return bool true if the course contains any modules pending deletion, false otherwise.
|
||||
*/
|
||||
function course_modules_pending_deletion($courseid) {
|
||||
function course_modules_pending_deletion(int $courseid, bool $onlygradable = false) : bool {
|
||||
if (empty($courseid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($onlygradable) {
|
||||
// Fetch modules with grade items.
|
||||
if (!$coursegradeitems = grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid])) {
|
||||
// Return early when there is none.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($courseid);
|
||||
foreach ($modinfo->get_cms() as $module) {
|
||||
if ($module->deletioninprogress == '1') {
|
||||
return true;
|
||||
if ($onlygradable) {
|
||||
// Check if the module being deleted is in the list of course modules with grade items.
|
||||
foreach ($coursegradeitems as $coursegradeitem) {
|
||||
if ($coursegradeitem->itemmodule == $module->modname && $coursegradeitem->iteminstance == $module->instance) {
|
||||
// The module being deleted is within the gradable modules.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -6519,8 +6519,10 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function provider_course_modules_pending_deletion() {
|
||||
return [
|
||||
['forum', true],
|
||||
['assign', true],
|
||||
['forum', false, true],
|
||||
['assign', false, true],
|
||||
['forum', true, false],
|
||||
['assign', true, true],
|
||||
];
|
||||
}
|
||||
|
||||
@ -6528,10 +6530,11 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
* Tests the function course_modules_pending_deletion.
|
||||
*
|
||||
* @param string $module The module we want to test with
|
||||
* @param bool $gradable The value to pass to the gradable argument of the course_modules_pending_deletion function
|
||||
* @param bool $expected The expected result
|
||||
* @dataProvider provider_course_modules_pending_deletion
|
||||
*/
|
||||
public function test_course_modules_pending_deletion(string $module, bool $expected) {
|
||||
public function test_course_modules_pending_deletion(string $module, bool $gradable, bool $expected) {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Ensure recyclebin is enabled.
|
||||
@ -6544,6 +6547,6 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$moduleinstance = $generator->create_module($module, array('course' => $course->id));
|
||||
|
||||
course_delete_module($moduleinstance->cmid, true); // Try to delete the instance asynchronously.
|
||||
$this->assertEquals($expected, course_modules_pending_deletion($course->id));
|
||||
$this->assertEquals($expected, course_modules_pending_deletion($course->id, $gradable));
|
||||
}
|
||||
}
|
||||
|
@ -986,7 +986,7 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null,
|
||||
|
||||
// Put a warning on all gradebook pages if the course has modules currently scheduled for background deletion.
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
if (course_modules_pending_deletion($courseid)) {
|
||||
if (course_modules_pending_deletion($courseid, true)) {
|
||||
\core\notification::add(get_string('gradesmoduledeletionpendingwarning', 'grades'),
|
||||
\core\output\notification::NOTIFY_WARNING);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user