YAFLogo

squirrel
  • squirrel
  • 100% (Exalted)
  • YAF Leader Topic Starter
11 years ago
When deleting posts from a thread, if one of the posts has been 'reported' to moderators but not 'resolved' you get a FK constraint error:

The DELETE statement conflicted with the REFERENCE constraint "FK_yaf_MessageReportedAudit_yaf_MessageReported". The conflict occurred in database "xxxxxx_fmdata", table "dbo.yaf_MessageReportedAudit", column 'MessageID'.
The statement has been terminated.

The messages got deleted from view, but I have not checked to see if they are removed from the database (DELETE PERMENANTLY was checked when deleting)

I'm sure there is work in progress but wanted to alert to this issue -- A refresh of the page threw a 'handled exception' that was caught by YAF error handler and displayed a YAF error screen, and upon reload of the topic, the threads were not visible. So it at least made the posts unavailable, and they no longer show up in the moderate posts section either.


If you can't find it using the forum search, try my signature link -- searches this site using Google: Google is my Friend 
Sponsor
bbobb
  • bbobb
  • 100% (Exalted)
  • YAF Developer
11 years ago
In message_delete sp,


    if (@EraseMessage = 1) begin
        delete [{databaseOwner}].[{objectQualifier}Attachment] where MessageID = @MessageID
        delete [{databaseOwner}].[{objectQualifier}MessageReported] where MessageID = @MessageID
        delete [{databaseOwner}].[{objectQualifier}MessageReportedAudit] where MessageID = @MessageID
        --delete thanks related to this message

change the order of deleting for tables MessageReportedAudit and MessageReported.

Put MessageReportedAudit first.

squirrel
  • squirrel
  • 100% (Exalted)
  • YAF Leader Topic Starter
11 years ago

In message_delete sp,


    if (@EraseMessage = 1) begin
        delete [{databaseOwner}].[{objectQualifier}Attachment] where MessageID = @MessageID
        delete [{databaseOwner}].[{objectQualifier}MessageReported] where MessageID = @MessageID
        delete [{databaseOwner}].[{objectQualifier}MessageReportedAudit] where MessageID = @MessageID
        --delete thanks related to this message

change the order of deleting for tables MessageReportedAudit and MessageReported.

Put MessageReportedAudit first.

Originally Posted by: bbobb 

This is the complete block as on our SP now -- have yet to test, but thank you for quick patch - in reading the error that should do it --


    -- should it be physically deleter or not?
    if (@EraseMessage = 1) begin
        delete [dbo].[yaf_Attachment] where MessageID = @MessageID
        delete [dbo].[yaf_MessageReportedAudit] where MessageID = @MessageID
        delete [dbo].[yaf_MessageReported] where MessageID = @MessageID
        --delete thanks related to this message
        delete [dbo].[yaf_Thanks] where MessageID = @MessageID
        delete [dbo].[yaf_MessageHistory] where MessageID = @MessageID
        delete [dbo].[yaf_Message] where MessageID = @MessageID
        
    end
    else begin
        -- "Delete" it only by setting deleted flag message
        update [dbo].[yaf_Message] set Flags = Flags | 8 where MessageID = @MessageID
    end

If you can't find it using the forum search, try my signature link -- searches this site using Google: Google is my Friend