Skip to content

Conversation

@TamaroWalter
Copy link
Member

@TamaroWalter TamaroWalter commented Dec 31, 2025

🔀 Purpose of this PR:

  • Fixes a bug
  • Updates for a new Moodle version
  • Adds a new feature of functionality
  • Improves or enhances existing features
  • Refactoring: restructures code for better performance or maintainability
  • Testing: add missing or improve existing tests
  • Miscellaneous: code cleaning (without functional changes), documentation, configuration, ...

📝 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 $draftid for
module 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 references
0 for the firstpost. 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 the post-id is 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 firstpost still had 0 as value. The render functionality then crashed because it did not found the post with id 0

What is the solution?

The solution is quite simple. By building the $draftid for 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):

  • Code passes the code checker without errors and warnings.
  • Code passes the moodle-ci/cd pipeline on all supported Moodle versions or the ones the plugin supports.
  • Code does not have var_dump() or var_export or any other debugging statements (or commented out code) that
    should not appear on the productive branch.

🔍 Related Issues

introeditor are used for module descriptions. Post messages need another draftid to wrap videos properly.
@TamaroWalter TamaroWalter self-assigned this Dec 31, 2025
@TamaroWalter TamaroWalter merged commit 16f6178 into main Dec 31, 2025
48 checks passed
@TamaroWalter TamaroWalter deleted the fix/videomessage branch December 31, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - adding video to message

2 participants