From a6f07c4c091230c47cecda4bfce1a89c246bb452 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 22 Mar 2024 09:34:17 +1100 Subject: [PATCH] issue #51: fix the issue when relateduserid is null --- classes/local/tool_dynamic_cohorts/condition/cohort_field.php | 1 - classes/observer.php | 3 +-- .../local/tool_dynamic_cohorts/condition/cohort_field_test.php | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/classes/local/tool_dynamic_cohorts/condition/cohort_field.php b/classes/local/tool_dynamic_cohorts/condition/cohort_field.php index 239cd4e..f34a390 100644 --- a/classes/local/tool_dynamic_cohorts/condition/cohort_field.php +++ b/classes/local/tool_dynamic_cohorts/condition/cohort_field.php @@ -491,7 +491,6 @@ public function get_sql(): condition_sql { */ public function get_events(): array { return [ - '\core\event\cohort_updated', '\core\event\cohort_member_added', '\core\event\cohort_member_removed', ]; diff --git a/classes/observer.php b/classes/observer.php index 5b6692c..161555b 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -17,7 +17,6 @@ namespace tool_dynamic_cohorts; use core\event\base; -use tool_dynamic_cohorts\rule_manager; /** * Event observer class. @@ -50,7 +49,7 @@ public static function process_event(base $event): void { protected static function get_userid_from_event(base $event): int { $data = $event->get_data(); - if (array_key_exists('relateduserid', $data)) { + if (array_key_exists('relateduserid', $data) && !empty($data['relateduserid'])) { $userid = $data['relateduserid']; } else { $userid = $data['userid']; diff --git a/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php b/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php index 855bece..94192fa 100644 --- a/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php +++ b/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php @@ -396,7 +396,6 @@ public function test_get_sql_data_custom_fields() { */ public function test_get_events() { $this->assertEquals([ - '\core\event\cohort_updated', '\core\event\cohort_member_added', '\core\event\cohort_member_removed', ], $this->get_condition()->get_events());