CustomField Bulk Updates

We’ve recently upgraded to 3.2.2 and were happy to see the bulk update
feature with custom fields. The only problem is by default, the bulk
updater will set all custom field values to ‘(no value)’ - all of our custom
fields are selections rather than free form. I was wondering if anyone else
had run into this issue and was looking into a fix or workaround. If not,
can anyone think of a simple fix or work around. I’ll be happy to look into
the code in more detail and post my findings but I wanted to check the list
first.

Thanks for any info.

I have a fix for this but it has only been tested by me, but it
has been used at our site, in production with good results. I
can send a patch later today if you want.

-ToddOn Tue, Nov 30, 2004 at 08:48:37AM -0500, Matthew Meyer wrote:

We’ve recently upgraded to 3.2.2 and were happy to see the bulk update
feature with custom fields. The only problem is by default, the bulk
updater will set all custom field values to ‘(no value)’ - all of our custom
fields are selections rather than free form. I was wondering if anyone else
had run into this issue and was looking into a fix or workaround. If not,
can anyone think of a simple fix or work around. I’ll be happy to look into
the code in more detail and post my findings but I wanted to check the list
first.

Thanks for any info.


The rt-users Archives

Be sure to check out the RT wiki at http://wiki.bestpractical.com

I have a fix for this but it has only been tested by me, but it
has been used at our site, in production with good results. I
can send a patch later today if you want.

Can you attach the patch to this ticket, or if you send it to me, I can
do so:

http://rt3.fsck.com/Ticket/Display.html?id=6267

–Bret

Here is a patch against 3.2.2. Please test before using for
anything important.

-Todd

Index: html/Ticket/Elements/EditCustomField
— html/Ticket/Elements/EditCustomField (revision 1949)
+++ html/Ticket/Elements/EditCustomField (working copy)
@@ -68,8 +68,8 @@

<textarea cols=<%$Cols%> rows=<%$Rows%> name="<%$NamePrefix%><%$CustomField->Id%>-Values"><%$content%>
% } elsif ($CustomField->Type =~ /^Select/) {

  •  <input type="hidden" name="<%$NamePrefix%><%$CustomField->Id%>-Values-Magic" value="1">
    
  •  <select name="<%$NamePrefix%><%$CustomField->Id%>-Values"
    
  •  <input type="hidden" name="<%$NamePrefix%><%$CustomField->Id%>-Values<% $NameSuffix ? "-$NameSuffix" : ""%>-Ma
    

gic" value=“1”>

  •  <select name="<%$NamePrefix%><%$CustomField->Id%>-Values<% $NameSuffix ? "-$NameSuffix" : ""%>"
       size="<%$Rows%>"
       <%$CustomField->Type eq 'SelectMultiple' && 'MULTIPLE'%>>
    

% my $CustomFieldValues = $CustomField->Values();
@@ -90,6 +90,7 @@
$TicketObj => undef
$CustomField => undef
$NamePrefix => undef
+$NameSuffix => undef
$Rows => 5
$Cols=> 15
$Default => undef
Index: html/Search/Bulk.html
— html/Search/Bulk.html (revision 1949)
+++ html/Search/Bulk.html (working copy)
@@ -171,11 +171,21 @@
% }
<%$pref%> <% $cf->Name %>

<% $cf->FriendlyType %>
+% if ($cf->Type =~ /SelectSingle/) {
+
<&|/l&>Don’t update</&>
+% }

