Update logic for lesson completion check#8025
Open
markcummins wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Sensei_Utils::user_completed_lesson() incorrectly returning false in HPPS (tables-based progress) when a lesson is manually marked complete for a quiz that has Pass Required enabled, but no corresponding quiz progress row exists.
Changes:
- Updates the Pass Required logic to only return early when quiz progress is missing and the lesson progress is not already
complete. - Adds an explanatory inline comment describing why lesson completion can be authoritative when quiz progress is missing (manual completions / migrated data).
- Tweaks an existing inline comment (but it still contains a typo after this PR).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // In the comments-based progress we use one entry to store both the lesson progress and the quiz progress. | ||
| // In the tables-based progress we split them. Here is important to use the quiz proress if the quiz pass is required. | ||
| // In the tables-based progress we split them. Here is important to use the quiz progess if the quiz pass is required. |
Comment on lines
1828
to
1835
| $quiz_progress = Sensei()->quiz_progress_repository->get( $lesson_quiz_id, $user_id ); | ||
| if ( $quiz_progress ) { | ||
| $user_lesson_status = $quiz_progress->get_status(); | ||
| } else { | ||
| } elseif ( $user_lesson_status !== 'complete' ) { | ||
| // A lesson already marked complete is authoritative: no quiz row exists for manual | ||
| // completions and lessons migrated from the comments-based system. | ||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #
Proposed Changes
user_completed_lesson()incorrectly returningfalsefor lessons manually marked complete when using HPPS (tables-based progress storage).In the comments-based system a single
sensei_lesson_statuscomment serves as both lesson progress and quiz progress. In HPPS these are stored as separate rows (type = 'lesson'andtype = 'quiz'insensei_lms_progress). When a lesson is manually marked complete (bypassing the normal quiz submission flow) only atype = 'lesson'row is created but notype = 'quiz'row exists.Previously, when
_pass_requiredwastrueandquiz_progress_repository->get()returnednull, the code unconditionally returnedfalse, even when the lesson progress row already heldstatus = 'complete'. The fix adds anelseifso that if a lesson is marked as complete, the function continues rather than returning early.Testing Instructions
Sensei_Utils::user_completed_lesson( $lesson_id, $user_id )returnstruefor that student.Before fix: step 4 returns
falsewith HPPS enabled; the same scenario returnstruewith comments-based storage.After fix: step 4 returns
truein both storage modes.New/Updated Hooks
Deprecated Code
Pre-Merge Checklist
Changelog entry
Changelog Entry Details
Significance
Type
Message
Fix
user_completed_lesson()returning false for manually-completed lessons when using HPPS (tables-based progress storage) with Pass Required enabled.