Generated with the help of an LLM (Gemini).
Problem/Motivation
When a course editor modifies a lesson (e.g., adds, removes, or reorders activities) and clicks the "Reset for updates" button in the course navigation block, the course becomes unplayable with the error:
This activity has been removed from the lesson.
Clicking "Continue" or "Start" does not recover, locking the user out of the course.
Three underlying issues contribute to this:
- Destination parameter trap:
CourseNavBlockBuilder.phpline 227 appends$this->redirectDestination->getAsArray()to the reset URL. If an editor is on an activity delta that is changed or removed (e.g./course/1/0/2), clicking reset immediately redirects back to the stale delta instead of restarting at the course canonical/start page. - Asynchronous status cleanup:
TrainingManager::resetTraining()deletes thelms_course_statusentity, butlmsCourseStatusDelete()(inLmsEntityHooks.php) queues childlms_lesson_statusentities into thelms_delete_entitiescron queue. Until cron runs, the stale lesson statuses and answers remain in the database, retaining obsolete activity deltas. - Broken auto-recovery in error handler: When
TrainingManager::validateCourseDeltas()detects a delta mismatch (lines 453 and 459), it throws:
throw new TrainingException(NULL, TrainingException::ACTIVITY_REMOVED);Because
$courseStatusis passed asNULL,CourseControllerTrait::handleError()cannot run its recovery loop (line 36:if ($course_status !== NULL)). It falls into theelseblock, sets an error messenger notification, and redirects back to group canonical without self-healing the attempt back to delta 0.
Steps to reproduce
- Enable the "Reset for updates" button for course editors option in
/admin/lms/settingsand place the course navigation block. - Take a course as an editor up to activity delta 2 (e.g., 3rd activity).
- Edit the lesson and delete or remove the 3rd activity (or reorder activities).
- Click "Reset for updates" to test the revised lesson.
- Notice the error message "This activity has been removed from the lesson" and that clicking "Continue" fails to restart the lesson.
Proposed resolution
- In
CourseNavBlockBuilder.php, avoid appending the current activity path as thedestinationfor the reset route so it redirects cleanly to the course start or canonical page. - In
TrainingManager::resetTraining(), when invoked for manual editor test resets, synchronously delete associatedlms_lesson_statusandlms_answerrecords rather than waiting for cron. - In
TrainingManager::validateCourseDeltas(), pass$course_statusinstead ofNULLwhen throwingTrainingException::ACTIVITY_REMOVEDandLESSON_REMOVEDsohandleError()can execute its recovery logic.
Remaining tasks
Discuss approach, create issue fork / merge request, and add test coverage.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork lms-3635292
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
graber commentedMerged solution to dev. Please test before we release this if possible.
Comment #6
graber commentedBehavior changes
UI changes
Comment #8
graber commentedThe solution was posted more than 1 week ago, no testing by the reporter or anyone else happened but this has test coverage and is already merged. Setting as fixed, please create follow-ups if needed.
Comment #10
chikeSorry it took me a while to test.
I had a course with a 'True or False' activity which I had taken with my admin account and passed. So to test this I deleted the activity and created a PDF Document activity. So I restarted the course and I only saw a one-time warning that an activity was removed but outside that I wasn't locked out of the course. I proceeded to take the PDF activity and successfully completed the course. Then a student account that had also completed the course restarted the course after I added the PDF activity and he was also able to take the course seamlessly without being locked out and without even seeing the one-time 'activity was removed' message. So it is a smoother experience now. Thanks for the fix.