Fix exception when adding a video to a post #255
Merged
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.
🔀 Purpose of this PR:
📝 Description:
This PR fixes #248.
When a user created a new discussion and added a video to the first post, the moodleoverflow crashed. When a user tried to edit a post by adding a video, the video would not play.
What was the problem?
Both situation were based on the same problem. THe
post-class function that moves files from the form into a permanent file area (file_save_draft_area_files) used a$draftidformodule descriptions (
introeditor) and not for post messages. Due to that, files like videos were not uploaded into the draft area and an error ocurred.A new discussion in particular crashed in this scenario because of the way a post is created. A discussion is created before the post and because of that the
discussion-object references0for thefirstpost. Then a post is created (which needs a valid discussion id to be created): the post is inserted into the database, the files are uploaded in the file area, the post gets updated in the database with the new files and then thepost-idis returned to the discussion, which updates the post reference.Due to the draft-id error, the post was in the database but not rightly updated and the discussion could not reference it because the
firstpoststill had0as value. The render functionality then crashed because it did not found the post with id0What is the solution?
The solution is quite simple. By building the
$draftidfor message forms, moodle can upload and show the videos. The post and the discussion get updated correctly and everything works as it should.📋 Checklist
Please confirm the following (check all that apply):
var_dump()orvar_exportor any other debugging statements (or commented out code) thatshould not appear on the productive branch.
🔍 Related Issues