Commit fd6dd521 authored by Eric - kg6wxc's avatar Eric - kg6wxc
Browse files

Merge branch 'removeDupes' into 'master'

Added duplicate record finder for node_info table.

See merge request !2
parents 01a94932 a3e8836b
<?php <?php
function wxc_check4Dupes() {
//this function should clear out any duplicate entries in the node_info table.
//sometimes, for various reasons, you'll end up with 2 nodes, with the same IP.
//that causes the trigger topology_get_latlons_brg_dist to explode,
//and you see no link lines on the map
$findDupeQuery = mysqli_query($GLOBALS['sql_connection'], "select node, wlan_ip from node_info group by wlan_ip having count(wlan_ip) > 1");
if(mysqli_num_rows($findDupeQuery) > 0) {
echo "FOUND DUPLICATES IN NODE_INFO TABLE! NOW REPAIRING...\n";
echo "Removed from Database:\n";
$findDupeQuery = mysqli_fetch_all($findDupeQuery, MYSQLI_ASSOC);
foreach($findDupeQuery as $dupe) {
mysqli_query($GLOBALS['sql_connection'], "delete from node_info where wlan_ip = '" . $dupe['wlan_ip'] . "'");
echo "\t" . $dupe['node'] . " (and it's duplicate) with wlan_ip's of " . $dupe['wlan_ip'] . "\n";
}
}
}
function wxc_checkDB () { function wxc_checkDB () {
//this function is now in its own file //this function is now in its own file
......
...@@ -146,6 +146,8 @@ if ($do_sql) { ...@@ -146,6 +146,8 @@ if ($do_sql) {
wxc_connectToMySQL(); wxc_connectToMySQL();
//check for new or changed database items (tables, columns,etc) //check for new or changed database items (tables, columns,etc)
wxc_checkDB(); wxc_checkDB();
//find and remove dupes in node_info
wxc_check4Dupes();
}else { }else {
if ($TEST_MODE_NO_SQL) { if ($TEST_MODE_NO_SQL) {
wxc_echoWithColor("SQL Server access disabled!", "red"); wxc_echoWithColor("SQL Server access disabled!", "red");
...@@ -621,6 +623,9 @@ if ($getNodeInfo) { ...@@ -621,6 +623,9 @@ if ($getNodeInfo) {
echo "API Version: "; echo "API Version: ";
switch($api_version) { switch($api_version) {
case "1.7":
wxc_echoWithColor($api_version, "greenBold");
break;
case "1.6": case "1.6":
wxc_echoWithColor($api_version, "green"); wxc_echoWithColor($api_version, "green");
break; break;
......
...@@ -449,6 +449,9 @@ function wxc_echoWithColor ($text, $color) { ...@@ -449,6 +449,9 @@ function wxc_echoWithColor ($text, $color) {
if ($color == "red") { if ($color == "red") {
echo "\33[31m" . $text . "\033[0m"; echo "\33[31m" . $text . "\033[0m";
} }
if ($color == 'redBold') {
echo "\033[1m\33[31m" . $text . "\033[0m";
}
if ($color == "purple") { if ($color == "purple") {
echo "\033[35m" . $text . "\033[0m"; echo "\033[35m" . $text . "\033[0m";
} }
...@@ -458,8 +461,8 @@ function wxc_echoWithColor ($text, $color) { ...@@ -458,8 +461,8 @@ function wxc_echoWithColor ($text, $color) {
if ($color == "green") { if ($color == "green") {
echo "\033[32m" . $text . "\033[0m"; echo "\033[32m" . $text . "\033[0m";
} }
if ($color == 'redBold') { if ($color == 'greenBold') {
echo "\033[1m\33[31m" . $text . "\033[0m"; echo "\033[1m\33[32m" . $text . "\033[0m";
} }
if ($color == 'alert') { if ($color == 'alert') {
echo "\033[41m\033[30m\033[1m" . $text . "\033[0m"; echo "\033[41m\033[30m\033[1m" . $text . "\033[0m";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment