[Rt-commit] rt branch, 4.4/unique-custom-fields, updated. rt-4.4.0-228-g3cb7552

Shawn Moore shawn at bestpractical.com
Fri May 20 16:15:25 EDT 2016


The branch, 4.4/unique-custom-fields has been updated
       via  3cb75521659c698e61ada915c424d6f38e50731e (commit)
      from  0d0362fe846dd43799bbf226c23b781b19b5693c (commit)

Summary of changes:
 lib/RT/CustomField.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

- Log -----------------------------------------------------------------
commit 3cb75521659c698e61ada915c424d6f38e50731e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 20 20:14:30 2016 +0000

    First pass at limiting unique custom fields
    
        This doesn't handle the case where the OCFV sticks around
        but isn't the current value of a record. Probably need to join
        the $CF->LookupType table.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 191fa67..d8aba07 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1681,6 +1681,21 @@ 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'},
+        );
+        if ($existing->Id) {
+            $RT::Logger->debug( "Non-unique custom field value for CF #" . $self->Id ." with object custom field value " . $existing->Id );
+            $RT::Handle->Rollback();
+            return ( 0, $self->loc('That is not a unique value') );
+        }
+    }
+
     my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
     my ($val, $msg) = $newval->Create(
         ObjectType   => ref($obj),

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


More information about the rt-commit mailing list