Skip to content

Add/consumable mass action link associated items#592

Open
Herafia wants to merge 4 commits into
mainfrom
add/consumable-mass-action-link-associated-items
Open

Add/consumable mass action link associated items#592
Herafia wants to merge 4 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
Comment on lines +639 to +645
$reference = new PluginOrderReference();
$reference->getFromDB($ma->POST["plugin_order_references_id"]);
$allow_multiple_link = in_array(
$reference->fields["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.

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

Suggested change
$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,
);

@stonebuzz

Copy link
Copy Markdown
Contributor

Awaiting customers validation

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

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