Problem/Motivation
I've got a fatal error, when a user just enroll in a training and go to the catalog page.
AssertionError: assert(is_numeric($result) && !empty($result)) in assert() (line 744 of modules/contrib/opigno_module/src/Entity/OpignoModule.php)
This error came from OpignoModule:getGroupIdCurrentTraining($group_id) method.
Steps to reproduce
Create a training. User can enroll to the training.
Login with a simple user.
Enroll the training. Don't start the training.
Go to the catalog page.
The website encountered an unexpected error. Please try again later.
AssertionError: assert(is_numeric($result) && !empty($result)) in assert() (line 744 of modules/contrib/opigno_module/src/Entity/OpignoModule.php).
assert(, 'assert(is_numeric($result) && !empty($result))') (Line: 744)
Drupal\opigno_module\Entity\OpignoModule->getGroupIdCurrentTraining(NULL) (Line: 434)
Drupal\opigno_module\Entity\OpignoModule->getModuleAttempts(Object, NULL, NULL, , NULL) (Line: 2839)
opigno_learning_path_get_module_activities('1', '12', , NULL, NULL) (Line: 2964)
opigno_learning_path_get_step_progress(Array, '12', , NULL, NULL) (Line: 3016)
opigno_learning_path_get_step_status(Array, '12', ) (Line: 3159)
If the user start the training then tere is no more fatal error.
Proposed resolution
Looks like the OpignoModule:getGroupIdCurrentTraining($group_id) method can be called with a group ID NULL so the assert check can cause this fatal error.
In this case, this is because the method
opigno_learning_path_is_passed($step, $uid, $current_attempt = FALSE, $expired = FALSE)
call the method
opigno_learning_path_get_step_status($step, $uid, $step_state_counting = FALSE, $latest_cert_date = NULL, $group_id = NULL)
without a group_id with this
$step['status'] = opigno_learning_path_get_step_status($step, $uid, $current_attempt);
The group_id is then NULL.
And this this call this method
$progress = opigno_learning_path_get_step_progress($step, $uid, $step_state_counting, $latest_cert_date, $group_id);
which call
$activities = opigno_learning_path_get_module_activities($step['id'], $uid, $step_state_counting, $latest_cert_date, $group_id);
which call
$attempts = $module->getModuleAttempts($user, NULL, $latest_cert_date, FALSE, $group_id);
which call
$group_id = $this->getGroupIdCurrentTraining($group_id);
and then the assert fails in
public function getGroupIdCurrentTraining($group_id) {
$context_id = OpignoGroupContext::getCurrentGroupId();
$group = $group_id ? Group::load($group_id) : NULL;
if (
$group instanceof Group &&
$group->getGroupType()->id() == 'opigno_course' &&
!empty($context_id) &&
$group_id != $context_id
) {
// If group is opigno_course, get parent training id.
$group_id = $context_id;
}
$result = $group_id ?: $context_id;
assert(is_numeric($result) && !empty($result));
return $result;
}
Remaining tasks
Looks like the assert here shouldn't be. The group ID and context ID can be NULL.
Remove it ?
User interface changes
None
API changes
None
Data model changes
None