| @@ -645,8 +645,20 @@ | ||
| 645 | 645 | //$user_course->save(); |
| 646 | 646 | $return = $user_course->complete( LP_COURSE_FINISHED ); |
| 647 | 647 | |
| 648 | 648 | if ( $return ) { |
| 649 | + /** | |
| 650 | + * LP_User_Item::complete() writes straight to the table, so it never runs | |
| 651 | + * UserCourseModel::clean_caches() the way UserItemModel::save() does. The | |
| 652 | + * cached model still reports the enrollment as in progress, and that cache | |
| 653 | + * outlives the request wherever a persistent object cache is installed - the | |
| 654 | + * course then reads back unfinished and keeps offering "Finish course". | |
| 655 | + */ | |
| 656 | + $userCourseModel = UserCourseModel::find( $this->get_id(), $course_id ); | |
| 657 | + if ( $userCourseModel instanceof UserCourseModel ) { | |
| 658 | + $userCourseModel->clean_caches(); | |
| 659 | + } | |
| 660 | + | |
| 649 | 661 | do_action( 'learn-press/user-course-finished', $course_id, $this->get_id(), $return ); |
| 650 | 662 | } |
| 651 | 663 | } |
| 652 | 664 | |