Koha-Contrib-Sudoc

 view release on metacpan or  search on metacpan

bin/sudoc-trans  view on Meta::CPAN

}
# FIN


# Envoi à l'ABES d'un email GTD en réponse à un message 'status 9'. Celui-ci
# contient le numéro du job
sub send_gtd {
    my $content = shift;

    # Récupération dans le courriel de l'ABES des info dont on a besoin pour
    # construire la réponse
    my ($jobid) = $content =~ /JobId\s*:\s*(\d*)/;

    # La date
    my $year = time();
    (undef, undef, undef, undef, undef, $year) = localtime($year);
    $year += 1900;

    syslog(LOG_INFO, "Réception 'status 9'. Envoi GTD: ILN $iln, job $jobid, année $year" );

    my $head = Mail::Message::Head->new;
    $head->add( From => $c->{email}->{koha} );
    $head->add( To => $c->{email}->{abes} );
    $head->add( Subject => 'GET TITLE DATA' );

    my $body = Mail::Message::Body::Lines->new(
        data =>
            "GTD_ILN = $iln\n" .
            "GTD_YEAR = $year\n" .
            "GTD_FILE_TO = " . $c->{ftp_host} . "\n" .
            "GTD_ORDER = TR$jobid*\n" .
            "GTD_REMOTE_DIR = staged\n",
    );

    my $message = Mail::Message->new(
        head => $head,
        body => $body );
    $message->send;
}


sub move_to_waiting {
    syslog(LOG_INFO, "Réception 'status 0'. Fin transfert: 'staged' déplacé en 'waiting'");

    my $staged = 'staged';
    opendir(my $hdir, $staged) || die "Impossible d'ouvrir $staged: $!";
    my @files = sort grep { not /^\./ } readdir($hdir);
    move("$staged/$_", "waiting") for @files;
}


sub transfert_abes {
    my $self = shift;

    # Ne rien faire si la MBOX est vide
    my $mbox = $c->{mbox};
    return unless -f $mbox;

    # Lit toute la MBOX qui ne peut contenir qu'un message à la fois, étant de
    # type status 0 ou status 9
    my $content = do { local(@ARGV, $/) = $mbox; <> };
    if    ( $content =~ /status is 9/ ) { send_gtd($content);        }
    elsif ( $content =~ /status: 0/ )   { move_to_waiting(); }
    unlink $mbox;
}

__END__

=pod

=encoding UTF-8

=head1 NAME

sudoc-trans - Service de transfert de fichiers ABES

=head1 VERSION

version 2.50

=head1 AUTHOR

Frédéric Demians <f.demians@tamil.fr>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Fréderic Demians.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007

=cut



( run in 0.634 second using v1.01-cache-2.11-cpan-8dfa8b56332 )