[Rt-commit] rt branch, 4.4/existing-unique-ocfv, created. rt-4.4.1-110-g8099aa6
Shawn Moore
shawn at bestpractical.com
Tue Aug 30 11:11:54 EDT 2016
The branch, 4.4/existing-unique-ocfv has been created
at 8099aa68be69453e1a052db284ca2a8749ed5939 (commit)
- Log -----------------------------------------------------------------
commit 8099aa68be69453e1a052db284ca2a8749ed5939
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..6626f55 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 => 'Content',
+ VALUE => $value,
);
- if ($existing->Id) {
+ while (my $ocfv = $existing->Next) {
+ next if $ocfv->ObjectId == $Object->Id
+ && $ocfv->ObjectType eq ref($Object);
+
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