Deleting tickets recursively

I have a script that creates a ticket, then one or more child tickets of
that ticket in a different queue, and then one or more child tickets of
them in yet another queue. I also wrote a test to call that script and
then verify that the expected tickets exist, etc. However, when I try to
clean up at the end of the test, I have a sub that takes the top level
ticket and recurses down through the children trying to delete them, but
unfortunately only the top level one gets deleted. Here’s the code:

sub recursiveDelete {
my $ticketId = shift;

my $ticket = RT::Ticket->new(RT::SystemUser);
$ticket->Load($ticketId);

my $children = $ticket->Members;
while (my $child = $children->Next)
{
recursiveDelete($child->id);
}

$ticket->Delete;
}

I traced through it in the perl debugger, and the problem appears to be in
Ticket::SetStatus(‘deleted’) where it calls $self->__Value(‘status’) and it
returns ‘deleted’. So it thinks it’s already deleted and doesn’t change
the status. Any suggestions why this is happening?

http://www.linkedin.com/in/paultomblin
http://careers.stackoverflow.com/ptomblin

recursiveDelete($child->id);

Never mind, figured it out. That should be
“recursiveDelete($child->BaseObj->id);”

http://www.linkedin.com/in/paultomblin
http://careers.stackoverflow.com/ptomblin