Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qual: Improvements to actions_massactions.inc.php #30805

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,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'],
Expand Down
54 changes: 48 additions & 6 deletions htdocs/core/actions_massactions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
// $toselect may be defined
// $diroutputmassaction may be defined

'
@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)) {
Expand All @@ -47,6 +59,14 @@
}
$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;
Expand Down Expand Up @@ -88,6 +108,7 @@
$contactidtosend = array();
$attachedfilesThirdpartyObj = array();
$oneemailperrecipient = (GETPOSTINT('oneemailperrecipient') ? 1 : 0);
$thirdparty = null;

if (!$error) {
$objecttmp = new $objectclass($db);
Expand All @@ -108,28 +129,38 @@

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)) {
$tmpobjectid = 0;
}

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) {
Expand All @@ -138,6 +169,7 @@
}
}
} 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) {
Expand Down Expand Up @@ -200,7 +232,7 @@
// 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
Expand Down Expand Up @@ -1135,6 +1167,11 @@
// 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) {
Expand All @@ -1151,7 +1188,7 @@
$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();
Expand Down Expand Up @@ -1263,6 +1300,8 @@
}

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')) {
Expand Down Expand Up @@ -1308,9 +1347,10 @@
}

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);
Expand Down Expand Up @@ -1358,7 +1398,7 @@
$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);
Expand Down Expand Up @@ -1596,6 +1636,7 @@
$db->begin();

$objecttmp = new $objectclass($db);
'@phan-var-force Holiday $objecttmp';
$nbok = 0;
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
Expand All @@ -1605,7 +1646,7 @@
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;
Expand Down Expand Up @@ -1712,7 +1753,8 @@
}
}

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;
Expand Down