[Rt-commit] rt branch 5.0/dont-insert-duplicate-cfs-on-queue created. rt-5.0.3-235-g7d563521b5

BPS Git Server git at git.bestpractical.com
Mon Jan 30 21:01:19 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  7d563521b503f3fdd6a6dbaba3ade7f46d5fc271 (commit)

- Log -----------------------------------------------------------------
commit 7d563521b503f3fdd6a6dbaba3ade7f46d5fc271
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Mon Jan 30 16:00:20 2023 -0500

    Don't add duplicate Cfs to queue when inserting data
    
    It is possible to inadvertently add a custom field to a queue 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..d1b3b04b0c 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1345,6 +1345,30 @@ sub InsertData {
 
             } 
 
+            if( $apply_to && $item->{ LookupType } eq "RT::Queue-RT::Ticket" ) {
+                my $dupe_check = RT::CustomField->new( $RT::SystemUser );
+                my ($ok, $msg ) = $dupe_check->LoadByCols(
+                    Name       => $item->{'Name'},
+                    LookupType => $item->{ LookupType },
+                    Disabled   => 0,
+                );
+                if( $ok ) {
+                    my $queue = RT::Queue->new( $RT::SystemUser );
+                    ( $ok, $msg ) = $queue->LoadByCols( Name => $apply_to );
+                    if( $ok ) {
+                        my $ocf = RT::ObjectCustomField->new( $RT::SystemUser );
+                        ( $ok, $msg ) = $ocf->LoadByCols(
+                            CustomField => $dupe_check->id,
+                            ObjectId    => $queue->id,
+                        );
+                        if( $ok ) {
+                            $RT::Logger->error( "Custom field " . $dupe_check->Name . " already exists for $apply_to. Skipping." );
+                            next;
+                        }
+                    }
+                }
+            }
+
             my ( $return, $msg ) = $new_entry->Create(%$item);
             unless( $return ) {
                 $RT::Logger->error( $msg );

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list