[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-334-g7500606
Shawn Moore
shawn at bestpractical.com
Tue Mar 14 17:22:41 EDT 2017
The branch, 4.4/serialize-json-initialdata has been updated
via 7500606c2457b8b5313cea072e872fb9aa2ea081 (commit)
via 893ee935bf4ea12e3daacbc9a401c39df3407dcd (commit)
via 8869e946198c7dd96cabb0bf0b293f34ec96e135 (commit)
from e107e99270e6c179e2aa1f031690899af1099d1c (commit)
Summary of changes:
lib/RT/Migrate/Serializer/JSON.pm | 72 ++++++++++++++++++++++++++++++++++-----
1 file changed, 63 insertions(+), 9 deletions(-)
- Log -----------------------------------------------------------------
commit 8869e946198c7dd96cabb0bf0b293f34ec96e135
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 14 20:58:37 2017 +0000
Canonicalize ObjectClass into Class.ApplyTo
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 54c1800..e1ad317 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -170,21 +170,32 @@ sub CanonicalizeReference {
return $record->{Name} || $ref;
}
-sub CanonicalizeObjects {
+sub _CanonicalizeObjectType {
my $self = shift;
-
- if (my $OCFs = delete $self->{Records}{'RT::ObjectCustomField'}) {
- for my $OCF (values %$OCFs) {
- my $CF = $self->{Records}{'RT::CustomField'}{ ${ $OCF->{CustomField} } };
- push @{ $CF->{ApplyTo} }, $OCF;
+ my $object_class = shift;
+ my $object_primary_ref = shift;
+ my $primary_class = shift;
+
+ if (my $objects = delete $self->{Records}{$object_class}) {
+ for my $object (values %$objects) {
+ my $primary = $self->{Records}{$primary_class}{ ${ $object->{$object_primary_ref} } };
+ push @{ $primary->{ApplyTo} }, $object;
}
- for my $CF (values %{ $self->{Records}{'RT::CustomField'} }) {
- @{ $CF->{ApplyTo} } = map { $_->{ObjectId} } sort { $a->{SortOrder} <=> $b->{SortOrder} } @{ $CF->{ApplyTo} || [] };
+ for my $primary (values %{ $self->{Records}{$primary_class} }) {
+ @{ $primary->{ApplyTo} } = map { $_->{ObjectId} }
+ sort { $a->{SortOrder} <=> $b->{SortOrder} }
+ @{ $primary->{ApplyTo} || [] };
}
}
}
+sub CanonicalizeObjects {
+ my $self = shift;
+ $self->_CanonicalizeObjectType('RT::ObjectCustomField' => CustomField => 'RT::CustomField');
+ $self->_CanonicalizeObjectType('RT::ObjectClass' => Class => 'RT::Class');
+}
+
sub WriteFile {
my $self = shift;
my %output;
commit 893ee935bf4ea12e3daacbc9a401c39df3407dcd
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 14 21:21:53 2017 +0000
Factor out _GetRecordByRef
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index e1ad317..54eb880 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -158,15 +158,24 @@ my %initialdataType = (
GroupMember => 'Members',
);
+sub _GetRecordByRef {
+ my $self = shift;
+ my $ref = shift;
+
+ my ($class) = $ref =~ /^([\w:]+)-/
+ or return undef;
+ return $self->{Records}{$class}{$ref};
+}
+
sub CanonicalizeReference {
my $self = shift;
my $ref = ${ shift(@_) };
my $context = shift;
my $for_key = shift;
- my ($class, $id) = $ref =~ /^(.*?)-(.*)/
+ my $record = $self->_GetRecordByRef($ref)
or return $ref;
- my $record = $self->{Records}{$class}{$ref};
+
return $record->{Name} || $ref;
}
commit 7500606c2457b8b5313cea072e872fb9aa2ea081
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 14 21:22:28 2017 +0000
Canonicalize ObjectScrips as Scrips.Queue
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 54eb880..418d9c6 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -179,30 +179,64 @@ sub CanonicalizeReference {
return $record->{Name} || $ref;
}
-sub _CanonicalizeObjectType {
+sub _CanonicalizeManyToMany {
my $self = shift;
- my $object_class = shift;
- my $object_primary_ref = shift;
- my $primary_class = shift;
+ my %args = (
+ object_class => '',
+ object_primary_ref => '',
+ primary_class => '',
+ primary_key => 'ApplyTo',
+ canonicalize_object => sub { $_->{ObjectId} },
+ @_,
+ );
+
+ my $object_class = $args{object_class};
+ my $object_primary_ref = $args{object_primary_ref};
+ my $primary_class = $args{primary_class};
+ my $primary_key = $args{primary_key};
+ my $canonicalize_object = $args{canonicalize_object};
if (my $objects = delete $self->{Records}{$object_class}) {
for my $object (values %$objects) {
my $primary = $self->{Records}{$primary_class}{ ${ $object->{$object_primary_ref} } };
- push @{ $primary->{ApplyTo} }, $object;
+ push @{ $primary->{$primary_key} }, $object;
}
for my $primary (values %{ $self->{Records}{$primary_class} }) {
- @{ $primary->{ApplyTo} } = map { $_->{ObjectId} }
- sort { $a->{SortOrder} <=> $b->{SortOrder} }
- @{ $primary->{ApplyTo} || [] };
+ @{ $primary->{$primary_key} }
+ = map &$canonicalize_object,
+ sort { $a->{SortOrder} <=> $b->{SortOrder} }
+ @{ $primary->{$primary_key} || [] };
}
}
}
sub CanonicalizeObjects {
my $self = shift;
- $self->_CanonicalizeObjectType('RT::ObjectCustomField' => CustomField => 'RT::CustomField');
- $self->_CanonicalizeObjectType('RT::ObjectClass' => Class => 'RT::Class');
+
+ $self->_CanonicalizeManyToMany(
+ object_class => 'RT::ObjectCustomField',
+ object_primary_ref => 'CustomField',
+ primary_class => 'RT::CustomField',
+ );
+
+ $self->_CanonicalizeManyToMany(
+ object_class => 'RT::ObjectClass',
+ object_primary_ref => 'Class',
+ primary_class => 'RT::Class'
+ );
+
+ $self->_CanonicalizeManyToMany(
+ object_class => 'RT::ObjectScrip',
+ object_primary_ref => 'Scrip',
+ primary_class => 'RT::Scrip',
+ primary_key => 'Queue',
+ canonicalize_object => sub {
+ ref($_->{ObjectId})
+ ? $self->_GetRecordByRef(${ $_->{ObjectId} })->{Name}
+ : $_->{ObjectId}
+ },
+ );
}
sub WriteFile {
-----------------------------------------------------------------------
More information about the rt-commit
mailing list