mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-46991 Availability: Conditional dates not updated on restore
This commit is contained in:
parent
272fec367f
commit
5176504d3f
8 changed files with 158 additions and 55 deletions
|
@ -49,6 +49,9 @@ abstract class info {
|
|||
/** @var tree Availability configuration, decoded from JSON; null if unset */
|
||||
protected $availabilitytree;
|
||||
|
||||
/** @var array|null Array of information about current restore if any */
|
||||
protected static $restoreinfo = null;
|
||||
|
||||
/**
|
||||
* Constructs with item details.
|
||||
*
|
||||
|
@ -307,9 +310,12 @@ abstract class info {
|
|||
* @param string $restoreid Restore identifier
|
||||
* @param int $courseid Target course id
|
||||
* @param \base_logger $logger Logger for any warnings
|
||||
* @param int $dateoffset Date offset to be added to any dates (0 = none)
|
||||
*/
|
||||
public function update_after_restore($restoreid, $courseid, \base_logger $logger) {
|
||||
public function update_after_restore($restoreid, $courseid, \base_logger $logger, $dateoffset) {
|
||||
$tree = $this->get_availability_tree();
|
||||
// Set static data for use by get_restore_date_offset function.
|
||||
self::$restoreinfo = array('restoreid' => $restoreid, 'dateoffset' => $dateoffset);
|
||||
$changed = $tree->update_after_restore($restoreid, $courseid, $logger,
|
||||
$this->get_thing_name());
|
||||
if ($changed) {
|
||||
|
@ -319,6 +325,24 @@ abstract class info {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date offset (amount by which any date values should be
|
||||
* adjusted) for the current restore.
|
||||
*
|
||||
* @param string $restoreid Restore identifier
|
||||
* @return int Date offset (0 if none)
|
||||
* @throws coding_exception If not in a restore (or not in that restore)
|
||||
*/
|
||||
public static function get_restore_date_offset($restoreid) {
|
||||
if (!self::$restoreinfo) {
|
||||
throw new coding_exception('Only valid during restore');
|
||||
}
|
||||
if (self::$restoreinfo['restoreid'] !== $restoreid) {
|
||||
throw new coding_exception('Data not available for that restore id');
|
||||
}
|
||||
return self::$restoreinfo['dateoffset'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the name of the item (cm_info or section_info, at present) that
|
||||
* this is controlling availability of. Name should be formatted ready
|
||||
|
|
|
@ -606,10 +606,13 @@ class tree extends tree_node {
|
|||
public function save() {
|
||||
$result = new \stdClass();
|
||||
$result->op = $this->op;
|
||||
if ($this->op === self::OP_AND || $this->op === self::OP_NOT_OR) {
|
||||
$result->showc = $this->showchildren;
|
||||
} else {
|
||||
$result->show = $this->show;
|
||||
// Only root tree has the 'show' options.
|
||||
if ($this->root) {
|
||||
if ($this->op === self::OP_AND || $this->op === self::OP_NOT_OR) {
|
||||
$result->showc = $this->showchildren;
|
||||
} else {
|
||||
$result->show = $this->show;
|
||||
}
|
||||
}
|
||||
$result->c = array();
|
||||
foreach ($this->children as $child) {
|
||||
|
|
|
@ -87,6 +87,9 @@ abstract class tree_node {
|
|||
* The default behaviour is simply to return false. If there is a problem
|
||||
* with the update, $logger can be used to output a warning.
|
||||
*
|
||||
* Note: If you need information about the date offset, call
|
||||
* \core_availability\info::get_restore_date_offset($restoreid).
|
||||
*
|
||||
* @param string $restoreid Restore ID
|
||||
* @param int $courseid ID of target course
|
||||
* @param \base_logger $logger Logger for any warnings
|
||||
|
|
|
@ -209,4 +209,15 @@ class condition extends \core_availability\condition {
|
|||
protected static function is_midnight($time) {
|
||||
return usergetmidnight($time) == $time;
|
||||
}
|
||||
|
||||
public function update_after_restore(
|
||||
$restoreid, $courseid, \base_logger $logger, $name) {
|
||||
// Update the date, if restoring with changed date.
|
||||
$dateoffset = \core_availability\info::get_restore_date_offset($restoreid);
|
||||
if ($dateoffset) {
|
||||
$this->time += $dateoffset;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue