fafd3e87f5
Prior patches to this bug had lots of comments like "I don't have a way to test this, so..." In the OCLC Connexion web, when you choose the option to export to MARC, it'll *send* it, and say, "Record Exported," but the web client does nothing whatever to confirm that the record actually landed in Koha. That's a flaw in their software, but can be easily checked by looking in Koha to see if an import batch got created. The desktop client is a little smarter about this, but needed much more testing, also. With this patch, both the client and web will actually work. With a config file and set up as previously described, The record will be staged and/or imported, and the desktop client returns a useful message about what happened, *and* the staff client URL to the record. Oodles of gobs of bunches of thanks to Virginia Military Institute, for loaning me their OCLC authorization credentials so this could be tested, as well as for great suggestions of cosmetic improvements to the mechanism and output.
109 lines
3.8 KiB
Perl
Executable file
109 lines
3.8 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright 2012 CatalystIT Ltd
|
|
#
|
|
# 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 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.
|
|
#
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use CGI;
|
|
use C4::Auth qw/check_api_auth/;
|
|
use C4::Context;
|
|
use C4::ImportBatch;
|
|
use C4::Matcher;
|
|
use XML::Simple;
|
|
# use Carp::Always;
|
|
|
|
my $query = new CGI;
|
|
binmode STDOUT, ':encoding(UTF-8)';
|
|
|
|
my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 'edit_catalogue'} );
|
|
unless ($status eq "ok") {
|
|
print $query->header(-type => 'text/xml', -status => '403 Forbidden');
|
|
print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
|
|
exit 0;
|
|
}
|
|
|
|
my $xml;
|
|
if ($query->request_method eq "POST") {
|
|
$xml = $query->param('xml');
|
|
}
|
|
if ($xml) {
|
|
my %params = map { $_ => $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);
|
|
} else {
|
|
print $query->header(-type => 'text/xml', -status => '400 Bad Request');
|
|
}
|
|
|
|
exit 0;
|
|
|
|
sub import_bib {
|
|
my ($inxml, $params) = @_;
|
|
|
|
my $result = {};
|
|
|
|
my $import_mode = delete $params->{import_mode} || '';
|
|
my $framework = delete $params->{framework} || '';
|
|
|
|
if (my $matcher_code = delete $params->{match}) {
|
|
$params->{matcher_id} = C4::Matcher::GetMatcherId($matcher_code);
|
|
}
|
|
|
|
my $batch_id = GetWebserviceBatchId($params);
|
|
unless ($batch_id) {
|
|
$result->{'status'} = "failed";
|
|
$result->{'error'} = "Batch create error";
|
|
return $result;
|
|
}
|
|
|
|
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
|
|
my $marc_record = eval {MARC::Record::new_from_xml( $inxml, "utf8", $marcflavour)};
|
|
if ($@) {
|
|
$result->{'status'} = "failed";
|
|
$result->{'error'} = $@;
|
|
return $result;
|
|
}
|
|
|
|
my $import_record_id = AddBiblioToBatch($batch_id, 0, $marc_record, "utf8", int(rand(99999)));
|
|
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);
|
|
|
|
# XXX we are ignoring the result of this;
|
|
BatchCommitBibRecords($batch_id, $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 =?");
|
|
$sth->execute($import_record_id);
|
|
my $biblionumber=$sth->fetchrow_arrayref->[0] || '';
|
|
$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;
|
|
|
|
$result->{'status'} = "ok";
|
|
$result->{'import_batch_id'} = $batch_id;
|
|
$result->{'match_status'} = $match_status;
|
|
$result->{'biblionumber'} = $biblionumber;
|
|
$result->{'url'} = $url;
|
|
return $result;
|
|
}
|