From f0d6c0fb6b2cc7785d3454ad23a975e2580b927b Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Thu, 12 Feb 2026 10:50:41 +0100 Subject: [PATCH] Fix: entity transfer --- CHANGELOG.md | 6 ++++++ hook.php | 17 +++++++++++++++++ inc/container.class.php | 32 ++++++++++++++++++++++++++++++++ setup.php | 3 +++ 4 files changed, 58 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4765d5..90274a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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/). +## [UNREALEASED] + +### Fixed + +- Fix field entity during parent asset entity transfer + ## [1.23.3] - 2026-02-12 ### Added diff --git a/hook.php b/hook.php index 3ccd34ea..b0ef3389 100644 --- a/hook.php +++ b/hook.php @@ -434,3 +434,20 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) return null; } + +function plugin_item_transfer_fields(array $options): void +{ + $itemtype = $options['type'] ?? null; + $container_ids = PluginFieldsContainer::findAllContainers($itemtype); + + $container = new PluginFieldsContainer(); + foreach ($container_ids as $id) { + $container->getFromDB($id); + $data = [ + 'plugin_fields_containers_id' => $id, + 'items_id' => $options['newID'], + 'entities_id' => $options['entities_id'], + ]; + $container->updateFieldsValues($data, $itemtype, true); + } +} diff --git a/inc/container.class.php b/inc/container.class.php index 4f9f3656..10f705b4 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1793,6 +1793,38 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '') return $id; } + public static function findAllContainers($itemtype) + { + $condition = ['is_active' => 1]; + + $entity = $_SESSION['glpiactiveentities'] ?? 0; + $condition += getEntitiesRestrictCriteria('', '', $entity, true, true); + + $container = new PluginFieldsContainer(); + $itemtypes = $container->find($condition); + + if (empty($itemtypes)) { + return false; + } + + $ids = []; + foreach ($itemtypes as $data) { + $dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']); + if (in_array($itemtype, $dataitemtypes)) { + $id = $data['id']; + //profiles restriction + if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $id > 0) { + $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $id); + if ($right >= READ) { + $ids[] = $id; + } + } + } + } + + return $ids; + } + /** * Post item hook for add * Do store data in db diff --git a/setup.php b/setup.php index e97c2e00..15fb4e62 100644 --- a/setup.php +++ b/setup.php @@ -76,6 +76,7 @@ use Glpi\Form\Destination\FormDestinationTicket; use Glpi\Form\Migration\TypesConversionMapper; use Glpi\Form\QuestionType\QuestionTypesManager; +use Glpi\Plugin\Hooks; use Symfony\Component\Yaml\Yaml; /** @@ -206,6 +207,8 @@ function plugin_init_fields() 'showForTab', ]; + $PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['fields'] = 'plugin_item_transfer_fields'; + // Register fields question type plugin_fields_register_plugin_types(); }