X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FObjectCustomFieldValue.pm;h=6bb09341a07225843592386a128a3eb113c777ae;hb=187086c479a09629b7d180eec513fb7657f4e291;hp=9af328a2fb0a9f91f796d77e7c41c1c0996c11e7;hpb=4639e25a658d9a0bf295415642fae8e8cdad846a;p=freeside.git diff --git a/rt/lib/RT/ObjectCustomFieldValue.pm b/rt/lib/RT/ObjectCustomFieldValue.pm index 9af328a2f..6bb09341a 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-2018 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.