[Rt-commit] rt branch 5.0/importer-dashboards created. rt-5.0.3-128-g3e14f309a7

BPS Git Server git at git.bestpractical.com
Mon Nov 14 15:10:53 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/importer-dashboards has been created
        at  3e14f309a7cda8b7b2716553dc6fce4a9b476c51 (commit)

- Log -----------------------------------------------------------------
commit 3e14f309a7cda8b7b2716553dc6fce4a9b476c51
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Oct 19 03:37:50 2022 +0800

    Import dashboards/savedsearches/subscriptions/prefs/bookmarks for merged users
    
    Previously they were skipped.
    
    "RecentlyViewedTickets" is a frequently updated ticket list, and it's
    not worth serializing and importing it, so we exclude it on purpose.

diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm
index 4552dbd52c..41b12e24f0 100644
--- a/lib/RT/Attribute.pm
+++ b/lib/RT/Attribute.pm
@@ -863,11 +863,72 @@ sub PreInflate {
     if ($data->{Object} and ref $data->{Object}) {
         my $on_uid = ${ $data->{Object} };
 
+        my $force;
+
         # skip attributes of objects we're not inflating
-        # exception: we don't inflate RT->System, but we want RT->System's searches
-        unless ($on_uid eq RT->System->UID && $data->{Name} =~ /Search/) {
-            return if $importer->ShouldSkipTransaction($on_uid);
+        if ( $on_uid eq RT->System->UID ) {
+
+            # We always want RT->System's searches and dashboards
+            $force = 1 if $data->{Name} =~ /^Search|^(?:SavedSearch|Dashboard|ContentHistory)$/;
+
+            # Do not import DefaultDashboard if it already exists
+            if ( $data->{Name} eq 'DefaultDashboard' ) {
+                if ( my $exists = RT->System->FirstAttribute('DefaultDashboard') ) {
+                    $importer->Resolve( $uid => ref($exists) => $exists->Id );
+                    return;
+                }
+                else {
+                    $force = 1;
+                }
+            }
         }
+        elsif ( $on_uid =~ /^RT::(?:User|Group)-/ ) {
+            if ( $importer->ShouldSkipTransaction($on_uid) ) {
+                if ( $data->{Name} eq 'Bookmarks' || $data->{Name} =~ /^Pref-/ ) {
+                    my $obj = $importer->LookupObj($on_uid);
+                    if ( $obj && $obj->Id ) {
+                        if ( my $exists = $obj->FirstAttribute( $data->{Name} ) ) {
+                            if ( $data->{Name} eq 'Bookmarks' ) {
+
+                                # Merge bookmarks if possible
+                                my $new_content = $exists->_DeserializeContent( $data->{Content} );
+                                if ( ref $new_content eq 'ARRAY' ) {
+                                    my $content = $exists->Content;
+                                    my $changed;
+                                    for my $uid (@$new_content) {
+                                        if ( my $ticket = $importer->LookupObj($$uid) ) {
+                                            $content->{ $ticket->Id } = 1;
+                                            $changed = 1;
+                                        }
+                                    }
+                                    if ($changed) {
+                                        my ( $ret, $msg ) = $exists->SetContent($content);
+                                        unless ($ret) {
+                                            RT->Logger->error("Couldn't update Bookmarks for user $on_uid: $msg");
+                                        }
+                                    }
+                                }
+                            }
+                            $importer->Resolve( $uid => ref($exists) => $exists->Id );
+                        }
+                        else {
+                            $force = 1;
+                        }
+                    }
+                }
+                elsif ( $data->{Name} =~ /SavedSearch|Dashboard|Subscription|ContentHistory/ ) {
+
+                    # We always want saved searches and dashboards
+                    $force = 1;
+                }
+            }
+            elsif ( $data->{Name} eq 'RecentlyViewedTickets' ) {
+                # Don't bother importing frequently updated recently viewed tickets
+                return;
+            }
+        }
+
+        return if !$force && $importer->ShouldSkipTransaction($on_uid);
     }
 
     return $class->SUPER::PreInflate( $importer, $uid, $data );

commit 80c4303d6294f3eaca07d4e6187c957e7bd78819
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Oct 23 02:37:42 2022 +0800

    Fix typo in DefaultDashboard handling of PostInflateFixup

diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm
index 62ee2a703f..4552dbd52c 100644
--- a/lib/RT/Attribute.pm
+++ b/lib/RT/Attribute.pm
@@ -916,7 +916,7 @@ sub PostInflateFixup {
     elsif ( $self->Name =~ /DefaultDashboard$/ ) {
         my $content = $self->Content;
         if ( ref($content) eq 'SCALAR' ) {
-            my $attr = $importer->LookupObj($$_);
+            my $attr = $importer->LookupObj($$content);
             if ($attr) {
                 $content = $attr->Id;
             }

commit 6149eb5f277f84c2342bfa494f4d2093af59f817
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Oct 23 03:07:23 2022 +0800

    No need to create transactions in PostInflateFixup

diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm
index a30c63f11c..62ee2a703f 100644
--- a/lib/RT/Attribute.pm
+++ b/lib/RT/Attribute.pm
@@ -315,7 +315,8 @@ sub SetContent {
             return(0, "Content couldn't be frozen");
         }
     }
-    my ($ok, $msg) = $self->_Set( Field => 'Content', Value => $content );
+    my ( $ok, $msg )
+        = $self->_Set( Field => 'Content', Value => $content, RecordTransaction => $args{RecordTransaction} );
     if ($ok) {
         $self->_SyncLinks if $args{SyncLinks};
         return ( $ok, $self->loc("Attribute updated") );
@@ -910,7 +911,7 @@ sub PostInflateFixup {
                 }
             }
         }
-        $self->SetContent( $content, SyncLinks => 0 );
+        $self->SetContent( $content, SyncLinks => 0, RecordTransaction => 0 );
     }
     elsif ( $self->Name =~ /DefaultDashboard$/ ) {
         my $content = $self->Content;
@@ -954,7 +955,7 @@ sub PostInflateFixup {
                 }
             }
         }
-        $self->SetContent( $content, SyncLinks => 0 );
+        $self->SetContent( $content, SyncLinks => 0, RecordTransaction => 0 );
     }
     elsif ($self->Name eq 'Subscription') {
         my $content = $self->Content;
@@ -971,7 +972,7 @@ sub PostInflateFixup {
                 );
             }
         }
