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 6ce7ba17f4, backported to keep 22.0 stable for the N-1 window.

Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-12 13:56:15 +02:00 committed by GitHub
parent 48cb717cd3
commit f7fdcb3c82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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');