[Rt-commit] rt branch, 4.2/pluggable-cf-types, updated. rt-4.0.1rc1-39-gb2ee7b3

Chia-liang Kao clkao at bestpractical.com
Tue Jun 7 05:09:57 EDT 2011


The branch, 4.2/pluggable-cf-types has been updated
       via  b2ee7b383a53be963d1bb46dca393da7cab0d8b1 (commit)
       via  76eacd2e9334f7861cac17b8bc4a3686acc01b50 (commit)
       via  f50d64409a66bcf8bc668d86895b70afe0feba58 (commit)
       via  7d84d0580f9f94803a8e7f492c96eaa0ae63c8de (commit)
       via  4d6f9add7cbd555683ed1b348943e503d89c089c (commit)
       via  ec7dc6a92f43ae86d1ffed0483cb5b90618d365d (commit)
       via  9cc997a631a8a686f208b9fd8aec080a338d2487 (commit)
       via  bc35271d70cbe6f08845f38be541086b8a419833 (commit)
      from  fb75c72b458286e4d272325140d55377865c1dfb (commit)

Summary of changes:
 lib/RT/CustomField.pm                       |   85 ++++++++--------------
 lib/RT/CustomField/Type.pm                  |   62 +++++++++++++++
 lib/RT/CustomField/Type/Date.pm             |   22 ++++++
 lib/RT/CustomField/Type/DateTime.pm         |   62 +++++++++++++++
 lib/RT/CustomField/Type/IPAddress.pm        |    4 +-
 lib/RT/CustomField/Type/IPAddressRange.pm   |   51 ++++++++++++-
 lib/RT/CustomField/Type/ImageWithCaption.pm |   18 ++---
 lib/RT/Interface/Web.pm                     |   59 ++------------
 lib/RT/ObjectCustomFieldValue.pm            |   27 ++-----
 lib/RT/Tickets.pm                           |  108 +--------------------------
 10 files changed, 252 insertions(+), 246 deletions(-)
 create mode 100644 lib/RT/CustomField/Type.pm
 create mode 100644 lib/RT/CustomField/Type/Date.pm
 create mode 100644 lib/RT/CustomField/Type/DateTime.pm

- Log -----------------------------------------------------------------
commit bc35271d70cbe6f08845f38be541086b8a419833
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 15:36:26 2011 +0800

    pass ocfv into customfield type methods, so we have access to currentUser

