MDL-54751 core_availability: Module restrictions exclude deletions

To make sure users can't add an access restriction based on a
course module scheduled for deletion, or its respective grade items.
This commit is contained in:
Jake Dallimore 2016-11-02 15:09:44 +08:00
parent 45bd824e59
commit 2f6e0d92b7
2 changed files with 6 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class frontend extends \core_availability\frontend {
foreach ($modinfo->cms as $id => $othercm) {
// Add each course-module if it has completion turned on and is not
// the one currently being edited.
if ($othercm->completion && (empty($cm) || $cm->id != $id)) {
if ($othercm->completion && (empty($cm) || $cm->id != $id) && !$othercm->deletioninprogress) {
$cms[] = (object)array('id' => $id, 'name' =>
format_string($othercm->name, true, array('context' => $context)));
}

View File

@ -42,6 +42,7 @@ class frontend extends \core_availability\frontend {
\section_info $section = null) {
global $DB, $CFG;
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/course/lib.php');
// Get grades as basic associative array.
$gradeoptions = array();
@ -49,6 +50,10 @@ class frontend extends \core_availability\frontend {
// For some reason the fetch_all things return null if none.
$items = $items ? $items : array();
foreach ($items as $id => $item) {
// Don't include the grade item if it's linked with a module that is being deleted.
if (course_module_instance_pending_deletion($item->courseid, $item->itemmodule, $item->iteminstance)) {
continue;
}
// Do not include grades for current item.
if ($cm && $cm->instance == $item->iteminstance
&& $cm->modname == $item->itemmodule