Added several new options to rebuild list statuses script

git-svn-id: svn://192.168.202.10@2426 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2015-12-10 02:42:04 +00:00
parent 3cd2ae3cb7
commit 0075a2e050
@@ -1,15 +1,18 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# VICIDIAL_rebuild_lead_statuses.pl version 2.6 # VICIDIAL_rebuild_lead_statuses.pl version 2.12
# #
# 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) 2013 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Copyright (C) 2015 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# CHANGES # CHANGES
# 130422-0905 - first build # 130422-0905 - first build
# 151209-1620 - Added user field update from logs,
# Added --no-cc-and-llct-update option to not update called_count, last_local_call_time
# Added --use-lead-id option to search logs by lead_id instead of phone number
# #
$secX = time(); $secX = time();
@@ -69,7 +72,7 @@ foreach(@conf)
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_rebuild_list_statuses.pl --\n\n"; print "\n\n\n\n\n\n\n\n\n\n\n\n-- VICIDIAL_rebuild_list_statuses.pl --\n\n";
print "This program is designed to scan all leads marked NOUSE and set them to their proper status, called_count and last_local_call_time according to the logs. \n\n"; print "This program is designed to scan all leads marked NOUSE and set them to their proper status, called_count, last_local_call_time and user according to the logs. \n\n";
$oldlistidSQL=''; $oldlistidSQL='';
@@ -94,6 +97,8 @@ if (length($ARGV[0])>1)
print " [--debugX] = extra debugging enabled\n"; print " [--debugX] = extra debugging enabled\n";
print " [--oldlistid=1234] = restrict log search to this list_id\n"; print " [--oldlistid=1234] = restrict log search to this list_id\n";
print " [--newlistid=1234] = restrict updates to this list_id\n"; print " [--newlistid=1234] = restrict updates to this list_id\n";
print " [--no-cc-and-llct-update] = do not update called_count, last_local_call_time\n";
print " [--use-lead-id] = search the logs by the lead_id instead of phone number\n";
print " [--help] = this help screen\n\n"; print " [--help] = this help screen\n\n";
print "\n"; print "\n";
@@ -121,6 +126,16 @@ if (length($ARGV[0])>1)
$TEST=1; $TEST=1;
print "\n----- TESTING -----\n\n"; print "\n----- TESTING -----\n\n";
} }
if ($args =~ /--no-cc-and-llct-update/i)
{
$no_cc_and_llct_update=1;
if ($q < 1) {print "\n----- NO called_count AND last_local_call_time UPDATES -----\n\n";}
}
if ($args =~ /--use-lead-id/i)
{
$use_lead_id=1;
if ($q < 1) {print "\n----- SEARCH LOGS BY LEAD ID -----\n\n";}
}
if ($args =~ /-oldlistid=/i) if ($args =~ /-oldlistid=/i)
{ {
@data_in = split(/-oldlistid=/,$args); @data_in = split(/-oldlistid=/,$args);
@@ -201,15 +216,24 @@ foreach(@lead_id)
$Nepoch=0; $Nepoch=0;
$Nlead_id=''; $Nlead_id='';
$Ncall_date=''; $Ncall_date='';
$Nuser='';
$Cstatus=''; $Cstatus='';
$Cepoch=0; $Cepoch=0;
$Clead_id=''; $Clead_id='';
$Ccall_date=''; $Ccall_date='';
$Cuser='';
$NEWstatus=''; $NEWstatus='';
$OLDlead_id=''; $OLDlead_id='';
$NEWcall_date=''; $NEWcall_date='';
$NEWuser='';
$LEADfound=0; $LEADfound=0;
$stmtA = "SELECT status,start_epoch,lead_id,call_date from vicidial_log where phone_number='$phone_number[$b]' $oldlistidSQL order by call_date desc LIMIT 1;";
if ($use_lead_id > 0)
{$searchSQL = "lead_id='$lead_id[$b]'";}
else
{$searchSQL = "phone_number='$phone_number[$b]'";}
$stmtA = "SELECT status,start_epoch,lead_id,call_date,user from vicidial_log where $searchSQL $oldlistidSQL 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;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -221,11 +245,12 @@ foreach(@lead_id)
$Nepoch = $aryA[1]; $Nepoch = $aryA[1];
$Nlead_id = $aryA[2]; $Nlead_id = $aryA[2];
$Ncall_date = $aryA[3]; $Ncall_date = $aryA[3];
$Nuser = $aryA[4];
$LEADfound++; $LEADfound++;
} }
$sthA->finish(); $sthA->finish();
$stmtA = "SELECT status,start_epoch,lead_id,call_date from vicidial_closer_log where phone_number='$phone_number[$b]' $oldlistidSQL order by closecallid desc LIMIT 1;"; $stmtA = "SELECT status,start_epoch,lead_id,call_date,user from vicidial_closer_log where $searchSQL $oldlistidSQL order by closecallid 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;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -237,13 +262,14 @@ foreach(@lead_id)
$Cepoch = $aryA[1]; $Cepoch = $aryA[1];
$Clead_id = $aryA[2]; $Clead_id = $aryA[2];
$Ccall_date = $aryA[3]; $Ccall_date = $aryA[3];
$Cuser = $aryA[4];
$LEADfound++; $LEADfound++;
} }
$sthA->finish(); $sthA->finish();
if ($LEADfound < 1) if ($LEADfound < 1)
{ {
$stmtA = "SELECT status,start_epoch,lead_id,call_date from vicidial_log where phone_number='$alt_phone[$b]' $oldlistidSQL order by call_date desc LIMIT 1;"; $stmtA = "SELECT status,start_epoch,lead_id,call_date,user from vicidial_log where $searchSQL $oldlistidSQL 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;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -255,6 +281,7 @@ foreach(@lead_id)
$Nepoch = $aryA[1]; $Nepoch = $aryA[1];
$Nlead_id = $aryA[2]; $Nlead_id = $aryA[2];
$Ncall_date = $aryA[3]; $Ncall_date = $aryA[3];
$Nuser = $aryA[4];
$LEADfound++; $LEADfound++;
} }
$sthA->finish(); $sthA->finish();
@@ -267,12 +294,14 @@ foreach(@lead_id)
$NEWstatus = $Cstatus; $NEWstatus = $Cstatus;
$OLDlead_id = $Clead_id; $OLDlead_id = $Clead_id;
$NEWcall_date = $Ccall_date; $NEWcall_date = $Ccall_date;
$NEWuser = $Cuser;
} }
else else
{ {
$NEWstatus = $Nstatus; $NEWstatus = $Nstatus;
$OLDlead_id = $Nlead_id; $OLDlead_id = $Nlead_id;
$NEWcall_date = $Ncall_date; $NEWcall_date = $Ncall_date;
$NEWuser = $Nuser;
} }
$stmtA = "SELECT count(*) from vicidial_log where lead_id='$OLDlead_id' $oldlistidSQL;"; $stmtA = "SELECT count(*) from vicidial_log where lead_id='$OLDlead_id' $oldlistidSQL;";
@@ -287,8 +316,12 @@ foreach(@lead_id)
} }
$sthA->finish(); $sthA->finish();
if ($no_cc_and_llct_update > 0)
{$cc_and_llct_updateSQL = '';}
else
{$cc_and_llct_updateSQL = ",called_count='$NEWcount',last_local_call_time='$NEWcall_date'";}
$stmtA = "UPDATE vicidial_list set status='$NEWstatus',called_count='$NEWcount',last_local_call_time='$NEWcall_date' where lead_id='$lead_id[$b]';"; $stmtA = "UPDATE vicidial_list set status='$NEWstatus',user='$NEWuser' $cc_and_llct_updateSQL where lead_id='$lead_id[$b]';";
if ($TEST < 1) if ($TEST < 1)
{$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|$phone_number[$b]| |$affected_rows|$stmtA|\n";} if($DB){print STDERR "|$b|$lead_id[$b]|$Nstatus|$Cstatus|$phone_number[$b]| |$affected_rows|$stmtA|\n";}