[Rt-commit] rt branch, 4.4.2-releng, updated. rt-4.4.1-426-g75be4d3

Shawn Moore shawn at bestpractical.com
Thu Jun 1 14:42:43 EDT 2017


The branch, 4.4.2-releng has been updated
       via  75be4d3d333b5218788df9e8b76d1065d8a21504 (commit)
      from  17da0d115b11cb598de2bcccc90f5df39ea87c63 (commit)

Summary of changes:
 lib/RT/CustomField.pm          | 18 +++++--------
 t/customfields/unique_values.t | 58 +++++++++++++++++++++++-------------------
 2 files changed, 39 insertions(+), 37 deletions(-)

- Log -----------------------------------------------------------------
commit 75be4d3d333b5218788df9e8b76d1065d8a21504
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Jun 1 18:42:37 2017 +0000

    Fix unique custom fields under Oracle
    
    By switching to ->LimitCustomField, we can reuse the existing fixups for
    Oracle not being able to search LargeContent directly due to it being a
    CLOB field.
    
    This also extends the tests to ensure that values over 256 characters
    (and so which are stored in LargeContent) also participate in
    uniqueness.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index c74c707..97010cb 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1443,8 +1443,8 @@ sub ObjectTypeFromLookupType {
 
 sub CollectionClassFromLookupType {
     my $self = shift;
+    my $record_class = shift || $self->RecordClassFromLookupType;
 
-    my $record_class = $self->RecordClassFromLookupType;
     return undef unless $record_class;
 
     my $collection_class;
@@ -1781,16 +1781,12 @@ sub AddValueForObject {
     }
 
     if ($self->UniqueValues) {
-        my $existing = RT::ObjectCustomFieldValue->new(RT->SystemUser);
-        $existing->LoadByCols(
-            CustomField  => $self->Id,
-            Content      => $args{'Content'},
-            LargeContent => $args{'LargeContent'},
-            ContentType  => $args{'ContentType'},
-            Disabled     => 0,
-        );
-        if ($existing->Id) {
-            $RT::Logger->debug( "Non-unique custom field value for CF #" . $self->Id ." with object custom field value " . $existing->Id );
+        my $class = $self->CollectionClassFromLookupType($self->ObjectTypeFromLookupType);
+        my $collection = $class->new(RT->SystemUser);
+        $collection->LimitCustomField(CUSTOMFIELD => $self->Id, OPERATOR => '=', VALUE => $args{'LargeContent'} // $args{'Content'});
+
+        if ($collection->Count) {
+            $RT::Logger->debug( "Non-unique custom field value for CF #" . $self->Id ." with object custom field value " . $collection->First->Id );
             $RT::Handle->Rollback();
             return ( 0, $self->loc('That is not a unique value') );
         }
diff --git a/t/customfields/unique_values.t b/t/customfields/unique_values.t
index 9751cea..577bbbb 100644
--- a/t/customfields/unique_values.t
+++ b/t/customfields/unique_values.t
@@ -3,11 +3,6 @@ use strict;
 
 use RT::Test tests => undef;
 
-
-my $alpha = RT::Test->create_ticket( Subject => 'test unique values alpha', Queue => 'General' );
-my $beta = RT::Test->create_ticket( Subject => 'test unique values beta', Queue => 'General' );
-my ( $ret, $msg );
-
 {
     diag "testing freeform single cf";
     my $unique_single = RT::Test->load_or_create_custom_field(
@@ -18,33 +13,44 @@ my ( $ret, $msg );
     );
     ok($unique_single->UniqueValues, 'unique values for this CF');
 
-    ( $ret, $msg ) =
-      $alpha->AddCustomFieldValue( Field => $unique_single, Value => 'foo' );
-    ok( $ret, $msg );
-    is( $alpha->FirstCustomFieldValue($unique_single), 'foo', 'value is foo' );
+    my @tests = (
+        ['foo', 'bar'], # Content
+        [('foo' x 256), ('bar' x 256)], # LargeContent
+    );
+
+    for (@tests) {
+        my ($foo, $bar) = @$_;
+        my $alpha = RT::Test->create_ticket( Subject => 'test unique values alpha', Queue => 'General' );
+        my $beta = RT::Test->create_ticket( Subject => 'test unique values beta', Queue => 'General' );
+
+        my ( $ret, $msg ) =
+          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $foo );
+        ok( $ret, $msg );
+        is( $alpha->FirstCustomFieldValue($unique_single), $foo, 'value is foo' );
 
-    ( $ret, $msg ) =
-      $beta->AddCustomFieldValue( Field => $unique_single, Value => 'foo' );
-    ok( !$ret, "can't reuse the OCFV 'foo'");
-    like($msg, qr/That is not a unique value/);
-    is( $beta->FirstCustomFieldValue($unique_single), undef, 'no value since it was a duplicate' );
+        ( $ret, $msg ) =
+          $beta->AddCustomFieldValue( Field => $unique_single, Value => $foo );
+        ok( !$ret, "can't reuse the OCFV 'foo'");
+        like($msg, qr/That is not a unique value/);
+        is( $beta->FirstCustomFieldValue($unique_single), undef, 'no value since it was a duplicate' );
 
-    ( $ret, $msg ) =
-      $alpha->AddCustomFieldValue( Field => $unique_single, Value => 'bar' );
-    ok( $ret, $msg );
+        ( $ret, $msg ) =
+          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $bar );
+        ok( $ret, $msg );
 
-    is( $alpha->FirstCustomFieldValue($unique_single), 'bar', 'value is now bar' );
+        is( $alpha->FirstCustomFieldValue($unique_single), $bar, 'value is now bar' );
 
-    ( $ret, $msg ) =
-      $beta->AddCustomFieldValue( Field => $unique_single, Value => 'foo' );
-    ok( $ret, "can reuse foo since alpha switched away");
-    is( $beta->FirstCustomFieldValue($unique_single), 'foo', 'now beta has foo' );
+        ( $ret, $msg ) =
+          $beta->AddCustomFieldValue( Field => $unique_single, Value => $foo );
+        ok( $ret, "can reuse foo since alpha switched away");
+        is( $beta->FirstCustomFieldValue($unique_single), $foo, 'now beta has foo' );
 
-    ( $ret, $msg ) =
-      $alpha->AddCustomFieldValue( Field => $unique_single, Value => 'foo' );
-    ok( !$ret, "alpha can't switch back to foo since beta uses it");
+        ( $ret, $msg ) =
+          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $foo );
+        ok( !$ret, "alpha can't switch back to foo since beta uses it");
 
-    is( $alpha->FirstCustomFieldValue($unique_single), 'bar', 'value is still bar' );
+        is( $alpha->FirstCustomFieldValue($unique_single), $bar, 'value is still bar' );
+    }
 }
 
 done_testing;

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


More information about the rt-commit mailing list