health-check
health-check copied to clipboard
Defect in class-health-check-site-status due to two different data models being treated as String
Feature request/bug description
During a deactivation and reactivation of the Health Check plugin, errors show up in the debug logs, because two different data models are being treated as a String:
Where $test['test'] is used, sometimes this is an Array of data with the FULL test name being located at element [1], and sometimes it is just a plain String (which worked with the existing code in this file).
FIX
The fix is to test if the variable test['test'] is an array or a String, and if an array, use the element at [1] with no alteration, else, use the String but prefix it with 'get_test_'
Here is the rewritten foreach I'm suggesting, where I located the issue:
foreach ( $tests as $test ) {
if (is_array($test['test'])) {
$function = sprintf(
'%s',
$test['test'][1]
);
} else {
$function = sprintf(
'get_test_%s',
$test['test']
);
}
if ( method_exists( $this, $function ) && is_callable( array( $this, $function ) ) ) {
$results[] = call_user_func( array( $this, $function ) );
} else {
if (is_array($test['test'])) {
$results[] = call_user_func( $test['test'][1] );
} else {
$results[] = call_user_func( 'get_test_%s' . $test['test'] );
}
}
}
DATA of test['test']
Sometimes it looks like this:
[test] => Array (
[0] => Health_Check_Site_Status Object
(
[mysql_min_version_check:Health_Check_Site_Status:private] => 1
[mysql_rec_version_check:Health_Check_Site_Status:private] => 1
[is_mariadb] => 1
[mysql_server_version:Health_Check_Site_Status:private] => 10.3.23-MariaDB-log-cll-lve
[health_check_mysql_required_version:Health_Check_Site_Status:private] => 5.5
[health_check_mysql_rec_version:Health_Check_Site_Status:private] => 10.0
)
[1] => get_test_timezone_not_utc
)
Sometimes it looks like this: ‘loopback_requests’ or ‘dotorg_communication’
+1
As the logic relating to Site Health Checks have been moved fully into core, where this issue was fixed, I'm going to close this ticket.
Thank you all for the valuable input, and the detailed bug report.