Skip to content

Commit dc5a394

Browse files
stonebuzztrasher
authored andcommitted
revert: fix(875): allow multi update from API
1 parent 178dbd2 commit dc5a394

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

CHANGELOG.md

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

1414
- Force decimal `datatype` of `numeric` fields for more accurate display.
1515
- Do not destroy the dropdown table/class if it is being used by another container.
16-
- Fix fields updates with multiple containers via the API.
1716

1817
## [1.21.16] - 2024-12-11
1918

inc/container.class.php

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,17 +1635,19 @@ public static function preItemUpdate(CommonDBTM $item)
16351635
{
16361636
self::preItem($item);
16371637
if (array_key_exists('_plugin_fields_data', $item->input)) {
1638-
foreach ($item->input['_plugin_fields_data'] as $container_class) {
1639-
//update container_class
1640-
$container = new self();
1641-
if (
1642-
count($container_class) !== 0
1643-
&& !$container->updateFieldsValues($container_class, $item->getType(), isset($_REQUEST['massiveaction']))
1644-
) {
1645-
return $item->input = [];
1646-
}
1638+
$data = $item->input['_plugin_fields_data'];
1639+
//update data
1640+
$container = new self();
1641+
if (
1642+
count($data) == 0
1643+
|| $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))
1644+
) {
1645+
$item->input['date_mod'] = $_SESSION['glpi_currenttime'];
1646+
1647+
return true;
16471648
}
1648-
$item->input['date_mod'] = $_SESSION['glpi_currenttime'];
1649+
1650+
return $item->input = [];
16491651
}
16501652

16511653
return true;
@@ -1661,14 +1663,9 @@ public static function preItemUpdate(CommonDBTM $item)
16611663
*/
16621664
public static function preItem(CommonDBTM $item)
16631665
{
1664-
/** @var DBmysql $DB */
1665-
global $DB;
1666-
1667-
$container_ids = [];
1668-
$field_container = new PluginFieldsContainer();
16691666
//find container (if not exist, do nothing)
16701667
if (isset($_REQUEST['c_id'])) {
1671-
$container_ids = [$_REQUEST['c_id']];
1668+
$c_id = $_REQUEST['c_id'];
16721669
} else {
16731670
$type = 'dom';
16741671
if (isset($_REQUEST['_plugin_fields_type'])) {
@@ -1678,54 +1675,57 @@ public static function preItem(CommonDBTM $item)
16781675
if ($type == 'domtab') {
16791676
$subtype = $_REQUEST['_plugin_fields_subtype'];
16801677
}
1681-
foreach ($item->input as $key => $value) {
1682-
if (!$DB->fieldExists(static::getTable(), $key) || false === ($container_id = self::findContainer(get_Class($item), $type, $subtype))) {
1683-
// tries for 'tab'
1684-
if (false === ($container_id = self::findContainer(get_Class($item)))) {
1685-
return false;
1686-
}
1687-
}
1688-
if (!in_array($container_id, $container_ids, true)) {
1689-
$container_ids[] = $container_id;
1678+
if (false === ($c_id = self::findContainer(get_Class($item), $type, $subtype))) {
1679+
// tries for 'tab'
1680+
if (false === ($c_id = self::findContainer(get_Class($item)))) {
1681+
return false;
16901682
}
16911683
}
16921684
}
16931685

1686+
$loc_c = new PluginFieldsContainer();
1687+
$loc_c->getFromDB($c_id);
1688+
16941689
// check rights on $c_id
1695-
foreach ($container_ids as $container_id) {
1696-
$field_container->getFromDB($container_id);
16971690

1698-
if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $container_id > 0) {
1699-
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $container_id);
1700-
if (($right > READ) === false) {
1701-
return;
1702-
}
1703-
} else {
1691+
if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $c_id > 0) {
1692+
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id);
1693+
if (($right > READ) === false) {
17041694
return;
17051695
}
1696+
} else {
1697+
return;
1698+
}
17061699

1707-
// need to check if container is usable on this object entity
1708-
$entities = [$field_container->fields['entities_id']];
1709-
if ($field_container->fields['is_recursive']) {
1710-
$entities = getSonsOf(getTableForItemType('Entity'), $field_container->fields['entities_id']);
1711-
}
17121700

1713-
if ($item->isEntityAssign() && !in_array($item->getEntityID(), $entities)) {
1714-
return false;
1715-
}
1701+
// need to check if container is usable on this object entity
1702+
$entities = [$loc_c->fields['entities_id']];
1703+
if ($loc_c->fields['is_recursive']) {
1704+
$entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']);
1705+
}
17161706

1717-
$populate_data = self::populateData($container_id, $item);
1718-
if (false !== $populate_data) {
1719-
if (self::validateValues($populate_data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) {
1720-
$item->input = [];
1707+
//workaround: when a ticket is created from readdonly profile,
1708+
//it is not initialized; see https://github.com/glpi-project/glpi/issues/1438
1709+
if (!isset($item->fields) || count($item->fields) == 0) {
1710+
$item->fields = $item->input;
1711+
}
17211712

1722-
return [];
1723-
}
1724-
$item->input['_plugin_fields_data'][] = $populate_data;
1713+
if ($item->isEntityAssign() && !in_array($item->getEntityID(), $entities)) {
1714+
return false;
1715+
}
1716+
1717+
if (false !== ($data = self::populateData($c_id, $item))) {
1718+
if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) {
1719+
$item->input = [];
1720+
1721+
return [];
17251722
}
1723+
$item->input['_plugin_fields_data'] = $data;
1724+
1725+
return $data;
17261726
}
17271727

1728-
return $item->input['_plugin_fields_data'];
1728+
return;
17291729
}
17301730

17311731
/**

0 commit comments

Comments
 (0)