Skip to content

Wrap discussion creation into db transaction#276

Merged
TamaroWalter merged 1 commit into
mainfrom
fix/discussion_transactions
Jul 6, 2026
Merged

Wrap discussion creation into db transaction#276
TamaroWalter merged 1 commit into
mainfrom
fix/discussion_transactions

Conversation

@TamaroWalter

@TamaroWalter TamaroWalter commented Jul 6, 2026

Copy link
Copy Markdown
Member

🔀 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:

The problem: the creation of a new discussion always involves the creation of the first post:

create discussion and save into db
create post and save into db
update discussion->firstpost reference to the recently created post 

If something goes wrong while saving the post into the db, both enitites are saved but the reference to the first post of the discussion does not get updated and stays in a bad state and lost from the discussion view.

The fix: wrapping the discussion creation + firstpost creation + firstpost update into an database transaction ensures that either everything goes correctly or the creation of the discussions fails and needs to be retried.


📋 Checklist

Please confirm the following (check all that apply):

  • I have phpunit and/or behat tests that cover my changes or additions.
  • 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.
  • Code only uses language strings instead of hard-coded strings.

🔍 Related Issues

@TamaroWalter TamaroWalter self-assigned this Jul 6, 2026
@TamaroWalter TamaroWalter linked an issue Jul 6, 2026 that may be closed by this pull request
@TamaroWalter TamaroWalter merged commit 0bb8927 into main Jul 6, 2026
71 of 72 checks passed
@TamaroWalter TamaroWalter deleted the fix/discussion_transactions branch July 6, 2026 22:07
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.

Error message, if the first post is not available

1 participant