X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FObjectCustomFieldValue.pm;h=9b699c4d432db592bc3624395fde46f17d59e698;hb=HEAD;hp=9af328a2fb0a9f91f796d77e7c41c1c0996c11e7;hpb=de9d037528895f7151a9aead6724ce2df95f9586;p=freeside.git diff --git a/rt/lib/RT/ObjectCustomFieldValue.pm b/rt/lib/RT/ObjectCustomFieldValue.pm index 9af328a2f..9b699c4d4 100644 --- a/rt/lib/RT/ObjectCustomFieldValue.pm +++ b/rt/lib/RT/ObjectCustomFieldValue.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -107,7 +107,7 @@ sub Create { $self->_EncodeLOB( $args{'LargeContent'}, $args{'ContentType'} ) if defined $args{'LargeContent'}; - return $self->SUPER::Create( + ( my $id, $msg ) = $self->SUPER::Create( CustomField => $args{'CustomField'}, ObjectType => $args{'ObjectType'}, ObjectId => $args{'ObjectId'}, @@ -117,6 +117,23 @@ sub Create { ContentType => $args{'ContentType'}, ContentEncoding => $args{'ContentEncoding'}, ); + + if ( $id ) { + my $new_value = RT::ObjectCustomFieldValue->new( $self->CurrentUser ); + $new_value->Load( $id ); + my $ocfv_key = $new_value->GetOCFVCacheKey(); + if ( $RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key} ) { + push @{ $RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key} }, + { + 'ObjectId' => $new_value->Id, + 'CustomFieldObj' => $new_value->CustomFieldObj, + 'Content' => $new_value->_Value('Content'), + 'LargeContent' => $new_value->LargeContent, + }; + } + } + + return wantarray ? ( $id, $msg ) : $id; } @@ -288,7 +305,15 @@ Disable this value. Used to remove "current" values from records while leaving t sub Delete { my $self = shift; - return $self->SetDisabled(1); + my ( $ret, $msg ) = $self->SetDisabled( 1 ); + if ( $ret ) { + my $ocfv_key = $self->GetOCFVCacheKey(); + if ( $RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key} ) { + @{ $RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key} } = + grep { $_->{'ObjectId'} != $self->Id } @{ $RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key} }; + } + } + return wantarray ? ( $ret, $msg ) : $ret; } =head2 _FillInTemplateURL URL @@ -481,6 +506,20 @@ sub ParseIP { } +=head2 GetOCFVCacheKey + +Get the OCFV cache key for this object + +=cut + +sub GetOCFVCacheKey { + my $self = shift; + my $ocfv_key = "CustomField-" . $self->CustomField + . '-ObjectType-' . $self->ObjectType + . '-ObjectId-' . $self->ObjectId; + return $ocfv_key; +} + =head2 id Returns the current value of id.