Class specific execution of the massive action (new system) by itemtypes
static public processMassiveActionsForOneItemtype ( MassiveAction $ma, CommonDBTM $item, array $ids ) : nothing | ||
$ma | MassiveAction | the current massive action object |
$item | CommonDBTM | the item on which apply the massive action |
$ids | array | an array of the ids of the item on which apply the action |
리턴 | nothing | (direct submit to $ma object) |
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'duplicate': $rulecollection = new RuleCollection(); foreach ($ids as $id) { if ($item->getFromDB($id)) { if ($rulecollection->duplicateRule($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(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } break; case 'export': if (count($ids)) { $_SESSION['exportitems'] = $ids; $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); $ma->setRedirect('rule.backup.php?action=download&itemtype=' . $item->getType()); } break; case 'move_rule': $input = $ma->getInput(); $collectionname = $input['rule_class_name'] . 'Collection'; $rulecollection = new $collectionname(); if ($rulecollection->canUpdate()) { foreach ($ids as $id) { if ($item->getFromDB($id)) { if ($rulecollection->moveRule($id, $input['ranking'], $input['move_type'])) { $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(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } break; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'force_user_ldap_update': foreach ($ids as $id) { if ($item->can($id, UPDATE)) { if ($item->fields["authtype"] == Auth::LDAP || $item->fields["authtype"] == Auth::EXTERNAL) { if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $item->fields["name"]), 1, $item->fields["auths_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(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'change_authtype': $input = $ma->getInput(); if (!isset($input["authtype"]) || !isset($input["auths_id"])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); return; } if (Session::haveRight(self::$rightname, self::UPDATEAUTHENT)) { if (User::changeAuthMethod($ids, $input["authtype"], $input["auths_id"])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; $certif_item = new PluginCertificatesCertificate_Item(); switch ($ma->getAction()) { case "plugin_certificates_add_item": $input = $ma->getInput(); foreach ($ids as $id) { $input = array('plugin_certificates_certificates_id' => $input['plugin_certificates_certificates_id'], 'items_id' => $id, 'itemtype' => $item->getType()); if ($certif_item->can(-1, UPDATE, $input)) { if ($certif_item->add($input)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginCertificatesCertificate') { foreach ($ids as $key) { $item->getFromDB($key); $type = PluginCertificatesCertificateType::transfer($item->fields["plugin_certificates_certificatetypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_certificates_certificatetypes_id"] = $type; $item->update($values); } $state = PluginCertificatesCertificateState::transfer($this->fields["plugin_certificates_certificatestates_id"], $input['entities_id']); if ($state > 0) { $values["id"] = $key; $values["plugin_certificates_certificatestates_id"] = $state; $item->update($values); } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($item->update($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; case 'install': $input = $ma->getInput(); foreach ($ids as $key) { if ($item->can($key, UPDATE)) { $values = array('plugin_certificates_certificates_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']); if ($certif_item->add($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'uninstall': $input = $ma->getInput(); foreach ($ids as $key) { if ($val == 1) { if ($certif_item->deleteItemByCertificatesAndItem($key, $input['item_item'], $input['typeitem'])) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'move_bookmark': $input = $ma->getInput(); if ($item->moveBookmark($ids, $input['bookmarks_id_ref'], $input['move_type'])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'add_followup': $input = $ma->getInput(); $fup = new self(); foreach ($ids as $id) { if ($item->getFromDB($id)) { $input2 = array('tickets_id' => $id, 'is_private' => $input['is_private'], 'requesttypes_id' => $input['requesttypes_id'], 'content' => $input['content']); if ($fup->can(-1, CREATE, $input2)) { if ($fup->add($input2)) { $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(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'add_to_static_group': if ($item->getType() == 'Computer') { $group_item = new PluginFusioninventoryDeployGroup_Staticdata(); foreach ($ids as $id) { //if ($group_item->can($id, UPDATE)) { if (!countElementsInTable($group_item->getTable(), "`plugin_fusioninventory_deploygroups_id`='" . $_POST['plugin_fusioninventory_deploygroups_id'] . "'\n AND `itemtype`='Computer'\n AND `items_id`='{$id}'")) { $values = array('plugin_fusioninventory_deploygroups_id' => $_POST['plugin_fusioninventory_deploygroups_id'], 'itemtype' => 'Computer', 'items_id' => $id); $group_item->add($values); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } //} else { // $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); // $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); //} } } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); } }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'merge': $fk = $item->getForeignKeyField(); foreach ($ids as $key) { if ($item->can($key, UPDATE)) { if ($item->getEntityID() == $_SESSION['glpiactive_entity']) { if ($item->update(array('id' => $key, 'is_recursive' => 1))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $input2 = $item->fields; // Remove keys (and name, tree dropdown will use completename) if ($item instanceof CommonTreeDropdown) { unset($input2['id'], $input2['name'], $input2[$fk]); } else { unset($input2['id']); } // Change entity $input2['entities_id'] = $_SESSION['glpiactive_entity']; $input2['is_recursive'] = 1; $input2 = Toolbox::addslashes_deep($input2); // Import new if ($newid = $item->import($input2)) { // Delete old if ($newid > 0) { // delete with purge for dropdown with dustbin (Budget) $item->delete(array('id' => $key, '_replace_by' => $newid), 1); } $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() * */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginTasklistsTask') { foreach ($ids as $key) { $item->getFromDB($key); $type = PluginTasklistsTaskType::transfer($item->fields["plugin_tasklists_tasktypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_tasklists_tasktypes_id"] = $type; $item->update($values); } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($item->update($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; $disposal = new PluginFinancialreportsDisposalItem(); switch ($ma->getAction()) { case "plugin_financialreports_add_date_disposal": $input = $ma->getInput(); foreach ($ids as $id) { if ($disposal->addDateDisposal($id, $item->getType(), $input['date_disposal'])) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { if (!is_a($item, __CLASS__)) { parent::processMassiveActionsForOneItemtype($ma, $item, $ids); return; } $itemtype = $item->getType(); $specificities = $itemtype::getConnexityMassiveActionsSpecificities(); $action = $ma->getAction(); $input = $ma->getInput(); // First, get normalized action : affect or unaffect if (in_array($action, $specificities['normalized']['affect'])) { $normalized_action = 'affect'; } else { if (in_array($action, $specificities['normalized']['unaffect'])) { $normalized_action = 'unaffect'; } else { // If we cannot get normalized action, then, its not for this method ! parent::processMassiveActionsForOneItemtype($ma, $item, $ids); return; } } switch ($normalized_action) { case 'unaffect': foreach ($ids as $key) { if ($item->can($key, UPDATE)) { if ($item instanceof CommonDBRelation) { if (isset($input['peer'][$item->getType()])) { if ($item->affectRelation($key, $input['peer'][$item->getType()])) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { if ($item instanceof CommonDBChild) { if ($item->affectChild($key)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'affect': if (!$specificities['reaffect']) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); return; } if (is_a($item, 'CommonDBRelation')) { if ($specificities['reaffect'] == 1) { $peertype = $itemtype::$itemtype_1; $peers_id = $itemtype::$items_id_1; } else { $peertype = $itemtype::$itemtype_2; $peers_id = $itemtype::$items_id_2; } } else { $peertype = $itemtype::$itemtype; $peers_id = $itemtype::$items_id; } $input2 = $itemtype::getConnexityInputForProcessingOfMassiveActions($action, $item, $ids, $input); $input2[$peers_id] = $input['peers_id']; if (preg_match('/^itemtype/', $peertype)) { if (!in_array($input['peertype'], $specificities['itemtypes'])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); return; } $input2[$peertype] = $input['peertype']; } else { if ($peertype != $input['peertype']) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); return; } } foreach ($ids as $key) { if (!$item->getFromDB($key)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); continue; } if (preg_match('/^itemtype/', $peertype)) { if ($input2[$peertype] == $item->fields[$peertype] && $input2[$peers_id] == $item->fields[$peers_id]) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ALREADY_DEFINED)); continue; } } else { if ($input2[$peers_id] == $item->fields[$peers_id]) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ALREADY_DEFINED)); continue; } } $input2[$item->getIndexName()] = $item->getID(); if ($item->can($item->getID(), UPDATE, $input2)) { if ($item->update($input2)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'DoIt': if ($item->getType() == 'Computer') { Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example')); Session::addMessageAfterRedirect(__('Write in item history', 'example')); $changes = array(0, 'old value', 'new value'); foreach ($ids as $id) { if ($item->getFromDB($id)) { Session::addMessageAfterRedirect("- " . $item->getField("name")); Log::history($id, 'Computer', $changes, 'PluginExampleExample', Log::HISTORY_PLUGIN); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example of ko count $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } } else { // When nothing is possible ... $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'do_nothing': if ($item->getType() == 'PluginExampleExample') { Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example')); Session::addMessageAfterRedirect(__("But... I say I will do nothing for:", 'example')); foreach ($ids as $id) { if ($item->getFromDB($id)) { Session::addMessageAfterRedirect("- " . $item->getField("name")); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example for noright / Maybe do it with can function is better $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() * */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginSimcardSimcard') { foreach ($ids as $key) { // Types $item->getFromDB($key); $type = PluginSimcardSimcardType::transfer($item->fields["plugin_simcard_simcardtypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_simcard_simcardtypes_id"] = $type; $item->update($values); } // Size $size = PluginSimcardSimcardSize::transfer($item->fields["plugin_simcard_simcardsizes_id"], $input['entities_id']); if ($size > 0) { $values["id"] = $key; $values["plugin_simcard_simcardsizes_id"] = $size; $item->update($values); } // Voltage $voltage = PluginSimcardSimcardVoltage::transfer($item->fields["plugin_simcard_simcardvoltages_id"], $input['entities_id']); if ($voltage > 0) { $values["id"] = $key; $values["plugin_simcard_simcardvoltages_id"] = $voltage; $item->update($values); } // Phoneoperator $phoneoperator = PluginSimcardPhoneOperator::transfer($item->fields["plugin_simcard_phoneoperators_id"], $input['entities_id']); if ($phoneoperator > 0) { $values["id"] = $key; $values["plugin_simcard_phoneoperators_id"] = $phoneoperator; $item->update($values); } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($item->update($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'sendmail': foreach ($ids as $id) { if ($item->canEdit($id)) { if ($item->sendMailById($id)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; $input = $ma->getInput(); switch ($ma->getAction()) { case 'import_group': $group = new Group(); if (!Session::haveRight("user", User::UPDATEAUTHENT) || !$group->canGlobal(UPDATE)) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); return; } foreach ($ids as $id) { if (isset($input["dn"][$id])) { $group_dn = $input["dn"][$id]; if (isset($input["ldap_import_entities"][$id])) { $entity = $input["ldap_import_entities"][$id]; } else { $entity = $_SESSION["glpiactive_entity"]; } // Is recursive is in the main form and thus, don't pass through // zero_on_empty mechanism inside massive action form ... $is_recursive = empty($input['ldap_import_recursive'][$id]) ? 0 : 1; $options = array('authldaps_id' => $_SESSION['ldap_server'], 'entities_id' => $entity, 'is_recursive' => $is_recursive, 'type' => $input['ldap_import_type'][$id]); if (AuthLdap::ldapImportGroup($group_dn, $options)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION, $group_dn)); } } // Clean history as id does not correspond to group $_SESSION['glpimassiveactionselected'] = array(); } return; case 'import': case 'sync': if (!Session::haveRight("user", User::IMPORTEXTAUTHUSERS)) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); return; } foreach ($ids as $id) { if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $id), $_SESSION['ldap_import']['mode'], $_SESSION['ldap_import']['authldaps_id'], true)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION, $id)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'delete_email': case 'import_email': if (!$item->canUpdate()) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); } else { $input = $ma->getInput(); if (count($ids)) { $mailcollector = new MailCollector(); if ($ma->getAction() == 'delete_email') { $mailcollector->deleteOrImportSeveralEmails($ids, 0); } else { $mailcollector->deleteOrImportSeveralEmails($ids, 1, $input['entities_id']); } } $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'reset': if (Config::canUpdate()) { foreach ($ids as $key) { if ($item->getFromDB($key)) { if ($item->resetDate()) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @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); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'add_actor': $input = $ma->getInput(); foreach ($ids as $id) { $input2 = array('id' => $id); if (isset($input['_itil_requester'])) { $input2['_itil_requester'] = $input['_itil_requester']; } if (isset($input['_itil_observer'])) { $input2['_itil_observer'] = $input['_itil_observer']; } if (isset($input['_itil_assign'])) { $input2['_itil_assign'] = $input['_itil_assign']; } if ($item->can($id, UPDATE)) { if ($item->update($input2)) { $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(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'update_notif': $input = $ma->getInput(); foreach ($ids as $id) { if ($item->can($id, UPDATE)) { $linkclass = new $item->userlinkclass(); foreach ($linkclass->getActors($id) as $type => $users) { foreach ($users as $data) { $data['use_notification'] = $input['use_notification']; $linkclass->update($data); } } $linkclass = new $this->supplierlinkclass(); foreach ($linkclass->getActors($id) as $type => $users) { foreach ($users as $data) { $data['use_notification'] = $input['use_notification']; $linkclass->update($data); } } $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'add_task': if (!($task = getItemForItemtype($item->getType() . 'Task'))) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); break; } $field = $item->getForeignKeyField(); $input = $ma->getInput(); foreach ($ids as $id) { if ($item->getFromDB($id)) { $input2 = array($field => $id, 'taskcategories_id' => $input['taskcategories_id'], 'content' => $input['content']); if ($task->can(-1, CREATE, $input2)) { if ($task->add($input2)) { $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(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * Execute massive action for PluginFormcreatorFrom * * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'Duplicate': foreach ($ids as $id) { if ($item->getFromDB($id) && $item->Duplicate()) { Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example of ko count $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'delete_for_user': $input = $ma->getInput(); if (isset($input['users_id'])) { $user = new User(); $user->getFromDB($input['users_id']); foreach ($ids as $id) { if ($input['users_id'] == Session::getLoginUserID()) { if ($item->deleteByCriteria(array('users_id' => $input['users_id'], 'itemtype' => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($user->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($user->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB, $REDIRECT; switch ($ma->getAction()) { case "plugin_ocsinventoryng_force_ocsng_update": $input = $ma->getInput(); foreach ($ids as $id) { $query = "SELECT `plugin_ocsinventoryng_ocsservers_id`, `id`\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `computers_id` = '" . $id . "'"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $data = $DB->fetch_assoc($result); if (self::updateComputer($data['id'], $data['plugin_ocsinventoryng_ocsservers_id'], 1, 1)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; case "plugin_ocsinventoryng_lock_ocsng_field": $input = $ma->getInput(); $fields = self::getLockableFields(); if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) { foreach ($ids as $id) { if ($_POST['field'] == 'all') { if (self::addToOcsArray($id, array_flip($fields), "computer_update")) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { if (self::addToOcsArray($id, array($_POST['field']), "computer_update")) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } } } return; case "plugin_ocsinventoryng_unlock_ocsng_field": $input = $ma->getInput(); $fields = self::getLockableFields(); if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) { foreach ($ids as $id) { if ($_POST['field'] == 'all') { if (self::replaceOcsArray($id, array(), "computer_update")) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { if (self::deleteInOcsArray($id, $_POST['field'], "computer_update", true)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }