Skip to content

Commit

Permalink
migration 9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
amma35 committed Dec 27, 2018
1 parent 0c118d6 commit 47b2773
Show file tree
Hide file tree
Showing 36 changed files with 203 additions and 398 deletions.
28 changes: 14 additions & 14 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@

Session::checkRight("plugin_ocsinventoryng", UPDATE);

$config = new PluginOcsinventoryngConfig();
$plugin = new Plugin();
if ($plugin->isActivated("ocsinventoryng")) {
$config = new PluginOcsinventoryngConfig();

global $CFG_GLPI;
global $CFG_GLPI;

if (isset($_POST["update"])) {
$config->update($_POST);
Html::back();
}
if (isset($_POST["soft_lock"])) {
$config->setScriptLock();
}
if (isset($_POST["soft_unlock"])) {
$config->removeScriptLock();
}
if (isset($_POST["update"])) {
$config->update($_POST);
Html::back();
}
if (isset($_POST["soft_lock"])) {
$config->setScriptLock();
}
if (isset($_POST["soft_unlock"])) {
$config->removeScriptLock();
}

$plugin = new Plugin();
if ($plugin->isActivated("ocsinventoryng")) {
Html::header(__("Automatic synchronization's configuration", 'ocsinventoryng'), '', "tools", "pluginocsinventoryngmenu", "config");

$config->display(['id' => 1]);
Expand Down
3 changes: 1 addition & 2 deletions front/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

$plugin = new Plugin();
if ($plugin->isActivated("ocsinventoryng")
&& Session::haveRight("plugin_ocsinventoryng", UPDATE)
) {
&& Session::haveRight("plugin_ocsinventoryng", UPDATE)) {

Html::header('OCSInventory NG', '', "tools", "pluginocsinventoryngmenu", "ocsinventoryng");

Expand Down
22 changes: 1 addition & 21 deletions front/ocsng.import.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,17 @@
$entity = -1;
}

if (isset($_SESSION["ocs_import"]["locations_id"][$key])) {
$location = $_SESSION["ocs_import"]["locations_id"][$key];
} else {
$location = -1;
}

if (isset($_SESSION["ocs_import"]["is_recursive"][$key])) {
$recursive = $_SESSION["ocs_import"]["is_recursive"][$key];
} else {
$recursive = -1;
}

if (isset($_SESSION["ocs_import"]["groups_id_tech"][$key])) {
$groupTech = $_SESSION["ocs_import"]["groups_id_tech"][$key];
} else {
$groupTech = -1;
}

$process_params = ['ocsid' => $key,
'plugin_ocsinventoryng_ocsservers_id' => $_SESSION["plugin_ocsinventoryng_ocsservers_id"],
'lock' => 0,
'defaultentity' => $entity,
'defaultlocation' => $location,
'defaultrecursive' => $recursive,
'defaultgrouptech' => $groupTech];
'defaultrecursive' => $recursive];
$action = PluginOcsinventoryngOcsProcess::processComputer($process_params);
PluginOcsinventoryngOcsProcess::manageImportStatistics($_SESSION["ocs_import"]['statistics'],
$action['status']);
Expand Down Expand Up @@ -142,15 +128,9 @@
if (isset($_POST['toimport_entities'])) {
$_SESSION["ocs_import"]["entities_id"][$key] = $_POST['toimport_entities'][$key];
}
if (isset($_POST['toimport_locations'])) {
$_SESSION["ocs_import"]["locations_id"][$key] = $_POST['toimport_locations'][$key];
}
if (isset($_POST['toimport_recursive'])) {
$_SESSION["ocs_import"]["is_recursive"][$key] = $_POST['toimport_recursive'][$key];
}
if (isset($_POST['toimport_technician_group'])) {
$_SESSION["ocs_import"]["groups_id_tech"][$key] = $_POST['toimport_technician_group'][$key];
}
$_SESSION["ocs_import_count"]++;
}
}
Expand Down
3 changes: 1 addition & 2 deletions front/ocsngsnmp.import.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@

$conf = PluginOcsinventoryngOcsServer::getConfig($_SESSION["plugin_ocsinventoryng_ocsservers_id"]);
$action = PluginOcsinventoryngSnmpOcslink::processSnmp($key,
$_SESSION["plugin_ocsinventoryng_ocsservers_id"],
0, $params);
$_SESSION["plugin_ocsinventoryng_ocsservers_id"], $params);
PluginOcsinventoryngOcsProcess::manageImportStatistics($_SESSION["ocs_importsnmp"]['statistics'],
$action['status'], true);
PluginOcsinventoryngOcsProcess::showStatistics($_SESSION["ocs_importsnmp"]['statistics'], false, true);
Expand Down
11 changes: 1 addition & 10 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function plugin_ocsinventoryng_install() {

/******************* Migration 1.6.0 *******************/
if ($DB->fieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'states_id_default')) {

$DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.6.0-update.sql");
}

