Lines 907-919
sub merge {
Link Here
|
907 |
my $ref_biblionumber = $c->param('biblio_id'); |
907 |
my $ref_biblionumber = $c->param('biblio_id'); |
908 |
my $json = decode_json( $c->req->body ); |
908 |
my $json = decode_json( $c->req->body ); |
909 |
my $bn_merge = $json->{'biblio_id_to_merge'}; |
909 |
my $bn_merge = $json->{'biblio_id_to_merge'}; |
910 |
my $framework = $json->{'framework_to_use'}; |
910 |
my $framework = $json->{'framework_to_use'} // q{}; |
911 |
my $rules = $json->{'rules'}; |
911 |
my $rules = $json->{'rules'} || q{override}; |
912 |
my $override_rec = $json->{'datarecord'}; |
912 |
my $override_rec = $json->{'datarecord'} // q{}; |
913 |
|
|
|
914 |
if ( ( !defined $rules ) || ( $rules eq '' ) ) { $rules = 'override'; } |
915 |
if ( ( !defined $override_rec ) ) { $override_rec = ''; } |
916 |
if ( ( !defined $framework ) ) { $framework = ''; } |
917 |
|
913 |
|
918 |
my $biblio = Koha::Biblios->find($ref_biblionumber); |
914 |
my $biblio = Koha::Biblios->find($ref_biblionumber); |
919 |
if ( not defined $biblio ) { |
915 |
if ( not defined $biblio ) { |
Lines 947-971
sub merge {
Link Here
|
947 |
); |
943 |
); |
948 |
} |
944 |
} |
949 |
|
945 |
|
950 |
my $results; |
946 |
return try { |
951 |
eval { |
|
|
952 |
if ( $rules eq 'override_ext' ) { |
947 |
if ( $rules eq 'override_ext' ) { |
953 |
my $record = MARC::Record::MiJ->new_from_mij_structure($override_rec); |
948 |
my $record = MARC::Record::MiJ->new_from_mij_structure($override_rec); |
954 |
$record->encoding('UTF-8'); |
949 |
$record->encoding('UTF-8'); |
955 |
if ( $framework eq '' ) { $framework = $biblio->frameworkcode; } |
950 |
$framework ||= $biblio->frameworkcode; |
956 |
my $chk = ModBiblio( $record, $ref_biblionumber, $framework ); |
951 |
my $chk = ModBiblio( $record, $ref_biblionumber, $framework ); |
957 |
if ( $chk != 1 ) { die "Error on ModBiblio"; } # ModBiblio returns 1 if everything as gone well |
952 |
if ( $chk != 1 ) { die "Error on ModBiblio"; } # ModBiblio returns 1 if everything as gone well |
958 |
my @biblio_ids_to_merge = ($bn_merge); |
|
|
959 |
$results = $biblio->merge_with( \@biblio_ids_to_merge ); |
960 |
} |
961 |
if ( $rules eq 'override' ) { |
962 |
my @biblio_ids_to_merge = ($bn_merge); |
963 |
$results = $biblio->merge_with( \@biblio_ids_to_merge ); |
964 |
} |
953 |
} |
965 |
}; |
954 |
|
966 |
if ($@) { |
955 |
$biblio->merge_with( [$bn_merge] ); |
967 |
return $c->render( status => 400, json => { error => $@ } ); |
956 |
|
968 |
} else { |
|
|
969 |
$c->respond_to( |
957 |
$c->respond_to( |
970 |
mij => { |
958 |
mij => { |
971 |
status => 200, |
959 |
status => 200, |
Lines 973-979
sub merge {
Link Here
|
973 |
data => $biblio->metadata->record->to_mij |
961 |
data => $biblio->metadata->record->to_mij |
974 |
} |
962 |
} |
975 |
); |
963 |
); |
976 |
} |
964 |
} catch { |
|
|
965 |
$c->render( status => 400, json => { error => $@ } ); |
966 |
}; |
977 |
} |
967 |
} |
978 |
|
968 |
|
979 |
1; |
969 |
1; |
980 |
- |
|
|