From 423e4c0698d29fd59d402b2dd453bb0d0f2eeb4f Mon Sep 17 00:00:00 2001 From: sunnavy Date: Wed, 19 Oct 2022 03:37:50 +0800 Subject: Import dashboards/savedsearches/subscriptions/prefs and related history There is no reason to skip them. --- lib/RT/Attribute.pm | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm index 4552dbd52c..cec98c1c5f 100644 --- a/lib/RT/Attribute.pm +++ b/lib/RT/Attribute.pm @@ -863,11 +863,49 @@ 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} =~ /^Pref-/ ) { + + # Do not import pref settings if they exist + my $obj = $importer->LookupObj($on_uid); + if ( $obj && $obj->Id ) { + if ( my $exists = RT->System->FirstAttribute( $data->{Name} ) ) { + $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; + } + } + } + + return if !$force && $importer->ShouldSkipTransaction($on_uid); } return $class->SUPER::PreInflate( $importer, $uid, $data ); -- cgit v1.2.3