Bugzilla – Attachment 34018 Details for
Bug 4283
Merge bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 4283 - Merge bibliographic records
Bug-4283---Merge-bibliographic-records.patch (text/plain), 12.35 KB, created by
Olli-Antti Kivilahti
on 2014-11-28 16:08:21 UTC
(
hide
)
Description:
Bug 4283 - Merge bibliographic records
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2014-11-28 16:08:21 UTC
Size:
12.35 KB
patch
obsolete
>From c77c56cded3f9c048eeb0a6ba49dc887d55ddee9 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Fri, 28 Nov 2014 14:18:32 +0200 >Subject: [PATCH] Bug 4283 - Merge bibliographic records > >Initial stuff. Some documents. >--- > C4/Biblio.pm | 27 ++++ > cataloguing/deduplicator.pl | 97 ++++++++++++++ > .../prog/en/modules/cataloguing/addbooks.tt | 3 + > .../prog/en/modules/cataloguing/deduplicator.tt | 135 ++++++++++++++++++++ > 4 files changed, 262 insertions(+) > create mode 100755 cataloguing/deduplicator.pl > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/deduplicator.tt > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 8bdb25f..30d785f 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -874,6 +874,33 @@ sub GetBiblionumberFromItemnumber { > return ($result); > } > >+=head2 GetBiblionumberSlice >+ >+ my $biblionumbers = C4::Biblio::GetBiblionumberSlice( 100, 450 ); >+ >+@PARAM1 Long, maximum amount of biblio-rows to return. Same as the SQL LIMIT-clause. >+ Defaults to 0. >+@PARAM2 Long, how many biblio-rows to skip starting from the first row. Same as the SQL OFFSET-clause. >+ Defaults to 500. >+@RETURN Array of Long, a slice of biblionumbers starting from the offset and no more rows than the limit-parameter. >+=cut >+ >+sub GetBiblionumberSlice { >+ my ($limit, $offset) = @_; >+ $limit = ($limit) ? $limit : 500 ; >+ $offset = ($offset) ? $offset : 0; >+ >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT biblionumber FROM biblio LIMIT ? OFFSET ?"); >+ $sth->execute($limit, $offset); >+ >+ my @biblionumbers; >+ while(my $bn = $sth->fetchrow()) { >+ push @biblionumbers, $bn; >+ } >+ return \@biblionumbers; >+} >+ > =head2 GetBiblioFromItemNumber > > $item = &GetBiblioFromItemNumber($itemnumber,$barcode); >diff --git a/cataloguing/deduplicator.pl b/cataloguing/deduplicator.pl >new file mode 100755 >index 0000000..d71bcd0 >--- /dev/null >+++ b/cataloguing/deduplicator.pl >@@ -0,0 +1,97 @@ >+#!/usr/bin/perl >+ >+ >+# Copyright 2009 BibLibre >+# Parts Copyright Catalyst IT 2011 >+# >+# 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 Modern::Perl; >+use CGI; >+use C4::Output; >+use C4::Auth; >+ >+use C4::Matcher; >+use C4::Items; >+use C4::Biblio; >+ >+ >+my $input = new CGI; >+ >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "cataloguing/deduplicator.tt", >+ query => $input, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { editcatalogue => 'edit_catalogue' }, >+ } >+); >+ >+my $max_matches = 100; >+my $matcher_id = $input->param('matcher_id'); >+my $op = $input->param('op'); >+ >+#Get the matchers list and set the selected matcher as selected. >+my @matchers = C4::Matcher::GetMatcherList( $matcher_id ); >+foreach (@matchers) { >+ if ($matcher_id && $_->{matcher_id} == $matcher_id) { >+ $_->{selected} = 1; >+ last(); >+ } >+} >+$template->param( matchers => \@matchers ); >+ >+if ($op && $op eq 'deduplicate') { >+ my $matcher = C4::Matcher->fetch($matcher_id); >+ my $biblionumbers = C4::Biblio::GetBiblionumberSlice( $input->param('limit'), $input->param('offset') ); >+ >+ my @duplicates; >+ foreach my $biblionumber (@$biblionumbers) { >+ my $marc = C4::Biblio::GetMarcBiblio($biblionumber); >+ my @matches = $matcher->get_matches( $marc, $max_matches ); >+ >+ if (scalar(@matches) > 1) { >+ foreach my $match (@matches) { >+ my $itemsCount = C4::Items::GetItemsCount($match->{record_id}); >+ $match->{itemsCount} = $itemsCount; >+ } >+ my $biblio = buildSlimBiblio($biblionumber, $marc); >+ $biblio->{matches} = \@matches; >+ >+ push @duplicates, $biblio; >+ } >+ } >+ $template->param( duplicates => \@duplicates ) if scalar(@duplicates) > 0; >+} >+ >+output_html_with_http_headers $input, $cookie, $template->output; >+ >+ >+sub buildSlimBiblio { >+ my ($biblionumber, $marc) = @_; >+ >+ my $biblio = {biblionumber => $biblionumber}; >+ my $title = $marc->subfield('245','a'); >+ $title = $marc->subfield('240','a') unless $title; >+ my $author = $marc->subfield('100','a'); >+ $author = $marc->subfield('110','a') unless $author; >+ >+ $biblio->{author} = $author; >+ $biblio->{title} = $title; >+ >+ return $biblio; >+} >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt >index 8a02dd5..6eae94d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt >@@ -73,6 +73,9 @@ > [% END %] > </ul> > </div> >+ <div class="btn-group"> >+ <a href="/cgi-bin/koha/cataloguing/deduplicator.pl"><button class="btn btn-small">Deduplicator</button></a> >+ </div> > </div> > [% END %] > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/deduplicator.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/deduplicator.tt >new file mode 100644 >index 0000000..052893c >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/deduplicator.tt >@@ -0,0 +1,135 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Cataloging › Deduplicator</title> >+[% INCLUDE 'greybox.inc' %] >+[% INCLUDE 'doc-head-close.inc' %] >+<style type="text/css"> >+ /* Prevent floating the main form */ >+ fieldset.rows { float:none; } >+ .mergeReference { color: #161; font-weight: bold; } >+ .cell {float: left;} >+</style> >+<script type="text/javascript"> >+//<![CDATA[ >+ >+ function updateMergereference(self) { >+ var matchContainer = $(self).parents(".matchContainer"); >+ var checkboxes = $(matchContainer).find('input[id^="checkbox"]'); >+ var mergeReferenceInput = $(matchContainer).parents("form").children("input.mergeReference"); >+ var checkedBoxes = 0; >+ $(checkboxes).each(function() { >+ if($(this).attr('checked') === 'checked' ) { >+ checkedBoxes++; >+ } >+ }); >+ >+ if (checkedBoxes == 1 && $(self).attr('checked') === 'checked') { >+ $(self).parent().find("span.matchDescription").addClass('mergeReference'); >+ $(mergeReferenceInput).val( $(self).val() ); //Save the biblionumber as the mergereference >+ } >+ else if (checkedBoxes == 0) { >+ $(matchContainer).find("span.matchDescription").removeClass('mergeReference'); >+ $(mergeReferenceInput).val( 0 ); >+ } >+ >+ return 1; >+ } >+//]]> >+</script> >+</head> >+<body id="deduplicator"> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'cataloging-search.inc' %] >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a> › Deduplicator</div> >+ >+<div id="doc" class="yui-t7"> >+<div id="bd"> >+ <div id="yui-main"> >+ >+ >+ <h1>Deduplicator</h1> >+ >+ <div id="deduplicatorForm"> >+ <form name="deduplicationForm" action="/cgi-bin/koha/cataloguing/deduplicator.pl" method="post"> >+ <input type="hidden" name="op" value="deduplicate"/> >+ <fieldset class="rows"> >+ <legend>Configure the deduplication search!</legend> >+ <ol> >+ <li> >+ <label>Limit</label><input type="number" name="limit" value="[% limit %]"/><i>How many bibliographic records to deduplicate? Hint: less than 1000.</i> >+ </li> >+ <li> >+ <label>Offset</label><input type="number" name="offset" value="[% offset %]"/><i>From which bibliographic record to start? Hint: increment this by the limit of previous deduplication run. If limit = 200, then first offset is 0, then 200, then 400...</i> >+ </li> >+ <li> >+ <label>Matcher</label> >+ <select name="matcher_id" size="1" id="matchers"> >+ [% FOREACH matcher IN matchers %] >+ [% IF ( matcher.selected ) %] >+ <option value="[% matcher.matcher_id %]" selected="selected">[% matcher.code %] - [% matcher.description %]</option> >+ [% ELSE %] >+ <option value="[% matcher.matcher_id %]">[% matcher.code %] - [% matcher.description %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ <i>The matcher to use to find duplicates. Hint: one can define matchers from the administration menu.</i> >+ </li> >+ <li> >+ <input type="submit" value="Deduplicate!"/> >+ </li> >+ </ol> >+ </fieldset> >+ </form> >+ </div> >+ >+ >+ >+[% IF duplicates %] >+ <div id="duplicatesContainer"> >+ <fieldset class="rows"> >+ <legend> >+ List of duplicates >+ </legend> >+ >+ <label>Matches - Score</label> >+ <label>Title</label> >+ <label>Author</label> >+ <label>Merge</label> >+ >+ <ol> >+ [% FOREACH duplicate IN duplicates %] >+ <form name="form[% duplicate.biblionumber %]" action="/cgi-bin/koha/cataloguing/merge.pl" method="post"> >+ <input type="hidden" class="mergeReference" name="mergereference" value=""/> >+ <li> >+ <div class="cell"> >+ <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% duplicate.biblionumber %]">[% duplicate.biblionumber %]</a> >+ <div class="matchContainer"> >+ [% FOREACH match IN duplicate.matches %] >+ <div> >+ <input id="checkbox[% match.record_id %]" name="biblionumber" value="[% match.record_id %]" type="checkbox" onclick="updateMergereference(this)"/> >+ <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% match.record_id %]"> >+ <span class="matchDescription"> >+ [% match.record_id %] - <i>[% match.score %]</i> >+ </span> >+ </a> >+ <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% match.record_id %]"> >+ [[% match.itemsCount %]] >+ </a> >+ </div> >+ [% END %] >+ </div> >+ </div> >+ <div class="cell">[% duplicate.title %]</div> >+ <div class="cell">[% duplicate.author %]</div> >+ <div class="cell"><input type="submit" value="Merge!"/></div> >+ </li> >+ </form> >+ [% END %] >+ </ol> >+ </fieldset> >+ </div><!--<div id="duplicatesContainer">%--> >+[% END %] >+ </div> >+</div> <!--EO <div id="bd"> --> >+ >+ >+[% INCLUDE 'intranet-bottom.inc' %] >\ No newline at end of file >-- >1.7.9.5
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 4283
:
1973
|
1974
|
1975
|
34018
|
34032
|
34509