Remove Test::utf8, and print number of contacts synced
This commit is contained in:
parent
5238af22d1
commit
34b0f36b72
|
@ -28,7 +28,6 @@ RUN set -eux &&\
|
||||||
Data::UUID \
|
Data::UUID \
|
||||||
HTML::Parse \
|
HTML::Parse \
|
||||||
HTML::FormatText \
|
HTML::FormatText \
|
||||||
Test::utf8 \
|
|
||||||
URI::Simple \
|
URI::Simple \
|
||||||
HTTP::DAV \
|
HTTP::DAV \
|
||||||
Term::ReadKey \
|
Term::ReadKey \
|
||||||
|
|
|
@ -71,7 +71,6 @@ The following perl modules are needed to run it
|
||||||
- Encode
|
- Encode
|
||||||
- HTML::Parse
|
- HTML::Parse
|
||||||
- HTML::FormatText
|
- HTML::FormatText
|
||||||
- Test::utf8
|
|
||||||
- URI::Simple
|
- URI::Simple
|
||||||
- Term::ReadKey
|
- Term::ReadKey
|
||||||
- HTTP::DAV
|
- HTTP::DAV
|
||||||
|
|
25
odoo2carddav
25
odoo2carddav
|
@ -9,7 +9,6 @@ use Data::UUID;
|
||||||
use Encode qw(encode decode);
|
use Encode qw(encode decode);
|
||||||
use HTML::Parse;
|
use HTML::Parse;
|
||||||
use HTML::FormatText;
|
use HTML::FormatText;
|
||||||
use Test::utf8 qw(is_within_latin_1);
|
|
||||||
use URI::Simple;
|
use URI::Simple;
|
||||||
use Term::ReadKey;
|
use Term::ReadKey;
|
||||||
use HTTP::DAV;
|
use HTTP::DAV;
|
||||||
|
@ -167,6 +166,7 @@ sub prompt_pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
my %odoo_uuid = ();
|
my %odoo_uuid = ();
|
||||||
|
my $contact_count = 0;
|
||||||
foreach my $contact_id (@{$odoo->search('res.partner', $conf->{odoo}->{filters})}){
|
foreach my $contact_id (@{$odoo->search('res.partner', $conf->{odoo}->{filters})}){
|
||||||
my $contact = $odoo->read('res.partner', [ $contact_id ])->[0];
|
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->{$_} = HTML::FormatText->new->format(HTML::Parse::parse_html($contact->{$_}));
|
||||||
$contact->{$_} =~ s/\r?\n/\\n/g;
|
$contact->{$_} =~ s/\r?\n/\\n/g;
|
||||||
}
|
}
|
||||||
if (is_within_latin_1($contact->{$_})){
|
# Check if the field contains non ASCII characters. If it does, it's UTF-8, else, it's Latin1
|
||||||
$vcard .= "$odoo2vcf->{$_}:" . encode("UTF-8", decode("Latin1", $contact->{$_})) . "\n";
|
if ($contact->{$_} =~ /([^\x{00}-\x{ff}])/){
|
||||||
} else {
|
|
||||||
$vcard .= "$odoo2vcf->{$_}:" . encode("UTF-8", $contact->{$_}) . "\n";
|
$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";
|
open VCARD, ">$conf->{path}->{workdir}/$uuid.vcf";
|
||||||
print VCARD $vcard;
|
print VCARD $vcard;
|
||||||
close VCARD;
|
close VCARD;
|
||||||
|
$countact_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $conf->{dav}->{url}){
|
if (defined $conf->{dav}->{url}){
|
||||||
|
@ -235,10 +237,23 @@ if (defined $conf->{dav}->{url}){
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Uploading vcards to webdav server $conf->{dav}->{url}\n";
|
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}){
|
if (not $conf->{path}->{keep_vcards}){
|
||||||
print "Deleting vcards from $conf->{path}->{workdir}\n";
|
print "Deleting vcards from $conf->{path}->{workdir}\n";
|
||||||
rmtree($conf->{path}->{workdir});
|
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";
|
||||||
|
|
Loading…
Reference in New Issue