Provide a standard library for adding/updating objets

Impact on standard objects

getSearchOptions()

  • Each object to inject must implement the getSearchOption function.
  • Each field must be described. A check condition can be added :
    $tab[8]['checktype'] = 'ip';
    
  • Each decimal field must decribe it's needed value to be displayed :
    $tab[9]['minvalue'] = 0; //Minimum value
    $tab[9]['maxvalue'] = 100; //Maximum value
    $tab[9]['step'] = 1; //Incrementation step
    $tab[9]['-1'] = $LANG['financial'][2] //Value to add to the list (in replacement of '-----')
    

    So that displaying decimal values will become easier.
  • Text fields can have additional values :
    $tab[9]['size'] = 255 //Size of the text field to display
    $tab[9]['default'] = 0 //Default value to display in the textfield
    

Find a solution to mutualize the display of fields : dropdowns, integers, etc

Import / Update / Delete

Goal : to have standard static function to handle import/export/update of core's objects
Theses functions should be used by plugins :
  • datainjection
  • webservices
  • fusioninventory
  • GLPI core

Functions must be standard and prototypes must be implemented into CommonDBTM
Note : functions cannot be called add/update/delete because it's already taken by basically, non static functions of the framework.

static function addObject($values,$options)
static function updateObject($values,$options)
static function deleteObject($values,$options)

  • params : an array of values (like in add())
  • options : array of options to be used during the import/update/delete process
    - perform_checks: true/false
  • return values is array(action,status,error_message,id)
    ID : the ID of the object (new ID if add, existing if update/delete)
    Action's values are :
    - SUCESS= 1
    - FAILED = 0
    Status can be
    - UNKNOWN_ID : ID unknown (for update/delete)
    - ALREADY_EXISTS : already exists (for add)
    - TYPE_MISMATCH : a field doesn't have the right type (for example IP Address, Mac Address, dates, integers, etc)
    Error_Message :
  • an ID which corresponds to a know error message
Ability to inject label (for example for name for a dropdown) :
  • computertypes_name

Checks

Should be based on datatype declaration for each field in getSearchOptions() method.
Function must be implemented, at term, in CommonDBTM.
Primtive checks to be included :
- integer : check if value is a real integer
- float : check if it's a floating value
- ipaddress : check if it's an ipaddress
- macaddress : check if it's a maccaddress
- date : check if date is the correct format
- yesno : 0 or 1
- itemtype : a value which represent an object's class (like Computer, Monitor, Ticket, and so on)

Note : More specific checks should be possible using an object's method performMoreChecks :
- 'interface' field in Profile
- right_rw, right_r, right_w in Profile

The developper using theses functions is responsible for providing data in the right format (for example data). In case of a plugin, like datainjection, pre-format action must occur (based on what's defined in the model)

List / Get objects

Provides 2 methods to list objects and get an object :
  • static function list($options)
  • static function get($options)

method list

Look for a results based on a request using the $options array.
//TODO : defined default values return

Maybe using the search engine to get the data ?

method get

Get all the object's values.
Options available :
  • id2name : for each value which is an foreign key, return the label value associated with it.
    It's easy to know how to get the label associated with an ID : look at the mapping informations in getSearchOptions()

This method could be use by GLPI, from NotificationTarget::getDatasForTemplate()

Specific types options and criterias

Computer

Monitor

Printer

Networking

Peripheral

Phone

Network Port

Checks :

Available options are :
- check_ipaddress : true/false
- check_macaddress : true/false
- check_ifnumber : true/false

Software

SoftwareLicense

SoftwareVersion

Dropdowns

Network ports