Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when removing a student from course #7740

Open
igotdes opened this issue Jan 17, 2025 · 1 comment
Open

Error when removing a student from course #7740

igotdes opened this issue Jan 17, 2025 · 1 comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Status] Triaged Issue has been triaged [Type] Bug

Comments

@igotdes
Copy link

igotdes commented Jan 17, 2025

Steps to Reproduce

So far, we haven't been able to reproduce, but this was reported in this forum thread:

https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18233249

On our site when we remove a user from a course, here is the relevant stack trace:

class-sensei-utils.php(733): Sensei_Lesson->lesson_quiz_questions(‘10055172’)
class-sensei-utils.php(811): Sensei_Utils::sensei_get_quiz_questions(10055172)
class-sensei-utils.php(660): Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405)
class-sensei-utils.php(706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true)
class-sensei-utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405)

Seems like to remove the user from the course it wants to delete their quiz answers but to do that it gets the lesson_quiz_questions but in our case the $questions_array used in this code is empty:

$selected_questions = array_rand(
$questions_array,
$show_questions > $questions_count ? $questions_count : $show_questions
);```

And it errors out because it can’t randomize an empty array.

What I Expected

User should be able to remove students without errors.

What Happened Instead

User said they also installed Twenty Twenty-Five and Health Check. They then went to the Students area of the admin and Reset Progress on a user and it still caused a fatal error:

[15-Jan-2025 20:03:18 UTC] PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty in /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php:3832
Stack trace: 0 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php(3832): array_rand(Array, 0) 1 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(733): Sensei_Lesson->lesson_quiz_questions(‘10055172’) 2 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(811): Sensei_Utils::sensei_get_quiz_questions(10055172) 3 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(660): Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405) 4 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true) 5 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405) 6 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/rest-api/class-sensei-rest-api-course-progress-controller.php(81): Sensei_Utils::reset_course_for_user(85579, 3405) 7 /wp-includes/rest-api/class-wp-rest-server.php(1292): Sensei_REST_API_Course_Progress_Controller->batch_delete_items(Object(WP_REST_Request)) 8 /wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request(Object(WP_REST_Request), ‘/sensei-interna…’, Array, NULL) 9 /wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch(Object(WP_REST_Request)) 10 /wp-includes/rest-api.php(449): WP_REST_Server->serve_request(‘/sensei-interna…’) 11 /wp-includes/class-wp-hook.php(324): rest_api_loaded(Object(WP)) 12 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(”, Array) 13 /wp-includes/plugin.php(565): WP_Hook->do_action(Array) 14 /wp-includes/class-wp.php(418): do_action_ref_array(‘parse_request’, Array) 15 /wp-includes/class-wp.php(813): WP->parse_request(”) 16 /wp-includes/functions.php(1336): WP->main(”) 17 /wp-blog-header.php(16): wp() 18 /index.php(17): require(‘/Users/jon…..’) 19 {main}

thrown in /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php on line 3832

PHP / WordPress / Sensei LMS version

Still waiting for more information from user.

Context / Source

@donnapep's comment on the forum ticket, #9288713-zen:

It would be good to open an issue for this one. Even if it's not reproducible, we can still add a check to ensure that the first parameter isn't empty before calling array_rand

@igotdes igotdes added [Status] Needs Triage Issue needs to be triaged [Type] Bug labels Jan 17, 2025
Copy link

Support References

This comment is automatically generated. Please do not edit it.

  • 9288713-zen

@github-actions github-actions bot added the Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". label Jan 17, 2025
@donnapep donnapep added [Status] Triaged Issue has been triaged and removed [Status] Needs Triage Issue needs to be triaged labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Status] Triaged Issue has been triaged [Type] Bug
Projects
None yet
Development

No branches or pull requests

2 participants