From 3c54f4d646ad57ed2f021f462db64c2efaddfd00 Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 3 Jan 2026 20:58:41 +0000 Subject: [PATCH] Added --vl-year flag option, to look in year-based vicidial_log_archive_YYYY tables Fix for QC in the DB git-svn-id: svn://192.168.202.10@3959 3d104415-ff17-0410-8863-d5cf3c621b8a --- .../bin/ADMIN_cold_storage_log_tables.pl | 219 ++++++++++++++++-- .../trunk/extras/MySQL_AST_CREATE_tables.sql | 5 +- agc_2-X/trunk/extras/upgrade_2.14.sql | 4 + 3 files changed, 211 insertions(+), 17 deletions(-) diff --git a/agc_2-X/trunk/bin/ADMIN_cold_storage_log_tables.pl b/agc_2-X/trunk/bin/ADMIN_cold_storage_log_tables.pl index 38091bea..cf4f95e7 100644 --- a/agc_2-X/trunk/bin/ADMIN_cold_storage_log_tables.pl +++ b/agc_2-X/trunk/bin/ADMIN_cold_storage_log_tables.pl @@ -16,12 +16,13 @@ # Please schedule to run this script at a time when the reports will not be # used for several hours. # -# Copyright (C) 2024 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2025 Matt Florell LICENSE: AGPLv2 # # CHANGES # 240704-1815 - First version # 240705-0954 - Added --query-count-test flag option # 240711-1938 - Added --no-optimize-tables flag option +# 251230-0853 - Added --vl-year flag option, to look in year-based vicidial_log_archive_YYYY tables # $DB=0; @@ -39,6 +40,9 @@ $api_log_only=0; $api_archive_only=0; $url_log_only=0; $url_log_archive=0; +$vl_year_tables=0; +$vl_year_A=''; +$vl_year_B=''; ### begin parsing run-time options ### if (length($ARGV[0])>1) @@ -58,6 +62,7 @@ if (length($ARGV[0])>1) print " [--calc-test] = date calculation test only\n"; print " [--query-count-test] = run archive counts test only\n"; print " [--no-optimize-tables] = do not optimize the archive tables after deletion of rows \n"; + print " [--vl-year] = look in year-based vicidial_log_archive_YYYY tables \n"; print " [--test] = test\n"; print " [--debug] = debug output for some options\n"; print " [--debugX] = extra debug output for some options\n"; @@ -100,6 +105,11 @@ if (length($ARGV[0])>1) $NO_OPTIMIZE_TABLES=1; print "\n-----DO NOT OPTIMIZE ARCHIVE TABLES AFTER ROWS DELETION: $NO_OPTIMIZE_TABLES-----\n\n"; } + if ($args =~ /--vl-year/i) + { + $vl_year_tables=1; + print "\n-----Use year-based vicidial_log_archive_YYYY tables: $vl_year_tables-----\n\n"; + } if ($args =~ /--days=/i) { @data_in = split(/--days=/,$args); @@ -159,6 +169,13 @@ if (!$Q) {print "other _archive tables and move them to the cold-storage log dat if (!$Q) {print "delete the records in original tables older than X days\n";} if (!$Q) {print "$CLIdays days ( $del_time [$del_date]|$del_epoch ) from current date \n\n";} +if ($vl_year_tables > 0) + { + $vl_year_A=$RMyear; + $vl_year_B=($RMyear - 1); + if (!$Q) {print "vicidial_log_archive_YYYY year-tables enabled: |$vl_year_A|$vl_year_B|$vl_year_tables| \n\n";} + } + # default path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; @@ -416,9 +433,181 @@ if (!$T) ##### END call_log_archive cold-storage processing ##### + if ($vl_year_tables > 0) + { + $vl_year_A=$RMyear; + $vl_year_B=($RMyear - 1); + if (!$Q) {print "vicidial_log_archive_YYYY year-tables enabled: |$vl_year_A|$vl_year_B|$vl_year_tables| \n\n";} + + ##### BEGIN vicidial_log_archive cold-storage processing ##### + $vicidial_log_archive_count=0; + $vicidial_log_archive = "vicidial_log_archive_$vl_year_B"; + $stmtA = "SELECT count(*) from $vicidial_log_archive WHERE call_date < '$del_time';"; + $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; + $vicidial_log_archive_count = $aryA[0]; + } + $sthA->finish(); + + $call_log_CS_count=0; + $stmtB = "SELECT count(*) from vicidial_log_archive;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $call_log_CS_count = $aryB[0]; + } + $sthB->finish(); + + if (!$Q) {print "\nAnalyzing $vicidial_log_archive table... ($vicidial_log_archive_count|$call_log_CS_count)\n";} + + if ( ($vicidial_log_archive_count < 1) || ($QUERY_COUNT_TEST > 0) ) + { + if (!$Q) {print "$vicidial_log_archive has no records to send to cold-storage, skipping this table...\n";} + } + else + { + $sthAfields=0; + $stmtA = "SELECT * from $vicidial_log_archive limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + $sthAfields = $sthA->{'NUM_OF_FIELDS'}; + } + $sthA->finish(); + + $sthBfields=0; + if ($call_log_CS_count > 0) + { + $stmtB = "SELECT * from vicidial_log_archive limit 1;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + $sthBfields = $sthB->{'NUM_OF_FIELDS'}; + } + $sthB->finish(); + } + else + { + if($DBX){print STDERR "DEBUG: empty cold-storage table, no field count check\n";} + $sthBfields = $sthAfields; + } + + if ( ($sthAfields < 1) || ($sthBfields ne $sthAfields) ) + { + if (!$Q) {print "$vicidial_log_archive cold-storage fields mismatch error($sthBfields|$sthAfields), skipping this table...\n";} + } + else + { + if (!$Q) {print "$vicidial_log_archive cold-storage fields count match($sthBfields|$sthAfields), starting cold-storage move...\n";} + + $stmtA = "SELECT * FROM $vicidial_log_archive WHERE call_date < '$del_time';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $Arow_ct=0; + $Irows_ct=0; + $Btotal_inserted=0; + $insert_stmt='INSERT IGNORE INTO vicidial_log_archive VALUES'; + while ($sthArows > $Arow_ct) + { + @aryA = $sthA->fetchrow_array; + $Afield_ct=0; + while ($sthAfields > $Afield_ct) + { + if ($Afield_ct < 1) {$insert_stmt .= '(';} + else{$insert_stmt .= ',';} + $tmp_field = $aryA[$Afield_ct]; + $tmp_field =~ s/\"//gi; + $insert_stmt .= "\"$tmp_field\""; + $Afield_ct++; + } + $insert_stmt .= '),'; + $Irows_ct++; + + if ($Irows_ct > 99) + { + chop($insert_stmt); + $stmtB = "$insert_stmt;"; + $affected_rowsB = $dbhB->do($stmtB); + $Btotal_inserted = ($Btotal_inserted + $affected_rowsB); + if($DBX){print STDERR "\n|$affected_rowsB|$stmtB|\n";} + $Irows_ct=0; + $insert_stmt='INSERT IGNORE INTO vicidial_log_archive VALUES'; + } + $Arow_ct++; + if ($Q < 1) + { + if ($Arow_ct =~ /10000$/i) {print STDERR "0 $Arow_ct\r";} + if ($Arow_ct =~ /20000$/i) {print STDERR "+ $Arow_ct\r";} + if ($Arow_ct =~ /30000$/i) {print STDERR "| $Arow_ct\r";} + if ($Arow_ct =~ /40000$/i) {print STDERR "\\ $Arow_ct\r";} + if ($Arow_ct =~ /50000$/i) {print STDERR "- $Arow_ct\r";} + if ($Arow_ct =~ /60000$/i) {print STDERR "/ $Arow_ct\r";} + if ($Arow_ct =~ /70000$/i) {print STDERR "| $Arow_ct\r";} + if ($Arow_ct =~ /80000$/i) {print STDERR "+ $Arow_ct\r";} + if ($Arow_ct =~ /90000$/i) {print STDERR "0 $Arow_ct\r";} + if ($Arow_ct =~ /00000$/i) {print "$Arow_ct|$Btotal_inserted|\n";} + } + } + $sthA->finish(); + + if ($Irows_ct > 0) + { + chop($insert_stmt); + $stmtB = "$insert_stmt;"; + $affected_rowsB = $dbhB->do($stmtB); + $Btotal_inserted = ($Btotal_inserted + $affected_rowsB); + if($DBX){print STDERR "\n|$affected_rowsB|LAST INSERT|$stmtB|\n";} + } + if (!$Q) {print "$vicidial_log_archive cold-storage inserts completed ($Btotal_inserted / $sthArows)\n";} + + if ($Btotal_inserted ne $sthArows) + { + print "ERROR! records inserted is les than records to be inserted ($Btotal_inserted / $sthArows)\n"; + exit; + } + else + { + if (!$Q) {print "$vicidial_log_archive $sthArows deletions starting...\n";} + + $stmtA = "DELETE FROM $vicidial_log_archive WHERE call_date < '$del_time';"; + $affected_rowsA = $dbhA->do($stmtA); + if (!$Q) {print STDERR "records deleted from $vicidial_log_archive: $affected_rowsA|$stmtA|\n";} + + if ($NO_OPTIMIZE_TABLES < 1) + { + $stmtA = "OPTIMIZE TABLE $vicidial_log_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + if (!$Q) {print STDERR "$vicidial_log_archive table optimized, cold-storage process is complete for this table!\n";} + } + else + { + if (!$Q) {print STDERR "$vicidial_log_archive table skip optimize\n";} + } + } + } + } + ##### END vicidial_log_archive cold-storage processing ##### + } + ##### BEGIN vicidial_log_archive cold-storage processing ##### $vicidial_log_archive_count=0; - $stmtA = "SELECT count(*) from vicidial_log_archive WHERE call_date < '$del_time';"; + $vicidial_log_archive = "vicidial_log_archive"; + if ($vl_year_tables > 0) + {$vicidial_log_archive = "vicidial_log_archive_$vl_year_A";} + $stmtA = "SELECT count(*) from $vicidial_log_archive WHERE call_date < '$del_time';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -441,16 +630,16 @@ if (!$T) } $sthB->finish(); - if (!$Q) {print "\nAnalyzing vicidial_log_archive table... ($vicidial_log_archive_count|$call_log_CS_count)\n";} + if (!$Q) {print "\nAnalyzing $vicidial_log_archive table... ($vicidial_log_archive_count|$call_log_CS_count)\n";} if ( ($vicidial_log_archive_count < 1) || ($QUERY_COUNT_TEST > 0) ) { - if (!$Q) {print "vicidial_log_archive has no records to send to cold-storage, skipping this table...\n";} + if (!$Q) {print "$vicidial_log_archive has no records to send to cold-storage, skipping this table...\n";} } else { $sthAfields=0; - $stmtA = "SELECT * from vicidial_log_archive limit 1;"; + $stmtA = "SELECT * from $vicidial_log_archive limit 1;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -481,13 +670,13 @@ if (!$T) if ( ($sthAfields < 1) || ($sthBfields ne $sthAfields) ) { - if (!$Q) {print "vicidial_log_archive cold-storage fields mismatch error($sthBfields|$sthAfields), skipping this table...\n";} + if (!$Q) {print "$vicidial_log_archive cold-storage fields mismatch error($sthBfields|$sthAfields), skipping this table...\n";} } else { - if (!$Q) {print "vicidial_log_archive cold-storage fields count match($sthBfields|$sthAfields), starting cold-storage move...\n";} + if (!$Q) {print "$vicidial_log_archive cold-storage fields count match($sthBfields|$sthAfields), starting cold-storage move...\n";} - $stmtA = "SELECT * FROM vicidial_log_archive WHERE call_date < '$del_time';"; + $stmtA = "SELECT * FROM $vicidial_log_archive WHERE call_date < '$del_time';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -546,7 +735,7 @@ if (!$T) $Btotal_inserted = ($Btotal_inserted + $affected_rowsB); if($DBX){print STDERR "\n|$affected_rowsB|LAST INSERT|$stmtB|\n";} } - if (!$Q) {print "vicidial_log_archive cold-storage inserts completed ($Btotal_inserted / $sthArows)\n";} + if (!$Q) {print "$vicidial_log_archive cold-storage inserts completed ($Btotal_inserted / $sthArows)\n";} if ($Btotal_inserted ne $sthArows) { @@ -555,22 +744,22 @@ if (!$T) } else { - if (!$Q) {print "vicidial_log_archive $sthArows deletions starting...\n";} + if (!$Q) {print "$vicidial_log_archive $sthArows deletions starting...\n";} - $stmtA = "DELETE FROM vicidial_log_archive WHERE call_date < '$del_time';"; + $stmtA = "DELETE FROM $vicidial_log_archive WHERE call_date < '$del_time';"; $affected_rowsA = $dbhA->do($stmtA); - if (!$Q) {print STDERR "records deleted from vicidial_log_archive: $affected_rowsA|$stmtA|\n";} + if (!$Q) {print STDERR "records deleted from $vicidial_log_archive: $affected_rowsA|$stmtA|\n";} if ($NO_OPTIMIZE_TABLES < 1) { - $stmtA = "OPTIMIZE TABLE vicidial_log_archive;"; + $stmtA = "OPTIMIZE TABLE $vicidial_log_archive;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - if (!$Q) {print STDERR "vicidial_log_archive table optimized, cold-storage process is complete for this table!\n";} + if (!$Q) {print STDERR "$vicidial_log_archive table optimized, cold-storage process is complete for this table!\n";} } else { - if (!$Q) {print STDERR "vicidial_log_archive table skip optimize\n";} + if (!$Q) {print STDERR "$vicidial_log_archive table skip optimize\n";} } } } diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index d90331a0..d34f26a9 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -5507,7 +5507,8 @@ INSERT INTO vicidial_lists SET list_id='998',list_name='Default Manual list',cam INSERT INTO system_settings (version,install_date,first_login_trigger) values('2.14b0.5', CURDATE(), 'Y'); -INSERT INTO vicidial_status_categories (vsc_id,vsc_name) values('UNDEFINED','Default Category'); +INSERT INTO vicidial_status_categories (vsc_id,vsc_name,vsc_description) values('UNDEFINED','Default Category',''); +INSERT INTO vicidial_status_categories (vsc_id,vsc_name,vsc_description) values('QC','QC-specific status','Quality control specific statuses'); INSERT INTO vicidial_user_groups SET user_group='ADMIN',group_name='VICIDIAL ADMINISTRATORS',allowed_campaigns=' -ALL-CAMPAIGNS- - -',agent_status_viewable_groups=' --ALL-GROUPS-- ',admin_viewable_groups=' ---ALL--- ',admin_viewable_call_times=' ---ALL--- ',agent_allowed_chat_groups=' --ALL-GROUPS-- '; @@ -5876,4 +5877,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues', UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1735',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1736',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.14.sql b/agc_2-X/trunk/extras/upgrade_2.14.sql index 0561741d..780fa3dd 100644 --- a/agc_2-X/trunk/extras/upgrade_2.14.sql +++ b/agc_2-X/trunk/extras/upgrade_2.14.sql @@ -3050,3 +3050,7 @@ ALTER TABLE vicidial_campaigns MODIFY dial_method ENUM('MANUAL','RATIO','ADAPT_H ALTER TABLE vicidial_campaigns ADD adaptive_percentmax_percentage TINYINT(2) UNSIGNED default '50'; UPDATE system_settings SET db_schema_version='1735',db_schema_update_date=NOW() where db_schema_version < 1735; + +INSERT IGNORE INTO vicidial_status_categories (vsc_id,vsc_name,vsc_description) values('QC','QC-specific status','Quality control specific statuses'); + +UPDATE system_settings SET db_schema_version='1736',db_schema_update_date=NOW() where db_schema_version < 1736;