Added look-ups from archive log tables if no recent log entries found in VICIDIAL_fix_list_statuses.pl script

git-svn-id: svn://192.168.202.10@2961 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2018-04-04 15:24:43 +00:00
parent c285a01208
commit 2f9112625e
+143 -14
View File
@@ -1,15 +1,19 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# VICIDIAL_fix_lead_statuses.pl version 2.0.5 # VICIDIAL_fix_list_statuses.pl version 2.14
# #
# DESCRIPTION: # DESCRIPTION:
# resets the status in vicidial_list for leads marked in status NOUSE # resets the status in vicidial_list for leads marked in status NOUSE
# Very useful if you manually mess up the list statuses with a SQL query # Very useful if you manually mess up the list statuses with a SQL query
# #
# Copyright (C) 2008 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Example run:
# /usr/share/astguiclient/VICIDIAL_fix_list_statuses.pl --not-found-status=NOTFND --debug
#
# Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# CHANGES # CHANGES
# 80308-0915 - first build # 80308-0915 - First build
# 180404-1046 - Added look-ups from archive log tables if no recent log entries found
# #
$secX = time(); $secX = time();
@@ -26,6 +30,61 @@ $pulldate0 = "$year-$mon-$mday $hour:$min:$sec";
$inSD = $pulldate0; $inSD = $pulldate0;
$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
$NFstatus='';
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
$i++;
}
if ($args =~ /--help/i)
{
print "allowed run time options:\n";
print " [-q] = quiet\n";
print " [--help] = this screen\n";
print " [--debug] = debugging messages\n";
print " [--debugX] = extra debugging messages\n";
print " [--not-found-status=XXX] = status to use if no logs found for lead(default is <empty>)\n";
print "\n";
exit;
}
else
{
if ($args =~ /-q/i)
{
$q=1; $Q=1;
}
if ($args =~ /--debug/i)
{
$DB=1;
print "\n----- DEBUGGING -----\n\n";
}
if ($args =~ /--debugX/i)
{
$DB=1; $DBX=1;
print "\n----- EXTRA DEBUGGING -----\n\n";
}
if ($args =~ /--not-found-status=/i)
{
@data_in = split(/--not-found-status=/,$args);
$NFstatus = $data_in[1];
$NFstatus =~ s/ .*$//gi;
if ($Q < 1)
{print "\n----- NOT FOUND STATUS: $NFstatus -----\n\n";}
}
}
}
else
{
print "no command line options set\n";
}
### end parsing run-time options ###
# default path to astguiclient configuration file: # default path to astguiclient configuration file:
@@ -76,15 +135,23 @@ use DBI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr; or die "Couldn't connect to database: " . DBI->errstr;
$DB=1;
$liveupdate=0; $liveupdate=0;
if (!$VDHLOGfile) {$VDHLOGfile = "$PATHlogs/dupleads.$year-$mon-$mday";} if (!$VDHLOGfile) {$VDHLOGfile = "$PATHlogs/dupleads.$year-$mon-$mday";}
print "\n\n\n\n\n\n\n\n\n\n\n\n-- VICIDIAL_fix_list_statuses.pl --\n\n"; if (!$Q)
print "This program is designed to scan all leads marked NOUSE and set them to their proper status according to the logs. \n\n"; {
print "\n\n\n\n\n\n\n\n\n\n\n\n-- VICIDIAL_fix_list_statuses.pl --\n\n";
print "This program is designed to scan all leads marked NOUSE and set them to their proper status according to the logs. \n\n";
}
### counters:
$not_found=0;
$found=0;
$archive_searches=0;
$archive_found=0;
$archive_not_found=0;
$stmtA = "select lead_id,list_id from vicidial_list where status='NOUSE';"; $stmtA = "select lead_id,list_id from vicidial_list where status='NOUSE';";
if($DBX){print STDERR "\n|$stmtA|\n";} if($DBX){print STDERR "\n|$stmtA|\n";}
@@ -108,10 +175,14 @@ $sthA->finish();
$b=0; $b=0;
foreach(@lead_id) foreach(@lead_id)
{ {
$Nstatus=''; $Nstatus=$NFstatus;
$Nepoch=0; $Nepoch=0;
$Cstatus=''; $Cstatus=$NFstatus;
$Cepoch=0; $Cepoch=0;
$rec_count=0;
$message='';
$archive=0;
$stmtA = "select status,start_epoch from vicidial_log where lead_id='$lead_id[$b]' order by call_date desc LIMIT 1;"; $stmtA = "select status,start_epoch from vicidial_log where lead_id='$lead_id[$b]' order by call_date desc LIMIT 1;";
if($DBX){print STDERR "\n|$stmtA|\n";} if($DBX){print STDERR "\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
@@ -140,12 +211,65 @@ foreach(@lead_id)
} }
$sthA->finish(); $sthA->finish();
### If no match found in active log tables, search in the _archive log tables
if ($rec_count < 1)
{
$stmtA = "select status,start_epoch from vicidial_log_archive where lead_id='$lead_id[$b]' order by call_date desc LIMIT 1;";
if($DBX){print STDERR "\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$Nstatus = $aryA[0];
$Nepoch = $aryA[1];
$rec_count++;
}
$sthA->finish();
$stmtA = "select status,start_epoch from vicidial_closer_log_archive where lead_id='$lead_id[$b]' order by closecallid desc LIMIT 1;";
if($DBX){print STDERR "\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$Cstatus = $aryA[0];
$Cepoch = $aryA[1];
$rec_count++;
}
$sthA->finish();
$message='Archive logs searched';
$archive++;
$archive_searches++;
}
if ($Cepoch > $Nepoch) {$NEWstatus = $Cstatus;} if ($Cepoch > $Nepoch) {$NEWstatus = $Cstatus;}
else {$NEWstatus = $Nstatus;} else {$NEWstatus = $Nstatus;}
if ($NEWstatus =~ /^$NFstatus$/)
{
$not_found++;
if ($archive > 0)
{
$archive_not_found++;
}
}
else
{
$found++;
if ($archive > 0)
{
$archive_found++;
}
}
$stmtA = "UPDATE vicidial_list set status='$NEWstatus' where lead_id='$lead_id[$b]';"; $stmtA = "UPDATE vicidial_list set status='$NEWstatus' where lead_id='$lead_id[$b]';";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n"; $affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "|$b|$lead_id[$b]|$Nstatus|$Cstatus|$list_id[$b]||$stmtA|\n";} if($DB){print STDERR "|$b|$lead_id[$b]|$Nstatus|$Cstatus|$list_id[$b]|$rec_count|$message||$stmtA|\n";}
$b++; $b++;
@@ -159,10 +283,7 @@ foreach(@lead_id)
if ($b =~ /800$/i) {print STDERR "+ $b\r";} if ($b =~ /800$/i) {print STDERR "+ $b\r";}
if ($b =~ /900$/i) {print STDERR "0 $b\r";} if ($b =~ /900$/i) {print STDERR "0 $b\r";}
if ($b =~ /000$/i) {print "|$b|$lead_id[$b]|$Nstatus|$Cstatus|$list_id[$b]|\n";} if ($b =~ /000$/i) {print "|$b|$lead_id[$b]|$Nstatus|$Cstatus|$list_id[$b]|\n";}
} }
chop($DUP_updates);
$dbhA->disconnect(); $dbhA->disconnect();
@@ -171,7 +292,15 @@ $secY = time();
$secZ = ($secY - $secX); $secZ = ($secY - $secX);
$secZm = ($secZ /60); $secZm = ($secZ /60);
print "script execution time in seconds: $secZ minutes: $secZm\n"; if (!$Q)
{
print "\nRUN SUMMARY:\n";
print "Total leads updated: $b \n";
print "Total archive searches: $archive_searches \n";
print " Old status found (found in archive): $found ($archive_found) \n";
print " Old status not found (looked in archive): $not_found ($archive_not_found) \n";
print "\n";
print "script execution time in seconds: $secZ minutes: $secZm\n";
}
exit; exit;