Lines 39-45
use JSON qw( decode_json );
Link Here
|
39 |
|
39 |
|
40 |
=head1 API |
40 |
=head1 API |
41 |
|
41 |
|
42 |
=head2 Methods |
42 |
=head2 REST Methods |
43 |
|
43 |
|
44 |
=head3 get |
44 |
=head3 get |
45 |
|
45 |
|
Lines 918-921
sub merge {
Link Here
|
918 |
}; |
918 |
}; |
919 |
} |
919 |
} |
920 |
|
920 |
|
|
|
921 |
=head2 RPC Methods |
922 |
|
923 |
=head3 populate_empty_callnumbers |
924 |
|
925 |
Controller function that handles populating empty callnumbers in bulk |
926 |
|
927 |
=cut |
928 |
|
929 |
sub populate_empty_callnumbers { |
930 |
my ( $c, $params ) = @_; |
931 |
|
932 |
my $biblio = Koha::Biblios->find( $params->{'biblio_id'} ); |
933 |
|
934 |
return $c->render_resource_not_found("Bibliographic record") |
935 |
unless $biblio; |
936 |
|
937 |
my $items = $biblio->items->search( |
938 |
{ |
939 |
-or => [ |
940 |
itemcallnumber => undef, |
941 |
itemcallnumber => q{}, |
942 |
] |
943 |
} |
944 |
); |
945 |
|
946 |
$items = $items->search( { itemnumber => $c->param('item_id') } ) |
947 |
if $c->param('item_id'); |
948 |
|
949 |
return try { |
950 |
|
951 |
my $cn_fields = C4::Context->preference('itemcallnumber'); |
952 |
return $c->render( |
953 |
status => 409, |
954 |
openapi => { |
955 |
error => "Callnumber fields not found", |
956 |
error_code => 'missing_configuration', |
957 |
} |
958 |
) unless $cn_fields; |
959 |
|
960 |
my $record = $biblio->record; |
961 |
my $callnumber; |
962 |
|
963 |
foreach my $callnumber_marc_field ( split( /,/, $cn_fields ) ) { |
964 |
my $callnumber_tag = substr( $callnumber_marc_field, 0, 3 ); |
965 |
my $callnumber_subfields = substr( $callnumber_marc_field, 3 ); |
966 |
|
967 |
next unless $callnumber_tag && $callnumber_subfields; |
968 |
|
969 |
my $field = $record->field($callnumber_tag); |
970 |
|
971 |
next unless $field; |
972 |
|
973 |
$callnumber = $field->as_string( $callnumber_subfields, '' ); |
974 |
last if $callnumber; |
975 |
} |
976 |
|
977 |
return $c->render( |
978 |
status => 409, |
979 |
openapi => { |
980 |
error => "Callnumber empty in bibliographic record", |
981 |
error_code => 'callnumber_empty', |
982 |
} |
983 |
) unless $callnumber; |
984 |
|
985 |
return $c->render( |
986 |
status => 200, |
987 |
openapi => { |
988 |
updated_items_count => 0, |
989 |
callnumber => $callnumber |
990 |
}, |
991 |
) unless $items->count; |
992 |
|
993 |
my ($res) = $items->batch_update( { new_values => { itemcallnumber => $callnumber } } ); |
994 |
my @modified_itemnumbers = @{ $res->{modified_itemnumbers} }; |
995 |
|
996 |
return $c->render( |
997 |
status => 200, |
998 |
openapi => { |
999 |
updated_items_count => scalar @modified_itemnumbers, |
1000 |
callnumber => $callnumber, |
1001 |
modified_item_ids => \@modified_itemnumbers, |
1002 |
}, |
1003 |
); |
1004 |
} catch { |
1005 |
$c->unhandled_exception($_); |
1006 |
}; |
1007 |
} |
1008 |
|
921 |
1; |
1009 |
1; |
922 |
- |
|
|