-        $self->SetContent( $content, SyncLinks => 0 );
+        $self->SetContent( $content, SyncLinks => 0, RecordTransaction => 0 );
     }
 }
 

commit 0f4d61e02a505f01a6a396594a00249c714cef09
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Oct 19 04:00:35 2022 +0800

    No need to sync attribute links in PostInflateFixup
    
    This is to avid errors like:
    
        duplicate key value violates unique constraint "links1"
    
    because related links will be imported from serialized data.

diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm
index d8d2db1434..a30c63f11c 100644
--- a/lib/RT/Attribute.pm
+++ b/lib/RT/Attribute.pm
@@ -303,7 +303,8 @@ sub _SerializeContent {
 
 sub SetContent {
     my $self = shift;
-    my $content = shift;
+    my %args = ( Content => undef, SyncLinks => 1, @_ % 2 ? ( Content => @_ ) : @_ );
+    my $content = $args{Content};
 
     # Call __Value to avoid ACL check.
     if ( ($self->__Value('ContentType')||'') eq 'storable' ) {
@@ -316,7 +317,7 @@ sub SetContent {
     }
     my ($ok, $msg) = $self->_Set( Field => 'Content', Value => $content );
     if ($ok) {
-        $self->_SyncLinks;
+        $self->_SyncLinks if $args{SyncLinks};
         return ( $ok, $self->loc("Attribute updated") );
     }
     return ($ok, $msg);
@@ -909,7 +910,7 @@ sub PostInflateFixup {
                 }
             }
         }
-        $self->SetContent($content);
+        $self->SetContent( $content, SyncLinks => 0 );
     }
     elsif ( $self->Name =~ /DefaultDashboard$/ ) {
         my $content = $self->Content;
@@ -953,7 +954,7 @@ sub PostInflateFixup {
                 }
             }
         }
-        $self->SetContent($content);
+        $self->SetContent( $content, SyncLinks => 0 );
     }
     elsif ($self->Name eq 'Subscription') {
         my $content = $self->Content;
@@ -970,7 +971,7 @@ sub PostInflateFixup {
                 );
             }
         }
-        $self->SetContent($content);
+        $self->SetContent( $content, SyncLinks => 0 );
     }
 }
 

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list