diff --git a/lib/RT/CustomField/Type/IPAddress.pm b/lib/RT/CustomField/Type/IPAddress.pm
index 01592cd..8e3ca91 100644
--- a/lib/RT/CustomField/Type/IPAddress.pm
+++ b/lib/RT/CustomField/Type/IPAddress.pm
@@ -8,7 +8,7 @@ use Regexp::IPv6 qw($IPv6_re);
 $IPv6_re = qr/(?:$IPv6_re|::)/;
 
 sub CanonicalizeForCreate {
-    my ($self, $cf, $args) = @_;
+    my ($self, $cf, $ocfv, $args) = @_;
 
     if ( $args->{'Content'} ) {
         $args->{'Content'} = $self->ParseIP( $args->{'Content'} );
diff --git a/lib/RT/CustomField/Type/IPAddressRange.pm b/lib/RT/CustomField/Type/IPAddressRange.pm
index 920d222..4d8649e 100644
--- a/lib/RT/CustomField/Type/IPAddressRange.pm
+++ b/lib/RT/CustomField/Type/IPAddressRange.pm
@@ -12,7 +12,7 @@ require Net::CIDR;
 $IPv6_re = qr/(?:$IPv6_re|::)/;
 
 sub CanonicalizeForCreate {
-    my ($self, $cf, $args) = @_;
+    my ($self, $cf, $ocfv, $args) = @_;
 
     if ($args->{'Content'}) {
         ($args->{'Content'}, $args->{'LargeContent'}) =
diff --git a/lib/RT/CustomField/Type/ImageWithCaption.pm b/lib/RT/CustomField/Type/ImageWithCaption.pm
index 9898ccc..51bc340 100644
--- a/lib/RT/CustomField/Type/ImageWithCaption.pm
+++ b/lib/RT/CustomField/Type/ImageWithCaption.pm
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 
 sub CanonicalizeForCreate {
-    my ($self, $cf, $args) = @_;
+    my ($self, $cf, $ocfv, $args) = @_;
 
     return wantarray ? (1) : 1;
 }
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 6480134..a6fdb3e 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -67,7 +67,7 @@ sub _CanonicalizeForCreate {
     my $class = $cf_as_sys->GetTypeClass;
 
     if ($class) {
-        my ($ret, $msg) = $class->CanonicalizeForCreate( $cf_as_sys, $args );
+        my ($ret, $msg) = $class->CanonicalizeForCreate( $cf_as_sys, $self, $args );
         unless ($ret) {
             return (0, $self->loc($msg));
         }

commit 9cc997a631a8a686f208b9fd8aec080a338d2487
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 15:37:00 2011 +0800

    migrate date and datetime cf type into their own classes.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index dba2c86..179b645 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -151,28 +151,8 @@ our %FieldTypes = (
                     'Enter up to [_1] values with autocompletion',    # loc
                   ]
     },
-
-    Date => {
-        sort_order => 90,
-        selection_type => 0,
-        labels         => [
-                    'Select multiple dates',                          # loc
-                    'Select date',                                    # loc
-                    'Select up to [_1] dates',                        # loc
-                  ]
-            },
-    DateTime => {
-        sort_order => 100,
-        selection_type => 0,
-        labels         => [
-                    'Select multiple datetimes',                      # loc
-                    'Select datetime',                                # loc
-                    'Select up to [_1] datetimes',                    # loc
-                  ]
-                },
 );
 
-
 our %FRIENDLY_OBJECT_TYPES =  ();
 
 RT::CustomField->_ForObjectType( 'RT::Queue-RT::Ticket' => "Tickets", );    #loc
@@ -217,6 +197,30 @@ sub GetTypeClass {
 }
 
 __PACKAGE__->RegisterType(
+    Date => {
+        class => 'RT::CustomField::Type::Date',
+        sort_order => 90,
+        selection_type => 0,
+        labels         => [
+                    'Select multiple dates',                          # loc
+                    'Select date',                                    # loc
+                    'Select up to [_1] dates',                        # loc
+                  ]
+            });
+
+__PACKAGE__->RegisterType(
+    DateTime => {
+        class => 'RT::CustomField::Type::DateTime',
+        sort_order => 100,
+        selection_type => 0,
+        labels         => [
+                    'Select multiple datetimes',                      # loc
+                    'Select datetime',                                # loc
+                    'Select up to [_1] datetimes',                    # loc
+                  ]
+    });
+
+__PACKAGE__->RegisterType(
     IPAddress => {
         sort_order => 110,
         selection_type => 0,
@@ -1440,12 +1444,6 @@ sub AddValueForObject {
         }
     }
 
-    if (my $canonicalizer = $self->can('_CanonicalizeValue'.$self->Type)) {
-         $canonicalizer->($self, \%args);
-    }
-
-
-
     my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
     my ($val, $msg) = $newval->Create(
         ObjectType   => ref($obj),
@@ -1467,31 +1465,6 @@ sub AddValueForObject {
 }
 
 
-
-sub _CanonicalizeValueDateTime {
-    my $self    = shift;
-    my $args    = shift;
-    my $DateObj = RT::Date->new( $self->CurrentUser );
-    $DateObj->Set( Format => 'unknown',
-                   Value  => $args->{'Content'} );
-    $args->{'Content'} = $DateObj->ISO;
-}
-
-# For date, we need to store Content as ISO date
-sub _CanonicalizeValueDate {
-    my $self = shift;
-    my $args = shift;
-
-    # in case user input date with time, let's omit it by setting timezone
-    # to utc so "hour" won't affect "day"
-    my $DateObj = RT::Date->new( $self->CurrentUser );
-    $DateObj->Set( Format   => 'unknown',
-                   Value    => $args->{'Content'},
-                   Timezone => 'UTC',
-                 );
-    $args->{'Content'} = $DateObj->Date( Timezone => 'UTC' );
-}
-
 =head2 MatchPattern STRING
 
 Tests the incoming string against the Pattern of this custom field object
diff --git a/lib/RT/CustomField/Type/Date.pm b/lib/RT/CustomField/Type/Date.pm
new file mode 100644
index 0000000..b26f466
--- /dev/null
+++ b/lib/RT/CustomField/Type/Date.pm
@@ -0,0 +1,32 @@
+package RT::CustomField::Type::Date;
+use strict;
+use warnings;
+
+sub CanonicalizeForCreate {
+    my ($self, $cf, $ocfv, $args) = @_;
+
+    # in case user input date with time, let's omit it by setting timezone
+    # to utc so "hour" won't affect "day"
+    my $DateObj = RT::Date->new( $ocfv->CurrentUser );
+    $DateObj->Set( Format   => 'unknown',
+                   Value    => $args->{'Content'},
+                   Timezone => 'UTC',
+                 );
+    $args->{'Content'} = $DateObj->Date( Timezone => 'UTC' );
+
+    return wantarray ? (1) : 1;
+}
+
+sub Stringify {
+    my ($self, $ocfv) = @_;
+    my $content = $ocfv->_Value('Content');
+
+    return $content
+}
+
+sub CanonicalizeForSearch {
+    my ($self, $cf, $value, $op ) = @_;
+    return $value;
+}
+
+1;
diff --git a/lib/RT/CustomField/Type/DateTime.pm b/lib/RT/CustomField/Type/DateTime.pm
new file mode 100644
index 0000000..cb2cc3a
--- /dev/null
+++ b/lib/RT/CustomField/Type/DateTime.pm
@@ -0,0 +1,28 @@
+package RT::CustomField::Type::DateTime;
+use strict;
+use warnings;
+
+sub CanonicalizeForCreate {
+    my ($self, $cf, $ocfv, $args) = @_;
+
+    my $DateObj = RT::Date->new( $ocfv->CurrentUser );
+    $DateObj->Set( Format => 'unknown',
+                   Value  => $args->{'Content'} );
+    $args->{'Content'} = $DateObj->ISO;
+
+    return wantarray ? (1) : 1;
+}
+
+sub Stringify {
+    my ($self, $ocfv) = @_;
+    my $content = $ocfv->_Value('Content');
+
+    return $content
+}
+
+sub CanonicalizeForSearch {
+    my ($self, $cf, $value, $op ) = @_;
+    return $value;
+}
+
+1;

commit ec7dc6a92f43ae86d1ffed0483cb5b90618d365d
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 15:40:01 2011 +0800

    move common things into RT::CustomField::Type base class

diff --git a/lib/RT/CustomField/Type/DateTime.pm b/lib/RT/CustomField/Type.pm
similarity index 59%
copy from lib/RT/CustomField/Type/DateTime.pm
copy to lib/RT/CustomField/Type.pm
index cb2cc3a..7f815b0 100644
--- a/lib/RT/CustomField/Type/DateTime.pm
+++ b/lib/RT/CustomField/Type.pm
@@ -1,15 +1,9 @@
-package RT::CustomField::Type::DateTime;
+package RT::CustomField::Type;
 use strict;
 use warnings;
 
 sub CanonicalizeForCreate {
     my ($self, $cf, $ocfv, $args) = @_;
-
-    my $DateObj = RT::Date->new( $ocfv->CurrentUser );
-    $DateObj->Set( Format => 'unknown',
-                   Value  => $args->{'Content'} );
-    $args->{'Content'} = $DateObj->ISO;
-
     return wantarray ? (1) : 1;
 }
 
diff --git a/lib/RT/CustomField/Type/Date.pm b/lib/RT/CustomField/Type/Date.pm
index b26f466..e0fce2a 100644
--- a/lib/RT/CustomField/Type/Date.pm
+++ b/lib/RT/CustomField/Type/Date.pm
@@ -2,6 +2,8 @@ package RT::CustomField::Type::Date;
 use strict;
 use warnings;
 
+use base qw(RT::CustomField::Type);
+
 sub CanonicalizeForCreate {
     my ($self, $cf, $ocfv, $args) = @_;
 
@@ -17,16 +19,4 @@ sub CanonicalizeForCreate {
     return wantarray ? (1) : 1;
 }
 
-sub Stringify {
-    my ($self, $ocfv) = @_;
-    my $content = $ocfv->_Value('Content');
-
-    return $content
-}
-
-sub CanonicalizeForSearch {
-    my ($self, $cf, $value, $op ) = @_;
-    return $value;
-}
-
 1;
diff --git a/lib/RT/CustomField/Type/DateTime.pm b/lib/RT/CustomField/Type/DateTime.pm
index cb2cc3a..bcbe76f 100644
--- a/lib/RT/CustomField/Type/DateTime.pm
+++ b/lib/RT/CustomField/Type/DateTime.pm
@@ -2,6 +2,8 @@ package RT::CustomField::Type::DateTime;
 use strict;
 use warnings;
 
+use base qw(RT::CustomField::Type);
+
 sub CanonicalizeForCreate {
     my ($self, $cf, $ocfv, $args) = @_;
 
@@ -13,16 +15,4 @@ sub CanonicalizeForCreate {
     return wantarray ? (1) : 1;
 }
 
-sub Stringify {
-    my ($self, $ocfv) = @_;
-    my $content = $ocfv->_Value('Content');
-
-    return $content
-}
-
-sub CanonicalizeForSearch {
-    my ($self, $cf, $value, $op ) = @_;
-    return $value;
-}
-
 1;
diff --git a/lib/RT/CustomField/Type/IPAddress.pm b/lib/RT/CustomField/Type/IPAddress.pm
index 8e3ca91..b7c2cc5 100644
--- a/lib/RT/CustomField/Type/IPAddress.pm
+++ b/lib/RT/CustomField/Type/IPAddress.pm
@@ -2,6 +2,8 @@ package RT::CustomField::Type::IPAddress;
 use strict;
 use warnings;
 
+use base qw(RT::CustomField::Type);
+
 use Regexp::Common qw(RE_net_IPv4);
 use Regexp::IPv6 qw($IPv6_re);
 
diff --git a/lib/RT/CustomField/Type/ImageWithCaption.pm b/lib/RT/CustomField/Type/ImageWithCaption.pm
index 51bc340..2d586e1 100644
--- a/lib/RT/CustomField/Type/ImageWithCaption.pm
+++ b/lib/RT/CustomField/Type/ImageWithCaption.pm
@@ -2,18 +2,7 @@ package RT::CustomField::Type::ImageWithCaption;
 use strict;
 use warnings;
 
-sub CanonicalizeForCreate {
-    my ($self, $cf, $ocfv, $args) = @_;
-
-    return wantarray ? (1) : 1;
-}
-
-sub Stringify {
-    my ($self, $ocfv) = @_;
-    my $content = $ocfv->_Value('Content');
-
-    return $content
-}
+use base qw(RT::CustomField::Type);
 
 sub CreateArgsFromWebArgs {
     my ($self, $cf, $web_args) = @_;

commit 4d6f9add7cbd555683ed1b348943e503d89c089c
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 15:44:01 2011 +0800

    Provide base type class for all cf types.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 179b645..5506639 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -61,6 +61,7 @@ sub Table {'CustomFields'}
 use RT::CustomFieldValues;
 use RT::ObjectCustomFields;
 use RT::ObjectCustomFieldValues;
+use RT::CustomField::Type;
 
 our %FieldTypes = (
     Select => {
@@ -179,7 +180,6 @@ our $RIGHT_CATEGORIES = {
 # Tell RT::ACE that this sort of object can get acls granted
 $RT::ACE::OBJECT_TYPES{'RT::CustomField'} = 1;
 
-
 sub RegisterType {
     my ($class, $name, $param) = @_;
     $FieldTypes{$name} = $param;
@@ -191,9 +191,11 @@ sub RegisterType {
 
 sub GetTypeClass {
     my ($self) = @_;
-    return unless $self->Type;
-    my $type = $FieldTypes{$self->Type};
-    $type ? $type->{class} : undef;
+    if ($self->Type) {
+        my $type = $FieldTypes{$self->Type};
+        return $type->{class} if $type && $type->{class};
+    }
+    return 'RT::CustomField::Type';
 }
 
 __PACKAGE__->RegisterType(

commit 7d84d0580f9f94803a8e7f492c96eaa0ae63c8de
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 16:16:32 2011 +0800

    split update args processing from create args processing.

diff --git a/lib/RT/CustomField/Type/ImageWithCaption.pm b/lib/RT/CustomField/Type/ImageWithCaption.pm
index 2d586e1..08592fb 100644
--- a/lib/RT/CustomField/Type/ImageWithCaption.pm
+++ b/lib/RT/CustomField/Type/ImageWithCaption.pm
@@ -15,4 +15,9 @@ sub CreateArgsFromWebArgs {
     return $args;
 }
 
+sub UpdateArgsFromWebArgs {
+    my ($self, $cf, $web_args) = @_;
+    $self->CreateArgsFromWebArgs($cf, $web_args);
+}
+
 1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 39e0031..1bafe61 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2259,8 +2259,8 @@ sub _ProcessObjectCustomFieldUpdates {
 
     my $class = $cf->GetTypeClass;
 
-    if ($class && $class->can('CreateArgsFromWebArgs')) {
-        my $args = $class->CreateArgsFromWebArgs($cf, $args{'ARGS'});
+    if ($class && $class->can('UpdateArgsFromWebArgs')) {
+        my $args = $class->UpdateArgsFromWebArgs($cf, $args{'ARGS'});
         if ($args) {
             my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
                 Field => $cf->id,

commit f50d64409a66bcf8bc668d86895b70afe0feba58
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 16:16:57 2011 +0800

    move CreateArgsFromWebArgs into base type class and simplify caller

diff --git a/lib/RT/CustomField/Type.pm b/lib/RT/CustomField/Type.pm
index 7f815b0..4bf4177 100644
--- a/lib/RT/CustomField/Type.pm
+++ b/lib/RT/CustomField/Type.pm
@@ -19,4 +19,36 @@ sub CanonicalizeForSearch {
     return $value;
 }
 
+sub CreateArgsFromWebArgs {
+    my ($self, $cf, $web_args) = @_;
+
+    for my $arg (keys %$web_args) {
+        next if $arg =~ /^(?:Magic|Category)$/;
+
+        if ( $arg eq 'Upload'  && $web_args->{$arg}) {
+            return HTML::Mason::Commands::_UploadedFileArgs($web_args->{Upload});
+        }
+
+        my $type = $cf->Type;
+
+        my @values = ();
+        if ( ref $web_args->{$arg} eq 'ARRAY' ) {
+            @values = @{ $web_args->{$arg} };
+        } elsif ( $type =~ /text/i ) {
+            @values = ( $web_args->{$arg} );
+        } else {
+            no warnings 'uninitialized';
+            @values = split /\r*\n/, $web_args->{$arg};
+        }
+        @values = grep length, map {
+            s/\r+\n/\n/g;
+            s/^\s+//;
+            s/\s+$//;
+            $_;
+        } grep defined, @values;
+
+        return \@values;
+    }
+}
+
 1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 1bafe61..fcc6c02 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1362,7 +1362,9 @@ sub CreateTicket {
                       : ()
                   } keys %ARGS;
 
-        _FillCreateArgsFromWebArgs($cf, \%web_args, \%create_args);
+        my $key = "CustomField-".$cf->Id;
+        my $class = $cf->GetTypeClass;
+        $create_args{$key} = $class->CreateArgsFromWebArgs($cf, \%web_args);
     }
 
     # turn new link lists into arrays, and pass in the proper arguments
@@ -1394,49 +1396,6 @@ sub CreateTicket {
 }
 
 
-sub _FillCreateArgsFromWebArgs {
-    my ($cf, $web_args, $create_args) = @_;
-
-    my $key = "CustomField-".$cf->Id;
-
-    my $class = $cf->GetTypeClass;
-
-    if ($class && $class->can('CreateArgsFromWebArgs')) {
-        $create_args->{$key} = $class->CreateArgsFromWebArgs($cf, $web_args);
-        return;
-    }
-
-    for my $arg (keys %$web_args) {
-        next if $arg =~ /^(?:Magic|Category)$/;
-        if ( $arg eq 'Upload' ) {
-            $create_args->{$key} = _UploadedFileArgs($web_args->{$arg})
-                if $web_args->{$arg};
-            next;
-        }
-
-        my $type = $cf->Type;
-
-        my @values = ();
-        if ( ref $web_args->{$arg} eq 'ARRAY' ) {
-            @values = @{ $web_args->{$arg} };
-        } elsif ( $type =~ /text/i ) {
-            @values = ( $web_args->{$arg} );
-        } else {
-            no warnings 'uninitialized';
-            @values = split /\r*\n/, $web_args->{$arg};
-        }
-        @values = grep length, map {
-            s/\r+\n/\n/g;
-            s/^\s+//;
-            s/\s+$//;
-            $_;
-        } grep defined, @values;
-
-        $create_args->{$key} = \@values;
-    }
-}
-
-
 =head2  LoadTicket id
 
 Takes a ticket id as its only variable. if it's handed an array, it takes

commit 76eacd2e9334f7861cac17b8bc4a3686acc01b50
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 16:31:10 2011 +0800

    cf type class is now always available.  remove the conditions for checking

diff --git a/lib/RT/CustomField/Type.pm b/lib/RT/CustomField/Type.pm
index 4bf4177..8e2b7f6 100644
--- a/lib/RT/CustomField/Type.pm
+++ b/lib/RT/CustomField/Type.pm
@@ -11,7 +11,11 @@ sub Stringify {
     my ($self, $ocfv) = @_;
     my $content = $ocfv->_Value('Content');
 
-    return $content
+    if ( !(defined $content && length $content) && $ocfv->ContentType && $ocfv->ContentType eq 'text/plain' ) {
+        return $ocfv->LargeContent;
+    } else {
+        return $content;
+    }
 }
 
 sub CanonicalizeForSearch {
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index a6fdb3e..43c21af 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -63,14 +63,10 @@ sub Table {'ObjectCustomFieldValues'}
 
 sub _CanonicalizeForCreate {
     my ($self, $cf_as_sys, $args) = @_;
-
-    my $class = $cf_as_sys->GetTypeClass;
-
-    if ($class) {
-        my ($ret, $msg) = $class->CanonicalizeForCreate( $cf_as_sys, $self, $args );
-        unless ($ret) {
-            return (0, $self->loc($msg));
-        }
+    my $class = $cf_as_sys->GetTypeClass;# or return;
+    my ($ret, $msg) = $class->CanonicalizeForCreate( $cf_as_sys, $self, $args );
+    unless ($ret) {
+        return (0, $self->loc($msg));
     }
 
     return wantarray ? (1) : 1;
@@ -83,9 +79,7 @@ sub _CanonicalizeForSearch {
 
     my $class = $cf->GetTypeClass;
 
-    if ($class) {
-        $value = $class->CanonicalizeForSearch( $cf, $value, $op );
-    }
+    $value = $class->CanonicalizeForSearch( $cf, $value, $op );
 
     return $value;
 }
@@ -254,16 +248,7 @@ sub Content {
 
     my $class = $self->CustomFieldObj->GetTypeClass;
 
-    if ($class) {
-        return $class->Stringify( $self );
-    }
-
-    my $content = $self->_Value('Content');
-    if ( !(defined $content && length $content) && $self->ContentType && $self->ContentType eq 'text/plain' ) {
-        return $self->LargeContent;
-    } else {
-        return $content;
-    }
+    return $class->Stringify( $self );
 }
 
 =head2 Object

commit b2ee7b383a53be963d1bb46dca393da7cab0d8b1
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Jun 7 17:09:19 2011 +0800

    Move per-type CF limits to their own class

diff --git a/lib/RT/CustomField/Type.pm b/lib/RT/CustomField/Type.pm
index 8e2b7f6..55d0e44 100644
--- a/lib/RT/CustomField/Type.pm
+++ b/lib/RT/CustomField/Type.pm
@@ -55,4 +55,8 @@ sub CreateArgsFromWebArgs {
     }
 }
 
+sub Limit {
+    return;
+}
+
 1;
diff --git a/lib/RT/CustomField/Type/DateTime.pm b/lib/RT/CustomField/Type/DateTime.pm
index bcbe76f..a8248fa 100644
--- a/lib/RT/CustomField/Type/DateTime.pm
+++ b/lib/RT/CustomField/Type/DateTime.pm
@@ -15,4 +15,48 @@ sub CanonicalizeForCreate {
     return wantarray ? (1) : 1;
 }
 
+sub Limit {
+    my ($self, $tickets, $field, $value, $op, %rest) = @_;
+    return unless $op eq '=';
+    if ( $value =~ /:/ ) {
+        # there is time speccified.
+        my $date = RT::Date->new( $tickets->CurrentUser );
+        $date->Set( Format => 'unknown', Value => $value );
+
+        $tickets->_CustomFieldLimit(
+            'CF', '=', $date->ISO, %rest,
+            SUBKEY => $rest{'SUBKEY'}. '.Content',
+        );
+    }
+    else {
+        # no time specified, that means we want everything on a
+        # particular day.  in the database, we need to check for >
+        # and < the edges of that day.
+        my $date = RT::Date->new( $tickets->CurrentUser );
+        $date->Set( Format => 'unknown', Value => $value );
+        $date->SetToMidnight( Timezone => 'server' );
+        my $daystart = $date->ISO;
+        $date->AddDay;
+        my $dayend = $date->ISO;
+
+        $tickets->_OpenParen;
+
+
+        $tickets->_CustomFieldLimit(
+            'CF', '>=', $daystart, %rest,
+            SUBKEY => $rest{'SUBKEY'}. '.Content',
+        );
+
+        $tickets->_CustomFieldLimit(
+            'CF', '<=', $dayend, %rest,
+            SUBKEY => $rest{'SUBKEY'}. '.Content',
+            ENTRYAGGREGATOR => 'AND',
+        );
+
+        $tickets->_CloseParen;
+    }
+    return 1;
+
+}
+
 1;
diff --git a/lib/RT/CustomField/Type/IPAddressRange.pm b/lib/RT/CustomField/Type/IPAddressRange.pm
index 4d8649e..9e5b3e9 100644
--- a/lib/RT/CustomField/Type/IPAddressRange.pm
+++ b/lib/RT/CustomField/Type/IPAddressRange.pm
@@ -135,5 +135,54 @@ sub ParseIPRange {
     return $sIP, $eIP;
 }
 
+sub Limit {
+    my ($self, $tickets, $field, $value, $op, %rest) = @_;
+
+    return if $op =~ /^[<>]=?$/;
+
+    my ($start_ip, $end_ip) = split /-/, $value;
+
+    $tickets->_OpenParen;
+
+    if ( $op !~ /NOT|!=|<>/i ) { # positive equation
+        $tickets->_CustomFieldLimit(
+            'CF', '<=', $end_ip, %rest,
+            SUBKEY => $rest{'SUBKEY'}. '.Content',
+        );
+        $tickets->_CustomFieldLimit(
+            'CF', '>=', $start_ip, %rest,
+            SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
+            ENTRYAGGREGATOR => 'AND',
+        );
+        # as well limit borders so DB optimizers can use better
+        # estimations and scan less rows
+        # have to disable this tweak because of ipv6
+        #            $tickets->_CustomFieldLimit(
+        #                $field, '>=', '000.000.000.000', %rest,
+        #                SUBKEY          => $rest{'SUBKEY'}. '.Content',
+        #                ENTRYAGGREGATOR => 'AND',
+        #            );
+        #            $tickets->_CustomFieldLimit(
+        #                $field, '<=', '255.255.255.255', %rest,
+        #                SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
+        #                ENTRYAGGREGATOR => 'AND',
+        #            );
+    }
+    else { # negative equation
+        $tickets->_CustomFieldLimit($field, '>', $end_ip, %rest);
+        $tickets->_CustomFieldLimit(
+            $field, '<', $start_ip, %rest,
+            SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
+            ENTRYAGGREGATOR => 'OR',
+        );
+        # TODO: as well limit borders so DB optimizers can use better
+        # estimations and scan less rows, but it's harder to do
+        # as we have OR aggregator
+    }
+    $tickets->_CloseParen;
+
+    return 1;
+}
+
 
 1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index fcc6c02..b03b78a 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2252,7 +2252,7 @@ sub _ProcessObjectCustomFieldUpdates {
         }
 
         my @values = $_arg_values->($args{'ARGS'}->{$arg});
-        if ( $arg eq 'AddValue' || $arg eq 'Value' ) {
+        if ( $arg eq 'AddValue' || $arg eq 'Value' ) { # tested by t/web/cf_onqueue.t 
             foreach my $value (@values) {
                 my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
                     Field => $cf->id,
@@ -2260,11 +2260,11 @@ sub _ProcessObjectCustomFieldUpdates {
                 );
                 push( @results, $msg );
             }
-        } elsif ( $arg eq 'Upload' ) {
+        } elsif ( $arg eq 'Upload' ) { # untested
             my $value_hash = _UploadedFile( $args{'Prefix'} . $arg ) or next;
             my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue( %$value_hash, Field => $cf, );
             push( @results, $msg );
-        } elsif ( $arg eq 'Values' && !$cf->Repeated ) {
+        } elsif ( $arg eq 'Values' && !$cf->Repeated ) { # tested by t/web/cf_select_one.t
             my $cf_values = $args{'Object'}->CustomFieldValues( $cf->id );
 
             my %values_hash;
@@ -2295,7 +2295,7 @@ sub _ProcessObjectCustomFieldUpdates {
                 );
                 push( @results, $msg );
             }
-        } elsif ( $arg eq 'Values' ) {
+        } elsif ( $arg eq 'Values' ) { # untested
             my $cf_values = $args{'Object'}->CustomFieldValues( $cf->id );
 
             # keep everything up to the point of difference, delete the rest
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 98edc7f..e0ee746 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -1431,116 +1431,12 @@ Meta Data:
 
 =cut
 
-use Regexp::Common qw(RE_net_IPv4);
-use Regexp::Common::net::CIDR;
-
-sub _CustomFieldLimit_IPAddressRange {
-    my ($self, $field, $value, $op, %rest) = @_;
-
-    return if $op =~ /^[<>]=?$/;
-
-    my ($start_ip, $end_ip) = split /-/, $value;
-
-    $self->_OpenParen;
-
-    if ( $op !~ /NOT|!=|<>/i ) { # positive equation
-        $self->_CustomFieldLimit(
-            'CF', '<=', $end_ip, %rest,
-            SUBKEY => $rest{'SUBKEY'}. '.Content',
-        );
-        $self->_CustomFieldLimit(
-            'CF', '>=', $start_ip, %rest,
-            SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
-            ENTRYAGGREGATOR => 'AND',
-        );
-        # as well limit borders so DB optimizers can use better
-        # estimations and scan less rows
-        # have to disable this tweak because of ipv6
-        #            $self->_CustomFieldLimit(
-        #                $field, '>=', '000.000.000.000', %rest,
-        #                SUBKEY          => $rest{'SUBKEY'}. '.Content',
-        #                ENTRYAGGREGATOR => 'AND',
-        #            );
-        #            $self->_CustomFieldLimit(
-        #                $field, '<=', '255.255.255.255', %rest,
-        #                SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
-        #                ENTRYAGGREGATOR => 'AND',
-        #            );
-    }
-    else { # negative equation
-        $self->_CustomFieldLimit($field, '>', $end_ip, %rest);
-        $self->_CustomFieldLimit(
-            $field, '<', $start_ip, %rest,
-            SUBKEY          => $rest{'SUBKEY'}. '.LargeContent',
-            ENTRYAGGREGATOR => 'OR',
-        );
-        # TODO: as well limit borders so DB optimizers can use better
-        # estimations and scan less rows, but it's harder to do
-        # as we have OR aggregator
-    }
-    $self->_CloseParen;
-
-    return 1;
-}
-
-
-sub _CustomFieldLimit_Date {
-    my ($self, $field, $value, $op, %rest) = @_;
-
-    return unless $op eq '=';
-    if ( $value =~ /:/ ) {
-        # there is time speccified.
-        my $date = RT::Date->new( $self->CurrentUser );
-        $date->Set( Format => 'unknown', Value => $value );
-
-        $self->_CustomFieldLimit(
-            'CF', '=', $date->ISO, %rest,
-            SUBKEY => $rest{'SUBKEY'}. '.Content',
-        );
-    }
-    else {
-        # no time specified, that means we want everything on a
-        # particular day.  in the database, we need to check for >
-        # and < the edges of that day.
-        my $date = RT::Date->new( $self->CurrentUser );
-        $date->Set( Format => 'unknown', Value => $value );
-        $date->SetToMidnight( Timezone => 'server' );
-        my $daystart = $date->ISO;
-        $date->AddDay;
-        my $dayend = $date->ISO;
-
-        $self->_OpenParen;
-
-
-        $self->_CustomFieldLimit(
-            'CF', '>=', $daystart, %rest,
-            SUBKEY => $rest{'SUBKEY'}. '.Content',
-        );
-
-        $self->_CustomFieldLimit(
-            'CF', '<=', $dayend, %rest,
-            SUBKEY => $rest{'SUBKEY'}. '.Content',
-            ENTRYAGGREGATOR => 'AND',
-        );
-
-        $self->_CloseParen;
-    }
-    return 1;
-}
-
 # returns true if the custom field type expansion has handled the rest of the query
 sub _CustomFieldLimit_TypeExpansion {
     my ($self, $field, $cf, $value, $op, %rest) = @_;
 
-    if ($cf->Type eq 'IPAddressRange') {
-        return $self->_CustomFieldLimit_IPAddressRange($field, $value, $op, %rest);
-    }
-
-    if ( $cf->Type eq 'DateTime' ) {
-        return $self->_CustomFieldLimit_Date($field, $value, $op, %rest);
-    }
-
-    return;
+    my $class = $cf->GetTypeClass;
+    return $class->Limit($self, $field, $value, $op, %rest);
 }
 
 sub _CustomFieldLimit {

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


More information about the Rt-commit mailing list