| 1 | package Koha::Contrib::ARK::Check; | ||
| 2 | # ABSTRACT: Check Koha ARK field | ||
| 3 | $Koha::Contrib::ARK::Check::VERSION = '1.1.2'; | ||
| 4 | use Moose; | ||
| 5 | use Modern::Perl; | ||
| 6 | |||
| 7 | with 'Koha::Contrib::ARK::Action'; | ||
| 8 | |||
| 9 | |||
| 10 | sub action { | ||
| 11 | my $self = shift; | ||
| 12 | my $ark = $self->ark; | ||
| 13 | my $current = $ark->current; | ||
| 14 | my $biblio = $current->{biblio}; | ||
| 15 | my $record = $biblio->{record}; | ||
| 16 | |||
| 17 | return unless $record; | ||
| 18 | |||
| 19 | my $ka = $ark->c->{ark}->{koha}->{ark}; | ||
| 20 | my ($tag, $letter) = ($ka->{tag}, $ka->{letter}); | ||
| 21 | |||
| 22 | # Searching ARK everywhere | ||
| 23 | my $ark_value = $current->{ark}; | ||
| 24 | my $found = 0; | ||
| 25 | |||
| 26 | # Is a bad ARK found in the correct field? | ||
| 27 | if (my $field = $record->field($tag)) { | ||
| 28 | my $value = $letter ? $field->subfield($letter) : $field->value; | ||
| 29 | $self->ark->what_append('found_bad_ark', "Found $value") | ||
| 30 | if $value ne $ark_value; | ||
| 31 | } | ||
| 32 | |||
| 33 | # Is the correct ARK somewhere, good/wrong field? | ||
| 34 | for my $field ( @{$record->fields} ) { | ||
| 35 | if ( ref $field eq 'MARC::Moose::Field::Std' ) { | ||
| 36 | for ( @{$field->subf} ) { | ||
| 37 | my ($let, $value) = @$_; | ||
| 38 | if ( $value eq $ark_value ) { | ||
| 39 | if ( $field->tag eq $tag && $let eq $letter ) { | ||
| 40 | $self->ark->what_append('found_right_field'); | ||
| 41 | $found = 1; | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | $self->ark->what_append('found_wrong_field', | ||
| 45 | 'Found in ' . $field->tag . '$' . $letter); | ||
| 46 | |||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | else { | ||
| 52 | if ( $field->value eq $ark_value ) { | ||
| 53 | if ($field->tag eq $tag) { | ||
| 54 | $self->ark->what_append('found_right_field'); | ||
| 55 | $found = 1; | ||
| 56 | } | ||
| 57 | else { | ||
| 58 | $self->ark->what_append('found_wrong_field', | ||
| 59 | 'Found in ' . $field->tag); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | $self->ark->what_append('not_found') unless $found; | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | __PACKAGE__->meta->make_immutable; | ||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ |