-
Notifications
You must be signed in to change notification settings - Fork 32
How to setup
The file setup.php is used to define :
- general behavior of the plugin (the used core features)
- functions that the plugin needs in order to be installed
The file must contain at least 4 functions :
init
plugin_init_<plugin_name>()
- Declares the type of plugin
- Declares the display
- Hook actions performed on core GLPI objects
- Using the CRON scheduler
- Use Planning
- Use of mass actions (massiveactions)
- Integration with Helpdesk
- Added javascript and CSS Personalized
version
plugin_version_<plugin_name>()
Must return an array with theses keys :
- Name
- Version
- Author
- Minimum GLPI version
- Maximum GLPI version
prerequisites
plugin_<plugin_name>_check_prerequisites()
- Check prerequisites to install the plugin
check_config
plugin_<plugin_name>_check_config()
- Verification of any GLPI config necessary to install the plugin
A plugin can have callbacks on each action taken in GLPI to perform custom actions. For each hook, a list of function names is included with call_user_func php function.
See doHook function for detail of inclusion.
- Before adding the object :
$PLUGIN_HOOKS['pre_item_add']['<plugin_name>'] = 'plugin_pre_item_add_<plugin_name>';
- After adding the object :
$PLUGIN_HOOKS['item_add']['<plugin_name>'] = 'plugin_item_add_<plugin_name>';
- Before updating the object :
$PLUGIN_HOOKS['pre_item_update']['<plugin_name>'] = 'plugin_pre_item_update_<plugin_name>';
- After updating the object :
$PLUGIN_HOOKS['item_update']['<plugin_name>'] = 'plugin_item_update_<plugin_name>';
- Before object deletion :
$PLUGIN_HOOKS['pre_item_delete']['<plugin_name>'] = 'plugin_pre_item_delete_<plugin_name>';
- After object deletion :
$PLUGIN_HOOKS['item_delete']['<plugin_name>'] = 'plugin_item_delete_<plugin_name>';
- Before purging the object from the database :
$PLUGIN_HOOKS['pre_item_purge']['<plugin_name>'] = 'plugin_pre_item_purge_<plugin_name>';
- After purging the object from the database :
$PLUGIN_HOOKS['item_purge']['<plugin_name>'] = 'plugin_item_purge_<plugin_name>';
- Before the object is restored :
$PLUGIN_HOOKS['pre_item_restore']['<plugin_name>'] = 'plugin_pre_item_restore_<plugin_name>';
- After the object is restored :
$PLUGIN_HOOKS['item_restore']['<plugin_name>'] = 'plugin_item_restore_<plugin_name>';
- Perform additional operations to declare an authenticated user or not :
$PLUGIN_HOOKS['restrict_ldap_auth']['<plugin_name>'] = 'plugin_authentication_restrict_ldap_auth_<plugin_name>';
- Perform additional operations to declare an authenticated user or not :
$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['<plugin_name>'] = 'plugin_retrieve_more_data_from_ldap_<votre plugin>';
- Indicates if the plugin should be displayed in the "Helpdesk" menu
$PLUGIN_HOOKS['helpdesk_menu_entry']['<plugin_name>'] = true;
It is possible to make an object visible in the Helpdesk (ie be able to report an incident on it).
- will make at least one type of plugin available from the Helpdesk. The definition of objects that are available is in the function plugin_<plugin_name>_assignToTicket in the file hook.php :
$PLUGIN_HOOKS['assign_to_ticket']['<plugin_name>']=1;
For an object to be visible in the "My Devices" list :
- the option linkuser_types is either TRUE in registerNewType and a FK_users field exists in the objec's table and/or
- the option linkgroup_types is either TRUE in registerNewType and a FK_groups field exists n the object's table
Two functions can be defined and used to populate the schedule and to define how elements are displayed:
- Add events to the schedule :
$PLUGIN_HOOKS['planning_populate']['<plugin_name>']="plugin_planning_populate_<plugin_name>";
- Manage the display of an event in the schedule :
$PLUGIN_HOOKS['display_planning']['<plugin_name>']="plugin_display_planning_<plugin_name>";
You can add a scheduled task to the GLPI internal CRON. Just define :
$PLUGIN_HOOKS['cron']['<plugin_name>'] = DAY_TIMESTAMP;
This will launch the function {{{cron_plugin_<plugin_name>}}} in hook.php in the background (daily).
Exemple : every 30 minutes :
$PLUGIN_HOOKS['cron']['<plugin_name>'] = 30*60
or
$PLUGIN_HOOKS['cron']['<plugin_name>'] = 30*MINUTE_TIMESTAMP
ou
$PLUGIN_HOOKS['cron']['<plugin_name>'] = HOUR_TIMESTAMP/2;
Deprecated, since 0.85 version, GLPI redirect to referer after login. System is still here for compatibility.
The call to the login page allows automatic redirection (eg for access when sending a link via email). You can perform an automatic redirect to a page of your plugin by defining:
$PLUGIN_HOOKS['redirect_page']['<plugin_name>']="PAGE_TO_REDIRECT.php";
calling index.php?redirect=plugin_<plugin_name>_IDTOREDIRECT redirects to plugins/PLUGINNAME/PAGE_TO_REDIRECT.php?ID=IDTOREDIRECT
- You must specify the table for a dropdown tree :
array_push($CFG_GLPI["dropdowntree_tables"],"glpi_dropdown_plugin_<plugin_name>");
- If a separate dropdown for each entity :
array_push($CFG_GLPI["specif_entities_tables"],"glpi_dropdown_plugin_<plugin_name>");
- For this you can use the function registerPluginType (replacing pluginNewType) :
Plugin::registerClass('pluginExample', // Class Name
array( // Attributes
'addtabon' => 'Computer' // Add tagb on specified itemtype
'contract_types' => '<PluginExampleNewtype' // push to $CFG_GLPI types
));
Attributes with empty or FALSE values will be omitted.
Default action types : modify / delete / purge / restore are accessible from the lists.
- To add specific actions, we must add :
$PLUGIN_HOOKS['use_massive_action']['<plugin_name>']=true;