Bugzilla – Attachment 10305 Details for
Bug 8202
Add authorities to export tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8202: Add authority export to tools/export.pl
Bug-8202-Add-authority-export-to-toolsexportpl.patch (text/plain), 15.05 KB, created by
Jared Camins-Esakov
on 2012-06-15 17:13:01 UTC
(
hide
)
Description:
Bug 8202: Add authority export to tools/export.pl
Filename:
MIME Type:
Creator:
Jared Camins-Esakov
Created:
2012-06-15 17:13:01 UTC
Size:
15.05 KB
patch
obsolete
>From 2da4073632538f924e0ab870a3f6fc14b56cc4b9 Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@cpbibliography.com> >Date: Wed, 30 May 2012 08:10:14 -0400 >Subject: [PATCH] Bug 8202: Add authority export to tools/export.pl >Content-Type: text/plain; charset="UTF-8" > >Adds a separate tab on tools/export.pl for exporting authority records. > >To test: >1. Try exporting authority records from the "Export data" tool >--- > .../intranet-tmpl/prog/en/modules/tools/export.tt | 75 +++++++- > .../prog/en/modules/tools/tools-home.tt | 4 +- > tools/export.pl | 220 +++++++++++++------- > 3 files changed, 216 insertions(+), 83 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt >index ae4d3ec..fa98d78 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt >@@ -5,6 +5,13 @@ > <script type="text/javascript" src="[% themelang %]/lib/calendar/calendar.js"></script> > <script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-en.js"></script> > <script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-setup.js"></script> >+<script type="text/javascript"> >+//<![CDATA[ >+$(document).ready(function() { >+ $('#exporttype').tabs(); >+}); >+//]]> >+</script> > </head> > <body id="tools_export" class="tools"> > [% INCLUDE 'header.inc' %] >@@ -18,6 +25,12 @@ > <div id="yui-main"> > <div class="yui-b"> > >+<div id="exporttype" class="toptabs"> >+<ul> >+<li><a href="#bibs">Export bibliographic records</a></li> >+<li><a href="#auths">Export authority records</a></li> >+</ul> >+<div id="bibs"> > <p> > <b>Note : The items are exported by this tool unless specified.</b> > </p> >@@ -132,9 +145,69 @@ Calendar.setup( > </li></ol> > </fieldset> > <input type="hidden" name="op" value="export" /> >+ <input type="hidden" name="record_type" value="bibs" /> >+ >+ <fieldset class="action"><input type="submit" value="Export bibliographic records" class="button" /></fieldset> >+</form> >+</div> >+ >+<div id="auths"> >+<form method="post" action="/cgi-bin/koha/tools/export.pl"> >+ <fieldset class="rows"> >+ <legend> Select records to export </legend> >+ <ol><li> >+ <label for="start">From authid: </label> >+ <input id="start" type="text" name="starting_authid" size="6" /> >+ </li> >+ <li> >+ <label for="end">To authid: </label> >+ <input id="end" type="text" name="ending_authid" size="6" /> >+ </li> >+ <li> >+ <label for="authtype">Authority type: </label> >+ <select name="authtype" id="authtype"> >+ <option value="">-- All --</option> >+ [% FOREACH authtypeloo IN authtypeloop %] >+ [% IF ( authtypeloo.selected ) %] >+ <option value="[% authtypeloo.value %]" selected="selected">[% authtypeloo.description %]</option> >+[% ELSE %] >+ <option value="[% authtypeloo.value %]">[% authtypeloo.description %]</option> >+[% END %] >+ [% END %] >+ </select> >+ </li> >+ </ol> >+ </fieldset> >+ <fieldset class="rows"> >+ <legend>Options</legend> >+ <ol> >+ <li> >+ <label for="dont_export_fields">Don't export fields</label> >+ <input id="dont_export_fields" type="text" name="dont_export_fields" /> >+ separate by a blank. (e.g., 100a 200 606) >+ </li></ol> >+ </fieldset> >+ <fieldset class="rows"> >+ <legend>Output format</legend> >+ <ol><li> >+ <label for="output_format">File format: </label> >+ <select id="output_format" name="output_format"> >+ <option value="marc">marc</option> >+ <option value="xml">xml</option> >+ </select> >+ </li> >+ <li> >+ <label for="filename">File name:</label><input id="filename" type="text" name="filename" value="koha.mrc" /> >+ </li></ol> >+ </fieldset> >+ <input type="hidden" name="op" value="export" /> >+ <input type="hidden" name="record_type" value="auths" /> > >- <fieldset class="action"><input type="submit" value="Export" class="button" /></fieldset> >+ <fieldset class="action"><input type="submit" value="Export authority records" class="button" /></fieldset> > </form> >+</div> >+ >+</div> > > </div> > </div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >index 1f4e1e2..52cc1e6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >@@ -113,8 +113,8 @@ > [% END %] > > [% IF ( CAN_user_tools_export_catalog ) %] >- <dt><a href="/cgi-bin/koha/tools/export.pl">Export bibliographic and holdings</a></dt> >- <dd>Export bibliographic and holdings data</dd> >+ <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt> >+ <dd>Export bibliographic, holdings, and authority records</dd> > [% END %] > > [% IF ( CAN_user_tools_inventory ) %] >diff --git a/tools/export.pl b/tools/export.pl >index d3d8646..b439a8d 100755 >--- a/tools/export.pl >+++ b/tools/export.pl >@@ -22,6 +22,7 @@ use warnings; > use C4::Auth; > use C4::Output; > use C4::Biblio; # GetMarcBiblio GetXmlBiblio >+use C4::AuthoritiesMarc; # GetAuthority > use CGI; > use C4::Koha; # GetItemTypes > use C4::Branch; # GetBranches >@@ -62,89 +63,136 @@ if ($op eq "export") { > -charset => 'utf-8', > -attachment=>$filename); > >- my $StartingBiblionumber = $query->param("StartingBiblionumber"); >- my $EndingBiblionumber = $query->param("EndingBiblionumber"); >- my $output_format = $query->param("output_format"); >- my $itemtype = $query->param("itemtype"); >- my $start_callnumber = $query->param("start_callnumber"); >- my $end_callnumber = $query->param("end_callnumber"); >- my $start_accession = ($query->param("start_accession")) ? C4::Dates->new($query->param("start_accession")) : '' ; >- my $end_accession = ($query->param("end_accession")) ? C4::Dates->new($query->param("end_accession")) : '' ; >- my $dont_export_items = $query->param("dont_export_item"); >- my $strip_nonlocal_items = $query->param("strip_nonlocal_items"); >- my $dont_export_fields = $query->param("dont_export_fields"); >+ my $record_type = $query->param("record_type"); >+ my $output_format = $query->param("output_format"); >+ my $dont_export_fields = $query->param("dont_export_fields"); > my @sql_params; >- >- my $items_filter = >- $branch || $start_callnumber || $end_callnumber || >- $start_accession || $end_accession || >- ($itemtype && C4::Context->preference('item-level_itypes')); >- my $query = $items_filter ? >- "SELECT DISTINCT biblioitems.biblionumber >- FROM biblioitems JOIN items >- USING (biblionumber) WHERE 1" >- : >- "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 "; >- >- if ( $StartingBiblionumber ) { >- $query .= " AND biblioitems.biblionumber >= ? "; >- push @sql_params, $StartingBiblionumber; >- } >- >- if ( $EndingBiblionumber ) { >- $query .= " AND biblioitems.biblionumber <= ? "; >- push @sql_params, $EndingBiblionumber; >- } >+ my $sql_query; > >- if ($branch) { >- $query .= " AND homebranch = ? "; >- push @sql_params, $branch; >- } >+ my $StartingBiblionumber = $query->param("StartingBiblionumber"); >+ my $EndingBiblionumber = $query->param("EndingBiblionumber"); >+ my $itemtype = $query->param("itemtype"); >+ my $start_callnumber = $query->param("start_callnumber"); >+ my $end_callnumber = $query->param("end_callnumber"); >+ my $start_accession = >+ ( $query->param("start_accession") ) >+ ? C4::Dates->new( $query->param("start_accession") ) >+ : ''; >+ my $end_accession = >+ ( $query->param("end_accession") ) >+ ? C4::Dates->new( $query->param("end_accession") ) >+ : ''; >+ my $dont_export_items = $query->param("dont_export_item"); >+ my $strip_nonlocal_items = $query->param("strip_nonlocal_items"); > >- if ($start_callnumber) { >- $query .= " AND itemcallnumber <= ? "; >- push @sql_params, $start_callnumber; >- } >+ my $starting_authid = $query->param('starting_authid'); >+ my $ending_authid = $query->param('ending_authid'); >+ my $authtype = $query->param('authtype'); > >- if ($end_callnumber) { >- $query .= " AND itemcallnumber >= ? "; >- push @sql_params, $end_callnumber; >- } >- if ($start_accession) { >- $query .= " AND dateaccessioned >= ? "; >- push @sql_params, $start_accession->output('iso'); >- } >+ if ( $record_type eq 'bibs' ) { >+ my $items_filter = >+ $branch || $start_callnumber || $end_callnumber || >+ $start_accession || $end_accession || >+ ($itemtype && C4::Context->preference('item-level_itypes')); >+ $sql_query = $items_filter ? >+ "SELECT DISTINCT biblioitems.biblionumber >+ FROM biblioitems JOIN items >+ USING (biblionumber) WHERE 1" >+ : >+ "SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 "; >+ >+ if ( $StartingBiblionumber ) { >+ $sql_query .= " AND biblioitems.biblionumber >= ? "; >+ push @sql_params, $StartingBiblionumber; >+ } >+ >+ if ( $EndingBiblionumber ) { >+ $sql_query .= " AND biblioitems.biblionumber <= ? "; >+ push @sql_params, $EndingBiblionumber; >+ } >+ >+ if ($branch) { >+ $sql_query .= " AND homebranch = ? "; >+ push @sql_params, $branch; >+ } >+ >+ if ($start_callnumber) { >+ $sql_query .= " AND itemcallnumber <= ? "; >+ push @sql_params, $start_callnumber; >+ } >+ >+ if ($end_callnumber) { >+ $sql_query .= " AND itemcallnumber >= ? "; >+ push @sql_params, $end_callnumber; >+ } >+ if ($start_accession) { >+ $sql_query .= " AND dateaccessioned >= ? "; >+ push @sql_params, $start_accession->output('iso'); >+ } >+ >+ if ($end_accession) { >+ $sql_query .= " AND dateaccessioned <= ? "; >+ push @sql_params, $end_accession->output('iso'); >+ } > >- if ($end_accession) { >- $query .= " AND dateaccessioned <= ? "; >- push @sql_params, $end_accession->output('iso'); >+ if ( $itemtype ) { >+ $sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?"; >+ push @sql_params, $itemtype; >+ } > } >- >- if ( $itemtype ) { >- $query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?"; >- push @sql_params, $itemtype; >+ elsif ( $record_type eq 'auths' ) { >+ $sql_query = >+ "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1"; >+ >+ if ($starting_authid) { >+ $sql_query .= " AND auth_header.authid >= ? "; >+ push @sql_params, $starting_authid; >+ } >+ >+ if ($ending_authid) { >+ $sql_query .= " AND auth_header.authid <= ? "; >+ push @sql_params, $ending_authid; >+ } >+ >+ if ($authtype) { >+ $sql_query .= " AND auth_header.authtypecode = ? "; >+ push @sql_params, $authtype; >+ } > } >- my $sth = $dbh->prepare($query); >+ >+ my $sth = $dbh->prepare($sql_query); > $sth->execute(@sql_params); >- >- while (my ($biblionumber) = $sth->fetchrow) { >- my $record = eval{ GetMarcBiblio($biblionumber); }; >- # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve >- if ($@) { >- next; >- } >- next if not defined $record; >- C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) unless $dont_export_items; >- if ($strip_nonlocal_items || $limit_ind_branch) { >- my ( $homebranchfield, $homebranchsubfield ) = >- GetMarcFromKohaField( 'items.homebranch', '' ); >- for my $itemfield ($record->field($homebranchfield)){ >- # if stripping nonlocal items, use loggedinuser's branch if they didn't select one >- $branch = C4::Context->userenv->{'branch'} unless $branch; >- $record->delete_field($itemfield) if($itemfield->subfield($homebranchsubfield) ne $branch) ; >+ >+ while ( my ($recordid) = $sth->fetchrow ) { >+ my $record; >+ if ( $record_type eq 'bibs' ) { >+ $record = eval { GetMarcBiblio($recordid); }; >+ >+ # FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve >+ if ($@) { >+ next; >+ } >+ next if not defined $record; >+ C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid ) >+ unless $dont_export_items; >+ if ( $strip_nonlocal_items || $limit_ind_branch ) { >+ my ( $homebranchfield, $homebranchsubfield ) = >+ GetMarcFromKohaField( 'items.homebranch', '' ); >+ for my $itemfield ( $record->field($homebranchfield) ) { >+ >+# if stripping nonlocal items, use loggedinuser's branch if they didn't select one >+ $branch = C4::Context->userenv->{'branch'} unless $branch; >+ $record->delete_field($itemfield) >+ if ( >+ $itemfield->subfield($homebranchsubfield) ne $branch ); >+ } > } > } >- >+ elsif ( $record_type eq 'auths' ) { >+ $record = C4::AuthoritiesMarc::GetAuthority($recordid); >+ next if not defined $record; >+ } >+ > if ( $dont_export_fields ) { > my @fields = split " ", $dont_export_fields; > foreach ( @fields ) { >@@ -165,12 +213,12 @@ if ($op eq "export") { > print $record->as_xml_record($marcflavour); > } > else { >- print $record->as_usmarc(); >+ print $record->as_usmarc(); > } > } > exit; >- >-} # if export >+ >+} # if export > > else { > >@@ -196,11 +244,23 @@ else { > }; > } > >+ my $authtypes = getauthtypes; >+ my @authtypesloop; >+ foreach my $thisauthtype ( sort keys %$authtypes ) { >+ next unless $thisauthtype; >+ my %row = ( >+ value => $thisauthtype, >+ description => $authtypes->{$thisauthtype}->{'authtypetext'}, >+ ); >+ push @authtypesloop, \%row; >+ } >+ > $template->param( >- branchloop => \@branchloop, >- itemtypeloop => \@itemtypesloop, >- DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), >+ branchloop => \@branchloop, >+ itemtypeloop => \@itemtypesloop, >+ DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), >+ authtypeloop => \@authtypesloop, > ); >- >+ > output_html_with_http_headers $query, $cookie, $template->output; > } >-- >1.7.2.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 8202
:
10305
|
10311
|
10607
|
10629
|
10630