Question about drafts messages

Good day.

I am using plugin https://metacpan.org/pod/RT::Extension::Drafts . The plugin works well, but I am not understand how to delete drafts. For example once in a while.

What is the most correct way to delete drafts using RT?

I see drafts being written to the Attributes table. and I can delete it with a third-party script like this:

delete from Attributes where Name like ‘Draft%’ and LastUpdated < now() - INTERVAL 7 DAY;

but maybe there is a way to solve this using RT?

If you wanted to do it in Perl, and assuming you had the ticket object for the ticket you’re interested in in $Ticket, I think something like this should do it:

    my $Draft = RT::Attribute->new( $session{'CurrentUser'} );
    $Draft->LoadByNameAndObject( Object => $session{'CurrentUser'}->UserObj, Name => 'Draft-'.$Ticket->id );
    $Draft->Delete if ( $Draft && $Draft->Id );

That was totally lifted out of the extension’s code. :slight_smile:

thanks for reply.
yes, you’re right - there is such a code. and it even works - the draft is really deleted after saving the ticket. Now I don’t understand why I have several drafts in this table …

I understand.
The draft is only deleted if the user has changed the ticket. if for some reason the changes in the ticket were not saved, the draft will remain in the database.