MDL-54751 core: introduce deletion flag for course modules

Created a flag, 'deletioninprogress' on the course_modules table to be
used when deleting course modules and course sections. Modified
modinfolib caches such that, when rebuilt, these caches hide the
relevant modules based on the value of the flag.
This commit is contained in:
Jake Dallimore 2016-11-02 15:05:56 +08:00
parent 7eb34671c1
commit 048f909b07
4 changed files with 33 additions and 5 deletions

View file

@ -300,6 +300,7 @@
<FIELD NAME="completionexpected" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Date at which students are expected to complete this activity. This field is used when displaying student progress."/> <FIELD NAME="completionexpected" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Date at which students are expected to complete this activity. This field is used when displaying student progress."/>
<FIELD NAME="showdescription" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Some module types support a 'description' which shows within the module pages. This option controls whether it also displays on the course main page. 0 = does not display (default), 1 = displays"/> <FIELD NAME="showdescription" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Some module types support a 'description' which shows within the module pages. This option controls whether it also displays on the course main page. 0 = does not display (default), 1 = displays"/>
<FIELD NAME="availability" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Availability restrictions for viewing this activity, in JSON format. Null if no restrictions."/> <FIELD NAME="availability" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Availability restrictions for viewing this activity, in JSON format. Null if no restrictions."/>
<FIELD NAME="deletioninprogress" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>

View file

@ -2322,5 +2322,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2016110300.00); 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; return true;
} }

View file

@ -554,8 +554,7 @@ class course_modinfo {
// Get section data // Get section data
$sections = $DB->get_records('course_sections', array('course' => $course->id), 'section', $sections = $DB->get_records('course_sections', array('course' => $course->id), 'section',
'section, id, course, name, summary, summaryformat, sequence, visible, ' . 'section, id, course, name, summary, summaryformat, sequence, visible, availability');
'availability');
$compressedsections = array(); $compressedsections = array();
$formatoptionsdef = course_get_format($course)->section_format_options(); $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 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 $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 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 { class cm_info implements IteratorAggregate {
/** /**
@ -1038,6 +1038,11 @@ class cm_info implements IteratorAggregate {
*/ */
private $afterediticons; 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. * List of class read-only properties and their getter methods.
* Used by magic functions __get(), __isset(), __empty() * Used by magic functions __get(), __isset(), __empty()
@ -1089,6 +1094,7 @@ class cm_info implements IteratorAggregate {
'uservisible' => 'get_user_visible', 'uservisible' => 'get_user_visible',
'visible' => false, 'visible' => false,
'visibleold' => false, 'visibleold' => false,
'deletioninprogress' => false
); );
/** /**
@ -1505,7 +1511,7 @@ class cm_info implements IteratorAggregate {
static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added', static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added',
'score', 'indent', 'visible', 'visibleold', 'groupmode', 'groupingid', 'score', 'indent', 'visible', 'visibleold', 'groupmode', 'groupingid',
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected', 'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
'showdescription', 'availability'); 'showdescription', 'availability', 'deletioninprogress');
foreach ($cmfields as $key) { foreach ($cmfields as $key) {
$cmrecord->$key = $this->$key; $cmrecord->$key = $this->$key;
} }
@ -1700,6 +1706,7 @@ class cm_info implements IteratorAggregate {
$this->added = isset($mod->added) ? $mod->added : 0; $this->added = isset($mod->added) ? $mod->added : 0;
$this->score = isset($mod->score) ? $mod->score : 0; $this->score = isset($mod->score) ? $mod->score : 0;
$this->visibleold = isset($mod->visibleold) ? $mod->visibleold : 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 // Note: it saves effort and database space to always include the
// availability and completion fields, even if availability or completion // availability and completion fields, even if availability or completion
@ -1861,6 +1868,12 @@ class cm_info implements IteratorAggregate {
} }
$this->uservisible = true; $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. // 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. // Additional checks are required to determine whether the activity is entirely hidden or just greyed out.
if ((!$this->visible or !$this->get_available()) and if ((!$this->visible or !$this->get_available()) and
@ -2465,7 +2478,7 @@ class section_info implements IteratorAggregate {
'summary' => '', 'summary' => '',
'summaryformat' => '1', // FORMAT_HTML, but must be a string 'summaryformat' => '1', // FORMAT_HTML, but must be a string
'visible' => '1', 'visible' => '1',
'availability' => null, 'availability' => null
); );
/** /**

View file

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die(); 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. // RR = release increments - 00 in DEV branches.
// .XX = incremental changes. // .XX = incremental changes.