From f7fdcb3c82fb9566985a76a311d47382b7b372bd Mon Sep 17 00:00:00 2001 From: w3houde Date: Fri, 12 Jun 2026 13:56:15 +0200 Subject: [PATCH] Fix #36905 guard project card thirdparty client check against null (#38732) When editing a project that has no thirdparty attached, the WON/customer conversion block dereferenced $object->thirdparty->client without first checking that the thirdparty was loaded. $object->fetch_thirdparty() leaves the property null in that case so PHP 8 raised a fatal error. Add !is_null($object->thirdparty) on both opportunity blocks (create and update paths). This is the same guard already shipped on 23.0 through 6ce7ba17f4d, backported to keep 22.0 stable for the N-1 window. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/projet/card.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index db00efbc520..d8e5873ed9b 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -365,16 +365,14 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors'); } - if (!$error) { - if ((int) $object->thirdparty->client == 0 || (int) $object->thirdparty->client == 2) { // If not yet customer - // Get ID of the special opportunity status code 'WON' - $idoppstatuswon = (int) dol_getIdFromCode($db, 'WON', 'c_lead_status', 'code', 'rowid'); + if (!$error && !is_null($object->thirdparty) && ((int) $object->thirdparty->client == 0 || (int) $object->thirdparty->client == 2)) { // If not yet customer + // Get ID of the special opportunity status code 'WON' + $idoppstatuswon = (int) dol_getIdFromCode($db, 'WON', 'c_lead_status', 'code', 'rowid'); - if ($object->opp_status == $idoppstatuswon) { - // Switch the thirdparty into a customer (only if thirdparty exists) - if (!empty($object->thirdparty) && !empty($object->thirdparty->id)) { - $object->thirdparty->setAsCustomer(); - } + if ($object->opp_status == $idoppstatuswon) { + // Switch the thirdparty into a customer (only if thirdparty exists) + if (!empty($object->thirdparty) && !empty($object->thirdparty->id)) { + $object->thirdparty->setAsCustomer(); } } } @@ -465,7 +463,7 @@ if (empty($reshook)) { // If opportunities are used and the customer is not yet a customer if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && $object->usage_opportunity) { - if ((int) $object->thirdparty->client == 0 || (int) $object->thirdparty->client == 2) { // If not yet customer + if (!is_null($object->thirdparty) && ((int) $object->thirdparty->client == 0 || (int) $object->thirdparty->client == 2)) { // If not yet customer // Get ID of the special opportunity status code 'WON' $idoppstatuswon = (int) dol_getIdFromCode($db, 'WON', 'c_lead_status', 'code', 'rowid');