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

Shawn Moore shawn at bestpractical.com
Tue Mar 21 12:11:20 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  7ba97298728fd305759aeb2996dbada46ac63669 (commit)
       via  4f009e587b81a344b7ac04dbc478829794a279e1 (commit)
       via  e4b0724c0cb02e4e848ea501be0945b1d357c3a9 (commit)
      from  56316be2a43c4e4a8e400d210c4ef9cd98f47914 (commit)

Summary of changes:
 lib/RT/Asset.pm                   | 26 ++++++++++++++++++++++++
 lib/RT/Catalog.pm                 | 42 +++++++++++++++++++++++++++++++++++++++
 lib/RT/Handle.pm                  |  8 ++++++++
 lib/RT/Migrate/Serializer.pm      |  7 ++++++-
 lib/RT/Migrate/Serializer/JSON.pm |  1 +
 sbin/rt-serializer.in             | 18 +++++++++++++----
 t/api/initialdata-roundtrip.t     |  8 ++++++--
 7 files changed, 103 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit e4b0724c0cb02e4e848ea501be0945b1d357c3a9
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 15:49:06 2017 +0000

    Add support for assets and catalogs to serializer

diff --git a/lib/RT/Asset.pm b/lib/RT/Asset.pm
index 33a46d3..658b91f 100644
--- a/lib/RT/Asset.pm
+++ b/lib/RT/Asset.pm
@@ -647,6 +647,32 @@ sub _CoreAccessible {
     }
 }
 
+sub FindDependencies {
+    my $self = shift;
+    my ($walker, $deps) = @_;
+
+    $self->SUPER::FindDependencies($walker, $deps);
+
+    # Links
+    my $links = RT::Links->new( $self->CurrentUser );
+    $links->Limit(
+        SUBCLAUSE       => "either",
+        FIELD           => $_,
+        VALUE           => $self->URI,
+        ENTRYAGGREGATOR => 'OR'
+    ) for qw/Base Target/;
+    $deps->Add( in => $links );
+
+    # Asset role groups( Owner, HeldBy, Contact)
+    my $objs = RT::Groups->new( $self->CurrentUser );
+    $objs->Limit( FIELD => 'Domain', VALUE => 'RT::Asset-Role', CASESENSITIVE => 0 );
+    $objs->Limit( FIELD => 'Instance', VALUE => $self->Id );
+    $deps->Add( in => $objs );
+
+    # Catalog
+    $deps->Add( out => $self->CatalogObj );
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/Catalog.pm b/lib/RT/Catalog.pm
index ae4abf8..801343f 100644
--- a/lib/RT/Catalog.pm
+++ b/lib/RT/Catalog.pm
@@ -499,6 +499,48 @@ sub _CoreAccessible {
     }
 }
 
