[Rt-commit] rt branch 5.0/initialdata-saved-chart-group-by-cf-names created. rt-5.0.2-113-gb383a29787

BPS Git Server git at git.bestpractical.com
Thu Mar 24 19:42:27 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/initialdata-saved-chart-group-by-cf-names has been created
        at  b383a29787b1fead8f3d64cc86131b5067ce4966 (commit)

- Log -----------------------------------------------------------------
commit b383a29787b1fead8f3d64cc86131b5067ce4966
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Mar 22 21:35:08 2022 +0800

    Dump GroupBy custom field items in saved charts using Name for portability
    
    It's like "CF.{3}" in db, so we need to convert it to name like
    "CF.{foo}" in exported json and convert it back when inserting into db.
    
    With this, we can dump saved charts that have custom field GroupBy items
    using rt-dump-initialdata and restore it successfully later.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 3f741fa7ff..a6330d41c5 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2865,6 +2865,50 @@ sub _CanonilizeAttributeContent {
             }
         }
     }
+    elsif ( $item->{Name} eq 'SavedSearch' ) {
+        if ( my $group_by = $item->{Content}{GroupBy} ) {
+            my $stacked_group_by = $item->{Content}{StackedGroupBy};
+            my @new_group_by;
+            for my $item ( ref $group_by ? @$group_by : $group_by ) {
+                if ( $item =~ /^CF\.\{(.+)\}$/ ) {
+                    my $id = $1;
+                    my $cf = RT::CustomField->new( RT->SystemUser );
+                    if ( $id =~ /\D/ ) {
+                        my $cfs = RT::CustomFields->new( RT->SystemUser );
+                        $cfs->LimitToLookupType( RT::Ticket->CustomFieldLookupType );
+                        $cfs->Limit( FIELD => 'Name', VALUE => $id, CASESENSITIVE => 0 );
+                        if ( my $count = $cfs->Count ) {
+                            if ( $count > 1 ) {
+                                RT->Logger->error(
+                                    "Found multiple ticket custom field $id, will use first one for search $item->{Description}"
+                                );
+                            }
+                            $cf = $cfs->First;
+                        }
+                    }
+                    else {
+                        $cf->Load($id);
+                    }
+
+                    if ( $cf->Id ) {
+                        my $by_id = 'CF.{' . $cf->Id . '}';
+                        push @new_group_by, $by_id;
+                        if ( $item eq ( $stacked_group_by // '' ) ) {
+                            $stacked_group_by = $by_id;
+                        }
+                    }
+                    else {
+                        RT->Logger->error("Couldn't find ticket custom field $id");
+                    }
+                }
+                else {
+                    push @new_group_by, $item;
+                }
+            }
+            $item->{Content}{GroupBy} = \@new_group_by;
+            $item->{Content}{StackedGroupBy} = $stacked_group_by if $stacked_group_by;
+        }
+    }
 }
 
 sub _CanonilizeObjectCustomFieldValue {
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 99fb6e2fe4..ca1d2034d6 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -536,6 +536,28 @@ sub CanonicalizeAttributes {
                         }
                     }
                 }
+                elsif ( $record->{Name} eq 'SavedSearch' ) {
+                    if ( my $group_by = $record->{Content}{GroupBy} ) {
+                        my @new_group_by;
+                        my $stacked_group_by = $record->{Content}{StackedGroupBy};
+                        for my $item ( ref $group_by ? @$group_by : $group_by ) {
+                            if ( $item =~ /^CF\.\{(\d+)\}$/ ) {
+                                my $cf = RT::CustomField->new( RT->SystemUser );
+                                $cf->Load($1);
+                                my $by_name = 'CF.{' . $cf->Name . '}';
+                                push @new_group_by, $by_name;
+                                if ( $item eq ( $stacked_group_by // '' ) ) {
+                                    $stacked_group_by = $by_name;
+                                }
+                            }
+                            else {
+                                push @new_group_by, $item;
+                            }
+                        }
+                        $record->{Content}{GroupBy}        = \@new_group_by;
+                        $record->{Content}{StackedGroupBy} = $stacked_group_by if $stacked_group_by;
+                    }
+                }
             }
         }
         elsif ( $record->{Name} =~ /DefaultDashboard$/ ) {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list