Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: fix(875): allow multi update from API #893

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Force decimal ‘datatype’ of `numeric` fields for more accurate display.
- Do not destroy the dropdown table/class if it is being used by another container.
- Fix fields updates with multiple containers via the API.

## [1.21.16] - 2024-11-12

Expand Down
98 changes: 49 additions & 49 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,17 +1635,19 @@ public static function preItemUpdate(CommonDBTM $item)
{
self::preItem($item);
if (array_key_exists('_plugin_fields_data', $item->input)) {
foreach ($item->input['_plugin_fields_data'] as $container_class) {
//update container_class
$container = new self();
if (
count($container_class) !== 0
&& !$container->updateFieldsValues($container_class, $item->getType(), isset($_REQUEST['massiveaction']))
) {
return $item->input = [];
}
$data = $item->input['_plugin_fields_data'];
//update data
$container = new self();
if (
count($data) == 0
|| $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))
) {
$item->input['date_mod'] = $_SESSION['glpi_currenttime'];

return true;
}
$item->input['date_mod'] = $_SESSION['glpi_currenttime'];

return $item->input = [];
}

return true;
Expand All @@ -1661,14 +1663,9 @@ public static function preItemUpdate(CommonDBTM $item)
*/
public static function preItem(CommonDBTM $item)
{
/** @var DBmysql $DB */
global $DB;

$container_ids = [];
$field_container = new PluginFieldsContainer();
//find container (if not exist, do nothing)
if (isset($_REQUEST['c_id'])) {
$container_ids = [$_REQUEST['c_id']];
$c_id = $_REQUEST['c_id'];
} else {
$type = 'dom';
if (isset($_REQUEST['_plugin_fields_type'])) {
Expand All @@ -1678,54 +1675,57 @@ public static function preItem(CommonDBTM $item)
if ($type == 'domtab') {
$subtype = $_REQUEST['_plugin_fields_subtype'];
}
foreach ($item->input as $key => $value) {
if (!$DB->fieldExists(static::getTable(), $key) || false === ($container_id = self::findContainer(get_Class($item), $type, $subtype))) {
// tries for 'tab'
if (false === ($container_id = self::findContainer(get_Class($item)))) {
return false;
}
}
if (!in_array($container_id, $container_ids, true)) {
$container_ids[] = $container_id;
if (false === ($c_id = self::findContainer(get_Class($item), $type, $subtype))) {
// tries for 'tab'
if (false === ($c_id = self::findContainer(get_Class($item)))) {
return false;
}
}
}

$loc_c = new PluginFieldsContainer();
$loc_c->getFromDB($c_id);

// check rights on $c_id
foreach ($container_ids as $container_id) {
$field_container->getFromDB($container_id);

if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $container_id > 0) {
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $container_id);
if (($right > READ) === false) {
return;
}
} else {
if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $c_id > 0) {
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id);
if (($right > READ) === false) {
return;
}
} else {
return;
}

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

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

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

return [];
}
$item->input['_plugin_fields_data'][] = $populate_data;
if ($item->isEntityAssign() && !in_array($item->getEntityID(), $entities)) {
return false;
}

if (false !== ($data = self::populateData($c_id, $item))) {
if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) {
$item->input = [];

return [];
}
$item->input['_plugin_fields_data'] = $data;

return $data;
}

return $item->input['_plugin_fields_data'];
return;
}

/**
Expand Down
Loading