[Rt-commit] r5709 - in rt/branches/3.7-EXPERIMENTAL: .
html/Admin/Tools/Shredder/Search lib/t/regression/shredder sbin
ruz at bestpractical.com
ruz at bestpractical.com
Sun Aug 6 23:03:32 EDT 2006
Author: ruz
Date: Sun Aug 6 23:03:30 2006
New Revision: 5709
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/Search/index.html
rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder.pm
rt/branches/3.7-EXPERIMENTAL/lib/t/regression/shredder/utils.pl
rt/branches/3.7-EXPERIMENTAL/sbin/rt-shredder.in
Log:
r3605 at cubic-pc: cubic | 2006-08-07 07:09:15 +0400
::Shredder
* switch to new dumper plugins
Modified: rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/Search/index.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/Search/index.html (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/Search/index.html Sun Aug 6 23:03:30 2006
@@ -54,8 +54,10 @@
if( $Wipeout ) {
{ # use additional block({}) to effectively exit block on errors
my $shredder = new RT::Shredder( force => 1 );
- my ($fn, $fh) = $shredder->SetFile;
- push @{ $messages{'Success'} }, "SQL dump file is '$fn'";
+ my $plugin = eval { $shredder->AddDumpPlugin };
+ $catch_non_fatals->() && last if $@;
+
+ push @{ $messages{'Success'} }, "SQL dump file is '". $plugin->FileName ."'";
$shredder->PutObjects( Objects => \@WipeoutObject );
eval { $shredder->WipeoutAll };
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder.pm Sun Aug 6 23:03:30 2006
@@ -1,4 +1,5 @@
package RT::Shredder;
+
use strict;
use warnings;
@@ -188,7 +189,7 @@
Most methods that takes C<Objects> argument use this method to
cast argument value to list of records.
-Returns array of the records.
+Returns an array of records.
For example:
@@ -409,9 +410,9 @@
{
my $self = $_[0];
- foreach ( values %{ $self->{'cache'} } ) {
- next if $_->{'State'} & (WIPED | IN_WIPING);
- $self->Wipeout( Object => $_->{'Object'} );
+ while ( my ($k, $v) = each %{ $self->{'cache'} } ) {
+ next if $v->{'State'} & (WIPED | IN_WIPING);
+ $self->Wipeout( Object => $v->{'Object'} );
}
}
@@ -444,8 +445,8 @@
unless( $object->BeforeWipeout ) {
RT::Shredder::Exception->throw( "BeforeWipeout check returned error" );
}
- my $deps = $object->Dependencies( Shredder => $self );
+ my $deps = $object->Dependencies( Shredder => $self );
$deps->List(
WithFlags => DEPENDS_ON | VARIABLE,
Callback => sub { $self->ApplyResolvers( Dependency => $_[0] ) },
@@ -456,9 +457,8 @@
Callback => sub { $self->_Wipeout( Object => $_[0]->TargetObject ) },
);
- my $insert_query = $object->_AsInsertQuery;
+ $self->DumpObject( Object => $object );
$object->__Wipeout;
- $self->DumpSQL( Query => $insert_query );
$record->{'State'} |= WIPED; delete $record->{'Object'};
$deps->List(
@@ -486,56 +486,38 @@
Shredder allow you to store data you delete in files as scripts with SQL
commands.
-=head3 SetFile( FileName => '<ISO DATETIME>-XXXX.sql', FromStorage => 1 )
-
-Calls C<GetFileName> method to check and translate file name, then checks
-if file is empty, opens it. After this you can dump records with C<DumpSQL>
-method.
+=head3 GetFileName( FileName => '<ISO DATETIME>-XXXX.sql', FromStorage => 1 )
-Returns name and handle.
+Takes desired C<FileName> and flag C<FromStorage> then translate file name to absolute
+path by next rules:
+* Default value of the C<FileName> option is C<< <ISO DATETIME>-XXXX.sql >>;
+* if C<FileName> has C<XXXX> (exactly four uppercase C<X> letters) then it would be
+changed with digits from 0000 to 9999 range, with first one free value;
+* if C<FromStorage> argument is true (default behaviour) then result path would always
+be relative to C<StoragePath>;
+* if C<FromStorage> argument is false then result would be relative to the current
+dir unless it's allready absolute path.
-B<NOTE:> If file allready exists then file content would be overriden.
-Also in this situation method prints warning to the STDERR unless C<force>
-shredder's option is used.
+Returns an absolute path of the file.
Examples:
# file from storage with default name format
- my ($fname, $fh) = $shredder->SetFile;
- # file from storage with custom name format
- my ($fname, $fh) = $shredder->SetFile( FileName => 'shredder-XXXX.backup' );
- # file with path relative to the current dir
- my ($fname, $fh) = $shredder->SetFile( FromStorage => 0, FileName => 'backups/shredder.sql' );
- # file with absolute path
- my ($fname, $fh) = $shredder->SetFile( FromStorage => 0, FileName => '/var/backups/shredder-XXXX.sql' );
-
-=cut
+ my $fname = $shredder->GetFileName;
-sub SetFile
-{
- my $self = shift;
- my $file = $self->GetFileName( @_ );
- if( -s $file ) {
- print STDERR "WARNING: file '$file' is not empty, content would be overwriten\n" unless $opt{'force'};
- }
- open my $fh, ">$file" or die "Couldn't open '$file' for write: $!";
- ($self->{'opt'}->{'sqldump_fn'}, $self->{'opt'}->{'sqldump_fh'}) = ($file, $fh);
- return ($file, $fh);
-}
-
-=head3 GetFileName( FileName => '<ISO DATETIME>-XXXX.sql', FromStorage => 1 )
-
-Takes desired C<FileName> and flag C<FromStorage> then translate file name to absolute
-path by next rules:
-* Default C<FileName> value is C<< <ISO DATETIME>-XXXX.sql >>;
-* if C<FileName> has C<XXXX> (exactly four uppercase C<X> letters) then it would be changed with
-digits from 0000 to 9999 range, with first one notexistant value;
-* if C<FromStorage> argument is true then result path would always be relative to C<StoragePath>;
-* if C<FromStorage> argument is false then result would be relative to the current dir unless it's
-allready absolute path.
+ # file from storage with custom name format
+ my $fname = $shredder->GetFileName( FileName => 'shredder-XXXX.backup' );
-Returns file absolute path.
+ # file with path relative to the current dir
+ my $fname = $shredder->GetFileName(
+ FromStorage => 0,
+ FileName => 'backups/shredder.sql',
+ );
-See example for method C<SetFile>
+ # file with absolute path
+ my $fname = $shredder->GetFileName(
+ FromStorage => 0,
+ FileName => '/var/backups/shredder-XXXX.sql'
+ );
=cut
@@ -548,7 +530,7 @@
my $file = $args{'FileName'};
unless( $file ) {
require POSIX;
- $file = POSIX::strftime("%Y%m%dT%H%M%S-XXXX.sql", gmtime );
+ $file = POSIX::strftime( "%Y%m%dT%H%M%S-XXXX.sql", gmtime );
}
# convert to absolute path
@@ -599,9 +581,9 @@
F</path-to-RT-var-dir/data/RTx-Shredder/>
(in default RT install would be F</opt/rt3/var/data/RTx-Shredder>),
but you can change this value with config option C<$RT::ShredderStoragePath>.
-See C<CONFIGURATION> sections in this doc.
+See L</CONFIGURATION> sections.
-See C<SetFile> and C<GetFileName> methods description.
+See also description of the L</GetFileName> method.
=cut
@@ -611,16 +593,31 @@
return File::Spec->catdir( $RT::VarPath, qw(data RTx-Shredder) );
}
-sub DumpSQL
-{
+sub AddDumpPlugin {
my $self = shift;
- return unless exists $self->{'opt'}->{'sqldump_fh'};
+ my %args = ( Name => 'SQLDump', Arguments => {}, @_ );
- my %args = ( Query => undef, @_ );
- $args{'Query'} .= "\n" unless $args{'Query'} =~ /\n$/;
+ my $plugin = RT::Shredder::Plugin->new;
+ my( $status, $msg ) = $plugin->LoadByName( $args{'Name'} );
+ die "Couldn't load dump plugin: $msg\n" unless $status;
+ die "Plugin '$args{'Name'}' is not of correct type"
+ unless $plugin->Type eq 'dump';
- my $fh = $self->{'opt'}->{'sqldump_fh'};
- return print $fh $args{'Query'} or die "Couldn't write to filehandle";
+ ($status, $msg) = $plugin->TestArgs( %{ $args{'Arguments'} } );
+ die "Couldn't set plugin args: $msg\n" unless $status;
+
+ push @{ $self->{'opt'}{'dump_plugins'} ||= [] }, $plugin;
+
+ return $plugin;
+}
+
+sub DumpObject {
+ my $self = shift;
+ foreach ( @{ $self->{'opt'}->{'dump_plugins'} } ) {
+ my ($state, $msg) = $_->Run( @_ );
+ die "Couldn't run plugin: $msg" unless $state;
+ }
+ return;
}
1;
@@ -646,7 +643,7 @@
=head1 BUGS AND HOW TO CONTRIBUTE
-I need your feedback in all cases: if you use it or not,
+We need your feedback in all cases: if you use it or not,
is it works for you or not.
=head2 Testing
@@ -689,7 +686,6 @@
=head1 SEE ALSO
-L<rtx-shredder>, L<rtx-validator>
+L<rt-shredder>, L<rt-validator>
=cut
-
Modified: rt/branches/3.7-EXPERIMENTAL/lib/t/regression/shredder/utils.pl
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/t/regression/shredder/utils.pl (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/t/regression/shredder/utils.pl Sun Aug 6 23:03:30 2006
@@ -177,8 +177,13 @@
sub shredder_new
{
my $obj = new RT::Shredder;
+
my $file = File::Spec->catfile( tmpdir(), test_name() .'.XXXX.sql' );
- $obj->SetFile( FileName => $file, FromStorage => 0 );
+ $obj->AddDumpPlugin( Arguments => {
+ file_name => $file,
+ from_storage => 0,
+ } );
+
return $obj;
}
Modified: rt/branches/3.7-EXPERIMENTAL/sbin/rt-shredder.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/sbin/rt-shredder.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/sbin/rt-shredder.in Sun Aug 6 23:03:30 2006
@@ -81,18 +81,20 @@
my $shredder = new RT::Shredder;
{
- local $@;
- my ($file, $fh) = eval { $shredder->SetFile( FileName => $opt{'sqldump'}, FromStorage => 0 ) };
+ my $plugin = eval { $shredder->AddDumpPlugin( Arguments => {
+ file_name => $opt{'sqldump'},
+ from_storage => 0,
+ } ) };
if( $@ ) {
print STDERR "ERROR: Couldn't open SQL dump file: $@\n";
- exit(1) if $opt{'sqldump'};
+ exit 1 if $opt{'sqldump'};
print STDERR "WARNING: It's strongly recommended to use '--sqldump <filename>' option\n";
unless( $opt{'force'} ) {
- exit(0) unless prompt_yN( "Do you want to proceed?" );
+ exit 0 unless prompt_yN( "Do you want to proceed?" );
}
} else {
- print "SQL dump file is '$file'\n";
+ print "SQL dump file is '". $plugin->FileName ."'\n";
}
}
@@ -182,8 +184,9 @@
sub process_plugins
{
- my @res;
my $shredder = shift;
+
+ my @res;
foreach my $str( @{ $opt{'plugin'} } ) {
my $plugin = new RT::Shredder::Plugin;
my( $status, $msg ) = $plugin->LoadByString( $str );
More information about the Rt-commit
mailing list