vanderbilt-redcap / email-alerts-module

Module to send customized emails alerts after a form/survey is completed to one or several recipients.
MIT License
1 stars 9 forks source link

Fatal error in PHP 8 #32

Open zenourn opened 2 years ago

zenourn commented 2 years ago

When using REDCap 12.2.1 and PHP 8.0.14 I get a fatal error when attempting to configure this within a project:

REDCap crashed due to an unexpected PHP fatal error!

Error message: Uncaught TypeError: sizeof(): Argument #1 ($value) must be of type Countable|array, null given in modules/email_alerts_v2.3.14/configure.php:46 Stack trace: #0 modules/email_alerts_v2.3.14/configure.php(46): sizeof() #1 redcap_v12.2.1/ExternalModules/index.php(126): require('...') #2 {main} thrown
File: modules/email_alerts_v2.3.14/configure.php
Line: 46

based upon a similar error in another external module:

https://community.projectredcap.org/questions/119956/cross-project-piping-php-8-error.html

It looks like this module is incompatible with PHP 8?

zenourn commented 2 years ago

I got around to fixing this, was due to some changes in PHP8.

in configure.php I changed:

$indexSubSet = sizeof($config['email-dashboard-settings'][1]['value']);

to

$indexSubSet = 0;
$value = $config['email-dashboard-settings'][1]['value'];
if (is_countable($value) && count($value) > 0) {
        $indexSubSet = sizeof($value);
}

in saveForm.php I changed:

$new_alert_id = max($alert_id) + 1;

to:

$max_alert_id = 1;
if (count($alert_id)>0) {
        $max_alert_id = max($alert_id) + 1;
}

and everything seems to work. After further testing and also testing under previous versions of PHP will then submit a PR.