diff --git a/lib/db/install.xml b/lib/db/install.xml
index af9e2dcd8b1..39bbd58abc4 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -300,6 +300,7 @@
+
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 7a2adeb3f8d..f7e6a77b669 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -2322,5 +2322,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2016110300.00);
}
+ if ($oldversion < 2016110400.02) {
+ // Define a field 'deletioninprogress' in the 'course_modules' table, to background deletion tasks.
+ $table = new xmldb_table('course_modules');
+ $field = new xmldb_field('deletioninprogress', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'availability');
+
+ // Conditionally launch add field 'deletioninprogress'.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2016110400.02);
+ }
+
return true;
}
diff --git a/lib/modinfolib.php b/lib/modinfolib.php
index d8d3c1ec484..a3664589392 100644
--- a/lib/modinfolib.php
+++ b/lib/modinfolib.php
@@ -554,8 +554,7 @@ class course_modinfo {
// Get section data
$sections = $DB->get_records('course_sections', array('course' => $course->id), 'section',
- 'section, id, course, name, summary, summaryformat, sequence, visible, ' .
- 'availability');
+ 'section, id, course, name, summary, summaryformat, sequence, visible, availability');
$compressedsections = array();
$formatoptionsdef = course_get_format($course)->section_format_options();
@@ -753,6 +752,7 @@ class course_modinfo {
* @property-read mixed $customdata Optional custom data stored in modinfo cache for this activity, or null if none
* @property-read string $afterlink Extra HTML code to display after link - calculated on request
* @property-read string $afterediticons Extra HTML code to display after editing icons (e.g. more icons) - calculated on request
+ * @property-read bool $deletioninprogress True if this course module is scheduled for deletion, false otherwise.
*/
class cm_info implements IteratorAggregate {
/**
@@ -1038,6 +1038,11 @@ class cm_info implements IteratorAggregate {
*/
private $afterediticons;
+ /**
+ * @var bool representing the deletion state of the module. True if the mod is scheduled for deletion.
+ */
+ private $deletioninprogress;
+
/**
* List of class read-only properties and their getter methods.
* Used by magic functions __get(), __isset(), __empty()
@@ -1089,6 +1094,7 @@ class cm_info implements IteratorAggregate {
'uservisible' => 'get_user_visible',
'visible' => false,
'visibleold' => false,
+ 'deletioninprogress' => false
);
/**
@@ -1505,7 +1511,7 @@ class cm_info implements IteratorAggregate {
static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added',
'score', 'indent', 'visible', 'visibleold', 'groupmode', 'groupingid',
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
- 'showdescription', 'availability');
+ 'showdescription', 'availability', 'deletioninprogress');
foreach ($cmfields as $key) {
$cmrecord->$key = $this->$key;
}
@@ -1700,6 +1706,7 @@ class cm_info implements IteratorAggregate {
$this->added = isset($mod->added) ? $mod->added : 0;
$this->score = isset($mod->score) ? $mod->score : 0;
$this->visibleold = isset($mod->visibleold) ? $mod->visibleold : 0;
+ $this->deletioninprogress = isset($mod->deletioninprogress) ? $mod->deletioninprogress : 0;
// Note: it saves effort and database space to always include the
// availability and completion fields, even if availability or completion
@@ -1861,6 +1868,12 @@ class cm_info implements IteratorAggregate {
}
$this->uservisible = true;
+ // If the module is being deleted, set the uservisible state to false and return.
+ if ($this->deletioninprogress) {
+ $this->uservisible = false;
+ return null;
+ }
+
// If the user cannot access the activity set the uservisible flag to false.
// Additional checks are required to determine whether the activity is entirely hidden or just greyed out.
if ((!$this->visible or !$this->get_available()) and
@@ -2465,7 +2478,7 @@ class section_info implements IteratorAggregate {
'summary' => '',
'summaryformat' => '1', // FORMAT_HTML, but must be a string
'visible' => '1',
- 'availability' => null,
+ 'availability' => null
);
/**
diff --git a/version.php b/version.php
index 84c1ef847e5..39211165821 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2016110400.01; // YYYYMMDD = weekly release date of this DEV branch.
+$version = 2016110400.02; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.