@@ -389,20 +389,28 @@ sub SetSubValues {
389389
390390}
391391
392+ =head2 Object
392393
393- sub Object {
394- my $self = shift ;
395- my $object_type = $self -> __Value(' ObjectType' );
396- my $object ;
397- eval { $object = $object_type -> new($self -> CurrentUser) };
398- unless (UNIVERSAL::isa($object , $object_type )) {
399- $RT::Logger -> error(" Attribute " .$self -> Id." has a bogus object type - $object_type (" .$@ ." )" );
400- return (undef );
401- }
402- $object -> Load($self -> __Value(' ObjectId' ));
394+ Returns the object current attribute blongs to.
403395
404- return ($object );
396+ CAVEAT: the returned object is cached, reload it to get the latest data.
397+
398+ =cut
405399
400+ sub Object {
401+ my $self = shift ;
402+ unless ( $self -> {_cached }{Object } ) {
403+ my $object_type = $self -> __Value(' ObjectType' );
404+ my $object ;
405+ eval { $object = $object_type -> new( $self -> CurrentUser ) };
406+ unless ( UNIVERSAL::isa( $object , $object_type ) ) {
407+ $RT::Logger -> error( " Attribute " . $self -> Id . " has a bogus object type - $object_type (" . $@ . " )" );
408+ return (undef );
409+ }
410+ $object -> Load( $self -> __Value(' ObjectId' ) );
411+ $self -> {_cached }{Object } = $object ;
412+ }
413+ return $self -> {_cached }{Object };
406414}
407415
408416
@@ -1031,6 +1039,22 @@ sub PostInflateFixup {
10311039 }
10321040 elsif ($self -> Name eq ' Subscription' ) {
10331041 my $content = $self -> Content;
1042+ for my $type ( qw/ Users Groups/ ) {
1043+ if ( my $list = $content -> {Recipients }{$type } ) {
1044+ my @ids ;
1045+ for my $item ( @$list ) {
1046+ if ( ref $item eq ' SCALAR' ) {
1047+ my $obj = $importer -> LookupObj($$item );
1048+ push @ids , $obj -> Id if $obj && $obj -> Id;
1049+ }
1050+ else {
1051+ push @ids , $item ;
1052+ }
1053+ }
1054+ @$list = @ids ;
1055+ }
1056+ }
1057+
10341058 if (ref ($content -> {DashboardId }) eq ' SCALAR' ) {
10351059 my $attr = $importer -> LookupObj(${ $content -> {DashboardId } });
10361060 if ($attr ) {
@@ -1046,6 +1070,17 @@ sub PostInflateFixup {
10461070 }
10471071 $self -> SetContent( $content , SyncLinks => 0, RecordTransaction => 0 );
10481072 }
1073+ elsif ( $self -> Name eq ' Bookmarks' ) {
1074+ my $content = $self -> Content;
1075+ my @ids ;
1076+ for my $uid (@$content ) {
1077+ if ( my $ticket = $importer -> LookupObj($$uid ) ) {
1078+ push @ids , $ticket -> Id;
1079+ }
1080+ }
1081+ $content = { map { $_ => 1 } @ids };
1082+ $self -> SetContent($content );
1083+ }
10491084}
10501085
10511086sub PostInflate {
@@ -1069,28 +1104,21 @@ sub Serialize {
10691104 my $content = $self -> _DeserializeContent($store {Content });
10701105 for my $pane (values %{ $content || {} }) {
10711106 for (@$pane ) {
1072- my $attr = RT::Attribute-> new($self -> CurrentUser);
1073- $attr -> LoadById($_ );
1074- $_ = \($attr -> UID);
1107+ $_ = \( join ' -' , ' RT::Attribute' , $RT::Organization , $_ );
10751108 }
10761109 }
10771110 $store {Content } = $self -> _SerializeContent($content );
10781111 }
10791112 elsif ( $store {Name } =~ / DefaultDashboard$ / ) {
1080- my $content = $store {Content };
1081- my $attr = RT::Attribute-> new( $self -> CurrentUser );
1082- $attr -> LoadById($content );
1083- $store {Content } = \$attr -> UID;
1113+ $store {Content } = \( join ' -' , ' RT::Attribute' , $RT::Organization , $store {Content } );
10841114 }
10851115 # encode saved searches and dashboards to be UIDs
10861116 elsif ($store {Name } eq ' Dashboard' ) {
10871117 my $content = $self -> _DeserializeContent($store {Content }) || {};
10881118 for my $pane (values %{ $content -> {Panes } || {} }) {
10891119 for (@$pane ) {
10901120 if ($_ -> {portlet_type } eq ' search' || $_ -> {portlet_type } eq ' dashboard' ) {
1091- my $attr = RT::Attribute-> new($self -> CurrentUser);
1092- $attr -> LoadById($_ -> {id });
1093- $_ -> {uid } = \($attr -> UID);
1121+ $_ -> {uid } = \( join ' -' , ' RT::Attribute' , $RT::Organization , $_ -> {id } );
10941122 }
10951123 # pass through everything else (e.g. component)
10961124 }
@@ -1100,9 +1128,30 @@ sub Serialize {
11001128 # encode subscriptions to have dashboard UID
11011129 elsif ($store {Name } eq ' Subscription' ) {
11021130 my $content = $self -> _DeserializeContent($store {Content });
1103- my $attr = RT::Attribute-> new($self -> CurrentUser);
1104- $attr -> LoadById($content -> {DashboardId });
1105- $content -> {DashboardId } = \($attr -> UID);
1131+ $content -> {DashboardId } = \( join ' -' , ' RT::Attribute' , $RT::Organization , $content -> {DashboardId } );
1132+
1133+ # encode user/groups to be UIDs
1134+ for my $type (qw/ Users Groups/ ) {
1135+ if ( $content -> {Recipients }{$type } ) {
1136+ my $class = $type eq ' Users' ? ' RT::User' : ' RT::Group' ;
1137+ my @uids ;
1138+ for my $id ( @{ $content -> {Recipients }{$type } } ) {
1139+ my $obj = $class -> new( RT-> SystemUser );
1140+ $obj -> Load($id );
1141+ if ( $obj -> Id ) {
1142+ push @uids ,
1143+ \( join ' -' , $class , $class eq ' RT::User' ? $obj -> Name : ( $RT::Organization , $obj -> Id ) );
1144+ }
1145+ }
1146+ $content -> {Recipients }{$type } = \@uids ;
1147+ }
1148+ }
1149+
1150+ $store {Content } = $self -> _SerializeContent($content );
1151+ }
1152+ elsif ( $self -> Name eq ' Bookmarks' ) {
1153+ my $content = $self -> Content;
1154+ $content = [ map { \( join ' -' , ' RT::Ticket' , $RT::Organization , $_ ) } keys %$content ];
11061155 $store {Content } = $self -> _SerializeContent($content );
11071156 }
11081157
0 commit comments