[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-331-ge107e99

Shawn Moore shawn at bestpractical.com
Tue Mar 14 16:50:16 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  e107e99270e6c179e2aa1f031690899af1099d1c (commit)
       via  bbedb35f779de6630a373616da7a8c51aa31369e (commit)
       via  fa5f384badaf912bef24a024a2b3ad81c7a49149 (commit)
      from  a539b41a546cc42ee22ffdb59d063c8c1e02e5fe (commit)

Summary of changes:
 lib/RT/Migrate/Serializer/JSON.pm | 40 +++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit fa5f384badaf912bef24a024a2b3ad81c7a49149
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:15:43 2017 +0000

    Defer canonicalizing away "RT::" from class names

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 50eb72a..cf623ea 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -149,10 +149,7 @@ sub WriteRecord {
     my $self = shift;
     my $record = shift;
 
-    my $type = $record->[0];
-    $type =~ s/^RT:://;
-
-    $self->{Records}{ $type }{$record->[1]} = $record->[2];
+    $self->{Records}{ $record->[0] }{ $record->[1] } = $record->[2];
 }
 
 my %initialdataType = (
@@ -166,7 +163,9 @@ sub WriteFile {
     my %output;
 
     for my $intype (keys %{ $self->{Records} }) {
-        my $outtype = $initialdataType{$intype} || ($intype . 's');
+        my $outtype = $intype;
+        $outtype =~ s/^RT:://;
+        $outtype = $initialdataType{$outtype} || ($outtype . 's');
 
         for my $id (keys %{ $self->{Records}{$intype} }) {
             my $record = $self->{Records}{$intype}{$id};

commit bbedb35f779de6630a373616da7a8c51aa31369e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:15:57 2017 +0000

    Canonicalize references by name
    
    e.g. "Queue: General" instead of "Queue: RT::Queue-example.com-1"

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index cf623ea..3cb21f6 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -158,6 +158,17 @@ my %initialdataType = (
     GroupMember => 'Members',
 );
 
+sub CanonicalizeReference {
+    my $self = shift;
+    my $ref = ${ shift(@_) };
+    my $context = shift;
+
+    my ($class, $id) = $ref =~ /^(.*?)-(.*)/
+        or return $ref;
+    my $record = $self->{Records}{$class}{$ref};
+    return $record->{Name} || $ref;
+}
+
 sub WriteFile {
     my $self = shift;
     my %output;
@@ -171,7 +182,7 @@ sub WriteFile {
             my $record = $self->{Records}{$intype}{$id};
             for my $key (keys %$record) {
                 if (ref($record->{$key}) eq 'SCALAR') {
-                    $record->{$key} = ${ $record->{$key} };
+                    $record->{$key} = $self->CanonicalizeReference($record->{$key}, $record);
                 }
             }
             push @{ $output{$outtype} }, $record;

commit e107e99270e6c179e2aa1f031690899af1099d1c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:49:34 2017 +0000

    Canonicalize OCFs as CF.ApplyTo
    
    We need to take some steps to preserve SortOrder, but initialdata
    ApplyTo doesn't support SortOrder directly

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 3cb21f6..54c1800 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -159,9 +159,10 @@ my %initialdataType = (
 );
 
 sub CanonicalizeReference {
-    my $self = shift;
-    my $ref = ${ shift(@_) };
+    my $self    = shift;
+    my $ref     = ${ shift(@_) };
     my $context = shift;
+    my $for_key = shift;
 
     my ($class, $id) = $ref =~ /^(.*?)-(.*)/
         or return $ref;
@@ -169,10 +170,27 @@ sub CanonicalizeReference {
     return $record->{Name} || $ref;
 }
 
+sub CanonicalizeObjects {
+    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;
+        }
+
+        for my $CF (values %{ $self->{Records}{'RT::CustomField'} }) {
+            @{ $CF->{ApplyTo} } = map { $_->{ObjectId} } sort { $a->{SortOrder} <=> $b->{SortOrder} } @{ $CF->{ApplyTo} || [] };
+        }
+    }
+}
+
 sub WriteFile {
     my $self = shift;
     my %output;
 
+    $self->CanonicalizeObjects;
+
     for my $intype (keys %{ $self->{Records} }) {
         my $outtype = $intype;
         $outtype =~ s/^RT:://;
@@ -182,7 +200,7 @@ sub WriteFile {
             my $record = $self->{Records}{$intype}{$id};
             for my $key (keys %$record) {
                 if (ref($record->{$key}) eq 'SCALAR') {
-                    $record->{$key} = $self->CanonicalizeReference($record->{$key}, $record);
+                    $record->{$key} = $self->CanonicalizeReference($record->{$key}, $record, $key);
                 }
             }
             push @{ $output{$outtype} }, $record;

-----------------------------------------------------------------------


More information about the rt-commit mailing list