From 2d736fc5e345815f23467dc0d2e93679cd707b80 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 10 Oct 2024 16:55:23 +0200 Subject: [PATCH 1/7] Add itemtype, item ans path injection for Database instance --- inc/databaseinstanceinjection.class.php | 61 ++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index 878c28c..99fc356 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -28,6 +28,8 @@ * ------------------------------------------------------------------------- */ +use Glpi\Inventory\Asset\Computer; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } @@ -53,7 +55,7 @@ public function isPrimaryType() public function connectedTo() { - return []; + return [Computer::class]; } @@ -65,6 +67,30 @@ public function getOptions($primary_type = '') $tab = Search::getOptions(get_parent_class($this)); + $tab[251]['name'] = __('Itemtype'); + $tab[251]['field'] = 'itemtype'; + $tab[251]['table'] = DatabaseInstance::getTable(); + $tab[251]['linkfield'] = "itemtype"; + $tab[251]['injectable'] = true; + $tab[251]['displaytype'] = 'text'; + $tab[251]['checktype'] = 'text'; + + $tab[252]['name'] = __('Item'); + $tab[252]['field'] = 'name'; + $tab[252]['table'] = DatabaseInstance::getTable(); + $tab[252]['linkfield'] = "items_name"; + $tab[252]['injectable'] = true; + $tab[252]['displaytype'] = 'text'; + $tab[252]['checktype'] = 'text'; + + $tab[253]['name'] = __('Path'); + $tab[253]['field'] = 'path'; + $tab[253]['table'] = DatabaseInstance::getTable(); + $tab[253]['linkfield'] = "path"; + $tab[253]['injectable'] = true; + $tab[253]['displaytype'] = 'text'; + $tab[253]['checktype'] = 'text'; + //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = []; @@ -85,4 +111,37 @@ public function addOrUpdateObject($values = [], $options = []) $lib->processAddOrUpdate(); return $lib->getInjectionResults(); } + + /** + * @param $values + * @param $add (true by default) + * @param $rights array + **/ + public function processAfterInsertOrUpdate($values, $add = true, $rights = []) + { + /** @var DBmysql $DB */ + global $DB; + + //Should the port be connected to another one ? + $use_itemtype = (isset($values['DatabaseInstance']["itemtype"]) + || !empty($values['DatabaseInstance']["itemtype"])); + $use_items_name = (isset($values['DatabaseInstance']["items_name"]) + || !empty($values['DatabaseInstance']["items_name"])); + + if (!$use_itemtype || !$use_items_name) { + return false; + } + + $itemtype = new $values['DatabaseInstance']["itemtype"](); + if ($itemtype->getFromDBByCrit(['name' => $values['DatabaseInstance']["items_name"], 'entities_id' => $values['DatabaseInstance']["entities_id"]])) { + $dbinstance = new DatabaseInstance(); + $success = $dbinstance->update( + [ + 'id' => $values['DatabaseInstance']['id'], + 'entities_id' => $values['DatabaseInstance']['entities_id'], + 'items_id' => $itemtype->getID() + ] + ); + } + } } From a4922d9e7618416ad3576356b7519bc2c885a2db Mon Sep 17 00:00:00 2001 From: Lainow Date: Fri, 11 Oct 2024 11:38:19 +0200 Subject: [PATCH 2/7] Fix category dropdown value --- inc/databaseinstanceinjection.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index 99fc356..ec3ab1b 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -95,6 +95,7 @@ public function getOptions($primary_type = '') $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = []; $options['ignore_fields'] = array_merge($blacklist, $notimportable); + $options['displaytype'] = ["dropdown" => [40]]; return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); From 849ffc1fb0806f8ea3bcbbe5d7588146e0513ff1 Mon Sep 17 00:00:00 2001 From: Lainow Date: Mon, 14 Oct 2024 11:17:49 +0200 Subject: [PATCH 3/7] Remove items_name and itemtype option --- inc/databaseinstanceinjection.class.php | 58 +------------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index ec3ab1b..87bdc78 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -66,30 +66,7 @@ public function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); - - $tab[251]['name'] = __('Itemtype'); - $tab[251]['field'] = 'itemtype'; - $tab[251]['table'] = DatabaseInstance::getTable(); - $tab[251]['linkfield'] = "itemtype"; - $tab[251]['injectable'] = true; - $tab[251]['displaytype'] = 'text'; - $tab[251]['checktype'] = 'text'; - - $tab[252]['name'] = __('Item'); - $tab[252]['field'] = 'name'; - $tab[252]['table'] = DatabaseInstance::getTable(); - $tab[252]['linkfield'] = "items_name"; - $tab[252]['injectable'] = true; - $tab[252]['displaytype'] = 'text'; - $tab[252]['checktype'] = 'text'; - - $tab[253]['name'] = __('Path'); - $tab[253]['field'] = 'path'; - $tab[253]['table'] = DatabaseInstance::getTable(); - $tab[253]['linkfield'] = "path"; - $tab[253]['injectable'] = true; - $tab[253]['displaytype'] = 'text'; - $tab[253]['checktype'] = 'text'; + $tab[5]['linkfield'] = 'items_id'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); @@ -112,37 +89,4 @@ public function addOrUpdateObject($values = [], $options = []) $lib->processAddOrUpdate(); return $lib->getInjectionResults(); } - - /** - * @param $values - * @param $add (true by default) - * @param $rights array - **/ - public function processAfterInsertOrUpdate($values, $add = true, $rights = []) - { - /** @var DBmysql $DB */ - global $DB; - - //Should the port be connected to another one ? - $use_itemtype = (isset($values['DatabaseInstance']["itemtype"]) - || !empty($values['DatabaseInstance']["itemtype"])); - $use_items_name = (isset($values['DatabaseInstance']["items_name"]) - || !empty($values['DatabaseInstance']["items_name"])); - - if (!$use_itemtype || !$use_items_name) { - return false; - } - - $itemtype = new $values['DatabaseInstance']["itemtype"](); - if ($itemtype->getFromDBByCrit(['name' => $values['DatabaseInstance']["items_name"], 'entities_id' => $values['DatabaseInstance']["entities_id"]])) { - $dbinstance = new DatabaseInstance(); - $success = $dbinstance->update( - [ - 'id' => $values['DatabaseInstance']['id'], - 'entities_id' => $values['DatabaseInstance']['entities_id'], - 'items_id' => $itemtype->getID() - ] - ); - } - } } From d3085e95a3aa072545ca516e56e71e779d2f54d9 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:06:37 +0200 Subject: [PATCH 4/7] Update inc/databaseinstanceinjection.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/databaseinstanceinjection.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index 87bdc78..60168da 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -28,8 +28,6 @@ * ------------------------------------------------------------------------- */ -use Glpi\Inventory\Asset\Computer; - if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } From 8733d15e4ae3281e61023199f4a54f8124d66c75 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:06:47 +0200 Subject: [PATCH 5/7] Update inc/databaseinstanceinjection.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/databaseinstanceinjection.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index 60168da..7ace7eb 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -53,7 +53,7 @@ public function isPrimaryType() public function connectedTo() { - return [Computer::class]; + return [\Glpi\Inventory\Asset\Computer::class]; } From 048399ff5c3023eb20daad86628075906eb070aa Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 17 Oct 2024 16:11:47 +0200 Subject: [PATCH 6/7] Add comments --- inc/databaseinstanceinjection.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/databaseinstanceinjection.class.php b/inc/databaseinstanceinjection.class.php index 7ace7eb..ac883c3 100644 --- a/inc/databaseinstanceinjection.class.php +++ b/inc/databaseinstanceinjection.class.php @@ -64,7 +64,7 @@ public function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); - $tab[5]['linkfield'] = 'items_id'; + $tab[5]['linkfield'] = 'items_id'; // 5 = databaseinstance items_id Search option //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); From ff3e77dca8e50274588988eeab46e4534004f7af Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 28 Nov 2024 14:37:10 +0100 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2171183..5891983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Add injection of the ```Itemtype```, ```Item``` and ```Path``` for the database instance + ## [2.14.0] - 2024-10-10 ### Added