X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=svc%2Fimport_bib;h=d5727e6589665d748f57df3d13be4d4b8bd7e21c;hb=b8dac5b1e296a56187990edca2193fba0e0360ef;hp=3e43339fded44c567844387f946d0400fe79506d;hpb=b764c1ee81728ce5007b89e28b8703742d202375;p=koha-ffzg.git diff --git a/svc/import_bib b/svc/import_bib index 3e43339fde..d5727e6589 100755 --- a/svc/import_bib +++ b/svc/import_bib @@ -4,32 +4,31 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . # -use strict; -use warnings; +use Modern::Perl; -use CGI; +use CGI qw ( -utf8 ); use C4::Auth qw/check_api_auth/; use C4::Context; -use C4::ImportBatch; +use C4::ImportBatch qw( GetWebserviceBatchId AddBiblioToBatch AddItemsToImportBiblio BatchFindDuplicates BatchCommitRecords ); use C4::Matcher; use XML::Simple; # use Carp::Always; -my $query = new CGI; +my $query = CGI->new; binmode STDOUT, ':encoding(UTF-8)'; my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 'edit_catalogue'} ); @@ -44,7 +43,7 @@ if ($query->request_method eq "POST") { $xml = $query->param('xml'); } if ($xml) { - my %params = map { $_ => $query->param($_) } $query->param; + my %params = map { $_ => scalar $query->param($_) } $query->param; my $result = import_bib($xml, \%params ); print $query->header(-type => 'text/xml'); print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1); @@ -74,22 +73,29 @@ sub import_bib { } my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21'; - my $marc_record = eval {MARC::Record::new_from_xml( $inxml, "utf8", $marcflavour)}; + my $marc_record = eval {MARC::Record::new_from_xml( $inxml, "UTF-8", $marcflavour)}; if ($@) { $result->{'status'} = "failed"; $result->{'error'} = $@; return $result; } + if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){ + my @control_num = $marc_record->field('001'); + $marc_record->delete_fields(@control_num); + } - my $import_record_id = AddBiblioToBatch($batch_id, 0, $marc_record, "utf8", int(rand(99999))); + my $import_record_id = AddBiblioToBatch($batch_id, 0, $marc_record, "utf8", 1); my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 'UPDATE COUNTS'); my $matcher = C4::Matcher->new($params->{record_type} || 'biblio'); $matcher = C4::Matcher->fetch($params->{matcher_id}); - my $number_of_matches = BatchFindBibDuplicates($batch_id, $matcher); + my $number_of_matches = BatchFindDuplicates($batch_id, $matcher); # XXX we are ignoring the result of this; - BatchCommitRecords($batch_id, $framework) if lc($import_mode) eq 'direct'; + BatchCommitRecords({ + batch_id => $batch_id, + framework => $framework + }) if lc($import_mode) eq 'direct'; my $dbh = C4::Context->dbh(); my $sth = $dbh->prepare("SELECT matched_biblionumber FROM import_biblios WHERE import_record_id =?"); @@ -98,7 +104,7 @@ sub import_bib { $sth = $dbh->prepare("SELECT overlay_status FROM import_records WHERE import_record_id =?"); $sth->execute($import_record_id); my $match_status = $sth->fetchrow_arrayref->[0] || 'no_match'; - my $url = 'http://'. C4::Context->preference('staffClientBaseURL') .'/cgi-bin/koha/catalogue/detail.pl?biblionumber='. $biblionumber; + my $url = C4::Context->preference('staffClientBaseURL') .'/cgi-bin/koha/catalogue/detail.pl?biblionumber='. $biblionumber; $result->{'status'} = "ok"; $result->{'import_batch_id'} = $batch_id;