[3.0] Save one recipient's copy of a personal message, not everybody's - #9460
Open
albertlast wants to merge 1 commit into
Open
[3.0] Save one recipient's copy of a personal message, not everybody's#9460albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
A row in pm_recipients is one member's copy of one personal message, and (id_pm, id_member) is its primary key. Received::save() named only the PM in its WHERE clause and set id_member in the SET clause, so the statement asked the database to hand every recipient's copy to the same member. Any PM with more than one recipient therefore fails with a duplicate key error the moment something saves it - labelling it, marking it read, deleting it. On this install, applying a label to a PM sent to two people gives "Duplicate entry '4-2' for key 'smf_pm_recipients.PRIMARY'". The member goes in the WHERE clause instead of the SET clause; a copy's owner is its identity, not something a save changes. Labels are owned by a member too, so the same applies to the labelled messages the save clears out: it deleted every label on that PM, including the ones belonging to the other recipients. That line is only reachable for a PM with other recipients now that the update above works, so both belong in the same change. Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
A row in
pm_recipientsis one member's copy of one personal message, and(id_pm, id_member)is its primary key.Received::save()named only the PM in itsWHEREclause, and setid_memberin theSETclause:So the statement asks the database to hand every recipient's copy to the same member. On any PM with more than one recipient that is a duplicate key error, every time, for anything that saves — labelling it, marking it read, deleting it.
Reproduced on a clean install: send a PM to two members, then apply a label to it from the inbox.
The member belongs in the
WHEREclause rather than theSETclause — a copy's owner is its identity, not something a save changes. With that, both recipients keep their own row and their own state; the unread flag on the copy that was not being saved survives, where before the whole statement was rejected.Labels are owned by a member too, so the same applies to the labelled messages the save clears out. It deleted every label on that PM:
pm_labelsrows carry anid_member, so a PM labelled by two recipients has a row per member here, and saving one member's labels threw away the other's. Fixture with(label 2, pm 4)owned by member 1 and(label 4, pm 4)owned by member 2, saving member 1's labels:2-42-4,4-4That line is only reachable for a PM that has other recipients once the update above works, which is why the two are one change. The subquery is over a different table, so it is fine on MySQL and on PostgreSQL.
Found while sweeping the personal messages area. Two other faults sit alongside this one and are going up separately:
Received::loadByPm()collapses every recipient of a PM into one, and the per-message label drop-down submits a valueapplyActions()no longer accepts.Issues References (Fixes|Related|Closes)
n/a