[Rt-commit] r9147 - in rt/branches/3.6-EXPERIMENTAL-CLI:
html/REST/1.0/Forms/ticket
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue Sep 25 16:08:33 EDT 2007
Author: sunnavy
Date: Tue Sep 25 16:08:31 2007
New Revision: 9147
Modified:
rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in
rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default
Log:
we can now do things right with multiple value CF with bin/rt.
Modified: rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in (original)
+++ rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in Tue Sep 25 16:08:31 2007
@@ -1327,11 +1327,41 @@
my ($word, @words);
my @values = ref $val eq 'ARRAY' ? @$val : $val;
- foreach my $line (map {split /\n/} @values) {
+ foreach my $line ( map { split /\n/ } @values ) {
+
# XXX: This should become a real parser, à la Text::ParseWords.
$line =~ s/^\s+//;
$line =~ s/\s+$//;
- push @words, split /\s*,\s*/, $line;
+ my ( $a, $b ) = split /,/, $line, 2;
+
+ while ($a) {
+ no warnings 'uninitialized';
+ if ( $a =~ /^'/ ) {
+ my $s = $a;
+ while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
+ && $a =~ /(\\)+'$/ )) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ push @words, $s;
+ }
+ elsif ( $a =~ /^q{/ ) {
+ my $s = $a;
+ while ( $a !~ /}$/ ) {
+ ( $a, $b ) =
+ split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^q{/'/;
+ $s =~ s/}/'/;
+ push @words, $s;
+ }
+ else {
+ push @words, $a;
+ }
+ ( $a, $b ) = split /,/, $b, 2;
+ }
+
}
return \@words;
Modified: rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default (original)
+++ rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default Tue Sep 25 16:08:31 2007
@@ -217,8 +217,21 @@
next unless (!%$fields || (exists $fields->{"cf-".lc $cf->Name}));
my $vals = $ticket->CustomFieldValues($cf->Id());
my @out = ();
- while (my $v = $vals->Next()) {
- push @out, $v->Content;
+ if ( $cf->SingleValue ) {
+ my $v = $vals->Next;
+ push @out, $v->Content if $v;
+ }
+ else {
+ while (my $v = $vals->Next()) {
+ my $content = $v->Content;
+ $content =~ s/'/\\'/g;
+ if ( $v->Content =~ /,/ ) {
+ push @out, q{'} . $content . q{'};
+ }
+ else {
+ push @out, $content;
+ }
+ }
}
push @data, [ 'CF-' . $cf->Name => join ',', @out ];
}
@@ -313,9 +326,77 @@
$s = "Unknown custom field.";
}
else {
- ($n, $s) = $ticket->AddCustomFieldValue(
+ my $vals = $ticket->CustomFieldValues($cf->id);
+
+ if ( $cf->SingleValue ) {
+ my $old = $vals->Next;
+ if ( $old ) {
+ if ( $val ne $old->Content ) {
+ $old->Delete;
+ ($n, $s) = $ticket->AddCustomFieldValue(
+ Field => $cf, Value => $val );
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ else {
+ ($n, $s) = $ticket->AddCustomFieldValue(
Field => $cf, Value => $val );
- $s =~ s/^# // if defined $s;
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ else {
+ my @new;
+ my ( $a, $b ) = split /,/, $val, 2;
+ while ($a) {
+ no warnings 'uninitialized';
+ if ( $a =~ /^'/ ) {
+ my $s = $a;
+ while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
+ && $a =~ /(\\)+'$/ ) ) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^'//;
+ $s =~ s/'$//;
+ $s =~ s/\\'/'/g;
+ push @new, $s;
+ }
+ elsif ( $a =~ /^q{/ ) {
+ my $s = $a;
+ while ( $a !~ /}$/ ) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^q{//;
+ $s =~ s/}//;
+ push @new, $s;
+ }
+ else {
+ push @new, $a;
+ }
+ ( $a, $b ) = split /,/, $b, 2;
+ }
+
+ my %new;
+ $new{$_}++ for @new;
+
+ while (my $v = $vals->Next()) {
+ my $c = $v->Content;
+ if ( $new{$c} ) {
+ $new{$c}--;
+ }
+ else {
+ $v->Delete();
+ }
+ }
+ for ( @new ) {
+ while ( $new{$_} && $new{$_}-- ) {
+ ($n, $s) = $ticket->AddCustomFieldValue(
+ Field => $cf, Value => $_ );
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ }
}
}
elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
More information about the Rt-commit
mailing list