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:

  1. Destination parameter trap: CourseNavBlockBuilder.php line 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.
  2. Asynchronous status cleanup: TrainingManager::resetTraining() deletes the lms_course_status entity, but lmsCourseStatusDelete() (in LmsEntityHooks.php) queues child lms_lesson_status entities into the lms_delete_entities cron queue. Until cron runs, the stale lesson statuses and answers remain in the database, retaining obsolete activity deltas.
  3. 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 $courseStatus is passed as NULL, CourseControllerTrait::handleError() cannot run its recovery loop (line 36: if ($course_status !== NULL)). It falls into the else block, sets an error messenger notification, and redirects back to group canonical without self-healing the attempt back to delta 0.

Steps to reproduce

  1. Enable the "Reset for updates" button for course editors option in /admin/lms/settings and place the course navigation block.
  2. Take a course as an editor up to activity delta 2 (e.g., 3rd activity).
  3. Edit the lesson and delete or remove the 3rd activity (or reorder activities).
  4. Click "Reset for updates" to test the revised lesson.
  5. Notice the error message "This activity has been removed from the lesson" and that clicking "Continue" fails to restart the lesson.

Proposed resolution

  1. In CourseNavBlockBuilder.php, avoid appending the current activity path as the destination for the reset route so it redirects cleanly to the course start or canonical page.
  2. In TrainingManager::resetTraining(), when invoked for manual editor test resets, synchronously delete associated lms_lesson_status and lms_answer records rather than waiting for cron.
  3. In TrainingManager::validateCourseDeltas(), pass $course_status instead of NULL when throwing TrainingException::ACTIVITY_REMOVED and LESSON_REMOVED so handleError() 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

Command icon 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

chike created an issue. See original summary.

graber made their first commit to this issue’s fork.

  • graber committed 68f0eff9 on 1.2.x
    #3635292: Implemented stricter lesson / activity nav rules.
    
graber’s picture

Status: Active » Needs review

Merged solution to dev. Please test before we release this if possible.

graber’s picture

Behavior changes

  • Students no longer get stuck after a course is changed while they are taking it, for example after "Reset for updates". Before, every attempt to continue ended with an error and a redirect to the course page.
  • Links to removed lessons or activities, such as bookmarks or browser history, take the student back to their current place in the course.
  • When a lesson is removed from a course, students who were in that lesson start again from the first lesson. Their course status and results are kept, but their answers in the first lesson are reset. If they open another lesson of the course instead, they simply continue there.
  • Removing an activity from a lesson doesn't affect students who already started that lesson. They finish it with the activities it had when they started.
  • With "Use revisions" enabled, students keep the version of the course they started, so removing lessons or activities doesn't affect them.

UI changes

  • A lesson or activity that is part of any student's progress, including finished courses, can no longer be deleted. The delete form shows "This lesson/activity is a part of student progress records and cannot be deleted." and the Delete button is disabled. With "Use revisions" enabled, this also applies to lessons that are still in the course version a student is taking. Removing them from courses and lessons is still possible.
  • The warnings shown when deleting or reverting an activity revision now also count students who started the lesson but haven't answered that activity yet.

  • graber committed 06d755cf on 1.2.x
    #3635292: Extend test coverage with removed cativities in non-revision...
graber’s picture

Status: Needs review » Fixed

The 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

chike’s picture

Sorry 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.