mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-70815 completion: Cast custom data to array
Since cm_info::customdata can be of any type, we need to cast it to an array first before checking for custom completion rules. Otherwise, an exception can be thrown (e.g. customdata has been set as an stdClass)
This commit is contained in:
parent
5a7c629f7c
commit
fc238f329d
@ -96,8 +96,9 @@ abstract class activity_custom_completion {
|
||||
public function get_available_custom_rules(): array {
|
||||
$rules = static::get_defined_custom_rules();
|
||||
$availablerules = [];
|
||||
$customdata = (array)$this->cm->customdata;
|
||||
foreach ($rules as $rule) {
|
||||
$customrule = $this->cm->customdata['customcompletionrules'][$rule] ?? false;
|
||||
$customrule = $customdata['customcompletionrules'][$rule] ?? false;
|
||||
if (!empty($customrule)) {
|
||||
$availablerules[] = $rule;
|
||||
}
|
||||
|
@ -1107,8 +1107,10 @@ class completion_info {
|
||||
|
||||
// Custom activity module completion data.
|
||||
|
||||
// Cast custom data to array before checking for custom completion rules.
|
||||
$customdata = (array)$cm->customdata;
|
||||
// Return early if the plugin does not define custom completion rules.
|
||||
if (empty($cm->customdata['customcompletionrules'])) {
|
||||
if (empty($customdata['customcompletionrules'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -1120,7 +1122,7 @@ class completion_info {
|
||||
|
||||
/** @var activity_custom_completion $customcmcompletion */
|
||||
$customcmcompletion = new $cmcompletionclass($cm, $userid);
|
||||
foreach ($cm->customdata['customcompletionrules'] as $rule => $enabled) {
|
||||
foreach ($customdata['customcompletionrules'] as $rule => $enabled) {
|
||||
if (!$enabled) {
|
||||
// Skip inactive completion rules.
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user