Refers to this ticket #2316

Goal : improve management of unicity for inventory objects.
*Perimeter: global. Unicity for all methods of input.

2 tasks :
  • Filter values before inserting them : extend checkValue function and rename it in "filterValues". Add checks on serveral fields (as it's done in datainjection lib):
    • mac address, ip address, float, int, string : see function checkType()
    • filter type and value (for example varchar 255, etc.)
    • add new datatype string to check varchar(255)
  • add a new method to check field unicity
    => Walid : done

Walid : will implement option 2.

Options 1 : Using the rules engine to perform checks

Pros and cons

  • Pros
    • Fine grain checks definition
    • Can check unicity AND mandatory fields at the same time
    • Can define more than one rule per type
    • Can easily deal with rules per entity (like business rules)
    • Can also deal with blacklisted values
  • Cons :
    • Need to modify again the rules engine
    • Less easy to understand for users than the current GUI
    • Performances issues ? This is my biggest concern, even if sql request may be cached in mysql

Rules engine modifications

Add a new type of rule : RuleCheckFields
Available criterias :
  • itemtype : mandatory (see below)
  • field (list of available fields) : stored in DB in a json array
  • entities_id : see if it's necessary if rules can be per entity & recursive
Actions :
  • Refuse import or update
  • Send notifications
  • import or update
    2 actions can be used at the same times :
  • refuse & notify
  • import & notify
Modifications do to :
  • Need to add a list of mandatory criterias per rule : when a rule is created, only theses options are available. Once the options are defined, then display all options
  • in ajax/rulecriteriavalue.php, when selecting the fields on which to check unicity, display the list of fields in a multivalued list. Save values in DB in a json array
  • add a blacklist object (Blacklistedfield extends CommonDropdown) per entity, recursive : field can be blacklisted per entity
  • use blacklist during the rules processing
  • migrate mandatory options for helpdesk as a new rule for itemtype Ticket

Option 2 : extend current GUI to allow complex criteria

Extend current form :
  • add new criterion form : allow to define a list of fields to check per criterion
  • add a list of available criteria :
    • fields
    • check unicity yes / no
    • check not empty yes / no
  • add a form to define actions to perform if criteria are not matched :
    • refuse yes / no
    • send notifications yes / no
  • Pros :
    • easy to setup
  • Cons :
    • less extensible and flexible than the rules engine

Aleady done

This feature is to be linked to MandatoryFields.

Walid :
  • Add a new menu in Configuration called "Controls" : it'll contains unicity criterias, and after, mandatory fields
  • Use search engine if possible
    List of possible fields to use for unicity in a <select multiple> + 2 more options : global yes/no (query on the current entity or global) and active yes/no
    All fields that are in searchOptions can be used to check unicity for an itemtype
  • In entity form, add a new tab to override global configuration is it's possible : allow for each type of material for a particular entity (or for all materials in all entities) to define criteria that define unicity.
    • MoYo : if it is define it must be done for all type of material for me. If not, which is the interest in unicity criteria ?
  • The unicity will be optional : if an administrator doesn't want to implement its own rules of unicity into GLPI all process will be realized exactly the same way right now.

Walid : extend the CommonDropdown method. Unicity criteria are managed as other objects, with an entities_id and an is_recursive.
If an unicity criteria for this type is already defined, in a parent entity, it's not possible to overwrite it => done

Walid : add a new OCS import return code to indicate that import failed (to be processed by massocsimport plugin) => done
Walid : add statistics on manual OCS import/update to display in real time what is imported and what is not imported => done

When submitting a form, call a validation page in Ajax to check values, and cancel form post if necessary => todo in a second time

Additional things to discuss :
  • need to manage a list of blacklisted items (for example IP and MAC)
  • for each itemtype's criterias, add a tab to list all possible doubles and a massive action to add them into the blacklist
  • add a notification when someone tries to enter a double in GLPI


Add new class FieldCriteria extends CommonDropdown

Extend commondropdown to display custom fields by itemtype


CREATE TABLE IF NOT EXISTS `glpi_fieldunicities` (
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `is_recursive` tinyint(1) NOT NULL DEFAULT '0',
  `itemtype` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `entities_id` int(11) NOT NULL DEFAULT '-1',
  `fields` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `is_active` tinyint(1) NOT NULL DEFAULT '0',
  `comment` text COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Stores field unicity criterias';


  • Files to edit : fr/glpi/config_common_restrict.dita
  • Section to add : <title>Unicité des objets d'inventaire</title>

Old discussions see UnicityCriteriaOld