-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1534 from OCSInventory-NG/update-2.12
Update 2.12
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters