Stored Procedures [dbo].[MssWebDeleteDocument]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inOrderIdint4
@inDocumentIdint4
@inDocumentDeletionReasonIdint4
@inClientSysUserIdint4
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE PROCEDURE [dbo].[MssWebDeleteDocument]
    @inOrderId int = 0,
    @inDocumentId int,
    @inDocumentDeletionReasonId int,
    @inClientSysUserId int
AS
begin
    set nocount on


    declare @thePreviousDocImageId int = (
        select top 1 MssDocumentImageFID
        from MssDocument
        where
            OrderFID = @inOrderId and --prevent bad actors from accessing documents for a different order.
            MssDocumentID = @inDocumentId )

    if @thePreviousDocImageId is null
    begin
        -- either the image is already gone (a race condition with another user), or the client is a bad actor, so
        -- stop doing work.
        return;
    end

    --delete metadata
    update MssDocument set
        DocumentDeletionReasonFID = @inDocumentDeletionReasonId,
        DeletedOn = getdate(),
        DeletedBy = @inClientSysUserId,
        MSSDocumentImageFID = null,

        -- At time of writing (2022-07-25), it is now known that all customers have moved past hosting their content at URLS
        -- Given that, we should probably think about removing this column (and any remaining functionality which references it)
        ContentUrl = null
    where MssDocument.MssDocumentID = @inDocumentId

    --delete document bytes
    delete from MssDocumentImage where MssDocumentImageId = @thePreviousDocImageId

end
GO
GRANT EXECUTE ON  [dbo].[MssWebDeleteDocument] TO [MssExec]
GO
Uses