gocodebox / gocodebox/lifterlms
Cannot delete enrollments with non 'order_X' trigger from the enrollment metabox in the order edit screen.
- Dominant language
- PHP
- Stars
- 212
- Forks
- 140
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 19
Description
### Reproduction Steps
+ In admin open the order edit screen on an order which has a related enrollment to a course triggered by the order itself:

+ Update the enrollment status to non active, e.g. Expired.
+ Now go edit the course related to the order and from the students table *re-enroll* the student:

The enrollment's trigger is now changed, as it became the "privileged" user who re-enrolled the student.
+ Now click on the 'x' to unenroll (cancel) the user again, now that you can:

+ Go back to the order screen, you'll see the Enrollment status and the trigger changed, also now you have the ability to delete the enrollment: the red button appears as the enrollment status is 'cancelled':

+ Click on `Delete Enrollment` and wait for the page reload.
### Expected Behavior
+ I'd expect the Enrollment to be deleted, hence the meta box showing something of the sort:

### Actual Behavior
+ The Enrollment is not deleted, and the meta box looks like this:

The reason for this is that, in the order screen, we delete the [enrollment passing](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L147) `"order_{$order_id}"` as enrollment trigger, but the trigger has been changed, is not that one anymore.
I'm not sure this is completely intended as it was not so at the beginning (when the enrollments deletion was introduced but before the "button refactoring"). Also consider that when unenrolling, from the same meta box, [we pass 'any' as trigger](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L175). We pass ['any' as trigger](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/class.llms.ajax.handler.php#L878) even when deleting the enrollment from the student's table mb in the course edit screen.
Of course keeping this different behavior for similar, but not equal, actions can make totally sense, and I actually think it does, but in this case we should not display the `Delete Enrollment` button in the order screen if the enrollment trigger is not the order itself.
Do you agree?
Please also note that under Order Notes a new entry has been added, saying that the student enrollment records have been deleted, while they're not.
The reason for this is that we don't expect a deletion failure and always log the success of that action:
https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L149
### Error Messages / Logs
n/a
### System Information
LifterLMS 3.36.1 (but this issue is there since the introduction of the Delete Enrollment button in v3.33.0 I guess)
Contributor guide
Assessment
This issue has not been assessed yet.