-% if ($cf->Type ne "FreeformMultiple") { +% if ($cf->Type eq "SelectMultiple") { +Add Values +<& /Ticket/Elements/EditCustomField, CustomField => $cf, NameSuffix => 'AddValue' &> +Delete Values +<& /Ticket/Elements/EditCustomField, CustomField => $cf, NameSuffix => 'DeleteValues' &> +% } +% elsif ($cf->Type ne "FreeformMultiple") { <& /Ticket/Elements/EditCustomField, CustomField => $cf &> -% } else { +% } +% else { Add Values
Index: lib/RT/Interface/Web.pm --- lib/RT/Interface/Web.pm (revision 1949) +++ lib/RT/Interface/Web.pm (working copy) @@ -294,8 +294,18 @@ ); foreach my $arg (%ARGS) { if ($arg =~ /^CustomField-(\d+)(.*?)$/) { + my $cfid = $1; next if ($arg =~ /-Magic$/); - $create_args{"CustomField-".$1} = $ARGS{"$arg"}; + my $cf = new RT::CustomField( $RT::SystemUser ); + $cf->Load($cfid); + if ($cf->Type eq 'FreeformMultiple') { + $ARGS{$arg} =~ s/\r\n/\n/g; + $ARGS{$arg} = [split('\n', $ARGS{$arg})]; + } + $create_args{"CustomField-".$cfid} = $ARGS{"$arg"}; } }

@@ -1006,7 +1016,8 @@
}
}

  • $ARGSRef->{‘Status’} ||= $TicketObj->Status;
  • #$ARGSRef->{‘Status’} ||= $TicketObj->Status;

  • delete $ARGSRef->{‘Status’} unless ($ARGSRef->{‘Status’});

    my @results = UpdateRecordObject(
    AttributesRef => @attribs,
    @@ -1053,50 +1064,55 @@
    my %custom_fields_to_mod;
    foreach my $arg ( keys %{$ARGSRef} ) {
    if ( $arg =~ /^Ticket-(\d+)-CustomField-(\d+)-/ ) {

  •        my ($tick, $cf) = ($1, $2);
    
  •        next if $ARGSRef->{"Ticket-$tick-CustomField-$cf-DoNotUpdate"};
    
           # For each of those tickets, find out what custom fields we want to work with.
    
  •        $custom_fields_to_mod{$1}{$2} = 1;
    
  •        $custom_fields_to_mod{$tick}{$cf} = 1;
       }
    

    }

    For each of those tickets

    foreach my $tick ( keys %custom_fields_to_mod ) {
    my $Ticket = $args{‘TicketObj’};

  •   if (!$Ticket or $Ticket->id != $tick) {
    
  •       $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
    
  •       $Ticket->Load($tick);
    
  •   }
    
  •    if (!$Ticket or $Ticket->id != $tick) {
    
  •        $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
    
  •        $Ticket->Load($tick);
    
  •    }
    
  •    # For each custom field
    
  •    # For each custom field
       foreach my $cf ( keys %{ $custom_fields_to_mod{$tick} } ) {
    
  •       my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
    
  •       $CustomFieldObj->LoadById($cf);
    
  •        my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
    
  •        $CustomFieldObj->LoadById($cf);
    
           foreach my $arg ( keys %{$ARGSRef} ) {
               # since http won't pass in a form element with a null value, we need
               # to fake it
    
  •            if ($arg =~ /^(.*?)-Values-Magic$/ ) {
    
  •            if ($arg =~ /^(.*?)-Values(.*)-Magic$/ ) {
                   # We don't care about the magic, if there's really a values element;
    
  •                next if (exists $ARGSRef->{$1.'-Values'}) ;
    
  •                next if (exists $ARGSRef->{$1.'-Values'.$2}) ;
    
  •                $arg = $1."-Values";
    
  •                $ARGSRef->{$1."-Values"} = undef;
    
  •                $arg = $1."-Values".$2;
    
  •                $ARGSRef->{$1."-Values".$2} = undef;
               }
               next unless ( $arg =~ /^Ticket-$tick-CustomField-$cf-/ );
               my @values =
    
  •              ( ref( $ARGSRef->{$arg} ) eq 'ARRAY' )
    
  •              ( ref( $ARGSRef->{$arg} ) eq 'ARRAY' )
                 ? @{ $ARGSRef->{$arg} }
                 : split /\n/, $ARGSRef->{$arg} ;
    
  •           #for poor windows boxen that pass in "\r\n"
    
  •           local $/ = "\r";
    
  •           chomp @values;
    
  •            #for poor windows boxen that pass in "\r\n"
    
  •            local $/ = "\r";
    
  •            chomp @values;
    
               if ( ( $arg =~ /-AddValue$/ ) || ( $arg =~ /-Value$/ ) ) {
    
  •                my $cf_values = $Ticket->CustomFieldValues($cf);
                   foreach my $value (@values) {
                       next unless length($value);
    
  •                    next if $cf_values->HasEntry($value);
                       my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
                           Field => $cf,
                           Value => $value
    

@@ -1105,8 +1121,10 @@
}
}
elsif ( $arg =~ /-DeleteValues$/ ) {

  •                my $cf_values = $Ticket->CustomFieldValues($cf);
                   foreach my $value (@values) {
                       next unless length($value);
    
  •                    next unless $cf_values->HasEntry($value);
                       my ( $val, $msg ) = $Ticket->DeleteCustomFieldValue(
                           Field => $cf,
                           Value => $value
    

@@ -1148,29 +1166,30 @@
elsif ( $arg =~ /-Values$/ ) {
my $cf_values = $Ticket->CustomFieldValues($cf);

  •               # keep everything up to the point of difference, delete the rest
    
  •               my $delete_flag;
    
  •               foreach my $old_cf (@{$cf_values->ItemsArrayRef}) {
    
  •                   if (!$delete_flag and @values and $old_cf->Content eq $values[0]) {
    
  •                       shift @values;
    
  •                       next;
    
  •                   }
    
  •                # keep everything up to the point of difference, delete the rest
    
  •                my $delete_flag;
    
  •                foreach my $old_cf (@{$cf_values->ItemsArrayRef}) {
    
  •                    if (!$delete_flag and @values and $old_cf->Content eq $values[0]) {
    
  •                        shift @values;
    
  •                        next;
    
  •                    }
    
  •                   $delete_flag ||= 1;
    
  •                   $old_cf->Delete;
    
  •               }
    
  •                    $delete_flag ||= 1;
    
  •                    $old_cf->Delete;
    
  •                }
    
  •               # now add/replace extra things, if any
    
  •               foreach my $value (@values) {
    
  •                   my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
    
  •                       Field => $cf,
    
  •                       Value => $value
    
  •                   );
    
  •                   push ( @results, $msg );
    
  •               }
    
  •           }
    
  •                # now add/replace extra things, if any
    
  •                foreach my $value (@values) {
    
  •                    my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
    
  •                        Field => $cf,
    
  •                        Value => $value
    
  •                    );
    
  •                    push ( @results, $msg );
    
  •                }
    
  •            }
               else {
    
  •                push ( @results, "User asked for an unknown update type for custom field " . $cf->Name . " for t
    

icket " . $Ticket->id );

  •                push ( @results, "User asked for an unknown update type for custom field " . $CustomFieldObj->Na
    

m
+e . " for ticket " . $Ticket->id );
}
}
}

I cannot apply this patch. There are some errors because of faulty line
breaks or something. Can somebody please send this patch as attachment
to me?

debian64:/usr/share/request-tracker3.2# cat patchfile|patch -p0
patching file html/Ticket/Elements/EditCustomField
patching file html/Search/Bulk.html
patching file lib/RT/Interface/Web.pm
Hunk #2 FAILED at 1016.
Hunk #3 FAILED at 1064.
patch: **** malformed patch at line 219:

Thanks in advance!
Stefan

Stefan,

I had similar problems and just worked through the diff and reject files to
get the right code.

I’ll see if I can work up a diff for Web.pm from my local repository and
send it on as an attachment.

– Matt-----Original Message-----
From: Stefan Fischer [mailto:stefan@van-boxmer.de]
Sent: Tuesday, January 18, 2005 9:00 AM
To: Todd Chapman
Cc: Bret Martin; mmeyer@jasi.com; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] CustomField Bulk Updates

I cannot apply this patch. There are some errors because of faulty line
breaks or something. Can somebody please send this patch as attachment
to me?

debian64:/usr/share/request-tracker3.2# cat patchfile|patch -p0
patching file html/Ticket/Elements/EditCustomField
patching file html/Search/Bulk.html
patching file lib/RT/Interface/Web.pm
Hunk #2 FAILED at 1016.
Hunk #3 FAILED at 1064.
patch: **** malformed patch at line 219:

Thanks in advance!
Stefan

Hi all,

is it possibile to make a search inside a ticket content using RT web
interface or CLI ? Is it a supported feature?
I have RT 3.0.6, perl 5.8.0, mysql 4.0.16, apache 1.3.29 installed on
FreeBSD 5.1

Thanks in advance

Francesca Del Corso

Istituto Nazionale di Fisica Nucleare - Sez. Firenze
c/o Polo Scientifico e Tecnologico
via G. Sansone, 1 50019 Sesto Fiorentino (FI) Italy
phone: +39-055-4572112 fax: +39-055-4572150
e-mail:delcorso@fi.infn.it

Matt,

the problem is solved, thanks for your help! I switched to the www-data
user and started the fastcgi handler by hand. This was the only way to
see a little syntax error in Web.pm after i patched the file by hand…

  • Stefan

Matthew Meyer wrote:

Stefan,

I also wanted to ask if you had made the database upgrades for 3.2.2 .
Hanging can also be a symptom of not updating the schema, in my experience
with RT. There is info in the installation documentation on how to upgrade
the schema.

– Matt-----Original Message-----
From: Matthew Meyer [mailto:mmeyer@jasi.com]
Sent: Tuesday, January 18, 2005 11:03 AM
To: ‘Stefan Fischer’
Subject: RE: [rt-users] CustomField Bulk Updates

Stefan,

That’s too bad. I’m not sure where the problem lies as this is working in
my local setup (Red Hat). Since Web.pm is a library file, you would also
need to restart apache to get the new version working.

I am not familiar with how Debian does packages and how closely they
resemble the original versions.

– Matt

-----Original Message-----
From: Stefan Fischer [mailto:stefan@van-boxmer.de]
Sent: Tuesday, January 18, 2005 10:33 AM
To: Matthew Meyer
Subject: Re: [rt-users] CustomField Bulk Updates

Hello Matt,

may i am doing something wrong here, i still get errors:

debian64:/usr/share/request-tracker3.2/lib/RT/Interface# patch Web.pm
Web.pm.diff
patching file Web.pm
Hunk #2 FAILED at 1016.
Hunk #3 FAILED at 1063.
patch unexpectedly ends in middle of line
Hunk #4 succeeded at 1164 with fuzz 1.
2 out of 4 hunks FAILED – saving rejects to file Web.pm.rej

when i try the fully patched Web.pm the whole RT System hangs, nothing
happens within the browser.
I am using 3.2.2 from Debian Package, maybe this is not the original Web.pm.

– Stefan

Matthew Meyer wrote:

Here ya go,

A Web.pm diff and a fully patched Web.pm file are attached.

This is for RT 3.2.2 and contains changes from Todd’s patch. The diff is
only for Web.pm as that appeared to be the problematic one.

Let me know how it works for ya.

– Matt

-----Original Message-----
From: Stefan Fischer [mailto:stefan@van-boxmer.de]
Sent: Tuesday, January 18, 2005 9:00 AM
To: Todd Chapman
Cc: Bret Martin; mmeyer@jasi.com; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] CustomField Bulk Updates

I cannot apply this patch. There are some errors because of faulty line
breaks or something. Can somebody please send this patch as attachment
to me?

debian64:/usr/share/request-tracker3.2# cat patchfile|patch -p0
patching file html/Ticket/Elements/EditCustomField
patching file html/Search/Bulk.html
patching file lib/RT/Interface/Web.pm
Hunk #2 FAILED at 1016.
Hunk #3 FAILED at 1064.
patch: **** malformed patch at line 219:

Thanks in advance!
Stefan

</pre></blockquote>