MDL-69726 calendar: fix raw event fetcher under postgres

Without this, there's a code path that under the right circumstances is hit and
results in a query with `FROM (mdl_event) ev` in it - which is not valid syntax
under postgres.
This commit is contained in:
Jenkins Automation
2020-10-20 07:46:00 +08:00
committed by Jake Dallimore
parent 31a98b3fb2
commit 213ea00afe
2 changed files with 13 additions and 2 deletions
@@ -281,7 +281,7 @@ class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_inter
$unionstartquery = "SELECT modulename, instance, eventtype, priority
FROM {event} ev
WHERE ";
$subqueryunion = $unionstartquery . implode(" UNION $unionstartquery ", $subqueryconditions);
$subqueryunion = '('.$unionstartquery . implode(" UNION $unionstartquery ", $subqueryconditions).')';
} else {
$subqueryunion = '{event}';
}
@@ -296,7 +296,7 @@ class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_inter
ev.instance,
ev.eventtype,
MIN(ev.priority) as priority
FROM ($subqueryunion) ev
FROM $subqueryunion ev
GROUP BY ev.modulename, ev.instance, ev.eventtype";
// Build the main query.
@@ -447,4 +447,15 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
array_column($events, 'name'),
'', 0.0, 10, true);
}
/**
* Test retrieval strategy with empty filters.
* This covers a edge case not covered elsewhere to ensure its SQL is cross
* db compatible. The test is ensuring we don't get a DML Exception with
* the filters setup this way.
*/
public function test_get_raw_events_with_empty_user_and_category_lists() {
$retrievalstrategy = new raw_event_retrieval_strategy;
$retrievalstrategy->get_raw_events([], null, null, []);
}
}