[Rt-commit] rt branch, 4.4/asset-serializer, created. rt-4.4.2-85-g2b6784ba3

? sunnavy sunnavy at bestpractical.com
Mon Feb 26 16:54:57 EST 2018


The branch, 4.4/asset-serializer has been created
        at  2b6784ba3b076496c96c717e26a82a169c5c5d2e (commit)

- Log -----------------------------------------------------------------
commit 2b6784ba3b076496c96c717e26a82a169c5c5d2e
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
    
    Based on Shawn's work, I also added the following fixes:
    
    * Add RT::Catalog to RT::_BuildTableAttributes
    
    This is to init RT::Catalog to make rt-importer happy.
    
    * Serialize transactions for catalogs and assets
    
    * Serialize custom fields for assets
    
    * Fix name duplicates for catalogs
    
    * Fix asset role groups for --no-deleted
    
    * Support --clone

diff --git a/lib/RT.pm b/lib/RT.pm
index e14211c71..f51d99529 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -551,6 +551,7 @@ sub _BuildTableAttributes {
         RT::ObjectTopic
         RT::Topic
         RT::Asset
+        RT::Catalog
         RT::CustomRole
         RT::ObjectCustomRole
     );
diff --git a/lib/RT/Asset.pm b/lib/RT/Asset.pm
index 33a46d33f..616c2aaad 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 ae4abf837..6314b4b9c 100644
--- a/lib/RT/Catalog.pm
+++ b/lib/RT/Catalog.pm
@@ -499,6 +499,59 @@ 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 );
+
+}
+
+sub PreInflate {
+    my $class = shift;
+    my ( $importer, $uid, $data ) = @_;
+
+    $class->SUPER::PreInflate( $importer, $uid, $data );
+    $data->{Name} = $importer->Qualify( $data->{Name} );
+
+    return if $importer->MergeBy( "Name", $class, $uid, $data );
+    return 1;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/Group.pm b/lib/RT/Group.pm
index db5e0b5da..f8d07535b 100644
--- a/lib/RT/Group.pm
+++ b/lib/RT/Group.pm
@@ -1308,6 +1308,8 @@ sub InstanceObj {
         $class = "RT::Queue";
     } elsif ($self->Domain eq 'RT::Ticket-Role') {
         $class = "RT::Ticket";
+    } elsif ($self->Domain eq 'RT::Asset-Role') {
+        $class = "RT::Asset";
     }
 
     return unless $class;
diff --git a/lib/RT/Migrate/Serializer.pm b/lib/RT/Migrate/Serializer.pm
index 7201f81fb..7d8ab7d38 100644
--- a/lib/RT/Migrate/Serializer.pm
+++ b/lib/RT/Migrate/Serializer.pm
@@ -71,6 +71,7 @@ sub Init {
         FollowScrips        => 0,
         FollowTickets       => 1,
         FollowACL           => 0,
+        FollowAssets        => 1,
 
         Clone       => 0,
         Incremental => 0,
@@ -88,6 +89,7 @@ sub Init {
                   FollowDeleted
                   FollowScrips
                   FollowTickets
+                  FollowAssets
                   FollowACL
                   Queues
                   CustomFields
@@ -168,6 +170,9 @@ sub PushAll {
     # Custom Roles
     $self->PushCollections(qw(CustomRoles ObjectCustomRoles));
 
+    # Assets
+    $self->PushCollections(qw(Catalogs Assets));
+
     # Custom Fields
     if (RT::ObjectCustomFields->require) {
         $self->PushCollections(map { ($_, "Object$_") } qw(CustomFields CustomFieldValues));
@@ -203,6 +208,9 @@ sub PushCollections {
                 $collection->{allow_deleted_search} = 1;
                 $collection->IgnoreType; # looking_at_type
             }
+            elsif ($collection->isa('RT::Assets')) {
+                $collection->{allow_deleted_search} = 1;
+            }
             elsif ($collection->isa('RT::ObjectCustomFieldValues')) {
                 # FindAllRows (find_disabled_rows) isn't used by OCFVs
                 $collection->{find_disabled_rows} = 1;
@@ -313,6 +321,7 @@ sub PushBasics {
     else {
         $self->PushCollections(qw(Queues));
     }
+    $self->PushCollections(qw(Catalogs));
 }
 
 sub InitStream {
@@ -438,6 +447,9 @@ sub Observe {
         my $id = $obj->CustomField;
         return 0 if $self->{CustomFields} && none { $id == $_ } @{ $self->{CustomFields} };
         return 1;
+    } 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::Scrip") or $obj->isa("RT::Template") or $obj->isa("RT::ObjectScrip")) {
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 076b19395..d8e2ee31d 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2432,6 +2432,8 @@ sub FindDependencies {
         or $self->isa("RT::User")
         or $self->isa("RT::Group")
         or $self->isa("RT::Article")
+        or $self->isa("RT::Asset")
+        or $self->isa("RT::Catalog")
         or $self->isa("RT::Queue") )
     {
         $objs = RT::Transactions->new( $self->CurrentUser );
@@ -2445,6 +2447,7 @@ sub FindDependencies {
          or $self->isa("RT::Ticket")
          or $self->isa("RT::User")
          or $self->isa("RT::Group")
+         or $self->isa("RT::Asset")
          or $self->isa("RT::Queue")
          or $self->isa("RT::Article") )
             and $self->can("CustomFieldValues") )
diff --git a/sbin/rt-serializer.in b/sbin/rt-serializer.in
index c9aa4846a..4f8a8d8ac 100644
--- a/sbin/rt-serializer.in
+++ b/sbin/rt-serializer.in
@@ -107,6 +107,7 @@ GetOptions(
     "limit-queues=s@",
     "limit-cfs=s@",
     "hyperlink-unmigrated!",
+    "assets!",
 
     "clone",
     "incremental",
@@ -132,6 +133,8 @@ $args{FollowACL}     = $OPT{acls}     if defined $OPT{acls};
 
 $args{HyperlinkUnmigrated} = $OPT{'hyperlink-unmigrated'} if defined $OPT{'hyperlink-unmigrated'};
 
+$args{FollowAssets} = $OPT{assets} if defined $OPT{assets};
+
 $args{Clone}         = $OPT{clone}       if $OPT{clone};
 $args{Incremental}   = $OPT{incremental} if $OPT{incremental};
 
@@ -178,7 +181,7 @@ if ($OPT{'limit-cfs'}) {
 }
 
 if (($OPT{clone} or $OPT{incremental})
-        and grep { /^(users|groups|deleted|scrips|tickets|acls)$/ } keys %OPT) {
+        and grep { /^(users|groups|deleted|scrips|tickets|acls|assets)$/ } keys %OPT) {
     die "You cannot specify object types when cloning.\n\nPlease see $0 --help.\n";
 }
 
@@ -236,6 +239,7 @@ sub estimate {
         User  Group  GroupMember Attribute
         CustomField CustomFieldValue
         ObjectCustomField ObjectCustomFieldValue
+        Catalog Asset
                                  /;
 
     for my $class (@types) {
@@ -245,7 +249,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";
@@ -346,10 +351,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>
 

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


More information about the rt-commit mailing list