Skip to content

Commit 5263d5d

Browse files
Custom integer fields: fix search by array of possible values
Summary: This minimal changes seems the natural expansion of this search function, that "seems" designed to only search with a single value, but the backend is designed to receive an array of possible values. Look at the same method in PhabricatorStandardCustomFieldLink that already works also for array inputs. To get extra confidence look at the method withApplicationSearchContainsConstraint() that works perfectly with arrays (to be honest it only works with arrays in mind...) This feature allows to avoid crashes when extension developers tries to run "IN" queries because for example they try to follow our performance guidelines: https://we.phorge.it/book/contrib/article/n_plus_one/ Closes T15752 Test Plan: Have a nice custom integer field, like this one for Maniphest: { "mycompany.estimated-hours": { "name": "Estimated Hours", "type": "int", "caption": "Estimated number of hours this will take.", "search": true } } You can reproduce T15752 before the change. It just works after the change. Or, just trust your instincts by looking at the same method in PhabricatorStandardCustomFieldLink. Also, use the "normal" frontend search page. Still works as usual. Reviewers: O1 Blessed Committers, 20after4 Reviewed By: O1 Blessed Committers, 20after4 Subscribers: tobiaswiese, Matthew, Cigaryno Maniphest Tasks: T15752 Differential Revision: https://we.phorge.it/D25554
1 parent 48e121c commit 5263d5d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,28 @@ public function readApplicationSearchValueFromRequest(
4848
return $request->getStr($this->getFieldKey());
4949
}
5050

51+
/**
52+
* Apply an application search constraint to a query.
53+
* If you have a field of type integer, and a value (or an array of values),
54+
* the result set will be limited to the rows with these values.
55+
* @param PhabricatorApplicationSearchEngine $engine
56+
* @param PhabricatorCursorPagedPolicyAwareQuery $query
57+
* @param mixed $value Single value or array of values (IN query).
58+
*/
5159
public function applyApplicationSearchConstraintToQuery(
5260
PhabricatorApplicationSearchEngine $engine,
5361
PhabricatorCursorPagedPolicyAwareQuery $query,
5462
$value) {
5563

56-
if (phutil_nonempty_scalar($value)) {
57-
$query->withApplicationSearchContainsConstraint(
58-
$this->newNumericIndex(null),
59-
$value);
64+
// The basic use case is with a single value.
65+
// The backend really works with an array. So also array allowed.
66+
if (is_array($value) || phutil_nonempty_scalar($value)) {
67+
$value = (array)$value;
68+
if ($value) {
69+
$query->withApplicationSearchContainsConstraint(
70+
$this->newNumericIndex(null),
71+
$value);
72+
}
6073
}
6174
}
6275

0 commit comments

Comments
 (0)