@@ -, +, @@
export tool
instance, "Add new field 999$9 with value foobar")
records
---
C4/Record.pm | 20 ++-
Koha/Exporter/Record.pm | 18 ++-
.../prog/en/modules/tools/export.tt | 25 ++-
t/db_dependent/Exporter/Record.t | 148 +++++++++++++++---
tools/export.pl | 5 +
5 files changed, 186 insertions(+), 30 deletions(-)
--- a/C4/Record.pm
+++ a/C4/Record.pm
@@ -29,6 +29,7 @@ use Unicode::Normalize; # _entity_encode
use C4::Biblio; #marc2bibtex
use C4::Koha; #marc2csv
use C4::XSLT ();
+use C4::MarcModificationTemplates;
use YAML; #marcrecords2csv
use Template;
use Text::CSV::Encoded; #marc2csv
@@ -403,10 +404,12 @@ C<$csvprofileid> - the id of the CSV profile to use for the export (see export_f
C<$itemnumbers> - a list of itemnumbers to export
+C<$marc_modification_template_id> - MARC modification template to apply
+
=cut
sub marc2csv {
- my ($biblios, $id, $itemnumbers) = @_;
+ my ($biblios, $id, $itemnumbers, $marc_modification_template_id) = @_;
$itemnumbers ||= [];
my $output;
my $csv = Text::CSV::Encoded->new();
@@ -426,12 +429,12 @@ sub marc2csv {
for my $itemnumber ( @$itemnumbers) {
my $item = Koha::Items->find( $itemnumber );
my $biblionumber = $item->biblio->biblionumber;
- $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ) // '';
+ $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber], $marc_modification_template_id ) // '';
$firstpass = 0;
}
} else {
foreach my $biblio (@$biblios) {
- $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing ) // '';
+ $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing, undef, $marc_modification_template_id ) // '';
$firstpass = 0;
}
}
@@ -444,7 +447,7 @@ sub marc2csv {
=head2 marcrecord2csv - Convert a single record from UNIMARC to CSV
- my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header);
+ my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id);
Returns a CSV scalar
@@ -460,10 +463,12 @@ C<$fieldprocessing>
C<$itemnumbers> a list of itemnumbers to export
+C<$marc_modification_template_id> - MARC modification template to apply
+
=cut
sub marcrecord2csv {
- my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
+ my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id) = @_;
my $output;
# Getting the record
@@ -473,6 +478,11 @@ sub marcrecord2csv {
marc_record => $record,
biblionumber => $biblio,
item_numbers => $itemnumbers });
+
+ if ($marc_modification_template_id) {
+ C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
+ }
+
# Getting the framework
my $frameworkcode = GetFrameworkCode($biblio);
--- a/Koha/Exporter/Record.pm
+++ a/Koha/Exporter/Record.pm
@@ -7,6 +7,7 @@ use MARC::File::USMARC;
use C4::AuthoritiesMarc;
use C4::Biblio;
use C4::Record;
+use C4::MarcModificationTemplates;
use Koha::CsvProfiles;
use Koha::Logger;
use List::Util qw(all any);
@@ -155,6 +156,7 @@ sub export {
my $dont_export_fields = $params->{dont_export_fields};
my $csv_profile_id = $params->{csv_profile_id};
my $output_filepath = $params->{output_filepath};
+ my $marc_modification_template_id = $params->{marc_modification_template_id};
if( !$record_type ) {
Koha::Logger->get->warn( "No record_type given." );
@@ -183,6 +185,11 @@ sub export {
Koha::Logger->get->info( $msg );
next;
}
+
+ if ($marc_modification_template_id) {
+ C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
+ }
+
print $record->as_usmarc();
}
} elsif ( $format eq 'xml' ) {
@@ -194,6 +201,11 @@ sub export {
for my $record_id (@$record_ids) {
my $record = _get_record_for_export( { %$params, record_id => $record_id } );
next unless $record;
+
+ if ($marc_modification_template_id) {
+ C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
+ }
+
print MARC::File::XML::record($record);
print "\n";
}
@@ -202,7 +214,7 @@ sub export {
} elsif ( $format eq 'csv' ) {
die 'There is no valid csv profile defined for this export'
unless Koha::CsvProfiles->find( $csv_profile_id );
- print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
+ print marc2csv( $record_ids, $csv_profile_id, $itemnumbers, $marc_modification_template_id );
}
close $fh if $output_filepath;
@@ -263,6 +275,10 @@ It will displays on STDOUT the generated file.
If the format is csv, you have to define a csv_profile_id.
+=item marc_modification_template_id
+
+ Apply MARC modification template to records before export
+
=cut
=back
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt
@@ -129,7 +129,19 @@
separate by a blank. (e.g., 100a 200 606)
-
+
+ [% IF marc_modification_templates.size > 0 %]
+
+
+
+
+ [% END %]
+