Qual: Improvements to actions_massactions.inc.php (#30805)

* Qual: Fix phan notices in actions_massactions.inc

# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from #30733.

* Adjust baseline for actions_massactions.inc improvements

* Update actions_massactions.inc.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
MDW 2024-09-10 03:07:57 +02:00 committed by GitHub
parent fb6677010d
commit 812ac85b20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 7 deletions

View File

@ -349,7 +349,7 @@ return [
'htdocs/core/actions_extrafields.inc.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/core/actions_lineupdown.inc.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredGlobalVariable'],
'htdocs/core/actions_linkedfiles.inc.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable'],
'htdocs/core/actions_massactions.inc.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/core/actions_massactions.inc.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'],
'htdocs/core/actions_printing.inc.php' => ['PhanUndeclaredProperty'],
'htdocs/core/actions_sendmails.inc.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/core/actions_setmoduleoptions.inc.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanPossiblyUndeclaredGlobalVariable'],

View File

@ -37,6 +37,18 @@
// $diroutputmassaction may be defined
// $confirm
'
@phan-var-force ?string $permissiontoread
@phan-var-force ?string $permissiontodelete
@phan-var-force ?string $permissiontoclose
@phan-var-force ?string $permissiontoapprove
@phan-var-force ?int[] $toselect
@phan-var-force ?string $diroutputmassaction
@phan-var-force ?string $objectlabel
@phan-var-force ?string $option
@phan-var-force ?string $deliveryreceipt
';
// Protection
if (empty($objectclass) || empty($uploaddir)) {
@ -48,6 +60,14 @@ if (empty($massaction)) {
}
$error = 0;
// Note: list of strings for objectclass could be extended to accepted/expected classes
'
@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
@phan-var-force string $massaction
@phan-var-force string $uploaddir
';
// For backward compatibility
if (!empty($permtoread) && empty($permissiontoread)) {
$permissiontoread = $permtoread;
@ -89,6 +109,7 @@ if (!$error && $massaction == 'confirm_presend') {
$contactidtosend = array();
$attachedfilesThirdpartyObj = array();
$oneemailperrecipient = (GETPOSTINT('oneemailperrecipient') ? 1 : 0);
$thirdparty = null;
if (!$error) {
$objecttmp = new $objectclass($db);
@ -109,21 +130,30 @@ if (!$error && $massaction == 'confirm_presend') {
foreach ($toselect as $toselectid) {
$objecttmp = new $objectclass($db); // we must create new instance because instance is saved into $listofobjectref array for future use
'@phan-var-force CommonObject $objecttmp';
$result = $objecttmp->fetch($toselectid);
if ($result > 0) {
$listofobjectid[$toselectid] = $toselectid;
// Set $tmpobjectid that is ID of parent object (thirdparty or user in most cases)
$tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
if ($objecttmp->element == 'societe') {
'@phan-var-force Societe $objecttmp';
$tmpobjectid = $objecttmp->id;
} elseif ($objecttmp->element == 'contact') {
'@phan-var-force Contact $objecttmp';
$tmpobjectid = $objecttmp->id;
} elseif ($objecttmp->element == 'expensereport') {
'@phan-var-force ExpenseReport $objecttmp';
$tmpobjectid = $objecttmp->fk_user_author;
} elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
'@phan-var-force Partnership $objecttmp';
$tmpobjectid = $objecttmp->fk_member;
} elseif ($objecttmp->element == 'holiday') {
'@phan-var-force Holiday $objecttmp';
$tmpobjectid = $objecttmp->fk_user;
} elseif ($objecttmp->element == 'conferenceorboothattendee') {
'@phan-var-force ConferenceOrBoothAttendee $objecttmp';
$tmpobjectid = $objecttmp->id;
}
if (empty($tmpobjectid)) {
@ -131,6 +161,7 @@ if (!$error && $massaction == 'confirm_presend') {
}
if ($objectclass == 'Facture') {
'@phan-var-force Facture $objecttmp';
$tmparraycontact = array();
$tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'BILLING');
if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
@ -139,6 +170,7 @@ if (!$error && $massaction == 'confirm_presend') {
}
}
} elseif ($objectclass == 'CommandeFournisseur') {
'@phan-var-force CommandeFournisseur $objecttmp';
$tmparraycontact = array();
$tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'CUSTOMER');
if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
@ -201,7 +233,7 @@ if (!$error && $massaction == 'confirm_presend') {
// Recipients are provided into free text
$tmparray[] = trim(GETPOST('sendto', 'alphawithlgt'));
}
if (count($receiver) > 0) {
if (count($receiver) > 0 && is_object($thirdparty)) {
foreach ($receiver as $key => $val) {
// Recipient was provided from combo list
if ($val == 'thirdparty') { // Id of third party or user
@ -1136,6 +1168,11 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == '
// Generate document foreach object according to model linked to object
// @todo : propose model selection
if (!$error && $massaction == 'generate_doc' && $permissiontoread) {
// Complete with classes that use this massaction
<<<'EOPHAN'
@phan-var-force 'Commande'|'CommandeFournisseur'|'Contrat'|'Expedition'|'ExpenseReport'|'Facture'|'FactureFournisseur'|'Fichinter'|'Project'|'Propal'|'SupplierProposal' $objectclass
EOPHAN;
$db->begin();
$nbok = 0;
foreach ($toselect as $toselectid) {
@ -1152,7 +1189,7 @@ if (!$error && $massaction == 'generate_doc' && $permissiontoread) {
$newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ...
}
if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
$newlang = $objecttmp->default_lang; // for thirdparty
$newlang = $objecttmp->default_lang; // for thirdparty @phan-suppress-current-line PhanUndeclaredProperty
}
if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) { //load lang from thirdparty
$objecttmp->fetch_thirdparty();
@ -1264,6 +1301,8 @@ if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd
}
if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) {
'@phan-var-force Product|ProductCustomerPrice $obj';
'@phan-var-force Product|ProductCustomerPrice $object';
$nbok = 0;
$db->begin();
if (GETPOSTISSET('pricerate')) {
@ -1309,9 +1348,10 @@ if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoa
}
if (!$error && ($action == 'setsupervisor' && $confirm == 'yes') && $permissiontoadd) {
'@phan-var-force User $object';
$nbok = 0;
$db->begin();
$supervisortoset = GETPOST('supervisortoset');
$supervisortoset = GETPOSTINT('supervisortoset');
if (!empty($supervisortoset)) {
foreach ($toselect as $toselectid) {
$result = $object->fetch($toselectid);
@ -1359,7 +1399,7 @@ if (!$error && ($action == 'affectuser' && $confirm == 'yes') && $permissiontoad
$res = $object->add_contact($usertoaffect, $projectrole, 'internal');
if ($res >= 0) {
$taskstatic = new Task($db);
$task_array = $taskstatic->getTasksArray(0, 0, $object->id, 0, 0);
$task_array = $taskstatic->getTasksArray(null, null, $object->id, 0, 0);
foreach ($task_array as $task) {
$tasksToAffect = new Task($db);
@ -1597,6 +1637,7 @@ if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $
$db->begin();
$objecttmp = new $objectclass($db);
'@phan-var-force Holiday $objecttmp';
$nbok = 0;
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
@ -1606,7 +1647,7 @@ if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $
continue;
}
if ($user->id == $objecttmp->fk_validator) {
$objecttmp->oldcopy = dol_clone($objecttmp, 2);
$objecttmp->oldcopy = dol_clone($objecttmp, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
$objecttmp->date_valid = dol_now();
$objecttmp->fk_user_valid = $user->id;
@ -1713,7 +1754,8 @@ if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $
}
}
if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove) {
if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove && is_array($toselect)) {
'@phan-var-force Holiday $holiday'; // Supposing that $holiday is set, it is needed.
$db->begin();
$objecttmp = new $objectclass($db);
$nbok = 0;