Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn M Moore <shawn@bestpractical.com>2017-03-27 23:51:39 +0300
committerShawn M Moore <shawn@bestpractical.com>2017-03-27 23:53:51 +0300
commitb2153330fe57302aceba56435d96de9b40f102b6 (patch)
treea0b041562f5cfed4cd79a0b1d6b0715038f8c8f2
parentaefb477bd68d1b0b5319b67d4881712fa854347c (diff)
Add --update-existing to rt-importer4.2/serialize-ticket
This lets you take updates from the dump for a subset of your record types.
-rw-r--r--lib/RT/Migrate/Importer.pm32
-rw-r--r--sbin/rt-importer.in25
2 files changed, 53 insertions, 4 deletions
diff --git a/lib/RT/Migrate/Importer.pm b/lib/RT/Migrate/Importer.pm
index 718b165096..4562091fa3 100644
--- a/lib/RT/Migrate/Importer.pm
+++ b/lib/RT/Migrate/Importer.pm
@@ -50,6 +50,7 @@ package RT::Migrate::Importer;
use strict;
use warnings;
+use 5.010;
use Storable qw//;
use File::Spec;
@@ -72,6 +73,7 @@ sub Init {
HandleError => undef,
ExcludeOrganization => undef,
FollowRenames => undef,
+ UpdateExisting => undef,
@_,
);
@@ -80,6 +82,7 @@ sub Init {
$self->{ExcludeOrganization} = $args{ExcludeOrganization};
$self->{FollowRenames} = $args{FollowRenames};
+ $self->{UpdateExisting} = $args{UpdateExisting};
$self->{Progress} = $args{Progress};
@@ -247,10 +250,20 @@ sub ShouldSkipTransaction {
sub MergeValues {
my $self = shift;
- my ($obj, $data) = @_;
+ my ($obj, $data, $update) = @_;
+
for my $col (keys %{$data}) {
- next if defined $obj->__Value($col) and length $obj->__Value($col);
- next unless defined $data->{$col} and length $data->{$col};
+ my $current = $obj->__Value($col);
+
+ if ($update) {
+ next if $col eq 'id';
+ next if !defined($data->{$col});
+ next if ($current // "") eq $data->{$col};
+ }
+ else {
+ next if defined $current and length $current;
+ next unless defined $data->{$col} and length $data->{$col};
+ }
if (ref $data->{$col}) {
my $uid = ${ $data->{$col} };
@@ -448,7 +461,8 @@ sub ReadStream {
$obj = $self->LoadForReuse( $class, $uid );
if ($obj) {
$self->Resolve( $uid => $class => $obj->Id );
- #$self->MergeValues( $obj, $data );
+ $self->MergeValues( $obj, $data, 1 )
+ if $self->ShouldUpdateExisting($obj, $data);
}
}
@@ -487,6 +501,16 @@ sub ReadStream {
$self->{Progress}->($obj) if $self->{Progress};
}
+sub ShouldUpdateExisting {
+ my $self = shift;
+ my $obj = shift;
+
+ my $type = ref($obj);
+ $type =~ s/^RT:://;
+
+ return grep { lc($_) eq lc($type) } @{ $self->{UpdateExisting} || [] };
+}
+
sub CloseStream {
my $self = shift;
diff --git a/sbin/rt-importer.in b/sbin/rt-importer.in
index 86338c893a..2246a71bd5 100644
--- a/sbin/rt-importer.in
+++ b/sbin/rt-importer.in
@@ -97,6 +97,7 @@ GetOptions(
"originalid|i=s",
"exclude-organization",
"follow-renames",
+ "update-existing=s@",
"ask",
"ignore-errors",
@@ -143,11 +144,26 @@ elsif ($OPT{'ignore-errors'}) {
};
}
+if ($OPT{'update-existing'}) {
+ die "--update-existing requires --follow-renames.\n"
+ unless $OPT{'follow-renames'};
+
+ my @types;
+
+ for my $type (split ',', join ',', @{ $OPT{'update-existing'} }) {
+ $type =~ s/^\s+//; $type =~ s/\s+$//;
+ push @types, $type;
+ }
+
+ $OPT{'update-existing'} = \@types;
+}
+
my $import = RT::Migrate::Importer::File->new(
Directory => $dir,
OriginalId => $OPT{originalid},
ExcludeOrganization => $OPT{'exclude-organization'},
FollowRenames => $OPT{'follow-renames'},
+ UpdateExisting => $OPT{'update-existing'},
DumpObjects => $OPT{dump},
Resume => $OPT{resume},
HandleError => $error_handler,
@@ -264,6 +280,15 @@ small collections.
This is not meant to be used with C<--clone> or C<--incremental>.
+=item B<--update-existing> I<types>
+
+When used with C<--follow-renames>, this I<updates> records of the
+specified types with the data from the dump. I<types> should be a
+comma-separated list of RT type names; specifically class names
+without the C<RT::> part). For example, to update queues and custom
+fields with updates from the dumped data, pass C<--update-existing
+Queue,CustomField>.
+
=item B<--ask>
Prompt for action when an error occurs inserting a record into the