[Rt-commit] rt branch 5.0/dont-insert-duplicate-cfs-on-queue created. rt-5.0.3-237-g69a9413130
BPS Git Server
git at git.bestpractical.com
Fri Feb 3 20:28:35 UTC 2023
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/dont-insert-duplicate-cfs-on-queue has been created
at 69a94131302cdcae909eec88b2f19ac46097c27a (commit)
- Log -----------------------------------------------------------------
commit 69a94131302cdcae909eec88b2f19ac46097c27a
Author: Jason Crome <jcrome at bestpractical.com>
Date: Mon Jan 30 16:00:20 2023 -0500
Don't add duplicate Cfs to object when inserting data
It is possible to inadvertently add a custom field to an object multiple
times when inserting from an initialdata file. This change prevents this
from happening.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 5b63911441..229f23e3a3 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1343,7 +1343,47 @@ sub InsertData {
delete $item->{'BasedOn'};
}
- }
+ }
+
+ my $cf_check = RT::CustomField->new( $RT::SystemUser );
+ my( $found ) = $cf_check->LoadByName(
+ Name => $item->{'Name'},
+ LookupType => $item->{ LookupType },
+ IncludeGlobal => 1,
+ );
+ if( $found ) {
+ my( $is_global, $is_applied, $what );
+
+ if( $cf_check->IsGlobal ) {
+ $is_global = 1;
+ } else {
+ my $thing;
+ my $class = $cf_check->RecordClassFromLookupType( $item->{ LookupType} );
+ if ($class) {
+ $thing = $class->new( RT->SystemUser );
+ $apply_to = [ $apply_to ] unless ref $apply_to;
+ foreach my $name ( @{ $apply_to } ) {
+ my ( $ok, $msg ) = $thing->LoadByCols( Name => $name );
+ if( $ok ) {
+ my $ocf = RT::ObjectCustomField->new( RT->SystemUser );
+ ( $is_applied ) = $ocf->LoadByCols(
+ CustomField => $cf_check->id,
+ ObjectId => $thing->id,
+ );
+ if( $is_applied ) {
+ $what = $name;
+ last;
+ }
+ }
+ }
+ }
+ }
+ if( $is_global or $is_applied ) {
+ $RT::Logger->warn( "Custom field " . $item->{ Name }. " already exists" .
+ ( $is_global ? " globally" : " for $what") . ". Skipping." );
+ next;
+ }
+ }
my ( $return, $msg ) = $new_entry->Create(%$item);
unless( $return ) {
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list