[Rt-commit] r4461 - in rt/branches/QUEBEC-EXPERIMENTAL: .
alexmv at bestpractical.com
alexmv at bestpractical.com
Tue Jan 31 23:42:41 EST 2006
Author: alexmv
Date: Tue Jan 31 23:42:41 2006
New Revision: 4461
Modified:
rt/branches/QUEBEC-EXPERIMENTAL/ (props changed)
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Action/CreateTickets.pm
Log:
r8869 at zoq-fot-pik: chmrr | 2006-01-31 23:41:57 -0500
* Custom field updating during processing
* Better error handling when ticket id doesn't exist during update
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Action/CreateTickets.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Action/CreateTickets.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Action/CreateTickets.pm Tue Jan 31 23:42:41 2006
@@ -673,13 +673,11 @@
my $id = $template_id;
$id =~ s/update-(\d+).*/$1/;
- $T::Tickets{$template_id}->Load($id);
+ my ($loaded, $msg) = $T::Tickets{$template_id}->LoadById($id);
- my $msg;
- if ( !$T::Tickets{$template_id}->Id ) {
- $msg = "Couldn't update ticket $template_id " . $msg;
-
- $RT::Logger->error($msg);
+ unless ( $loaded ) {
+ $RT::Logger->error("Couldn't update ticket $template_id: " . $msg);
+ push @results, $self->loc( "Couldn't load ticket '[_1]'", $id );
next;
}
@@ -715,6 +713,9 @@
push @results,
$self->UpdateWatchers( $T::Tickets{$template_id}, $ticketargs );
+ push @results,
+ $self->UpdateCustomFields( $T::Tickets{$template_id}, $ticketargs );
+
next unless $ticketargs->{'MIMEObj'};
if ( $ticketargs->{'UpdateType'} =~ /^(private|comment)$/i ) {
my ( $Transaction, $Description, $Object )
@@ -1316,6 +1317,47 @@
return @results;
}
+sub UpdateCustomFields {
+ my $self = shift;
+ my $ticket = shift;
+ my $args = shift;
+
+ my @results;
+ foreach my $arg (keys %{$args}) {
+ warn "Looking at arg $arg";
+ next unless $arg =~ /^CustomField-(\d+)$/;
+ my $cf = $1;
+
+ my $CustomFieldObj = RT::CustomField->new($self->CurrentUser);
+ $CustomFieldObj->LoadById($cf);
+
+ my @values;
+ if ($CustomFieldObj->Type =~ /text/i) { # Both Text and Wikitext
+ @values = ($args->{$arg});
+ } else {
+ @values = split /\n/, $args->{$arg};
+ }
+
+ if ( ($CustomFieldObj->Type eq 'Freeform'
+ && ! $CustomFieldObj->SingleValue) ||
+ $CustomFieldObj->Type =~ /text/i) {
+ foreach my $val (@values) {
+ $val =~ s/\r//g;
+ }
+ }
+
+ foreach my $value (@values) {
+ next unless length($value);
+ my ( $val, $msg ) = $ticket->AddCustomFieldValue(
+ Field => $cf,
+ Value => $value
+ );
+ push ( @results, $msg );
+ }
+ }
+ return @results;
+}
+
sub PostProcess {
my $self = shift;
my $links = shift;
More information about the Rt-commit
mailing list