|
60 | 60 | ); |
61 | 61 | Html::back(); |
62 | 62 | } else if (isset($_POST['reset'])) { |
63 | | - if (!isset($_POST['id'])) { |
| 63 | + if (!isset($_POST['itemtype']) || !isset($_POST['items_id'])) { |
64 | 64 | Session::addMessageAfterRedirect(__('Missing arguments in request.', 'carbon'), false, ERROR); |
65 | 65 | Html::back(); |
66 | 66 | } |
67 | 67 | $usage_impact = new UsageImpact(); |
68 | | - $usage_impact->check($_POST['id'], PURGE); |
| 68 | + $usage_impact->getFromDBByCrit([ |
| 69 | + 'itemtype' => $_POST['itemtype'], |
| 70 | + 'items_id' => $_POST['items_id'], |
| 71 | + ]); |
| 72 | + if (!$usage_impact->isNewItem()) { |
| 73 | + $usage_impact->check($usage_impact->getID(), PURGE); |
| 74 | + } |
69 | 75 |
|
70 | | - $gwp_impact_class = '\\GlpiPlugin\\Carbon\\Impact\\History\\' . $usage_impact->fields['itemtype']; |
| 76 | + $gwp_impact_class = '\\GlpiPlugin\\Carbon\\Impact\\History\\' . $_POST['itemtype']; |
71 | 77 | if (!class_exists($gwp_impact_class) || !is_subclass_of($gwp_impact_class, AbstractAsset::class)) { |
72 | 78 | Session::addMessageAfterRedirect(__('Bad arguments.', 'carbon'), false, ERROR); |
73 | 79 | Html::back(); |
|
77 | 83 | $gwp_impact = new $gwp_impact_class(); |
78 | 84 | $itemtype = $gwp_impact->getItemtype(); |
79 | 85 | $item = new $itemtype(); |
80 | | - $item->getFromDB($usage_impact->fields['items_id']); |
| 86 | + $item->getFromDB($_POST['items_id']); |
81 | 87 | if (!$item->canUpdateItem()) { |
82 | 88 | Session::addMessageAfterRedirect(__('Reset denied.', 'carbon'), false, ERROR); |
83 | 89 | Html::back(); |
84 | 90 | } |
85 | 91 |
|
86 | | - if (!$gwp_impact->resetForItem($usage_impact->fields['items_id'])) { |
| 92 | + if (!$gwp_impact->resetForItem($item->getID())) { |
87 | 93 | Session::addMessageAfterRedirect(__('Reset failed.', 'carbon'), false, ERROR); |
88 | 94 | } |
89 | 95 |
|
90 | | - if (!$usage_impact->delete($usage_impact->fields)) { |
| 96 | + if (!$usage_impact->isNewItem() && !$usage_impact->delete($usage_impact->fields)) { |
91 | 97 | Session::addMessageAfterRedirect(__('Delete of usage impact failed.', 'carbon'), false, ERROR); |
92 | 98 | } |
93 | 99 | } else if (isset($_POST['calculate'])) { |
|
0 commit comments