Delete old calendar events before creating new ones #786
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.
We are currently creating duplicate events in the Moodle calendar when we change the name of a TT assignment part. This is because in our logic to update an existing calendar event we find the event using a sql query with the event name. Since the name has just been changed, we look for the event using the new name and fail to find it, so instead of updating the old record a new one is created. To fix this I delete the event before updating the name. After that the name is updated, the new event is created.
You may very well ask why we don't just store the ID of the event as a foreign key in the TT database table. To that I say good question. I agree this would be a better solution, but it would require adding database fields and would not be backward compatible when migrating plugin versions. Also it is possible to create additional events and link them to a TT assignment, further complicating things. Ideally a full rewrite of the way we handle events would be in order, but for now this will suffice to fix the bug we are seeing.