Skip to content

Add/consumable mass action link associated items#592

Merged
Rom1-B merged 6 commits into
mainfrom
add/consumable-mass-action-link-associated-items
Jul 6, 2026
Merged

Add/consumable mass action link associated items#592
Rom1-B merged 6 commits into
mainfrom
add/consumable-mass-action-link-associated-items

Conversation

@Herafia

@Herafia Herafia commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !45040
  • Add grouped actions to link consumables and related items : 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

Screenshots (if appropriate):

@Herafia Herafia self-assigned this Jul 2, 2026
@Herafia Herafia requested review from Rom1-B and stonebuzz July 2, 2026 09:53
Comment thread inc/link.class.php Outdated
@stonebuzz

Copy link
Copy Markdown
Contributor

Awaiting customers validation

Comment thread inc/link.class.php Outdated
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'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well seen

@Herafia Herafia requested a review from Rom1-B July 6, 2026 08:35
@Rom1-B Rom1-B merged commit a199c98 into main Jul 6, 2026
3 checks passed
@Rom1-B Rom1-B deleted the add/consumable-mass-action-link-associated-items branch July 6, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants