Added utility to synchronize users, remote agents, dids, call menus, in-groups and campaigns with entries in QM: ADMIN_qm_sync.pl
git-svn-id: svn://192.168.202.10@1654 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -552,6 +552,9 @@ OTHER CHANGES:
|
||||
preview mode as well as lead info viewing from the callbacks list, the
|
||||
call log and search results in the agent interface.
|
||||
|
||||
125. Added utility to synchronize users, remote agents, dids, call menus,
|
||||
in-groups and campaigns with entries in QM: ADMIN_qm_sync.pl
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+541
-10
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# to be run frequently to sync the vicidial_users and remote agents to the QM
|
||||
# agenti_noti table
|
||||
# agenti_noti table, also can sync dids, ivrs, in-groups and campaigns
|
||||
#
|
||||
# This program only needs to be run by one server
|
||||
#
|
||||
@@ -12,6 +12,7 @@
|
||||
#
|
||||
# CHANGES
|
||||
# 110425-0853 - First Build
|
||||
# 110506-1516 - Added DIDs, IVRs, in-groups(queues), campaigns(queues) and all-alias to the sync options
|
||||
#
|
||||
|
||||
# constants
|
||||
@@ -31,12 +32,18 @@ if (length($ARGV[0])>1)
|
||||
if ($args =~ /--help/i)
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [-user] = will synchronize users\n";
|
||||
print " [-remote-agents] = will check for remote agents and sync for the number of lines defined for each\n";
|
||||
print " [--user] = will synchronize users\n";
|
||||
print " [--remote-agents] = will check for remote agents and sync for the number of lines defined for each\n";
|
||||
print " [--dids] = will sync did entries to dnis entries in QM\n";
|
||||
print " [--ivrs] = will sync call menu entries to ivr entries in QM\n";
|
||||
print " [--ingroups] = will sync in-group entries to queue entries in QM\n";
|
||||
print " [--campaigns] = will sync campaign entries to queue entries in QM\n";
|
||||
print " [--all-sync] = will sync all of the above in QM\n";
|
||||
print " [--all-alias-sync] = will sync all queues in QM into the default \"00 All Queues\" alias\n";
|
||||
print " [-q] = quiet, no output\n";
|
||||
print " [-test] = test\n";
|
||||
print " [-debug] = verbose debug messages\n";
|
||||
print " [-debugX] = Extra-verbose debug messages\n\n";
|
||||
print " [--test] = test\n";
|
||||
print " [--debug] = verbose debug messages\n";
|
||||
print " [--debugX] = Extra-verbose debug messages\n\n";
|
||||
exit;
|
||||
}
|
||||
else
|
||||
@@ -61,6 +68,21 @@ if (length($ARGV[0])>1)
|
||||
$T=1;
|
||||
if ($Q < 1) {print "\n----- TEST RUN, NO UPDATES -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-all-alias-sync/i)
|
||||
{
|
||||
$SYNC_all_alias=1;
|
||||
if ($Q < 1) {print "\n----- ALL ALIAS SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-all-sync/i)
|
||||
{
|
||||
$SYNC_user=1;
|
||||
$SYNC_remoteagents=1;
|
||||
$SYNC_dids=1;
|
||||
$SYNC_ivrs=1;
|
||||
$SYNC_ingroups=1;
|
||||
$SYNC_campaigns=1;
|
||||
if ($Q < 1) {print "\n----- ALL SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-user/i)
|
||||
{
|
||||
$SYNC_user=1;
|
||||
@@ -71,6 +93,26 @@ if (length($ARGV[0])>1)
|
||||
$SYNC_remoteagents=1;
|
||||
if ($Q < 1) {print "\n----- REMOTE AGENT SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-dids/i)
|
||||
{
|
||||
$SYNC_dids=1;
|
||||
if ($Q < 1) {print "\n----- DID SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-ivrs/i)
|
||||
{
|
||||
$SYNC_ivrs=1;
|
||||
if ($Q < 1) {print "\n----- IVR SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-ingroups/i)
|
||||
{
|
||||
$SYNC_ingroups=1;
|
||||
if ($Q < 1) {print "\n----- IN-GROUP SYNC -----\n\n";}
|
||||
}
|
||||
if ($args =~ /-campaigns/i)
|
||||
{
|
||||
$SYNC_campaigns=1;
|
||||
if ($Q < 1) {print "\n----- CAMPAIGN SYNC -----\n\n";}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -203,7 +245,7 @@ if ($SYNC_user > 0)
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if agent record exists with user id and fullname identical
|
||||
### Find if agent record exists with user id identical
|
||||
$stmtB = "SELECT count(*) FROM agenti_noti where nome_agente='Agent/$Vuser[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
@@ -264,8 +306,6 @@ if ($SYNC_user > 0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of vicidial_remote_agents to agenti_noti #####
|
||||
if ($SYNC_remoteagents > 0)
|
||||
{
|
||||
@@ -314,7 +354,7 @@ if ($SYNC_remoteagents > 0)
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if agent record exists with user id and fullname identical
|
||||
### Find if agent record exists with user id identical
|
||||
$stmtB = "SELECT count(*) FROM agenti_noti where nome_agente='Agent/$Vuser[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
@@ -376,7 +416,498 @@ if ($SYNC_remoteagents > 0)
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of vicidial_inbound_dids to dnis #####
|
||||
if ($SYNC_dids > 0)
|
||||
{
|
||||
if ($DBX) {print "\n\n";}
|
||||
if ($DB) {print " - starting sync of vicidial_inbound_dids to dnis\n";}
|
||||
$found_records=0;
|
||||
$updated_records=0;
|
||||
$added_records=0;
|
||||
|
||||
### Gather distinct dids in vicidial_inbound_dids
|
||||
$stmtA = "SELECT did_pattern,did_description from vicidial_inbound_dids limit 1000000;";
|
||||
if ($DBX) {print "$stmtA\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsD=$sthA->rows;
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$Vdid[$i] = $aryA[0];
|
||||
$Vdescription[$i] = $aryA[1];
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
### Find if dnis exists with did and description identical
|
||||
$stmtB = "SELECT count(*) FROM dnis where dnis_k='$Vdid[$i]' and dnis_v='$Vdid[$i] - $Vdescription[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AN_records=$sthB->rows;
|
||||
if ($AN_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AN_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if did record exists with did identical
|
||||
$stmtB = "SELECT count(*) FROM dnis where dnis_k='$Vdid[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$ANX_records=$sthB->rows;
|
||||
if ($ANX_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$ANX_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($ANX_count < 1)
|
||||
{
|
||||
### add a new dnis record
|
||||
$stmtB = "INSERT INTO dnis (dnis_k,dnis_v,sys_dt_creazione,sys_user_creazione,sys_dt_modifica,sys_user_modifica,sys_optilock) values('$Vdid[$i]','$Vdid[$i] - $Vdescription[$i]',NOW(),'32',NOW(),'32','82946');";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " DNIS record inserted: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "DNIS INSERT: $i|$Vdid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$added_records++;
|
||||
}
|
||||
else
|
||||
{
|
||||
### update dnis record with proper description
|
||||
$stmtB = "UPDATE dnis SET dnis_v='$Vdid[$i] - $Vdescription[$i]' where dnis_k='$Vdid[$i]' LIMIT 1;";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " DNIS record updated: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "DNIS UPDATE: $i|$Vdid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$updated_records++;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ($DB) {print " did exists: $Vdid[$i] - $Vdescription[$i]\n";}
|
||||
$found_records++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($DB) {print " - finished did sync:\n";}
|
||||
if ($DB) {print " records scanned: $i\n";}
|
||||
if ($DB) {print " records found: $found_records\n";}
|
||||
if ($DB) {print " records updated: $updated_records\n";}
|
||||
if ($DB) {print " records added: $added_records\n";}
|
||||
}
|
||||
##### END sync of vicidial_inbound_dids to dnis #####
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of vicidial_call_menu to ivr #####
|
||||
if ($SYNC_ivrs > 0)
|
||||
{
|
||||
if ($DBX) {print "\n\n";}
|
||||
if ($DB) {print " - starting sync of vicidial_call_menu to ivr\n";}
|
||||
$found_records=0;
|
||||
$updated_records=0;
|
||||
$added_records=0;
|
||||
|
||||
### Gather distinct dids in vicidial_call_menu
|
||||
$stmtA = "SELECT menu_id,menu_name from vicidial_call_menu limit 1000000;";
|
||||
if ($DBX) {print "$stmtA\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsD=$sthA->rows;
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$Vivr[$i] = $aryA[0];
|
||||
$Vdescription[$i] = $aryA[1];
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
### Find if ivr exists with ivr and description identical
|
||||
$stmtB = "SELECT count(*) FROM ivr where ivr_k='$Vivr[$i]' and ivr_v='$Vivr[$i] - $Vdescription[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AN_records=$sthB->rows;
|
||||
if ($AN_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AN_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if ivr record exists with ivr identical
|
||||
$stmtB = "SELECT count(*) FROM ivr where ivr_k='$Vivr[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$ANX_records=$sthB->rows;
|
||||
if ($ANX_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$ANX_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($ANX_count < 1)
|
||||
{
|
||||
### add a new ivr record
|
||||
$stmtB = "INSERT INTO ivr (ivr_k,ivr_v,sys_dt_creazione,sys_user_creazione,sys_dt_modifica,sys_user_modifica,sys_optilock) values('$Vivr[$i]','$Vivr[$i] - $Vdescription[$i]',NOW(),'32',NOW(),'32','82946');";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " ivr record inserted: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "ivr INSERT: $i|$Vivr[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$added_records++;
|
||||
}
|
||||
else
|
||||
{
|
||||
### update ivr record with proper description
|
||||
$stmtB = "UPDATE ivr SET ivr_v='$Vivr[$i] - $Vdescription[$i]' where ivr_k='$Vivr[$i]' LIMIT 1;";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " ivr record updated: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "ivr UPDATE: $i|$Vivr[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$updated_records++;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ($DB) {print " ivr exists: $Vivr[$i] - $Vdescription[$i]\n";}
|
||||
$found_records++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($DB) {print " - finished ivr sync:\n";}
|
||||
if ($DB) {print " records scanned: $i\n";}
|
||||
if ($DB) {print " records found: $found_records\n";}
|
||||
if ($DB) {print " records updated: $updated_records\n";}
|
||||
if ($DB) {print " records added: $added_records\n";}
|
||||
}
|
||||
##### END sync of vicidial_call_menu to ivr #####
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of vicidial_inbound_groups to code_possibili #####
|
||||
if ($SYNC_ingroups > 0)
|
||||
{
|
||||
if ($DBX) {print "\n\n";}
|
||||
if ($DB) {print " - starting sync of vicidial_inbound_groups to code_possibili\n";}
|
||||
$found_records=0;
|
||||
$updated_records=0;
|
||||
$added_records=0;
|
||||
|
||||
### Gather distinct in-groups in vicidial_inbound_groups
|
||||
$stmtA = "SELECT group_id,group_name from vicidial_inbound_groups limit 1000000;";
|
||||
if ($DBX) {print "$stmtA\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsD=$sthA->rows;
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$Vid[$i] = $aryA[0];
|
||||
$Vdescription[$i] = $aryA[1];
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
### Find if queue exists with id and description identical
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where composizione_coda='$Vid[$i]' and nome_coda='$Vdescription[$i]' and q_direction='inbound';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AN_records=$sthB->rows;
|
||||
if ($AN_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AN_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if queue record exists with id identical
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where composizione_coda='$Vid[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$ANX_records=$sthB->rows;
|
||||
if ($ANX_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$ANX_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($ANX_count < 1)
|
||||
{
|
||||
### add a new queue record in code_possibili
|
||||
$stmtB = "INSERT INTO code_possibili (composizione_coda,nome_coda,q_direction,sys_dt_creazione,sys_user_creazione,sys_dt_modifica,sys_user_modifica) values('$Vid[$i]','$Vdescription[$i]','inbound',NOW(),'32',NOW(),'32');";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " code_possibili in-group record inserted: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "code_possibili INSERT: $i|$Vid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$added_records++;
|
||||
}
|
||||
else
|
||||
{
|
||||
### update queue record with proper description
|
||||
$stmtB = "UPDATE code_possibili SET nome_coda='$Vdescription[$i]',q_direction='inbound' where composizione_coda='$Vid[$i]' LIMIT 1;";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " code_possibili in-group record updated: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "code_possibili UPDATE: $i|$Vid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$updated_records++;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ($DB) {print " code_possibili in-group exists: $Vid[$i] - $Vdescription[$i]\n";}
|
||||
$found_records++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($DB) {print " - finished inbound queue sync:\n";}
|
||||
if ($DB) {print " records scanned: $i\n";}
|
||||
if ($DB) {print " records found: $found_records\n";}
|
||||
if ($DB) {print " records updated: $updated_records\n";}
|
||||
if ($DB) {print " records added: $added_records\n";}
|
||||
}
|
||||
##### END sync of vicidial_inbound_groups to code_possibili #####
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of vicidial_campaigns to code_possibili #####
|
||||
if ($SYNC_campaigns > 0)
|
||||
{
|
||||
if ($DBX) {print "\n\n";}
|
||||
if ($DB) {print " - starting sync of vicidial_campaigns to code_possibili\n";}
|
||||
$found_records=0;
|
||||
$updated_records=0;
|
||||
$added_records=0;
|
||||
|
||||
### Gather distinct in-groups in vicidial_campaigns
|
||||
$stmtA = "SELECT campaign_id,campaign_name from vicidial_campaigns limit 100000;";
|
||||
if ($DBX) {print "$stmtA\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArowsD=$sthA->rows;
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$Vid[$i] = $aryA[0];
|
||||
$Vdescription[$i] = $aryA[1];
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$i=0;
|
||||
while ($sthArowsD > $i)
|
||||
{
|
||||
### Find if queue exists with id and description identical
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where composizione_coda='$Vid[$i]' and nome_coda='$Vdescription[$i]' and q_direction='outbound';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AN_records=$sthB->rows;
|
||||
if ($AN_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AN_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### Find if queue record exists with id identical
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where composizione_coda='$Vid[$i]';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$ANX_records=$sthB->rows;
|
||||
if ($ANX_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$ANX_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($ANX_count < 1)
|
||||
{
|
||||
### add a new queue record in code_possibili
|
||||
$stmtB = "INSERT INTO code_possibili (composizione_coda,nome_coda,q_direction,sys_dt_creazione,sys_user_creazione,sys_dt_modifica,sys_user_modifica) values('$Vid[$i]','$Vdescription[$i]','outbound',NOW(),'32',NOW(),'32');";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " code_possibili campaign record inserted: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "code_possibili INSERT: $i|$Vid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$added_records++;
|
||||
}
|
||||
else
|
||||
{
|
||||
### update queue record with proper description
|
||||
$stmtB = "UPDATE code_possibili SET nome_coda='$Vdescription[$i]',q_direction='outbound' where composizione_coda='$Vid[$i]' LIMIT 1;";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " code_possibili campaign record updated: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "code_possibili UPDATE: $i|$Vid[$i]|$Vdescription[$i]|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$updated_records++;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ($DB) {print " code_possibili campaign exists: $Vid[$i] - $Vdescription[$i]\n";}
|
||||
$found_records++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($DB) {print " - finished campaign queue sync:\n";}
|
||||
if ($DB) {print " records scanned: $i\n";}
|
||||
if ($DB) {print " records found: $found_records\n";}
|
||||
if ($DB) {print " records updated: $updated_records\n";}
|
||||
if ($DB) {print " records added: $added_records\n";}
|
||||
}
|
||||
##### END sync of vicidial_campaigns to code_possibili #####
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### BEGIN sync of all alias entry in code_possibili #####
|
||||
if ($SYNC_all_alias > 0)
|
||||
{
|
||||
if ($DBX) {print "\n\n";}
|
||||
if ($DB) {print " - starting sync of code_possibili All Queues alias\n";}
|
||||
$found_records=0;
|
||||
$updated_records=0;
|
||||
$added_records=0;
|
||||
|
||||
### Find if All Alias queue exists
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where nome_coda='00 All Queues';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AAQ_records=$sthB->rows;
|
||||
if ($AAQ_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AAQ_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AAQ_count < 1)
|
||||
{
|
||||
if ($DB) {print " - All Alias queue does not exist\n";}
|
||||
}
|
||||
else
|
||||
{
|
||||
### Gather distinct code_possibili queues
|
||||
$AAQ_list='';
|
||||
$stmtB = "SELECT composizione_coda FROM code_possibili where nome_coda NOT IN('00 All Queues','00 All');";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AAQD_records=$sthB->rows;
|
||||
$i=0;
|
||||
while ($AAQD_records > $i)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AAQ_list .= "$aryB[0]|";
|
||||
$i++;
|
||||
}
|
||||
$sthB->finish();
|
||||
chop($AAQ_list);
|
||||
|
||||
### Find if queue exists with id and description identical
|
||||
$stmtB = "SELECT count(*) FROM code_possibili where composizione_coda='$AAQ_list' and nome_coda='00 All Queues';";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
|
||||
$AN_records=$sthB->rows;
|
||||
if ($AN_records > 0)
|
||||
{
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$AN_count = $aryB[0];
|
||||
}
|
||||
$sthB->finish();
|
||||
|
||||
if ($AN_count < 1)
|
||||
{
|
||||
### update queue record with proper description
|
||||
$stmtB = "UPDATE code_possibili SET composizione_coda='$AAQ_list' where nome_coda='00 All Queues' LIMIT 1;";
|
||||
if ($TEST < 1)
|
||||
{$Baffected_rows = $dbhB->do($stmtB);}
|
||||
if ($DB) {print " code_possibili all alias record updated: $Baffected_rows|$stmtB|\n";}
|
||||
|
||||
$event_string = "code_possibili UPDATE: $i|all alias|$Baffected_rows|$stmtB";
|
||||
&event_logger;
|
||||
|
||||
$updated_records++;
|
||||
}
|
||||
|
||||
if ($DB) {print " - finished All Alias queue sync:\n";}
|
||||
if ($DB) {print " records scanned: $i\n";}
|
||||
if ($DB) {print " records found: $AAQ_count\n";}
|
||||
if ($DB) {print " records updated: $updated_records\n";}
|
||||
}
|
||||
}
|
||||
##### END sync of all alias in code_possibili #####
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user