$migration->executeMigration();
Expand Down Expand Up @@ -2234,9 +2234,6 @@ function addNotifications() {
'##FOREACHcheckruleimportentityitems##
##lang.checkruleimportentity.entity## : ##checkruleimportentity.entity##
##lang.checkruleimportentity.computer## : ##checkruleimportentity.computer##
##lang.checkruleimportentity.location## : ##checkruleimportentity.location##
##lang.checkruleimportentity.is_recursive## : ##checkruleimportentity.is_recursive##
##lang.checkruleimportentity.groups_id_tech## : ##checkruleimportentity.groups_id_tech##
##lang.checkruleimportentity.error## : ##checkruleimportentity.error##
##lang.checkruleimportentity.dataerror## : ##checkruleimportentity.dataerror##
##lang.checkruleimportentity.name_rule## ##checkruleimportentity.name_rule##
Expand All @@ -2246,9 +2243,6 @@ function addNotifications() {
<tr>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.entity##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.computer##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.location##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.is_recursive##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.groups_id_tech##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.error##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.dataerror##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.name_rule##</span></td>
Expand All @@ -2257,9 +2251,6 @@ function addNotifications() {
<tr>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.entity##</span></td>
<td><a href=\"##checkruleimportentity.url##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.computer##</span></a></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.location##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.is_recursive##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.groups_id_tech##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.error##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.dataerror##</span></td>
<td><a href=\"##checkruleimportentity.url_rule##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.name_rule##</span></a></td>
Expand Down
6 changes: 4 additions & 2 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ function showScriptLock() {
echo "<td class='center'>";
$status = $this->isScriptLocked();
if (!$status) {
echo __('Lock not activated', 'ocsinventoryng') . "&nbsp;<img src='../pics/export.png'>";
echo __('Lock not activated', 'ocsinventoryng');
echo "&nbsp;<i style='color:darkgreen' class='fas fa-unlock'></i>";
} else {
echo __('Lock activated', 'ocsinventoryng') . "&nbsp;<img src='../pics/ok2.png'>";
echo __('Lock activated', 'ocsinventoryng');
echo "&nbsp;<i style='color:firebrick' class='fas fa-lock'></i>";
}
echo "</td></tr>";

Expand Down
93 changes: 41 additions & 52 deletions inc/hardware.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ static function getHardwareLockableFields($plugin_ocsinventoryng_ocsservers_id =
$locks["domains_id"] = __('Domain');
}

if (intval($cfg_ocs["import_user"]) > 0) {
$locks["users_id"] = __('User');
}

if (intval($cfg_ocs["import_general_uuid"]) > 0) {
$locks["uuid"] = __('UUID');
}
Expand Down Expand Up @@ -151,7 +147,7 @@ static function getRuleLockableFields($plugin_ocsinventoryng_ocsservers_id = 0,
'groups_id' => $groups_id],
['ocsid' => $ocsid]);

if (intval($cfg_ocs["import_user_group"]) > 0) {
if (intval($cfg_ocs["import_user_group"]) > 0 || intval($cfg_ocs["import_user_group_default"])) {
$locks["groups_id"] = __('Group');
} else if (isset($data['groups_id']) && $data['groups_id'] > 0) {
$locks["groups_id"] = __('Group');
Expand Down Expand Up @@ -208,18 +204,6 @@ static function updateComputerHardware($options = []) {
&& !in_array("contact", $options['computers_updates'])) {

$updates["contact"] = PluginOcsinventoryngOcsProcess::encodeOcsDataInUtf8($is_utf8, $hardware["USERID"]);

if (intval($options['cfg_ocs']["import_user"]) > 0) {
$query = "SELECT `id`
FROM `glpi_users`
WHERE `name` = '" . $hardware["USERID"] . "';";
$result = $DB->query($query);

if ($DB->numrows($result) == 1
&& !in_array("users_id", $options['computers_updates'])) {
$updates["users_id"] = $DB->result($result, 0, 0);
}
}
}

if (intval($options['cfg_ocs']["import_general_name"]) > 0
Expand Down Expand Up @@ -250,6 +234,8 @@ static function updateComputerHardware($options = []) {
$updates["entities_id"] = $options['entities_id'];
$updates["_nolock"] = true;
$updates["_no_history"] = !$update_history;
$updates['_auto'] = true;

$comp = new Computer();
$comp->update($updates, $update_history);
}
Expand Down Expand Up @@ -311,52 +297,38 @@ static function updateComputerFields($line_links, $data, $cfg_ocs) {
$tmp['is_recursive'] = $data['is_recursive'];
}

//If there's a Group Tech to update
if (isset($data['groups_id_tech'])) {

$group = new Group();
if ($group->getFromDB($data['groups_id_tech'])) {
//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;
$locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']);
if (is_array($locks) && count($locks)) {
if (in_array("groups_id_tech", $locks)) {
$ko = 1;
}
}
if ($ko == 0) {
$tmp['groups_id_tech'] = $data['groups_id_tech'];
}
}
}
}

//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;
$locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']);
$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'];

}
} else if($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 (count($tmp) > 0) {
$tmp["_nolock"] = true;
Expand All @@ -366,6 +338,21 @@ static function updateComputerFields($line_links, $data, $cfg_ocs) {
}
}
}

/**
* @param $userid
*
* @return array|int
*/
static function getUserDefaultGroup($userid) {

$user = new User();
if ($user->getFromDB($userid)) {
return $user->getField('groups_id');
}
return 0;
}

/**
* @param $entity
* @param $userid
Expand Down Expand Up @@ -400,17 +387,16 @@ static function getUserGroup($entity, $userid, $filter = '', $first = true) {
/**
* @param $ocsComputer
* @param $cfg_ocs
* @param $values
* @param int $computers_id
*
* @return array
* @throws \GlpitestSQLError
*/
static function getFields($ocsComputer, $cfg_ocs, $computers_id = 0) {
static function getFields($ocsComputer, $cfg_ocs, &$values, $computers_id = 0) {
global $DB;

$values = [];
$contact = (isset($ocsComputer['META']["USERID"])) ? $ocsComputer['META']["USERID"] : "";
if (!empty($contact) && $cfg_ocs["import_general_contact"] > 0) {
if (!empty($contact)) {
$query = "SELECT `id`
FROM `glpi_users`
WHERE `name` = '" . $contact . "';";
Expand All @@ -423,7 +409,12 @@ static function getFields($ocsComputer, $cfg_ocs, $computers_id = 0) {
if ($cfg_ocs["import_user_location"] > 0) {
$values['locations_id'] = $user->fields["locations_id"];
}
if ($cfg_ocs["import_user_group"] > 0) {
if ($cfg_ocs["import_user_group_default"]) {
$values['groups_id'] = self::getUserDefaultGroup($user_id);
}
if ($cfg_ocs["import_user_group"] > 0 &&
(isset($values['groups_id']) && $values['groups_id'] == 0
|| !isset($values['groups_id']))) {
$comp = new Computer();
$entities_id = 0;
if ($computers_id > 0 && $comp->getFromDB($computers_id)) {
Expand All @@ -433,7 +424,5 @@ static function getFields($ocsComputer, $cfg_ocs, $computers_id = 0) {
}
}
}

return $values;
}
}
13 changes: 5 additions & 8 deletions inc/ipdiscoverocslink.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,7 @@ public static function showSubnets($plugin_ocsinventoryng_ocsservers_id, $subnet
static function ipDiscoverMenu() {
global $CFG_GLPI, $DB;
$ocsservers = [];
//echo "<div class='center'>";
//echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/pics/ocsinventoryng.png' " .
//"alt='OCS Inventory NG' title='OCS Inventory NG'>";
//echo "</div>";

$dbu = new DbUtils();
$numberActiveServers = $dbu->countElementsInTable('glpi_plugin_ocsinventoryng_ocsservers', ["is_active" => 1]);
if ($numberActiveServers > 0) {
Expand All @@ -360,7 +357,7 @@ static function ipDiscoverMenu() {
$ocsservers[] = $data['id'];
}
Dropdown::show('PluginOcsinventoryngOcsServer',
["condition" => "`id` IN ('" . implode("','", $ocsservers) . "')",
["condition" => ["id" => $ocsservers],
"value" => $_SESSION["plugin_ocsinventoryng_ocsservers_id"],
"on_change" => "this.form.submit()",
"display_emptychoice" => false]);
Expand Down Expand Up @@ -1134,7 +1131,7 @@ static function updateIpDiscover($ipDiscoveryObject, $datas, $plugin_ocsinventor
* @return array
*/

static function getIpDiscoverobject($macAdresses, $entities = [], $glpiItemsTypes, $itemsNames = "", $itemsDescription, $itempsIp, $ocsItemsTypes = []) {
static function getIpDiscoverobject($macAdresses, $entities, $glpiItemsTypes, $itemsNames, $itemsDescription, $itempsIp, $ocsItemsTypes = []) {
$objectToImport = [];
$macs = self::getMacAdressKeyVal($macAdresses);
if (!empty($entities)) {
Expand Down Expand Up @@ -1215,7 +1212,7 @@ static function showPercentBar($status) {
*
* @global type $CFG_GLPI
*/
static function showHardware($hardware, $lim, $start = 0, $ipAdress, $status, $subnet, $action) {
static function showHardware($hardware, $lim, $start, $ipAdress, $status, $subnet, $action) {
global $CFG_GLPI, $DB;

$output_type = Search::HTML_OUTPUT; //0
Expand All @@ -1241,7 +1238,7 @@ static function showHardware($hardware, $lim, $start = 0, $ipAdress, $status, $s
echo "&nbsp;";
$refresh = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php?" . $reload;
Html::showSimpleForm($refresh, 'refresh', _sx('button', 'Refresh'), [],
$CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/pics/synchro.png");
"fa-sync-alt fa-3x");
echo "</h2>";
echo "</div>";

Expand Down
Loading

0 comments on commit 47b2773

Please sign in to comment.