[Rt-commit] rt branch, 4.4/existing-unique-ocfv, created. rt-4.4.1-110-gc7e880d
Shawn Moore
shawn at bestpractical.com
Mon Sep 12 11:21:23 EDT 2016
The branch, 4.4/existing-unique-ocfv has been created
at c7e880d9e31fef494629a687c5717d881b580b66 (commit)
- Log -----------------------------------------------------------------
commit c7e880d9e31fef494629a687c5717d881b580b66
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Aug 30 15:08:46 2016 +0000
Avoid uniqueness violation when submitting an unchanged OCFV
The ValidateCustomFields component would load the current object's
existing OCFV which triggers uniqueness violation. Instead of
using LoadByCols, switch to a collection so we can skip over the
current $Object's existing OCFV when checking uniqueness.
This problem affects only the ValidateCustomField components and not
the core RT::CustomField::AddValueForObject implementation because the
latter is not used for records whose OCFV didn't change in an update.
diff --git a/share/html/Elements/ValidateCustomFields b/share/html/Elements/ValidateCustomFields
index 4c32c5c..4f1cb5a 100644
--- a/share/html/Elements/ValidateCustomFields
+++ b/share/html/Elements/ValidateCustomFields
@@ -106,17 +106,22 @@ while ( my $CF = $CustomFields->Next ) {
}
if ($CF->UniqueValues) {
- my $existing = RT::ObjectCustomFieldValue->new(RT->SystemUser);
- $existing->LoadByCols(
- CustomField => $CF->Id,
- Content => $value,
- Disabled => 0,
+ my $existing = RT::ObjectCustomFieldValues->new(RT->SystemUser);
+ $existing->LimitToCustomField($CF->Id);
+ $existing->LimitToEnabled;
+ $existing->Limit(FIELD => 'ObjectType', VALUE => ref($Object));
+ $existing->Limit(FIELD => 'ObjectId', VALUE => $Object->id, OPERATOR => '!=');
+ $existing->Limit(
+ FIELD => 'Content',
+ VALUE => $value,
);
- if ($existing->Id) {
+
+ while (my $ocfv = $existing->Next) {
my $msg = loc("That is not a unique value");
$m->notes( ('InvalidField-' . $CF->Id) => $msg );
push @res, $CF->Name .': '. $msg;
$valid = 0;
+ last;
}
}
}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list