Commit f4bf4dca authored by Paul Holden's avatar Paul Holden
Browse files

MDL-73112 reportbuilder: improve handling of concatenated columns.

This change overcomes limitations in certain DB engines (such as
MySQL[1]) which can lead to truncation of data when applying group
concatenation to columns.

Ensure we account for that by validating that we are able to extract
the expected number of fields from each concatenated value.

[1] https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_group_concat_max_len
parent 7013bda3
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -21,6 +21,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Notification from 'core/notification';
import * as reportEvents from 'core_reportbuilder/local/events';
import * as reportSelectors from 'core_reportbuilder/local/selectors';
import {setPageNumber, refreshTableContent} from 'core_table/dynamic';
......@@ -58,7 +59,8 @@ export const init = () => {
const pageNumber = event.detail?.preservePagination ? null : 1;
await setPageNumber(tableRoot, pageNumber, false)
.then(refreshTableContent);
.then(refreshTableContent)
.catch(Notification.exception);
});
// Listen for trigger popup events.
......
......@@ -132,11 +132,19 @@ class groupconcat extends base {
// Store original names of all values that would be present without aggregation.
$valuenames = array_keys($values);
$values = explode(self::FIELD_VALUE_DELIMETER, (string) reset($values));
$valuenamescount = count($valuenames);
// Loop over each extracted value from the concatenated string.
$values = explode(self::FIELD_VALUE_DELIMETER, (string) reset($values));
foreach ($values as $value) {
$originalvalue = array_combine($valuenames, explode(self::COLUMN_FIELD_DELIMETER, $value));
// Ensure we have equal number of value names/data, account for truncation by DB.
$valuedata = explode(self::COLUMN_FIELD_DELIMETER, $value);
if ($valuenamescount !== count($valuedata)) {
continue;
}
$originalvalue = array_combine($valuenames, $valuedata);
$originalfirstvalue = reset($originalvalue);
// Once we've re-constructed each value, we can apply callbacks to it.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment