<%ARGS> $Plugin => '' $Search => '' $Wipeout => '' @WipeoutObject => () <& /Admin/Elements/Header, Title => $title &> <& /Admin/Elements/ToolTabs, current_tab => 'Admin/Tools/Shredder', current_subtab => 'Admin/Tools/Shredder', Title => $title, &>
<& /Elements/ListActions, actions => $messages{'Errors'} &> <& /Elements/ListActions, actions => $messages{'Success'} &> <& Elements/SelectPlugin, Plugin => $Plugin, %ARGS &>
<& /Elements/Submit, Name => 'Search', Label => loc('Search') &>

% if( $Search || $Wipeout ) { <& Elements/SelectObjects, Objects => \@objs &> % }
<%INIT> require RTx::Shredder; my $title = loc('Shredder'); my %messages = ( Errors => [], Success => [] ); my ($plugin_obj, @objs); my $catch_non_fatals = sub { require RTx::Shredder::Exceptions; die $@ unless my $e = RTx::Shredder::Exception::Info->caught; push @{ $messages{Errors} }, "$e"; $Search = ''; @objs = (); return 1; }; if( $Plugin ) { { # use additional block({}) to effectively exit block on errors use RTx::Shredder::Plugin; $plugin_obj = new RTx::Shredder::Plugin; my( $status, $msg ) = $plugin_obj->LoadByName( $Plugin ); unless( $status ) { push @{ $messages{Errors} }, $msg; $Search = ''; last; } my %args; foreach my $k( keys %ARGS ) { next unless $k =~ /^\Q$Plugin\E:(.*)$/; $args{ $1 } = $ARGS{$k}; } ( $status, $msg ) = $plugin_obj->HasSupportForArgs( keys %args ); unless( $status ) { push @{ $messages{Errors} }, $msg; $Search = ''; last; } ($status, $msg) = eval { $plugin_obj->TestArgs( %args ) }; $catch_non_fatals->() && last if $@; unless( $status ) { push @{ $messages{Errors} }, $msg; $Search = ''; last; } } } if( $Plugin && $Wipeout ) { { # use additional block({}) to effectively exit block on errors my $shredder = new RTx::Shredder( force => 1 ); my ($fn, $fh) = $shredder->SetFile; push @{ $messages{'Success'} }, "SQL dump file is '$fn'"; $shredder->PutObjects( Objects => \@WipeoutObject ); my ($status, $msg) = $plugin_obj->SetResolvers( Shredder => $shredder ); unless( $status ) { push @{ $messages{Errors} }, $msg; $Search = ''; @objs = (); last; } eval { $shredder->WipeoutAll }; $catch_non_fatals->() && last if $@; push @{ $messages{Success} }, 'objects were successfuly removed'; } } if( $Plugin && ( $Search || $Wipeout ) ) { { # use additional block({}) to effectively exit block on errors my $status; ($status, @objs) = eval { $plugin_obj->Run }; $catch_non_fatals->() && last if $@; unless( $status ) { push @{ $messages{Errors} }, $objs[0]; $Search = ''; @objs = (); last; } push @{ $messages{Success} }, 'executed plugin successfuly'; my $shredder = new RTx::Shredder; foreach my $o( splice @objs ) { eval { push @objs, $shredder->CastObjectsToRecords( Objects => $o ) }; $catch_non_fatals->() && last if $@; } unless( @objs ) { push @{ $messages{Success} }, 'plugin returned empty list'; } else { push @{ $messages{Success} }, 'see object list below'; } } }