Bugzilla – Attachment 130713 Details for
Bug 18618
Mana - Add reading suggestions (crontab and scripts for Koha)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18618: Add MARC21 support
Bug-18618-Add-MARC21-support.patch (text/plain), 12.67 KB, created by
Marion Durand
on 2022-02-17 10:12:18 UTC
(
hide
)
Description:
Bug 18618: Add MARC21 support
Filename:
MIME Type:
Creator:
Marion Durand
Created:
2022-02-17 10:12:18 UTC
Size:
12.67 KB
patch
obsolete
>From 11e2ce4233884c786c684f36aaabdc3955d43198 Mon Sep 17 00:00:00 2001 >From: Marion Durand <marion.durand@biblibre.com> >Date: Thu, 9 Dec 2021 14:22:43 +0100 >Subject: [PATCH] Bug 18618: Add MARC21 support > >This functionnality is now working for both MARC21 and UNIMARC. >--- > misc/cronjobs/mana_send_pairs.pl | 57 ++++++++++++++++++----------- > opac/svc/mana/getSuggestion | 63 ++++++++++++++++++++++++-------- > 2 files changed, 83 insertions(+), 37 deletions(-) > >diff --git a/misc/cronjobs/mana_send_pairs.pl b/misc/cronjobs/mana_send_pairs.pl >index 59845491ee..66c45ca58e 100644 >--- a/misc/cronjobs/mana_send_pairs.pl >+++ b/misc/cronjobs/mana_send_pairs.pl >@@ -33,36 +33,50 @@ if (C4::Context->preference("Mana") == 1){ > #It is used to exlude huge borrower such as libraries or instution (because the issues won't have any connection) > my $current_issues_max = 50; > >+ #choose the field to select depending on marc flavour >+ my $marcflavour = C4::Context->preference("marcflavour"); >+ my %fields; >+ my %inds1; >+ if ($marcflavour eq "UNIMARC"){ >+ %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073"); >+ %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => ""); >+ } >+ else{ >+ #if nor UNIMARC, assume MARC21 >+ %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024"); >+ %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\""); >+ } >+ > my $dbh = C4::Context->dbh; >- my $query_part1 = " >+ my $query = q{ > SELECT >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc2, >- ExtractValue(biblio_metadata1.metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean1, >- ExtractValue(biblio_metadata2.metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean2 >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[@code="a"]') as isbn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[@code="a"]') as isbn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[@code="a"]') as issn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[@code="a"]') as issn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean2 > FROM > issues AS issues1 > JOIN > (SELECT borrowernumber FROM issues GROUP BY borrowernumber HAVING COUNT(*) < $current_issues_max) AS number ON number.borrowernumber=issues1.borrowernumber >- JOIN >+ LEFT JOIN > issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber >- JOIN >+ LEFT JOIN > items AS items1 ON issues1.itemnumber=items1.itemnumber >- JOIN >+ LEFT JOIN > biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber >- JOIN >+ LEFT JOIN > items AS items2 ON issues2.itemnumber=items2.itemnumber >- JOIN >+ LEFT JOIN > biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber > WHERE > issues1.issuedate LIKE ? >@@ -70,7 +84,8 @@ if (C4::Context->preference("Mana") == 1){ > AND (DATE(issues1.issuedate) != DATE(issues2.issuedate) OR items1.biblionumber < items2.biblionumber) > AND biblio_metadata1.format='marcxml' > AND biblio_metadata2.format='marcxml' >- "; >+ }; >+ > my $query_part2 = $query_part1; > $query_part2 =~ s/issues AS issues2/old_issues AS issues2/; > >diff --git a/opac/svc/mana/getSuggestion b/opac/svc/mana/getSuggestion >index b6cea9cd4c..89dab8ce1e 100755 >--- a/opac/svc/mana/getSuggestion >+++ b/opac/svc/mana/getSuggestion >@@ -108,20 +108,34 @@ else{ > if ($documentids) { $found = 1; }; > } > if ($found == 0){ >+ #choose the field to select depending on marc flavour >+ my $marcflavour = C4::Context->preference("marcflavour"); >+ my %fields; >+ my %inds1; >+ if ($marcflavour eq "UNIMARC"){ >+ %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073"); >+ %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => ""); >+ } >+ else{ >+ #if nor UNIMARC, assume MARC21 >+ %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024"); >+ %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\""); >+ } >+ > my $dbh = C4::Context->dbh; >- my $query = " >+ my $query = q{ > SELECT >- ExtractValue(metadata, '//datafield[\@tag=\"010\"]/subfield[\@code=\"a\"]') as isbn, >- ExtractValue(metadata, '//datafield[\@tag=\"011\"]/subfield[\@code=\"a\"]') as issn, >- ExtractValue(metadata, '//datafield[\@tag=\"013\"]/subfield[\@code=\"a\"]') as ismn, >- ExtractValue(metadata, '//datafield[\@tag=\"015\"]/subfield[\@code=\"a\"]') as isrn, >- ExtractValue(metadata, '//datafield[\@tag=\"016\"]/subfield[\@code=\"a\"]') as isrc, >- ExtractValue(metadata, '//datafield[\@tag=\"072\"]/subfield[\@code=\"a\"]') as upc, >- ExtractValue(metadata, '//datafield[\@tag=\"073\"]/subfield[\@code=\"a\"]') as ean >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{isbn}.q{"}.$inds1{isbn}.q{]/subfield[\@code="a"]') as isbn, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{issn}.q{"}.$inds1{issn}.q{]/subfield[\@code="a"]') as issn, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{ismn}.q{"}.$inds1{ismn}.q{]/subfield[@code="a"]') as ismn, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{isrn}.q{"}.$inds1{isrn}.q{]/subfield[@code="a"]') as isrn, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{isrc}.q{"}.$inds1{isrc}.q{]/subfield[@code="a"]') as isrc, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{upc}.q{"}.$inds1{upc}.q{]/subfield[@code="a"]') as upc, >+ ExtractValue(metadata, '//datafield[@tag="}.$fields{ean}.q{"}.$inds1{ean}.q{]/subfield[@code="a"]') as ean > FROM biblio_metadata >- WHERE biblionumber = ? >- AND format=\"marcxml\" >- "; >+ WHERE biblionumber="}.$biblionumber.q{" >+ AND format="marcxml" >+ }; > my $sth = $dbh->prepare( $query ); > $sth->execute($biblionumber); > my $row = $sth->fetchrow_hashref; >@@ -154,6 +168,10 @@ else{ > $idtype = "ean"; > $documentids = $row->{ean}; > } >+ elsif ($row->{ean}){ >+ $idtype = "ean"; >+ $documentid = $row->{ean}; >+ } > else{ > die "error: no propper identifier"; > } >@@ -197,11 +215,12 @@ else{ > > #create the list of owned suggested resources > my $ownedbiblioitem; >+ my $marcflavour = C4::Context->preference("marcflavour"); > foreach my $resource ( @{ $resources } ){ > my $found = 0; > >- #isbn, issn and ean can be search for with Koha::Biblioitems->search >- if ($resource->{idtype} eq "isbn" || $resource->{idtype} eq "issn" || $resource->{idtype} eq "ean"){ >+ #isbn and issn can be search for with Koha::Biblioitems->search, ean too for unimarc but not for marc21 >+ if ($resource->{idtype} eq "isbn" || $resource->{idtype} eq "issn" || ($resource->{idtype} eq "ean" && $marcflavour eq "UNIMARC")){ > #isbn processsing > if ( $resource->{idtype} eq "isbn" ){ > $documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); >@@ -247,12 +266,24 @@ else{ > # other id need to be search with sql > if ($found != 1) { > my @params; >- my %field=("isbn" => "010", "issn" => "011", "ismn" => "013", "isrn" => "015", "isrc" => "016", "upc" => "072", "ean" => "073"); >+ >+ #choose the field to select depending on marc flavour >+ my %fields; >+ my %inds1; >+ if ($marcflavour eq "UNIMARC"){ >+ %fields = (isbn => "010", issn => "011", ismn => "013", isrn => "015", isrc => "016", upc => "072", ean => "073"); >+ %inds1 = (isbn => "", issn => "", ismn => "", isrn => "", isrc => "", upc => "", ean => ""); >+ } >+ else{ >+ #if nor UNIMARC, assume MARC21 >+ %fields = (isbn => "020", issn => "022", ismn => "024", isrn => "027", isrc => "024", upc => "024", ean => "024"); >+ %inds1 = (isbn => "", issn => "", ismn => " and \@ind1=\"2\"", isrn => "", isrc => " and \@ind1=\"0\"", upc => " and \@ind1=\"1\"", ean => " and \@ind1=\"3\""); >+ } > > #pattern to be tolerent on the hyphens > my $pattern=""; > foreach my $p (split('', $resource->{documentid})){ >- $pattern .= "$p-*"; >+ $pattern .= "$p-?"; > } > > my $dbh = C4::Context->dbh; >@@ -260,7 +291,7 @@ else{ > SELECT biblioitems.biblionumber as biblionumber > FROM biblioitems > LEFT JOIN biblio_metadata ON biblioitems.biblionumber=biblio_metadata.biblionumber >- WHERE ExtractValue(biblio_metadata.metadata, '//datafield[@tag="}.$field{$resource->{idtype}}.q{"]/subfield[@code="a"]') REGEXP "}.$pattern.q{" >+ WHERE ExtractValue(biblio_metadata.metadata, '//datafield[@tag="}.$fields{$resource->{idtype}}.q{"}.$inds1{$resource->{idtype}}.q{]/subfield[@code="a"]') REGEXP "}.$pattern.q{" > AND biblio_metadata.format="marcxml" > }; > my $sth = $dbh->prepare( $query ); >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18618
:
63496
|
63497
|
64531
|
64960
|
65066
|
65067
|
65068
|
65069
|
65070
|
130706
|
130707
|
130708
|
130709
|
130710
|
130711
|
130712
|
130713
|
130714
|
130715
|
130735
|
130736
|
130737
|
130738
|
130739
|
130740
|
130741
|
130742
|
130743
|
130744
|
132690
|
132691