Skip to content

Commit cf665af

Browse files
authored
Fix: entity transfer (#1132)
1 parent fe1869f commit cf665af

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fix SQL errors with custom dropdown fields
1313
- Fix wrong values displayed in massive actions when a form contains multiple custom dropdowns
14+
- Fix field entity during parent asset entity transfer
1415

1516
## [1.23.3] - 2026-02-12
1617

hook.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,20 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
434434

435435
return null;
436436
}
437+
438+
function plugin_item_transfer_fields(array $options): void
439+
{
440+
$itemtype = $options['type'] ?? null;
441+
$container_ids = PluginFieldsContainer::findAllContainers($itemtype);
442+
443+
$container = new PluginFieldsContainer();
444+
foreach ($container_ids as $id) {
445+
$container->getFromDB($id);
446+
$data = [
447+
'plugin_fields_containers_id' => $id,
448+
'items_id' => $options['newID'],
449+
'entities_id' => $options['entities_id'],
450+
];
451+
$container->updateFieldsValues($data, $itemtype, true);
452+
}
453+
}

inc/container.class.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,38 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '')
17931793
return $id;
17941794
}
17951795

1796+
public static function findAllContainers($itemtype)
1797+
{
1798+
$condition = ['is_active' => 1];
1799+
1800+
$entity = $_SESSION['glpiactiveentities'] ?? 0;
1801+
$condition += getEntitiesRestrictCriteria('', '', $entity, true, true);
1802+
1803+
$container = new PluginFieldsContainer();
1804+
$itemtypes = $container->find($condition);
1805+
1806+
if (empty($itemtypes)) {
1807+
return false;
1808+
}
1809+
1810+
$ids = [];
1811+
foreach ($itemtypes as $data) {
1812+
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']);
1813+
if (in_array($itemtype, $dataitemtypes)) {
1814+
$id = $data['id'];
1815+
//profiles restriction
1816+
if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $id > 0) {
1817+
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $id);
1818+
if ($right >= READ) {
1819+
$ids[] = $id;
1820+
}
1821+
}
1822+
}
1823+
}
1824+
1825+
return $ids;
1826+
}
1827+
17961828
/**
17971829
* Post item hook for add
17981830
* Do store data in db

setup.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
use Glpi\Form\Destination\FormDestinationTicket;
7777
use Glpi\Form\Migration\TypesConversionMapper;
7878
use Glpi\Form\QuestionType\QuestionTypesManager;
79+
use Glpi\Plugin\Hooks;
7980
use Symfony\Component\Yaml\Yaml;
8081

8182
/**
@@ -206,6 +207,8 @@ function plugin_init_fields()
206207
'showForTab',
207208
];
208209

210+
$PLUGIN_HOOKS[Hooks::ITEM_TRANSFER]['fields'] = 'plugin_item_transfer_fields';
211+
209212
// Register fields question type
210213
plugin_fields_register_plugin_types();
211214
}

0 commit comments

Comments
 (0)