Skip to content

Commit

Permalink
Merge pull request #1534 from OCSInventory-NG/update-2.12
Browse files Browse the repository at this point in the history
Update 2.12
  • Loading branch information
gillesdubois committed Jul 12, 2023
2 parents f5ce869 + d5fd351 commit 95a2282
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
33 changes: 33 additions & 0 deletions crontab/cron_clean_orphan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/php
<?php
require_once(__DIR__.'/../var.php');
require_once(CONF_MYSQL);
require_once(ETC_DIR.'/require/function_commun.php');
require_once(ETC_DIR.'/require/config/include.php');
require_once(ETC_DIR.'/require/fichierConf.class.php');

$_SESSION['OCS']["writeServer"] = dbconnect(SERVER_WRITE, COMPTE_BASE, PSWD_BASE, DB_NAME, SSL_KEY, SSL_CERT, CA_CERT, SERVER_PORT);
$_SESSION['OCS']["readServer"] = dbconnect(SERVER_READ, COMPTE_BASE, PSWD_BASE, DB_NAME, SSL_KEY, SSL_CERT, CA_CERT, SERVER_PORT);

$query = "SELECT CONCAT('DELETE FROM `',TABLE_NAME,'` WHERE HARDWARE_ID NOT IN (SELECT ID FROM hardware);') as deletequery, TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND COLUMN_NAME='HARDWARE_ID';";
$args = array(DB_NAME);

$queryList = mysql2_query_secure($query, $_SESSION['OCS']["readServer"], $args);

print("[".date("Y-m-d H:i:s"). "] Start to clean orphan HARDWARE_ID\n");

if($queryList) {
foreach($queryList as $key => $values) {
print("[".date("Y-m-d H:i:s"). "] Clean orphan HARDWARE_ID from ".$values["TABLE_NAME"]."\n");
$countDeletetionRowQuery = "SELECT DISTINCT HARDWARE_ID FROM `%s` WHERE HARDWARE_ID NOT IN (SELECT ID FROM hardware)";
$args = array($values["TABLE_NAME"]);
$countDeletetionRow = mysql2_query_secure($countDeletetionRowQuery, $_SESSION['OCS']["readServer"], $args);

$deleteResult = mysql2_query_secure($values["deletequery"], $_SESSION['OCS']["writeServer"]);

if($deleteResult) print("[".date("Y-m-d H:i:s"). "] ".$countDeletetionRow->num_rows." orphan HARDWARE_ID have been deleted from ".$values["TABLE_NAME"]."\n");
else print("[".date("Y-m-d H:i:s"). "] An error occurs when attempt to clean orphan HARDWARE_ID from ".$values["TABLE_NAME"]."\n");
}
}

print("[".date("Y-m-d H:i:s"). "] End of process\n");
6 changes: 5 additions & 1 deletion plugins/main_sections/ms_snmp_inventory/ms_snmp_detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@
if ((isset($temp_field[1]) && isset($info_account_id[$getType][$getId]) && (array_key_exists($temp_field[0] . '_' . $temp_field[1], $info_account_id[$getType][$getId]))) || $temp_field[0] == 'TAG') {
//cas of checkbox
if (isset($temp_field[2])) {
$data_fields_account[$temp_field[0] . "_" . $temp_field[1]] .= $temp_field[2] . "&&&";
$temp_field2 = $temp_field;
unset($temp_field2[0]);
unset($temp_field2[1]);
$new_value = implode(' ', $temp_field2);
$data_fields_account[$temp_field[0] . "_" . $temp_field[1]] .= $new_value . "&&&";
} else {
$data_fields_account[$field] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion var.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
/**
* GUI Version
*/
define('GUI_VER_SHOW', '2.11.1');
define('GUI_VER_SHOW', '2.12.0');
/**
* Default GUI language
*/
Expand Down

0 comments on commit 95a2282

Please sign in to comment.