Skip to content
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [UNRELEASED]

### Added
- Add grouped actions to link consumables and related items

## [2.12.8] - 2026-06-24

### Added
Expand Down
12 changes: 11 additions & 1 deletion inc/link.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,17 @@ public static function processMassiveActionsForOneItemtype(
break;

case 'createLink':
if (count($ids) > 1) {
// 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'],
Comment on lines +636 to +642

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

true,
);

if (!$allow_multiple_link && count($ids) > 1) {
$ma->addMessage(__s("Cannot link several items to one detail line", "order"));
foreach ($ids as $id) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
Expand Down
1 change: 0 additions & 1 deletion inc/order.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,6 @@ public function generateOrder($params)
$this->getFromDB($ID);

if (file_exists(PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php")) {
// @phpstan-ignore-next-line: custom.php is not a file or it does not exist.
include_once(PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php");
}

Expand Down