diff --git a/bin/ADMIN_area_code_populate.pl b/bin/ADMIN_area_code_populate.pl index c387d5f7..d3261afb 100644 --- a/bin/ADMIN_area_code_populate.pl +++ b/bin/ADMIN_area_code_populate.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# ADMIN_area_code_populate.pl version 2.10 +# ADMIN_area_code_populate.pl version 2.12 # # Copyright (C) 2015 Matt Florell LICENSE: AGPLv2 # @@ -21,6 +21,7 @@ # 110424-0735 - Added timezone abbreviation column # 130419-1237 - Added lata_type field to NANPA file format # 150203-1751 - code cleanup +# 151228-1043 - Added ISO-TLD table and import # @@ -30,6 +31,7 @@ $domain = "http://phonecodes.vicidial.com"; #$URL1 = "$domain/phone_codes_GMT-latest.txt"; $URL1 = "$domain/phone_codes_GMT-latest-24.txt"; $URL2 = "$domain/GMT_USA_zip-latest.txt"; +$URL3 = "$domain/country_ISO_TLD-latest.txt"; ### begin parsing run-time options ### @@ -54,6 +56,7 @@ if (length($ARGV[0])>1) print "\n files used by this script are:\n"; print " phone_codes_GMT-latest-24.txt - Phone codes and country codes with time zone data\n"; print " GMT_USA_zip-latest.txt - USA zip code and time zone data\n"; + print " country_ISO_TLD-latest.txt - Country code ISO and TLD data\n"; print " NANPA_prefix-latest.txt - North American areacode, prefix and time zone data\n"; exit; @@ -288,10 +291,12 @@ else # move old files `mv -f $PATHhome/phone_codes_GMT-latest-24.txt $PATHhome/phone_codes_GMT-latest-24-old.txt`; `mv -f $PATHhome/GMT_USA_zip-latest.txt $PATHhome/GMT_USA_zip-latest-old.txt`; + `mv -f $PATHhome/country_ISO_TLD-latest.txt $PATHhome/country_ISO_TLD-latest-old.txt`; # get files `wget $URL1`; `wget $URL2`; + `wget $URL3`; } #### BEGIN vicidial_phone_codes population from phone_codes_GMT-latest-24.txt file #### @@ -391,6 +396,51 @@ else $ins_stmt="insert into vicidial_postal_codes VALUES "; print STDERR "$pc\n"; #### END vicidial_postal_codes population #### + + + #### BEGIN vicidial_country_iso_tld population from GMT_USA_zip-latest.txt file #### + open(isofile, "$PATHhome/country_ISO_TLD-latest.txt") || die "can't open $PATHhome/country_ISO_TLD-latest.txt: $!\n"; + @isofile = ; + close(isofile); + if ( ($purge_table > 0) && ($#isofile > 10) ) + { + print "\n----- PURGING DATA IN vicidial_country_iso_tld TABLE -----\n\n"; + + $stmtA = "DELETE from vicidial_country_iso_tld;"; + if($DB){print STDERR "\n|$stmtA|\n";} + $affected_rows = $dbhA->do($stmtA); + $stmtA = "OPTIMIZE table vicidial_country_iso_tld;"; + if($DB){print STDERR "\n|$stmtA|\n";} + $affected_rows = $dbhA->do($stmtA); + } + $pc=0; + $ins_stmt="insert into vicidial_country_iso_tld VALUES "; + foreach (@isofile) + { + @row=split(/\t/, $isofile[$pc]); + $pc++; + $row[0] =~ s/\r|\n|\t| $//gi; + $row[1] =~ s/\r|\n|\t| $//gi; + $row[2] =~ s/\r|\n|\t| $//gi; + $row[3] =~ s/\r|\n|\t| $//gi; + $row[4] =~ s/\r|\n|\t| $//gi; + $ins_stmt.="(\"$row[0]\", '$row[1]', '$row[2]', '$row[3]', '$row[4]'), "; + if ($pc =~ /00$/) + { + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt) || die "can't execute query: |$ins_stmt| $!\n"; + $ins_stmt="insert into vicidial_country_iso_tld VALUES "; + print STDERR "$pc\r"; + } + } + + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt); + $ins_stmt="insert into vicidial_country_iso_tld VALUES "; + print STDERR "$pc\n"; + #### END vicidial_country_iso_tld population #### } $dbhA->disconnect(); diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 64ff3d76..c55266fe 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -3403,6 +3403,15 @@ KEY lead_id (lead_id), KEY filter_date (filter_date) ) ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci; +CREATE TABLE vicidial_country_iso_tld ( +country_name VARCHAR(200) default '', +iso2 VARCHAR(2) default '', +iso3 VARCHAR(3) default '', +num3 VARCHAR(4) default '', +tld VARCHAR(20) default '', +index(iso3) +)ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -3652,4 +3661,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1441',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1442',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/extras/upgrade_2.12.sql b/extras/upgrade_2.12.sql index c2fa637c..b44cd8a8 100644 --- a/extras/upgrade_2.12.sql +++ b/extras/upgrade_2.12.sql @@ -412,3 +412,14 @@ ALTER TABLE phones ADD nva_new_phone_code VARCHAR(10) default '1'; ALTER TABLE phones ADD nva_new_status VARCHAR(6) default 'NVAINS'; UPDATE system_settings SET db_schema_version='1441',db_schema_update_date=NOW() where db_schema_version < 1441; + +CREATE TABLE vicidial_country_iso_tld ( +country_name VARCHAR(200) default '', +iso2 VARCHAR(2) default '', +iso3 VARCHAR(3) default '', +num3 VARCHAR(4) default '', +tld VARCHAR(20) default '', +index(iso3) +)ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci; + +UPDATE system_settings SET db_schema_version='1442',db_schema_update_date=NOW() where db_schema_version < 1442;