Skip to content

Commit 068bddd

Browse files
committed
MD-1661: Trigger course_module_updated event on date save (PR moodleou#50)
Add final save_new_dates() wrapper method to both base extractor classes: - report_editdates_mod_date_extractor: calls save_dates() then triggers \core\event\course_module_updated so calendar and other observers react - report_editdates_block_date_extractor: calls save_dates() for consistent API Update index.php to call save_new_dates() instead of save_dates() for both module and block date updates. Ref: moodleou#50 (commit bb1f9b3) Made-with: Cursor
1 parent a8d7e86 commit 068bddd

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

index.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@
189189
$cm = $cms[$modid];
190190
$mod = report_editdates_mod_date_extractor::make($cm->modname, $course);
191191
if ($mod) {
192-
$mod->save_dates($cm, $datesettings);
192+
// BEGIN LSU MD-1661: Use save_new_dates to trigger course_module_updated event
193+
// See: https://github.com/moodleou/moodle-report_editdates/pull/50 (commit bb1f9b3)
194+
$mod->save_new_dates($cm, $datesettings);
195+
// END LSU MD-1661: Use save_new_dates to trigger course_module_updated event
193196
}
194197
}
195198

@@ -206,7 +209,10 @@
206209
$blockdatextrator =
207210
report_editdates_block_date_extractor::make($block->blockname, $course);
208211
if ($blockdatextrator) {
209-
$blockdatextrator->save_dates($blockobj, $datesettings);
212+
// BEGIN LSU MD-1661: Use save_new_dates for consistent API with mod extractors
213+
// See: https://github.com/moodleou/moodle-report_editdates/pull/50 (commit bb1f9b3)
214+
$blockdatextrator->save_new_dates($blockobj, $datesettings);
215+
// END LSU MD-1661: Use save_new_dates for consistent API with mod extractors
210216
}
211217
}
212218
}

lib.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ abstract public function get_settings(cm_info $cm);
174174
*/
175175
abstract public function validate_dates(cm_info $cm, array $dates);
176176

177+
// BEGIN LSU MD-1661: Trigger course_module_updated event after saving mod dates
178+
// See: https://github.com/moodleou/moodle-report_editdates/pull/50 (commit bb1f9b3)
179+
// This final wrapper ensures course_module_updated is always fired regardless of which
180+
// activity type overrides save_dates(), enabling calendar and other observers to react.
181+
/**
182+
* Save the new dates for this course_module instance and trigger the updated event.
183+
*
184+
* Having this method final gives us a possibility to add any logic
185+
* (e.g. triggering events) before or after saving dates for any activity.
186+
*
187+
* @param cm_info $cm the activity to save the dates for.
188+
* @param array $dates a list of new dates.
189+
* @throws \coding_exception
190+
*/
191+
final public function save_new_dates(cm_info $cm, array $dates) {
192+
$this->save_dates($cm, $dates);
193+
\core\event\course_module_updated::create_from_cm($cm)->trigger();
194+
}
195+
// END LSU MD-1661: Trigger course_module_updated event after saving mod dates
196+
177197
/**
178198
* Save the new dates for this course_module instance.
179199
* @param cm_info $cm the activity to save the dates for.
@@ -294,6 +314,22 @@ abstract public function get_settings(block_base $block);
294314
*/
295315
abstract public function validate_dates(block_base $block, array $dates);
296316

317+
// BEGIN LSU MD-1661: Consistent save_new_dates API for block extractors
318+
// See: https://github.com/moodleou/moodle-report_editdates/pull/50 (commit bb1f9b3)
319+
/**
320+
* Save the new dates for this block instance.
321+
*
322+
* Having this method final gives us a possibility to add any logic
323+
* (e.g. triggering events) before or after saving dates for any block.
324+
*
325+
* @param \block_base $block the block to save the dates for.
326+
* @param array $dates a list of new dates.
327+
*/
328+
final public function save_new_dates(block_base $block, array $dates) {
329+
$this->save_dates($block, $dates);
330+
}
331+
// END LSU MD-1661: Consistent save_new_dates API for block extractors
332+
297333
/**
298334
* Save the new dates for this course_module instance.
299335
* @param block_base $block The activity to save the dates for.

0 commit comments

Comments
 (0)