diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 151ba4d8..9868e1de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,9 @@ on: push: # Sequence of patterns matched against refs/tags tags: - - '*.*.*' # Push events to matching ex:20.15.10 - + - '*.*.*' # Push events to matching ex:20.15.10 +permissions: + contents: write name: Create release with tag env: TAG_VALUE: ${GITHUB_REF/refs\/tags\//} @@ -14,15 +15,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 - name: Build project # This would actually build your project, using zip for an example artifact id: build_ env: - GITHUB_NAME: ${{ github.event.repository.name }} - - - run: sudo apt-get install libxml-xpath-perl;echo $(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml);echo ::set-output name=version_glpi::$(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml); rm -rf $GITHUB_NAME.xml tools wiki screenshots test .git .github ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png;cd ..; tar jcvf glpi-$GITHUB_NAME-${GITHUB_REF/refs\/tags\//}.tar.bz2 $GITHUB_NAME;ls -al;echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//};echo ${{ steps.getxml.outputs.info }}; - # run: rm -rf $GITHUB_NAME.xml tools wiki screenshots test ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png; tar -zcvf glpi-$GITHUB_NAME-$GITHUB_TAG.tar.gz $GITHUB_NAME + GITHUB_NAME: ${{ github.event.repository.name }} + + + run: php -v ;sudo apt-get install libxml-xpath-perl; sudo apt-get install composer;echo $(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml);echo ::set-output name=version_glpi::$(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml); [[ -f composer.json ]] && composer install --no-dev; rm -rf $GITHUB_NAME.xml tools wiki screenshots test .git .github ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png;cd ..; tar -jcvf glpi-$GITHUB_NAME-${GITHUB_REF/refs\/tags\//}.tar.bz2 $GITHUB_NAME;ls -al;echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//};echo ${{ steps.getxml.outputs.info }}; + # run: rm -rf $GITHUB_NAME.xml tools wiki screenshots test ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png; tar -zcvf glpi-$GITHUB_NAME-$GITHUB_TAG.tar.bz2 $GITHUB_NAME - name: Create Release id: create_release uses: actions/create-release@v1 @@ -30,13 +35,13 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} - release_name: | - GLPI ${{ steps.build_.outputs.version_glpi }} : Version ${{ github.ref }} disponible / available + release_name: | + GLPI ${{ steps.build_.outputs.version_glpi }} : Version ${{ github.ref }} disponible / available body : Version ${{ steps.build_.outputs.tag }} released for GLPI ${{ steps.build_.outputs.version_glpi }} draft: false prerelease: true - name: Upload Release Asset - id: upload-release-asset + id: upload-release-asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/hook.php b/hook.php index b30877fe..b0f953c4 100644 --- a/hook.php +++ b/hook.php @@ -655,7 +655,7 @@ function plugin_ocsinventoryng_uninstall() "glpi_plugin_ocsinventoryng_ocsalerts"]; foreach ($tables as $table) { - $DB->query("DROP TABLE IF EXISTS `$table`;"); + $DB->dropTable($table); } $old_tables = ["glpi_plugin_ocsinventoryng_profiles", @@ -663,20 +663,15 @@ function plugin_ocsinventoryng_uninstall() "glpi_plugin_ocsinventoryng_items_devicebiosdatas"]; foreach ($old_tables as $table) { - $DB->query("DROP TABLE IF EXISTS `$table`;"); + $DB->dropTable($table); } $tables_glpi = ["glpi_savedsearches", "glpi_displaypreferences", "glpi_logs"]; foreach ($tables_glpi as $table_glpi) { - $DB->query("DELETE - FROM `" . $table_glpi . "` - WHERE `itemtype` IN ('PluginMassocsimportNotimported', - 'PluginMassocsimportDetail', - 'PluginOcsinventoryngOcsServer', - 'PluginOcsinventoryngNotimportedcomputer', - 'PluginOcsinventoryngDetail', - 'PluginOcsinventoryngRuleImportEntity')"); + $DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginMassocsimport%']]); + + $DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginOcsinventoryng%']]); } $tables_ocs = ["ocs_glpi_crontasks", "ocs_glpi_displaypreferences", @@ -810,8 +805,8 @@ function plugin_ocsinventoryng_getDatabaseRelations() "glpi_plugin_ocsinventoryng_registrykeys" => "computers_id", "glpi_plugin_ocsinventoryng_details" => "computers_id"], - "glpi_networkports" - => ["glpi_plugin_ocsinventoryng_networkports" => "networkports_id"], + //"glpi_networkports" + //=> ["glpi_plugin_ocsinventoryng_networkports" => "networkports_id"], "glpi_profiles" => ["glpi_plugin_ocsinventoryng_ocsservers_profiles" => "profiles_id"]]; @@ -1374,9 +1369,13 @@ function plugin_ocsinventoryng_ruleCollectionPrepareInputDataForProcess($params) case 'RuleImportAsset': $ocsservers_id = 0; if ($params['rule_itemtype'] == 'RuleImportEntity') { - $ocsservers_id = $params['values']['input']['ocsservers_id']; + if (isset($params['values']['input']['ocsservers_id'])) { + $ocsservers_id = $params['values']['input']['ocsservers_id']; + } } else { - $ocsservers_id = $params['values']['params']['plugin_ocsinventoryng_ocsservers_id']; + if (isset($params['values']['params']['plugin_ocsinventoryng_ocsservers_id'])) { + $ocsservers_id = $params['values']['params']['plugin_ocsinventoryng_ocsservers_id']; + } } $rule_parameters = [ diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php index 213fd5d1..26a5cd87 100644 --- a/inc/dashboard.class.php +++ b/inc/dashboard.class.php @@ -31,7 +31,7 @@ /** * Class PluginOcsinventoryngDashboard */ -class PluginOcsinventoryngDashboard extends CommonGLPI +class PluginOcsinventoryngDashboard extends PluginMydashboardHtml { public $widgets = []; private $options; @@ -56,14 +56,16 @@ public function init() /** * @return \array[][] */ - public function getWidgetsForItem() + public static function getWidgetsForItem() { $widgets = [ PluginMydashboardMenu::$INVENTORY => [ - $this->getType() . "1" => ["title" => __("Last synchronization of computers by month", "ocsinventoryng"), + self::getType() . "1" => ["id" => 1, + "title" => __("Last synchronization of computers by month", "ocsinventoryng"), "type" => PluginMydashboardWidget::$BAR, "comment" => __("Display synchronization of computers by month", "ocsinventoryng")], - $this->getType() . "2" => ["title" => __("Detail of imported computers", "ocsinventoryng"), + self::getType() . "2" => ["id" => 2, + "title" => __("Detail of imported computers", "ocsinventoryng"), "type" => PluginMydashboardWidget::$PIE, "comment" => __("Number of OCSNG computers, Fusion Inventory computer, without agent computers", "ocsinventoryng")], ], @@ -128,10 +130,13 @@ public function getWidgetContentForItem($widgetId, $opt = []) } } - $widget = new PluginMydashboardHtml(); - $title = __("Last synchronization of computers by month", "ocsinventoryng"); - $comment = ""; + $widget = new parent(); + $widgets = self::getWidgetsForItem(); + $title = __("Last synchronization of computers by month", "ocsinventoryng"); + $comment = __("Display synchronization of computers by month", "ocsinventoryng"); $widget->setWidgetTitle($title); + $widget->setWidgetComment($comment); + $widget->toggleWidgetRefresh(); $dataBarset = json_encode($tabdata); @@ -264,10 +269,13 @@ public function getWidgetContentForItem($widgetId, $opt = []) } } - $widget = new PluginMydashboardHtml(); - $title = __("Detail of imported computers", "ocsinventoryng"); + $widget = new parent(); + $widgets = self::getWidgetsForItem(); + $title = __("Detail of imported computers", "ocsinventoryng"); + $comment = __("Number of OCSNG computers, Fusion Inventory computer, without agent computers", "ocsinventoryng"); $widget->setWidgetTitle($title); - $comment = ""; + $widget->setWidgetComment($comment); + $widget->toggleWidgetRefresh(); $dataPieset = json_encode($counts); $labelsPie = json_encode($name_agent); diff --git a/inc/hardware.class.php b/inc/hardware.class.php index d033d192..09b08be3 100644 --- a/inc/hardware.class.php +++ b/inc/hardware.class.php @@ -85,7 +85,7 @@ public static function updateLockforComputer(CommonDBTM $item) public static function getHardwareLockableFields($plugin_ocsinventoryng_ocsservers_id = 0) { if ($plugin_ocsinventoryng_ocsservers_id > 0) { - $locks = []; + $locks = []; $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id); if (intval($cfg_ocs["import_general_name"]) > 0) { @@ -97,7 +97,7 @@ public static function getHardwareLockableFields($plugin_ocsinventoryng_ocsserve } if (intval($cfg_ocs["import_general_contact"]) > 0) { - $locks["contact"] = __('Alternate username'); + $locks["contact"] = __('Alternate username'); } if (intval($cfg_ocs["link_with_user"]) > 0) { @@ -113,11 +113,11 @@ public static function getHardwareLockableFields($plugin_ocsinventoryng_ocsserve $locks["uuid"] = __('UUID'); } } else { - $locks = ["name" => __('Name'), - "comment" => __('Comments'), - "contact" => __('Alternate username'), - "uuid" => __('UUID'), - "users_id" => __('User')]; + $locks = ["name" => __('Name'), + "comment" => __('Comments'), + "contact" => __('Alternate username'), + "uuid" => __('UUID'), + "users_id" => __('User')]; } return $locks; @@ -133,19 +133,19 @@ public static function getHardwareLockableFields($plugin_ocsinventoryng_ocsserve public static function getRuleLockableFields($plugin_ocsinventoryng_ocsservers_id = 0, $ocsid = 0) { if ($plugin_ocsinventoryng_ocsservers_id > 0 && $ocsid > 0) { - $locks = []; + $locks = []; $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id); - $rule = new RuleImportEntityCollection(); + $rule = new RuleImportEntityCollection(); $locations_id = 0; - $groups_id = 0; - $data = $rule->processAllRules( + $groups_id = 0; + $data = $rule->processAllRules( ['ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, - '_source' => 'ocsinventoryng', - 'locations_id' => $locations_id, - 'groups_id' => $groups_id], + '_source' => 'ocsinventoryng', + 'locations_id' => $locations_id, + 'groups_id' => $groups_id], ['locations_id' => $locations_id, - 'groups_id' => $groups_id], + 'groups_id' => $groups_id], ['ocsid' => $ocsid] ); @@ -162,12 +162,12 @@ public static function getRuleLockableFields($plugin_ocsinventoryng_ocsservers_i } if (isset($data['groups_id_tech']) && $data['groups_id_tech'] > 0) { - $locks["groups_id_tech"] = __('Group in charge of the hardware'); + $locks["groups_id_tech"] = __('Group in charge'); } } else { - $locks = ["locations_id" => __('Location'), - "groups_id" => __('Group'), - "groups_id_tech" => __('Group in charge of the hardware')]; + $locks = ["locations_id" => __('Location'), + "groups_id" => __('Group'), + "groups_id_tech" => __('Group in charge')]; } return $locks; @@ -183,7 +183,7 @@ public static function getRuleLockableFields($plugin_ocsinventoryng_ocsservers_i public static function updateComputerHardware($options = []) { $is_utf8 = $options['cfg_ocs']["ocs_db_utf8"]; - $force = $options["force"]; + $force = $options["force"]; $cfg_ocs = $options['cfg_ocs']; $update_history = 0; @@ -197,11 +197,11 @@ public static function updateComputerHardware($options = []) $updates = []; if (intval($options['cfg_ocs']["import_general_domain"]) > 0) { - $opt["domains_id"] = PluginOcsinventoryngOcsProcess::encodeOcsDataInUtf8($is_utf8, $hardware["WORKGROUP"]); - $opt["entities_id"] = $options['entities_id']; + $opt["domains_id"] = PluginOcsinventoryngOcsProcess::encodeOcsDataInUtf8($is_utf8, $hardware["WORKGROUP"]); + $opt["entities_id"] = $options['entities_id']; $opt["computers_id"] = $options['computers_id']; - $opt["dohistory"] = $update_history; - $opt["force"] = $options['force']; + $opt["dohistory"] = $update_history; + $opt["force"] = $options['force']; self::updateComputerDomain($opt); } @@ -231,7 +231,7 @@ public static function updateComputerHardware($options = []) if (!empty($hardware["DESCRIPTION"]) && $hardware["DESCRIPTION"] != NOT_AVAILABLE) { $updates["comment"] .= PluginOcsinventoryngOcsProcess::encodeOcsDataInUtf8($is_utf8, $hardware["DESCRIPTION"]) - . "\r\n"; + . "\r\n"; } $updates["comment"] .= sprintf(__('%1$s: %2$s'), __('Swap', 'ocsinventoryng'), PluginOcsinventoryngOcsProcess::encodeOcsDataInUtf8($is_utf8, $hardware["SWAP"])); } @@ -243,11 +243,11 @@ public static function updateComputerHardware($options = []) } if (count($updates) || $force) { - $updates["id"] = $options['computers_id']; - $updates["_nolock"] = true; + $updates["id"] = $options['computers_id']; + $updates["_nolock"] = true; $updates["_no_history"] = !$update_history; - $updates['_auto'] = true; - $comp = new Computer(); + $updates['_auto'] = true; + $comp = new Computer(); $comp->update($updates, $update_history); } } @@ -275,32 +275,33 @@ public static function updateComputerFields($line_links, $data, $cfg_ocs) $computer = new Computer(); if ($computer->getFromDB($line_links['computers_id'])) { - $dbu = new DbUtils(); + $dbu = new DbUtils(); $ancestors = $dbu->getAncestorsOf('glpi_entities', $computer->fields['entities_id']); - //If there's a location to update - if (isset($data['locations_id'])) { - $location = new Location(); - if ($location->getFromDB($data['locations_id'])) { - //If location is in the same entity as the computer, or if the location is - //defined in a parent entity, but recursive - if ($location->fields['entities_id'] == $computer->fields['entities_id'] - || (in_array($location->fields['entities_id'], $ancestors) - && $location->fields['is_recursive'])) { - $ko = 0; - $locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']); - if (is_array($locks) && count($locks)) { - if (in_array("locations_id", $locks)) { - $ko = 1; + if ($cfg_ocs["import_user_location"] > 0) { + //If there's a location to update + if (isset($data['locations_id'])) { + $location = new Location(); + if ($location->getFromDB($data['locations_id'])) { + //If location is in the same entity as the computer, or if the location is + //defined in a parent entity, but recursive + if ($location->fields['entities_id'] == $computer->fields['entities_id'] + || (in_array($location->fields['entities_id'], $ancestors) + && $location->fields['is_recursive'])) { + $ko = 0; + $locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']); + if (is_array($locks) && count($locks)) { + if (in_array("locations_id", $locks)) { + $ko = 1; + } + } + if ($ko == 0) { + $tmp['locations_id'] = $data['locations_id']; } - } - if ($ko == 0) { - $tmp['locations_id'] = $data['locations_id']; } } } } - if (isset($data['users_id'])) { $tmp['users_id'] = $data['users_id']; } @@ -311,39 +312,44 @@ public static function updateComputerFields($line_links, $data, $cfg_ocs) } //If there's a Group to update - if (isset($data['groups_id'])) { - $group = new Group(); - $ko = 1; - $locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']); - if ($group->getFromDB($data['groups_id'])) { - //If group is in the same entity as the computer, or if the group is - //defined in a parent entity, but recursive - if ($group->fields['entities_id'] == $computer->fields['entities_id'] - || (in_array($group->fields['entities_id'], $ancestors) - && $group->fields['is_recursive'])) { - $ko = 0; + + if ($cfg_ocs["import_user_group_default"] || $cfg_ocs["import_user_group"]) { + + if (isset($data['groups_id'])) { + $group = new Group(); + $ko = 1; + $locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']); + if ($group->getFromDB($data['groups_id'])) { + //If group is in the same entity as the computer, or if the group is + //defined in a parent entity, but recursive + if ($group->fields['entities_id'] == $computer->fields['entities_id'] + || (in_array($group->fields['entities_id'], $ancestors) + && $group->fields['is_recursive'])) { + $ko = 0; + + if (is_array($locks) && count($locks)) { + if (in_array("groups_id", $locks)) { + $ko = 1; + } + } + } + } elseif ($data['groups_id'] == 0) { + $ko = 0; if (is_array($locks) && count($locks)) { if (in_array("groups_id", $locks)) { $ko = 1; } } } - } elseif ($data['groups_id'] == 0) { - $ko = 0; - if (is_array($locks) && count($locks)) { - if (in_array("groups_id", $locks)) { - $ko = 1; - } + if ($ko == 0) { + $tmp['groups_id'] = $data['groups_id']; } } - if ($ko == 0) { - $tmp['groups_id'] = $data['groups_id']; - } } if (count($tmp) > 0) { - $tmp["_nolock"] = true; - $tmp['id'] = $line_links['computers_id']; + $tmp["_nolock"] = true; + $tmp['id'] = $line_links['computers_id']; $tmp["_no_history"] = !$update_history; $computer->update($tmp, $update_history); } @@ -368,7 +374,7 @@ public static function getUserDefaultGroup($userid) * @param $entity * @param $userid * @param string $filter - * @param bool $first + * @param bool $first * * @return array|int */ @@ -376,12 +382,12 @@ public static function getUserGroup($entity, $userid, $filter = '', $first = tru { global $DB; - $dbu = new DbUtils(); + $dbu = new DbUtils(); $query = "SELECT `glpi_groups`.`id` FROM `glpi_groups_users` INNER JOIN `glpi_groups` ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`) WHERE `glpi_groups_users`.`users_id` = " . $userid . - $dbu->getEntitiesRestrictRequest(' AND ', 'glpi_groups', '', $entity, true); + $dbu->getEntitiesRestrictRequest(' AND ', 'glpi_groups', '', $entity, true); if ($filter) { $query .= "AND (" . $filter . ")"; @@ -409,19 +415,19 @@ public static function getFields($ocsComputer, $cfg_ocs, &$values, $computers_id { global $DB; - $comp = new Computer(); + $comp = new Computer(); $contact = (isset($ocsComputer['META']["USERID"])) ? $ocsComputer['META']["USERID"] : ""; if (!empty($contact) && $cfg_ocs["link_with_user"] > 0) { - $query = "SELECT `id` + $query = "SELECT `id` FROM `glpi_users` WHERE `name` = '" . $contact . "';"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $user_id = $DB->result($result, 0, 0); - $user = new User(); + $user = new User(); $user->getFromDB($user_id); $values['users_id'] = $user_id; @@ -434,7 +440,7 @@ public static function getFields($ocsComputer, $cfg_ocs, &$values, $computers_id } if ($cfg_ocs["import_user_group"] > 0 && (isset($values['groups_id']) && $values['groups_id'] == 0 - || !isset($values['groups_id']))) { + || !isset($values['groups_id']))) { $entities_id = 0; if ($computers_id > 0 && $comp->getFromDB($computers_id)) { $entities_id = $comp->fields["entities_id"]; @@ -458,6 +464,8 @@ public static function getFields($ocsComputer, $cfg_ocs, &$values, $computers_id $values['itemtype'] = 'Computer'; //TODO TAG OCS / sous-reseau / systeme eploit comment / source / domaine / adresse ip + $values['ip'] = $ocsComputer['HARDWARE']['IPADDR']; + } /** @@ -470,10 +478,10 @@ public static function updateComputerDomain($options = []) { if (isset($options['domains_id'])) { $uninstall_history = 0; - $install_history = 0; + $install_history = 0; if ($options['dohistory'] == 1) { $uninstall_history = 1; - $install_history = 1; + $install_history = 1; } $hardware = Glpi\Toolbox\Sanitizer::sanitize($options['domains_id']); @@ -481,10 +489,10 @@ public static function updateComputerDomain($options = []) $domain = new Domain(); $dbu = new DbUtils(); $condition = ['name' => ['LIKE', $hardware], - 'is_deleted' => 0] - + $dbu->getEntitiesRestrictCriteria('glpi_domains', '', $options['entities_id'], true); + 'is_deleted' => 0] + + $dbu->getEntitiesRestrictCriteria('glpi_domains', '', $options['entities_id'], true); - $tab = $domain->find($condition); + $tab = $domain->find($condition); if ($options['force']) { self::resetDomain($options['computers_id'], $uninstall_history); @@ -493,22 +501,22 @@ public static function updateComputerDomain($options = []) && count($tab) > 0) { foreach ($tab as $id => $item) { $CompDomain = new Domain_Item(); - $CompDomain->update(['items_id' => $options['computers_id'], - 'itemtype' => 'Computer', - 'domains_id' => $id, - ], [], $install_history); + $CompDomain->update(['items_id' => $options['computers_id'], + 'itemtype' => 'Computer', + 'domains_id' => $id, + ], [], $install_history); } } else { - $domain = new Domain(); - $id = $domain->add(['name' => $hardware, - 'entities_id' => $options['entities_id'], - 'is_deleted' => 0]); + $domain = new Domain(); + $id = $domain->add(['name' => $hardware, + 'entities_id' => $options['entities_id'], + 'is_deleted' => 0]); if ($id) { $CompDomain = new Domain_Item(); - $CompDomain->add(['items_id' => $options['computers_id'], - 'itemtype' => 'Computer', - 'domains_id' => $id, - ], [], $install_history); + $CompDomain->add(['items_id' => $options['computers_id'], + 'itemtype' => 'Computer', + 'domains_id' => $id, + ], [], $install_history); } } } @@ -529,8 +537,8 @@ public static function resetDomain($glpi_computers_id, $uninstall_history) $item = new $linktype(); $item->deleteByCriteria( ['items_id' => $glpi_computers_id, - 'itemtype' => 'Computer', - ], + 'itemtype' => 'Computer', + ], 1, $uninstall_history ); diff --git a/inc/networkport.class.php b/inc/networkport.class.php index 8ad2bc0e..bd95c301 100644 --- a/inc/networkport.class.php +++ b/inc/networkport.class.php @@ -259,19 +259,22 @@ static private function updateNetworkPort($mac, $name, $computers_id, $instantia } } - if ($ips) { - foreach ($ips as $ip) { - $ip_input = ['name' => $ip, - 'itemtype' => 'NetworkName', - 'items_id' => $networknames_id, - '_no_history' => !$install_network_history, - 'is_dynamic' => 1, - 'is_deleted' => 0]; - $ip_address->add($ip_input); - } - } - - return $network_port->getID(); + if ($ips) { + foreach ($ips as $ip) { + $ip_address = new IPAddress(); + $ip_input = [ + 'name' => $ip, + 'itemtype' => 'NetworkName', + 'items_id' => $networknames_id, + '_no_history' => !$install_network_history, + 'is_dynamic' => 1, + 'is_deleted' => 0 + ]; + $ip_address->add($ip_input); + } + } + + return $network_port->getID(); } // importNetwork @@ -425,7 +428,7 @@ static function importNetwork($cfg_ocs, $ocsComputer, $computers_id, $entities_i } $already_known_ifaces[] = $item_device->getID(); } - + $networkports_id = -1; if ($cfg_ocs["import_ip"] == 1) { if ($type->fields['instantiation_type'] == __CLASS__) { $result = $main['result']; @@ -489,31 +492,31 @@ static function importNetwork($cfg_ocs, $ocsComputer, $computers_id, $entities_i } } - $query = "SELECT `id` - FROM `glpi_networkports` - WHERE `itemtype` = 'Computer' - AND `items_id` = $computers_id - AND `is_dynamic` = 1"; - if (count($already_known_ports) > 0) { - $query .= " AND `id` NOT IN ('" . implode("', '", $already_known_ports) . "')"; - } - $network_ports = new NetworkPort(); - foreach ($DB->request($query) as $line) { - $network_ports->delete($line, true, $uninstall_network_history); - } - - $query = "SELECT `id` - FROM `glpi_items_devicenetworkcards` - WHERE `itemtype` = 'Computer' - AND `items_id` = $computers_id - AND `is_dynamic` = 1"; - if (count($already_known_ifaces) > 0) { - $query .= " AND `id` NOT IN ('" . implode("', '", $already_known_ifaces) . "')"; - } - $item_device = new Item_DeviceNetworkCard(); - foreach ($DB->request($query) as $line) { - $item_device->delete($line, true, $uninstall_network_history); - } +// $query = "SELECT `id` +// FROM `glpi_networkports` +// WHERE `itemtype` = 'Computer' +// AND `items_id` = $computers_id +// AND `is_dynamic` = 1"; +// if (count($already_known_ports) > 0) { +// $query .= " AND `id` NOT IN ('" . implode("', '", $already_known_ports) . "')"; +// } +// $network_ports = new NetworkPort(); +// foreach ($DB->request($query) as $line) { +// $network_ports->delete($line, true, $uninstall_network_history); +// } +// +// $query = "SELECT `id` +// FROM `glpi_items_devicenetworkcards` +// WHERE `itemtype` = 'Computer' +// AND `items_id` = $computers_id +// AND `is_dynamic` = 1"; +// if (count($already_known_ifaces) > 0) { +// $query .= " AND `id` NOT IN ('" . implode("', '", $already_known_ifaces) . "')"; +// } +// $item_device = new Item_DeviceNetworkCard(); +// foreach ($DB->request($query) as $line) { +// $item_device->delete($line, true, $uninstall_network_history); +// } } /** diff --git a/inc/ocsprocess.class.php b/inc/ocsprocess.class.php index 37126948..a53d2d8e 100644 --- a/inc/ocsprocess.class.php +++ b/inc/ocsprocess.class.php @@ -537,8 +537,10 @@ public static function importComputer($import_params) // 'id' => $id, ]; $computerinput = $input; - $computerinput['ip'] = $ocsComputer['NETWORKS'][0]['IPADDRESS']; - $computerinput['subnet'] = $ocsComputer['NETWORKS'][0]['IPSUBNET']; + if (isset($ocsComputer['NETWORKS'])) { + $computerinput['ip'] = $ocsComputer['NETWORKS'][0]['IPADDRESS']; + $computerinput['subnet'] = $ocsComputer['NETWORKS'][0]['IPSUBNET']; + } if (isset($ocsComputer['HARDWARE']['WORKGROUP'])) { $computerinput['domain'] = $ocsComputer['HARDWARE']['WORKGROUP']; } @@ -911,7 +913,7 @@ public static function synchronizeComputer($sync_params, $transfer = true) $ocsClient = PluginOcsinventoryngOcsServer::getDBocs($plugin_ocsinventoryng_ocsservers_id); $options = [ "DISPLAY" => [ - "CHECKSUM" => PluginOcsinventoryngOcsClient::CHECKSUM_HARDWARE, + "CHECKSUM" => PluginOcsinventoryngOcsClient::CHECKSUM_HARDWARE | PluginOcsinventoryngOcsClient::CHECKSUM_NETWORK_ADAPTERS, 'PLUGINS' => PluginOcsinventoryngOcsClient::PLUGINS_ALL ] ]; diff --git a/inc/profile.class.php b/inc/profile.class.php index 6a485875..6778363f 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -347,10 +347,11 @@ public static function migrateOneProfile($profiles_id) return true; } - foreach ($DB->request( - 'glpi_plugin_ocsinventoryng_profiles', - "`profiles_id`=$profiles_id" - ) as $profile_data) { + $it = $DB->request([ + 'FROM' => 'glpi_plugin_ocsinventoryng_profiles', + 'WHERE' => ['profiles_id' => $profiles_id] + ]); + foreach ($it as $profile_data) { $matching = ['ocsng' => 'plugin_ocsinventoryng', 'sync_ocsng' => 'plugin_ocsinventoryng_sync', 'view_ocsng' => 'plugin_ocsinventoryng_view', @@ -359,10 +360,10 @@ public static function migrateOneProfile($profiles_id) $current_rights = ProfileRight::getProfileRights($profiles_id, array_values($matching)); foreach ($matching as $old => $new) { if (!isset($current_rights[$old])) { - $query = "UPDATE `glpi_profilerights` - SET `rights` = '" . self::translateARight($profile_data[$old]) . "' - WHERE `name` = '$new' AND `profiles_id` = $profiles_id"; - $DB->query($query); + $DB->update('glpi_profilerights', ['rights' => self::translateARight($profile_data[$old])], [ + 'name' => $new, + 'profiles_id' => $profiles_id + ]); } } } @@ -387,13 +388,21 @@ public static function initProfile() } //Migration old rights in new ones - foreach ($DB->request("SELECT `id` FROM `glpi_profiles`") as $prof) { + $it = $DB->request([ + 'SELECT' => ['id'], + 'FROM' => 'glpi_profiles' + ]); + foreach ($it as $prof) { self::migrateOneProfile($prof['id']); } - foreach ($DB->request("SELECT * - FROM `glpi_profilerights` - WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "' - AND `name` LIKE '%plugin_ocsinventoryng%'") as $prof) { + $it = $DB->request([ + 'FROM' => 'glpi_profilerights', + 'WHERE' => [ + 'profiles_id' => $_SESSION['glpiactiveprofile']['id'], + 'name' => ['LIKE', '%plugin_ocsinventoryng%'] + ] + ]); + foreach ($it as $prof) { if (isset($_SESSION['glpiactiveprofile'])) { $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; } diff --git a/ocsinventoryng.xml b/ocsinventoryng.xml index 6ae3b0c1..c4934aa7 100644 --- a/ocsinventoryng.xml +++ b/ocsinventoryng.xml @@ -28,6 +28,11 @@ Walid Nouh + + 2.0.5 + ~10.0 + https://github.com/pluginsGLPI/ocsinventoryng/releases/download/2.0.5/glpi-ocsinventoryng-2.0.5.tar.bz2 + 2.0.4 ~10.0 diff --git a/setup.php b/setup.php index 6d7734b5..0e6f56b2 100644 --- a/setup.php +++ b/setup.php @@ -32,7 +32,7 @@ define("PLUGIN_OCSINVENTORYNG_STATE_FINISHED", 3); define("PLUGIN_OCSINVENTORYNG_LOCKFILE", GLPI_LOCK_DIR . "/ocsinventoryng.lock"); -define('PLUGIN_OCS_VERSION', '2.0.4'); +define('PLUGIN_OCS_VERSION', '2.0.5'); if (!defined("PLUGIN_OCS_DIR")) { define("PLUGIN_OCS_DIR", Plugin::getPhpDir("ocsinventoryng"));