$params["manufacturers_id"] = $soft->fields["manufacturers_id"]; $params["comment"] = $soft->fields["comment"]; //Process rules $soft->update($softcatrule->processAllRules(null, $soft->fields, $params)); } } break; case "replay_dictionnary": $softdictionnayrule = new RuleDictionnarySoftwareCollection(); $ids = array(); foreach ($_POST["item"] as $key => $val) { if ($val == 1) { $ids[] = $key; } } $softdictionnayrule->replayRulesOnExistingDB(0, 0, $ids); break; case "force_user_ldap_update": checkRight("user", "w"); $user = new User(); $ids = array(); foreach ($_POST["item"] as $key => $val) { if ($val == 1) { $user->getFromDB($key); if ($user->fields["authtype"] == Auth::LDAP || $user->fields["authtype"] == Auth::EXTERNAL) { AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $user->fields["name"]), 1, $user->fields["auths_id"]); } } } break; case "add_transfer_list":
/** * @see CommonDBTM::doSpecificMassiveActions() **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($input['action']) { case "mergesoftware": if (isset($input["id"]) && isset($input["item"]) && is_array($input["item"]) && count($input["item"])) { if ($this->can($_POST["id"], 'w')) { if ($this->merge($_POST["item"])) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['ko']++; } break; case "compute_software_category": $softcatrule = new RuleSoftwareCategoryCollection(); foreach ($input["item"] as $key => $val) { if ($val == 1) { $params = array(); //Get software name and manufacturer if ($this->can($key, 'w')) { $params["name"] = $this->fields["name"]; $params["manufacturers_id"] = $this->fields["manufacturers_id"]; $params["comment"] = $this->fields["comment"]; $output = array(); $output = $softcatrule->processAllRules(null, $output, $params); //Process rules if (isset($output['softwarecategories_id']) && $this->update(array('id' => $key, 'softwarecategories_id' => $output['softwarecategories_id']))) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; case "replay_dictionnary": $softdictionnayrule = new RuleDictionnarySoftwareCollection(); $ids = array(); foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'w')) { $ids[] = $key; } else { $res['noright']++; } } } if ($softdictionnayrule->replayRulesOnExistingDB(0, 0, $ids) > 0) { $res['ok'] += count($ids); } else { $res['ko'] += count($ids); } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'merge': $input = $ma->getInput(); if (isset($input['item_items_id'])) { $items = array(); foreach ($ids as $id) { $items[$id] = 1; } if ($item->can($input['item_items_id'], UPDATE)) { if ($item->merge($items)) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'compute_software_category': $softcatrule = new RuleSoftwareCategoryCollection(); foreach ($ids as $id) { $params = array(); //Get software name and manufacturer if ($item->can($id, UPDATE)) { $params["name"] = $item->fields["name"]; $params["manufacturers_id"] = $item->fields["manufacturers_id"]; $params["comment"] = $item->fields["comment"]; $output = array(); $output = $softcatrule->processAllRules(null, $output, $params); //Process rules if (isset($output['softwarecategories_id']) && $item->update(array('id' => $id, 'softwarecategories_id' => $output['softwarecategories_id']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'replay_dictionnary': $softdictionnayrule = new RuleDictionnarySoftwareCollection(); $allowed_ids = array(); foreach ($ids as $id) { if ($item->can($id, UPDATE)) { $allowed_ids[] = $id; } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } if ($softdictionnayrule->replayRulesOnExistingDB(0, 0, $allowed_ids) > 0) { $ma->itemDone($item->getType(), $allowed_ids, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $allowed_ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }