Remove Test::utf8, and print number of contacts synced

This commit is contained in:
Daniel Berteaud 2023-10-25 00:03:23 +02:00
parent 5238af22d1
commit 34b0f36b72
3 changed files with 20 additions and 7 deletions

View File

@ -28,7 +28,6 @@ RUN set -eux &&\
Data::UUID \
HTML::Parse \
HTML::FormatText \
Test::utf8 \
URI::Simple \
HTTP::DAV \
Term::ReadKey \

View File

@ -71,7 +71,6 @@ The following perl modules are needed to run it
- Encode
- HTML::Parse
- HTML::FormatText
- Test::utf8
- URI::Simple
- Term::ReadKey
- HTTP::DAV

View File

@ -9,7 +9,6 @@ use Data::UUID;
use Encode qw(encode decode);
use HTML::Parse;
use HTML::FormatText;
use Test::utf8 qw(is_within_latin_1);
use URI::Simple;
use Term::ReadKey;
use HTTP::DAV;
@ -167,6 +166,7 @@ sub prompt_pass {
}
my %odoo_uuid = ();
my $contact_count = 0;
foreach my $contact_id (@{$odoo->search('res.partner', $conf->{odoo}->{filters})}){
my $contact = $odoo->read('res.partner', [ $contact_id ])->[0];
@ -184,10 +184,11 @@ _EOV
$contact->{$_} = HTML::FormatText->new->format(HTML::Parse::parse_html($contact->{$_}));
$contact->{$_} =~ s/\r?\n/\\n/g;
}
if (is_within_latin_1($contact->{$_})){
$vcard .= "$odoo2vcf->{$_}:" . encode("UTF-8", decode("Latin1", $contact->{$_})) . "\n";
} else {
# Check if the field contains non ASCII characters. If it does, it's UTF-8, else, it's Latin1
if ($contact->{$_} =~ /([^\x{00}-\x{ff}])/){
$vcard .= "$odoo2vcf->{$_}:" . encode("UTF-8", $contact->{$_}) . "\n";
} else {
$vcard .= "$odoo2vcf->{$_}:" . encode("UTF-8", decode("Latin1", $contact->{$_})) . "\n";
}
}
@ -201,6 +202,7 @@ _EOV
open VCARD, ">$conf->{path}->{workdir}/$uuid.vcf";
print VCARD $vcard;
close VCARD;
$countact_count++;
}
if (defined $conf->{dav}->{url}){
@ -235,10 +237,23 @@ if (defined $conf->{dav}->{url}){
}
print "Uploading vcards to webdav server $conf->{dav}->{url}\n";
$d->put( -local => "$conf->{path}->{workdir}/*.vcf" );
my $dav_success = 0;
my $dav_error = 0;
foreach my $vcf (glob("$conf->{path}->{workdir}/*.vcf")){
if ($d->put( -local => "$vcf" ) == 0){
$dav_success++;
} else {
print "An error occured while uploading $vcf : " . $d->message . "\n";
$dav_error++;
}
}
}
if (not $conf->{path}->{keep_vcards}){
print "Deleting vcards from $conf->{path}->{workdir}\n";
rmtree($conf->{path}->{workdir});
}
print "$contact_count contacts found in Odoo\n";
print "$dav_success contacts successfuly uploaded to $conf->{dav}->{url}\n";
print "$dav_error contacts failed while uploading to $conf->{dav}->{url}\n";