| 1 | package Retro; | ||
| 2 | # ABSTRACT: Convertisseur spécifique pour une rétroconversion | ||
| 3 | |||
| 4 | use Moose; | ||
| 5 | |||
| 6 | extends 'Koha::Contrib::Sudoc::Converter'; | ||
| 7 | |||
| 8 | |||
| 9 | override 'merge' => sub { | ||
| 10 | my ($self, $sudoc, $koha) = @_; | ||
| 11 | |||
| 12 | # On ajoute à la notice Koha les champ 6xx et 995 de la notice Sudoc | ||
| 13 | my @tags = ( (map { sprintf("6%02d", $_) } ( 0..99 )), '995'); | ||
| 14 | for my $tag (@tags) { | ||
| 15 | my @fields = $sudoc->field($tag); | ||
| 16 | next unless @fields; | ||
| 17 | $koha->append(@fields); | ||
| 18 | } | ||
| 19 | |||
| 20 | # On ajoute à la notice Koha les champs de la notice Sudoc qui n'existe | ||
| 21 | # pas déjà dans la notice Koha, exception faite des champs traités plus | ||
| 22 | # haut et du champ 410. | ||
| 23 | my @all_tags = map { sprintf("%03d", $_) } ( 1..999 ); | ||
| 24 | for my $tag (@all_tags) { | ||
| 25 | next if $tag ~~ @tags || $tag == '410'; # On passe, déjà traité plus haut | ||
| 26 | my @fields = $sudoc->field($tag); | ||
| 27 | next unless @fields; | ||
| 28 | next if $koha->field($tag); | ||
| 29 | $koha->append(@fields); | ||
| 30 | } | ||
| 31 | |||
| 32 | # On remplace la notice Sudoc par la notice Koha. | ||
| 33 | $sudoc->fields( $koha->fields ); | ||
| 34 | }; | ||
| 35 | |||
| 36 | |||
| 37 | # Les champs à supprimer de la notice entrante. | ||
| 38 | my @todelete = qw(035 917 930 991 999); | ||
| 39 | |||
| 40 | after 'clean' => sub { | ||
| 41 | my ($self, $record) = @_; | ||
| 42 | |||
| 43 | # Suppression des champs SUDOC dont on ne veut pas dans le catalogue | ||
| 44 | $record->fields( [ grep { not $_->tag ~~ @todelete } @{$record->fields} ] ); | ||
| 45 | }; | ||
| 46 | |||
| 47 | |||
| 48 | 1; |