Merge pull request #20256 from marc-dll/13.0_FIX_project_creation_role_not_found

FIX: project creation prevented if PROJECTLEADER contact role renamed, de-activated or deleted
This commit is contained in:
Laurent Destailleur 2022-03-17 02:38:11 +01:00 committed by GitHub
commit 6617cbc531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -267,4 +267,5 @@ NewInvoice=New invoice
OneLinePerTask=One line per task
OneLinePerPeriod=One line per period
RefTaskParent=Ref. Parent Task
ProfitIsCalculatedWith=Profit is calculated using
ProfitIsCalculatedWith=Profit is calculated using
ErrorPROJECTLEADERRoleMissingRestoreIt=The "PROJECTLEADER" role is missing or has been de-activited, please restore in the dictionary of contact types

View File

@ -174,10 +174,14 @@ if (empty($reshook))
if (!$error && $result > 0)
{
// Add myself as project leader
$typeofcontact = 'PROJECTLEADER'; // TODO If use rename this code in dictionary, the add_contact will generate an error.
$typeofcontact = 'PROJECTLEADER';
$result = $object->add_contact($user->id, $typeofcontact, 'internal');
if ($result < 0)
{
// -3 means type not found (PROJECTLEADER renamed, de-activated or deleted), so don't prevent creation if it has been the case
if ($result == -3) {
setEventMessage('ErrorPROJECTLEADERRoleMissingRestoreIt', 'errors');
$error++;
} elseif ($result < 0) {
$langs->load("errors");
setEventMessages($object->error, $object->errors, 'errors');
$error++;