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

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


The branch, 4.4/serialize-json-initialdata has been updated
       via  a539b41a546cc42ee22ffdb59d063c8c1e02e5fe (commit)
       via  ddcdafa4abdd65a99ffe5072d7bd9e807db96122 (commit)
       via  a68a231d11df4aeaeff91e85bdfb79acea95fe65 (commit)
       via  4bcb1796b7e37200c014d19961909bb3268e0972 (commit)
      from  9d3282fa88a17b217d044dfc6321202f5b96691e (commit)

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

- Log -----------------------------------------------------------------
commit 4bcb1796b7e37200c014d19961909bb3268e0972
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 19:58:42 2017 +0000

    Sort JSON keys so its output can be versioned

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 0bf16d5..0a5cdbf 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -122,7 +122,7 @@ sub Directory {
 
 sub JSON {
     my $self = shift;
-    return $self->{JSON} ||= JSON->new->pretty;
+    return $self->{JSON} ||= JSON->new->pretty->canonical;
 }
 
 sub OpenFile {

commit a68a231d11df4aeaeff91e85bdfb79acea95fe65
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:00:21 2017 +0000

    Store records by id
    
    This way we can more easily patch them up later (e.g. canonicalizing
    ObjectScrips to Scrips.Queue)

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 0a5cdbf..05d1b56 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -152,7 +152,7 @@ sub WriteRecord {
     my $type = $record->[0];
     $type =~ s/^RT:://;
 
-    push @{ $self->{Records}{ $type } }, $record->[2];
+    $self->{Records}{ $type }{$record->[1]} = $record->[2];
 }
 
 sub WriteFile {
@@ -160,7 +160,8 @@ sub WriteFile {
     my %output;
 
     for my $type (keys %{ $self->{Records} }) {
-        for my $record (@{ $self->{Records}{$type} }) {
+        for my $id (keys %{ $self->{Records}{$type} }) {
+            my $record = $self->{Records}{$type}{$id};
             for my $key (keys %$record) {
                 if (ref($record->{$key}) eq 'SCALAR') {
                     delete $record->{$key};

commit ddcdafa4abdd65a99ffe5072d7bd9e807db96122
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:01:11 2017 +0000

    For now, rather than deleting references, dereference them
    
    It's not perfect, but it's better baseline behavior

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 05d1b56..f522f18 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -164,7 +164,7 @@ sub WriteFile {
             my $record = $self->{Records}{$type}{$id};
             for my $key (keys %$record) {
                 if (ref($record->{$key}) eq 'SCALAR') {
-                    delete $record->{$key};
+                    $record->{$key} = ${ $record->{$key} };
                 }
             }
             push @{ $output{$type} }, $record;

commit a539b41a546cc42ee22ffdb59d063c8c1e02e5fe
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 14 20:01:50 2017 +0000

    Use initialdata's type names rather than RT class names

diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index f522f18..50eb72a 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -155,19 +155,27 @@ sub WriteRecord {
     $self->{Records}{ $type }{$record->[1]} = $record->[2];
 }
 
+my %initialdataType = (
+    ACE => 'ACL',
+    Class => 'Classes',
+    GroupMember => 'Members',
+);
+
 sub WriteFile {
     my $self = shift;
     my %output;
 
-    for my $type (keys %{ $self->{Records} }) {
-        for my $id (keys %{ $self->{Records}{$type} }) {
-            my $record = $self->{Records}{$type}{$id};
+    for my $intype (keys %{ $self->{Records} }) {
+        my $outtype = $initialdataType{$intype} || ($intype . 's');
+
+        for my $id (keys %{ $self->{Records}{$intype} }) {
+            my $record = $self->{Records}{$intype}{$id};
             for my $key (keys %$record) {
                 if (ref($record->{$key}) eq 'SCALAR') {
                     $record->{$key} = ${ $record->{$key} };
                 }
             }
-            push @{ $output{$type} }, $record;
+            push @{ $output{$outtype} }, $record;
         }
     }
 

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


More information about the rt-commit mailing list