Add/consumable mass action link associated items#592
Merged
Conversation
stonebuzz
requested changes
Jul 2, 2026
stonebuzz
approved these changes
Jul 3, 2026
Contributor
|
Awaiting customers validation |
Rom1-B
requested changes
Jul 3, 2026
Comment on lines
+636
to
+642
| // 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'], |
Contributor
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.
Suggested change
| // 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, | |
| ), |
Rom1-B
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Screenshots (if appropriate):