Skip to content

Commit f056102

Browse files
author
David Ala
committed
Bugfix: simply changing evasys form not correctly working with update
1 parent d7ddcfc commit f056102

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

classes/option/fields/evasys.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public static function changes_collected_action(
553553
$taskdata = [
554554
'teacherchanges' => $changes["mod_booking\\option\\fields\\teachers"],
555555
'namechanges' => $changes["mod_booking\\option\\fields\\text"],
556-
'relevantchanges' => isset($changes["bookingextension_evasys\\option\\fields\\evasys"]['changes']) ?? [],
556+
'relevantchanges' => $changes["bookingextension_evasys\\option\\fields\\evasys"]['changes'] ?? [],
557557
'newoption' => $relevantoptiondata,
558558
'relevantkeyssurvey' => self::$relevantkeyssurvey,
559559
'relevantkeyscourse' => self::$relevantkeyscourse,

classes/task/evasys_send_to_api.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public function execute() {
9595
mtrace($this->get_name() . ': Skipping task - no teachers assigned.');
9696
return;
9797
}
98+
// Normalize changed keys so update checks work with array or object payloads.
99+
$changedkeys = [];
100+
if (is_array($relevantchanges)) {
101+
$changedkeys = array_keys($relevantchanges);
102+
} else if (is_object($relevantchanges)) {
103+
$changedkeys = array_keys((array)$relevantchanges);
104+
}
98105
// If by any chance the option is a selflearningcourse and slips through validation, we skip the task.
99106
if (!empty($newoption->selflearningcourse)) {
100107
mtrace($this->get_name() . ': Skipping task - option is a self-learning course.');
@@ -144,15 +151,16 @@ public function execute() {
144151
}
145152
// Checks if the survey and therefore the course needs to be updated.
146153
if (!$updatesurvey) {
147-
foreach ($relevantchanges as $key => $value) {
154+
foreach ($changedkeys as $key) {
148155
if (in_array($key, $relevantkeyssurvey, true)) {
149156
$updatesurvey = true;
157+
break;
150158
}
151159
}
152160
// Checks for the only key where just the course needs to be updated.
153161
if (
154162
!$updatesurvey
155-
&& isset($courserelevantchanges->$relevankeyscourse)
163+
&& !empty(array_intersect($changedkeys, $relevankeyscourse))
156164
) {
157165
$updatecourse = true;
158166
}

0 commit comments

Comments
 (0)