Error with REDCap v13.7 and PHP v8.2
Closed this issue · 3 comments
Line 287 in 2fef6e6
The REDCap::getEventNames() function returns a boolean false value if the project is not longitudinal.
The php array_flip() function expects an array, not a boolean value. If a project is not longitudinal, an error is sent from REDCap:
[This message was automatically generated by REDCap]
The 'report_tweaks' module threw the following exception when calling the hook method 'redcap_every_page_top':
TypeError: array_flip(): Argument #1 ($array) must be of type array, bool given in /redcap/modules/report_tweaks_v1.2.4/ReportTweaks.php:289
Possible solution:
The first two lines of the makeEventMap() function checks first if the REDCap function returns a false value and assigns the flipped array to the $map variable if possible. Otherwise the code is unchanged.
/*
Util functions used by writeback. Creates a map of event display
names to event ids.
*/
private function makeEventMap()
{
$getEventNames = REDCap::getEventNames(false);
$map = !$getEventNames ?: array_flip($getEventNames);
$map = $map + REDCap::getEventNames(true);
if (empty($map)) {
$map[""] = reset(array_keys(reset(REDCap::getData('array', null, REDCap::getRecordIdField()))));
}
return $map;
}
Hi @jgardner-qha ! Thanks for pointing out this issue. I think the fix will probably look more like the below. I'll probably be able to test and issue a fix tonight.
private function makeEventMap()
{
$map = [];
if ( REDCap::isLongitudinal() ) {
$map = array_flip(REDCap::getEventNames(false));
$map = $map + REDCap::getEventNames(true);
}
if (empty($map)) {
$map[""] = reset(array_keys(reset(REDCap::getData('array', null, REDCap::getRecordIdField()))));
}
return $map;
}
Just pushed the fix for this. I'll be submitting to Vandy in a few. Please let me know when you install and if you can confirm this resolves the issue. Thanks.
I have installed v1.2.5 and it does seem to resolve the problem. Thank you very much!