diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
commit | 1c538bfabc2cd31f27067505f0c3d1a46cba6ef0 (patch) | |
tree | 96922ad4459eda1e649327fd391d60c58d454c53 /rt/lib/RT/Migrate/Serializer | |
parent | 4f5619288413a185e9933088d9dd8c5afbc55dfa (diff) |
RT 4.2.11, ticket#13852
Diffstat (limited to 'rt/lib/RT/Migrate/Serializer')
-rw-r--r-- | rt/lib/RT/Migrate/Serializer/File.pm | 171 | ||||
-rw-r--r-- | rt/lib/RT/Migrate/Serializer/IncrementalRecord.pm | 80 | ||||
-rw-r--r-- | rt/lib/RT/Migrate/Serializer/IncrementalRecords.pm | 69 |
3 files changed, 320 insertions, 0 deletions
diff --git a/rt/lib/RT/Migrate/Serializer/File.pm b/rt/lib/RT/Migrate/Serializer/File.pm new file mode 100644 index 000000000..283236595 --- /dev/null +++ b/rt/lib/RT/Migrate/Serializer/File.pm @@ -0,0 +1,171 @@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# <sales@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} + +package RT::Migrate::Serializer::File; + +use strict; +use warnings; + +use base 'RT::Migrate::Serializer'; + +sub Init { + my $self = shift; + + my %args = ( + Directory => undef, + Force => undef, + MaxFileSize => 32, + + @_, + ); + + # Set up the output directory we'll be writing to + my ($y,$m,$d) = (localtime)[5,4,3]; + $args{Directory} = $RT::Organization . + sprintf(":%d-%02d-%02d",$y+1900,$m+1,$d) + unless defined $args{Directory}; + system("rm", "-rf", $args{Directory}) if $args{Force}; + die "Output directory $args{Directory} already exists" + if -d $args{Directory}; + mkdir $args{Directory} + or die "Can't create output directory $args{Directory}: $!\n"; + $self->{Directory} = delete $args{Directory}; + + # How many megabytes each chunk should be, approximitely + $self->{MaxFileSize} = delete $args{MaxFileSize}; + + # Which file we're writing to + $self->{FileCount} = 1; + + $self->SUPER::Init(@_); +} + +sub Metadata { + my $self = shift; + return $self->SUPER::Metadata( + Files => [ $self->Files ], + @_, + ) +} + +sub Export { + my $self = shift; + + # Set up our output file + $self->OpenFile; + + # Write the initial metadata + $self->InitStream; + + # Walk the objects + $self->Walk( @_ ); + + # Close everything back up + $self->CloseFile; + + # Write the summary file + Storable::nstore( + $self->Metadata( Final => 1 ), + $self->Directory . "/rt-serialized" + ); + + return $self->ObjectCount; +} + +sub Visit { + my $self = shift; + + # Rotate if we get too big + my $maxsize = 1024 * 1024 * $self->{MaxFileSize}; + $self->RotateFile if tell($self->{Filehandle}) > $maxsize; + + # Serialize it + $self->SUPER::Visit( @_ ); +} + + +sub Files { + my $self = shift; + return @{ $self->{Files} }; +} + +sub Filename { + my $self = shift; + return sprintf( + "%s/%03d.dat", + $self->{Directory}, + $self->{FileCount} + ); +} + +sub Directory { + my $self = shift; + return $self->{Directory}; +} + +sub OpenFile { + my $self = shift; + open($self->{Filehandle}, ">", $self->Filename) + or die "Can't write to file @{[$self->Filename]}: $!"; + push @{$self->{Files}}, $self->Filename; +} + +sub CloseFile { + my $self = shift; + close($self->{Filehandle}) + or die "Can't close @{[$self->Filename]}: $!"; + $self->{FileCount}++; +} + +sub RotateFile { + my $self = shift; + $self->CloseFile; + $self->OpenFile; +} + +1; diff --git a/rt/lib/RT/Migrate/Serializer/IncrementalRecord.pm b/rt/lib/RT/Migrate/Serializer/IncrementalRecord.pm new file mode 100644 index 000000000..d5df8c875 --- /dev/null +++ b/rt/lib/RT/Migrate/Serializer/IncrementalRecord.pm @@ -0,0 +1,80 @@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# <sales@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} + +package RT::Migrate::Serializer::IncrementalRecord; +use base qw/RT::Record/; + +use strict; +use warnings; + +sub Table {'IncrementalRecords'} + +sub _CoreAccessible { + return { + id => { read => 1 }, + ObjectType => { read => 1 }, + ObjectId => { read => 1 }, + UpdateType => { read => 1 }, + AlteredAt => { read => 1 }, + }; +}; + +1; + +__END__ + +CREATE TABLE IncrementalRecords ( + id INTEGER NOT NULL AUTO_INCREMENT, + ObjectType VARCHAR(50) NOT NULL, + ObjectId INTEGER NOT NULL, + UpdateType TINYINT NOT NULL, + AlteredAt TIMESTAMP NOT NULL, + PRIMARY KEY(ObjectType, ObjectId), + UNIQUE KEY(id), + KEY(UpdateType) +); diff --git a/rt/lib/RT/Migrate/Serializer/IncrementalRecords.pm b/rt/lib/RT/Migrate/Serializer/IncrementalRecords.pm new file mode 100644 index 000000000..a729caa8d --- /dev/null +++ b/rt/lib/RT/Migrate/Serializer/IncrementalRecords.pm @@ -0,0 +1,69 @@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# <sales@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} + +package RT::Migrate::Serializer::IncrementalRecords; +use base qw/RT::SearchBuilder/; + +use strict; +use warnings; + +sub _Init { + my $self = shift; + $self->{'table'} = 'IncrementalRecords'; + $self->{'primary_key'} = 'id'; + return ( $self->SUPER::_Init(@_) ); +} + +sub Table {'IncrementalRecords'} + +sub NewItem { + my $self = shift; + return(RT::Migrate::Serializer::IncrementalRecord->new($self->CurrentUser)); +} + +1; |