Add/consumable mass action link associated items#592
Conversation
| $reference = new PluginOrderReference(); | ||
| $reference->getFromDB($ma->POST["plugin_order_references_id"]); | ||
| $allow_multiple_link = in_array( | ||
| $reference->fields["itemtype"] ?? '', | ||
| ['ConsumableItem', 'CartridgeItem'], | ||
| true, | ||
| ); |
There was a problem hiding this comment.
The new getFromDB call fetches itemtype from PluginOrderReference, but that field is already loaded into $ma->POST['add_items'] by the JOIN query executed at the top of processMassiveActionsForOneItemtype (lines 595-618).
| $reference = new PluginOrderReference(); | |
| $reference->getFromDB($ma->POST["plugin_order_references_id"]); | |
| $allow_multiple_link = in_array( | |
| $reference->fields["itemtype"] ?? '', | |
| ['ConsumableItem', 'CartridgeItem'], | |
| true, | |
| ); | |
| $first_item_data = reset($ma->POST['add_items']); | |
| $allow_multiple_link = is_array($first_item_data) && in_array( | |
| $first_item_data['itemtype'] ?? '', | |
| ['ConsumableItem', 'CartridgeItem'], | |
| true, | |
| ); |
|
Awaiting customers validation |
| // For consumables and cartridges, createLinkWithItem creates a new item | ||
| // (glpi_consumables/glpi_cartridges) for each selected detail line; | ||
| // therefore, multiple items can be linked to the same reference item at once | ||
| $first_item_data = reset($ma->POST['add_items']); | ||
| $allow_multiple_link = is_array($first_item_data) && in_array( | ||
| $first_item_data['itemtype'] ?? '', | ||
| ['ConsumableItem', 'CartridgeItem'], |
There was a problem hiding this comment.
reset() returns the first entry in add_items, so $allow_multiple_link is determined by one item's itemtype. An order can mix types (e.g., one Computer line and one ConsumableItem line). If the first entry happens to be a consumable, the guard passes and all selected lines — including non-consumable ones — are processed, linking multiple non-consumable order lines to the same asset. The original restriction was intended to prevent exactly that.
| // For consumables and cartridges, createLinkWithItem creates a new item | |
| // (glpi_consumables/glpi_cartridges) for each selected detail line; | |
| // therefore, multiple items can be linked to the same reference item at once | |
| $first_item_data = reset($ma->POST['add_items']); | |
| $allow_multiple_link = is_array($first_item_data) && in_array( | |
| $first_item_data['itemtype'] ?? '', | |
| ['ConsumableItem', 'CartridgeItem'], | |
| // For consumables and cartridges, createLinkWithItem creates a new item | |
| // (glpi_consumables/glpi_cartridges) for each selected detail line; | |
| // therefore, multiple items can be linked to the same reference item at once | |
| $allow_multiple_link = !empty($ma->POST['add_items']) && array_reduce( | |
| $ma->POST['add_items'], | |
| fn($carry, $data) => $carry && in_array( | |
| $data['itemtype'] ?? '', | |
| ['ConsumableItem', 'CartridgeItem'], | |
| true, | |
| ), |
Checklist before requesting a review
Please delete options that are not relevant.
Description
Screenshots (if appropriate):