diff options
author | sunnavy <sunnavy@bestpractical.com> | 2022-11-08 04:29:22 +0300 |
---|---|---|
committer | sunnavy <sunnavy@bestpractical.com> | 2022-11-09 01:11:40 +0300 |
commit | 51bfaca09c9a5a140006619176c6ff5e7d4296a5 (patch) | |
tree | 3d6ec15c1391bfa3c4fa605aeffab39bdfdb18b8 | |
parent | 32f8de14d50cb998860b1ba5ebb0ce01f0a62fbe (diff) |
Serialize/Import subscriptions correctly5.0/speed-up-importer
Previously the recipients were not serialized to UIDs.
-rw-r--r-- | lib/RT/Attribute.pm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm index 20bbea2e3d..15e3ce6f6c 100644 --- a/lib/RT/Attribute.pm +++ b/lib/RT/Attribute.pm @@ -958,6 +958,22 @@ sub PostInflateFixup { } elsif ($self->Name eq 'Subscription') { my $content = $self->Content; + for my $type ( qw/Users Groups/ ) { + if ( my $list = $content->{Recipients}{$type} ) { + my @ids; + for my $item ( @$list ) { + if ( ref $item eq 'SCALAR' ) { + my $obj = $importer->LookupObj($$item); + push @ids, $obj->Id if $obj && $obj->Id; + } + else { + push @ids, $item; + } + } + @$list = @ids; + } + } + if (ref($content->{DashboardId}) eq 'SCALAR') { my $attr = $importer->LookupObj(${ $content->{DashboardId} }); if ($attr) { @@ -1021,6 +1037,24 @@ sub Serialize { elsif ($store{Name} eq 'Subscription') { my $content = $self->_DeserializeContent($store{Content}); $content->{DashboardId} = \( join '-', 'RT::Attribute', $RT::Organization, $content->{DashboardId} ); + + # encode user/groups to be UIDs + for my $type (qw/Users Groups/) { + if ( $content->{Recipients}{$type} ) { + my $class = $type eq 'Users' ? 'RT::User' : 'RT::Group'; + my @uids; + for my $id ( @{ $content->{Recipients}{$type} } ) { + my $obj = $class->new( RT->SystemUser ); + $obj->Load($id); + if ( $obj->Id ) { + push @uids, + \( join '-', $class, $class eq 'RT::User' ? $obj->Name : ( $RT::Organization, $obj->Id ) ); + } + } + $content->{Recipients}{$type} = \@uids; + } + } + $store{Content} = $self->_SerializeContent($content); } |