1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Fix PHP 8.1 "strlen(null)" exception rendering dashboard panel with latest tasks when custom int field configured

Summary:
`strlen()` was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If phutil_nonempty_string() throws an exception in your
instance, report it to Phorge to evaluate and fix that specific corner case.

```
ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php:56]
```

Closes T15685

Test Plan: After configuring a custom `int` field and a dashboard panel to query and listed the latest created tasks, access the panel and check the PHP error log.

Reviewers: O1 Blessed Committers, speck, valerio.bozzolan

Reviewed By: O1 Blessed Committers, speck, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15685

Differential Revision: https://we.phorge.it/D25489
This commit is contained in:
Andre Klapper 2024-01-22 19:39:37 +01:00
parent 821708414e
commit 052b5f41c7

View file

@ -11,7 +11,7 @@ final class PhabricatorStandardCustomFieldInt
$indexes = array();
$value = $this->getFieldValue();
if (strlen($value)) {
if (phutil_nonempty_scalar($value)) {
$indexes[] = $this->newNumericIndex((int)$value);
}
@ -53,7 +53,7 @@ final class PhabricatorStandardCustomFieldInt
PhabricatorCursorPagedPolicyAwareQuery $query,
$value) {
if (strlen($value)) {
if (phutil_nonempty_scalar($value)) {
$query->withApplicationSearchContainsConstraint(
$this->newNumericIndex(null),
$value);
@ -84,7 +84,7 @@ final class PhabricatorStandardCustomFieldInt
foreach ($xactions as $xaction) {
$value = $xaction->getNewValue();
if (strlen($value)) {
if (phutil_nonempty_scalar($value)) {
if (!preg_match('/^-?\d+/', $value)) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
@ -104,9 +104,9 @@ final class PhabricatorStandardCustomFieldInt
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
if (!strlen($old) && strlen($new)) {
if (!phutil_nonempty_scalar($old) && phutil_nonempty_scalar($new)) {
return true;
} else if (strlen($old) && !strlen($new)) {
} else if (phutil_nonempty_scalar($old) && !phutil_nonempty_scalar($new)) {
return true;
} else {
return ((int)$old !== (int)$new);