Deleting dead tickets from RT 2.0.x


I’m wanting to rid our RT database of all references to dead tickets.
Can anyone see any errors in the below script logic.

The main part is the user deletion - could a User be referenced in some
other table, without having an entry in the Transactions table?



remove tickets,transactions,attachments,watchers

@tickets = “select id from Tickets where (Status = ‘dead’)”;
foreach my $ticket (@tickets) {
@trans = "select id from Transactions where (Ticket = ‘$ticket’)
foreach my $trans (@trans) {
“delete from Attachments where (TransactionID = ‘$trans’)”;
“delete from Transactions where (Ticket = ‘$ticket’)”;
“delete from Watchers where (Value = ‘$ticket’)”;
“delete from Tickets where (id = ‘$ticket’)”;

remove any users with no ticket association

@users = “select id from Users where (Priveleged = 0)”;
foreach my $user (@users) {
$num = “select count(*) from Transactions where (Creator = ‘$user’)”;
if ($num == 0) { “delete from Users where (id = ‘$user’)”; }