+sub FindDependencies {
+    my $self = shift;
+    my ($walker, $deps) = @_;
+
+    $self->SUPER::FindDependencies($walker, $deps);
+
+    # Role groups( HeldBy, Contact)
+    my $objs = RT::Groups->new( $self->CurrentUser );
+    $objs->Limit( FIELD => 'Domain', VALUE => 'RT::Catalog-Role', CASESENSITIVE => 0 );
+    $objs->Limit( FIELD => 'Instance', VALUE => $self->Id );
+    $deps->Add( in => $objs );
+
+    # Custom Fields on assets _in_ this catalog
+    $objs = RT::ObjectCustomFields->new( $self->CurrentUser );
+    $objs->Limit( FIELD           => 'ObjectId',
+                  OPERATOR        => '=',
+                  VALUE           => $self->id,
+                  ENTRYAGGREGATOR => 'OR' );
+    $objs->Limit( FIELD           => 'ObjectId',
+                  OPERATOR        => '=',
+                  VALUE           => 0,
+                  ENTRYAGGREGATOR => 'OR' );
+    my $cfs = $objs->Join(
+        ALIAS1 => 'main',
+        FIELD1 => 'CustomField',
+        TABLE2 => 'CustomFields',
+        FIELD2 => 'id',
+    );
+    $objs->Limit( ALIAS    => $cfs,
+                  FIELD    => 'LookupType',
+                  OPERATOR => 'STARTSWITH',
+                  VALUE    => 'RT::Catalog-' );
+    $deps->Add( in => $objs );
+
+    # Assets
+    $objs = RT::Assets->new( $self->CurrentUser );
+    $objs->Limit( FIELD => "Catalog", VALUE => $self->Id );
+    $objs->{allow_deleted_search} = 1;
+    $deps->Add( in => $objs );
+
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/Migrate/Serializer.pm b/lib/RT/Migrate/Serializer.pm
index 26d5ed3..6330b48 100644
--- a/lib/RT/Migrate/Serializer.pm
+++ b/lib/RT/Migrate/Serializer.pm
@@ -70,6 +70,7 @@ sub Init {
         FollowTickets       => 1,
         FollowTransactions  => 1,
         FollowACL           => 0,
+        FollowAssets        => 1,
 
         Clone       => 0,
         Incremental => 0,
@@ -88,6 +89,7 @@ sub Init {
                   FollowScrips
                   FollowTickets
                   FollowTransactions
+                  FollowAssets
                   FollowACL
                   Clone
                   Incremental
@@ -294,7 +296,7 @@ sub PushBasics {
         $self->PushCollections(qw(Topics Classes));
     }
 
-    $self->PushCollections(qw(Queues));
+    $self->PushCollections(qw(Queues Catalogs));
 }
 
 sub InitStream {
@@ -399,6 +401,9 @@ sub Observe {
     if ($obj->isa("RT::Ticket")) {
         return 0 if $obj->Status eq "deleted" and not $self->{FollowDeleted};
         return $self->{FollowTickets};
+    } elsif ($obj->isa("RT::Asset")) {
+        return 0 if $obj->Status eq "deleted" and not $self->{FollowDeleted};
+        return $self->{FollowAssets};
     } elsif ($obj->isa("RT::ACE")) {
         return $self->{FollowACL};
     } elsif ($obj->isa("RT::Transaction")) {
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index d8a7e68..77ca7f7 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -144,6 +144,7 @@ sub PushBasics {
     # we want to include all CFs, scrips, etc, not just the reachable ones
     $self->PushCollections(qw(CustomFields CustomRoles));
     $self->PushCollections(qw(Scrips)) if $self->{FollowScrips};
+    $self->PushCollections(qw(Assets)) if $self->{FollowAssets};
 }
 
 sub JSON {
diff --git a/sbin/rt-serializer.in b/sbin/rt-serializer.in
index d1b75f5..d130b45 100644
--- a/sbin/rt-serializer.in
+++ b/sbin/rt-serializer.in
@@ -106,6 +106,7 @@ GetOptions(
     "tickets!",
     "transactions!",
     "acls!",
+    "assets!",
 
     "clone",
     "incremental",
@@ -129,6 +130,7 @@ $args{FollowScrips}       = $OPT{scrips}       if defined $OPT{scrips};
 $args{FollowTickets}      = $OPT{tickets}      if defined $OPT{tickets};
 $args{FollowTransactions} = $OPT{transactions} if defined $OPT{transactions};
 $args{FollowACL}          = $OPT{acls}         if defined $OPT{acls};
+$args{FollowAssets}       = $OPT{assets}       if defined $OPT{assets};
 
 $args{Clone}         = $OPT{clone}       if $OPT{clone};
 $args{Incremental}   = $OPT{incremental} if $OPT{incremental};
@@ -137,7 +139,7 @@ $args{GC}   = defined $OPT{gc}   ? $OPT{gc}   : 5000;
 $args{Page} = defined $OPT{page} ? $OPT{page} : 100;
 
 if (($OPT{clone} or $OPT{incremental})
-        and grep { /^(users|groups|deleted|scrips|tickets|transactions|acls)$/ } keys %OPT) {
+        and grep { /^(users|groups|deleted|scrips|tickets|transactions|acls|assets)$/ } keys %OPT) {
     die "You cannot specify object types when cloning.\n\nPlease see $0 --help.\n";
 }
 
@@ -199,6 +201,7 @@ sub estimate {
         User  Group  GroupMember Attribute
         CustomField CustomFieldValue
         ObjectCustomField ObjectCustomFieldValue
+        Catalog Asset
                                  /;
 
     for my $class (@types) {
@@ -208,7 +211,8 @@ sub estimate {
             my $objs = $collection->new( RT->SystemUser );
             $objs->FindAllRows;
             $objs->UnLimit;
-            $objs->{allow_deleted_search} = 1 if $class eq "RT::Ticket";
+            $objs->{allow_deleted_search} = 1
+                if $class eq "RT::Ticket" || $class eq "RT::Asset";
             $e{$class} = $objs->DBIx::SearchBuilder::Count;
         }
         print "\r", " "x60, "\r";
@@ -315,10 +319,16 @@ By default, all groups are serialized; passing C<--no-groups> limits it
 to only system-internal groups, which are needed for internal
 consistency.
 
+=item B<--no-assets>
+
+By default, all assets are serialized; passing C<--no-assets> skips
+assets during serialization.
+
 =item B<--no-deleted>
 
-By default, all tickets, including deleted tickets, are serialized;
-passing C<--no-deleted> skips deleted tickets during serialization.
+By default, all tickets and assets, including deleted ones, are
+serialized; passing C<--no-deleted> skips deleted tickets and assets
+during serialization.
 
 =item B<--scrips>
 
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index d8f0177..4b64731 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -158,7 +158,7 @@ my @tests = (
         create => sub {
             my %extra = (
                 Group => { method => 'CreateUserDefinedGroup' },
-                Asset => { Catalog => 'General assets' },
+                Asset => undef,
                 Article => undef,
                 Ticket => undef,
                 Transaction => undef,
@@ -203,6 +203,7 @@ my @tests = (
                 Ticket => undef,
                 Article => undef,
                 User => undef,
+                Asset => undef,
             );
 
             for my $type (qw/Asset Article Group Queue Ticket Transaction User/) {
@@ -470,6 +471,7 @@ for my $test (@tests) {
             qr/^Invalid value for Name$/,
             qr/^Queue already exists$/,
             qr/^Use of uninitialized value in/,
+            qr/^Invalid Name \(names must be unique and may not be all digits\)$/,
         );
 
         # Avoid reporting this anonymous call frame as the source of the warning
@@ -533,6 +535,8 @@ sub export_initialdata {
         FollowACL          => 1,
         FollowScrips       => 1,
         FollowTransactions => 0,
+        FollowTickets      => 0,
+        FollowAssets       => 0,
     );
 
     $migrator->Export;

commit 4f009e587b81a344b7ac04dbc478829794a279e1
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 15:57:01 2017 +0000

    Have test failures mention the exact initialdata path

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 4b64731..a39d6c8 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -493,7 +493,7 @@ for my $test (@tests) {
         });
     };
 
-    subtest "$name (from initialdata)" => sub {
+    subtest "$name (from export-$id/initialdata.json)" => sub {
         autorollback(sub {
             $absent->() if $absent;
             import_initialdata($directory);

commit 7ba97298728fd305759aeb2996dbada46ac63669
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 16:11:03 2017 +0000

    Add support for asset and catalog attributes for initialdata

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 445bca9..6b6c1c8 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1128,6 +1128,7 @@ sub InsertData {
         $RT::Logger->debug("Creating Catalogs...");
 
         for my $item (@Catalogs) {
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::Catalog->new(RT->SystemUser);
             my ( $return, $msg ) = $new_entry->Create(%$item);
             unless ( $return ) {
@@ -1136,6 +1137,9 @@ sub InsertData {
             else {
                 $RT::Logger->debug( $return ."." );
             }
+
+            $_->{Object} = $new_entry for @{$attributes || []};
+            push @Attributes, @{$attributes || []};
         }
 
         $RT::Logger->debug("done.");
@@ -1144,6 +1148,7 @@ sub InsertData {
         $RT::Logger->debug("Creating Assets...");
 
         for my $item (@Catalogs) {
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::Asset->new(RT->SystemUser);
             my ( $return, $msg ) = $new_entry->Create(%$item);
             unless ( $return ) {
@@ -1152,6 +1157,9 @@ sub InsertData {
             else {
                 $RT::Logger->debug( $return ."." );
             }
+
+            $_->{Object} = $new_entry for @{$attributes || []};
+            push @Attributes, @{$attributes || []};
         }
 
         $RT::Logger->debug("done.");

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


More information about the rt-commit mailing list