From 234cced91df51c2460152897f8c08e0b891d240c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 11 Jan 2021 14:57:45 +0000 Subject: [PATCH] Bug 24108: Make export file names consistent This patch renames the systempreference to be a bit clearer and uses explicit options rather than a yes/no Additionally it standardizes the export from the advanced cataloging editor with that from the details page To test: 1 - Apply patches 2 - Update database and restart all the things 3 - Open a record in the advanced editor and save it as marc and xml 4 - Note the file name is 'bib-{biblionumber.{format}' 5 - Edit the syspref 'DefaultSaveRecordFileID' to be control number 6 - Repeate 3-4 on a record with and without a control number 7 - If control number present fiule name should be 'record-{controlnumber}.{format}' 8 - Otherwise it should be as above 9 - Repeat tests from the details page of a record 10 - Repeat tests from the opac details page of a record Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- catalogue/export.pl | 13 +++++++++- ...dd_SaveRecordbyControlNumber_syspref.perl} | 2 +- installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/includes/cateditor-ui.inc | 24 +++++++++---------- .../admin/preferences/cataloguing.pref | 11 ++++----- opac/opac-export.pl | 19 +++++++++++---- 6 files changed, 46 insertions(+), 24 deletions(-) rename installer/data/mysql/atomicupdate/{bug_24108-add_SaveRecordbyControlNumber_syspref.sql => bug_24108-add_SaveRecordbyControlNumber_syspref.perl} (52%) diff --git a/catalogue/export.pl b/catalogue/export.pl index b42b95b7ab..f12cd57c53 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -25,11 +25,22 @@ my $error = ''; if ($op eq "export") { my $biblionumber = $query->param("bib"); if ($biblionumber){ + my $file_id = $biblionumber; + my $file_pre = "bib-"; my $marc = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); + if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ + my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour + my $control_num = GetMarcControlnumber( $marc, $marcflavour ); + if( $control_num ){ + $file_id = $control_num; + $file_pre = "record-"; + } + } + if ($format =~ /endnote/) { $marc = marc2endnote($marc); $format = 'endnote'; @@ -74,7 +85,7 @@ if ($op eq "export") { } print $query->header( -type => 'application/octet-stream', - -attachment=>"bib-$biblionumber.$format"); + -attachment=>"$file_pre$file_id.$format"); print $marc; } } diff --git a/installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.sql b/installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.perl similarity index 52% rename from installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.sql rename to installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.perl index de105c3d54..9e27bcd8c2 100644 --- a/installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.sql +++ b/installer/data/mysql/atomicupdate/bug_24108-add_SaveRecordbyControlNumber_syspref.perl @@ -3,7 +3,7 @@ if( CheckVersion( $DBversion ) ) { $dbh->do(q{ INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES - ('SaveRecordbyControlNumber', '0', 'If set, advanced cataloging editor will use the control number field to populate the name of the save file, otherwise it uses the biblionumber.', NULL, 'YesNo') + ('DefaultSaveRecordFileID', 'biblionumber', 'Defines whether the advanced cataloging editor will use the bibliographic record number or control number field to populate the name of the save file.', 'biblionumber|controlnumber', 'Choice') }); NewVersion( $DBversion, 24108, "Add system preference SaveRecordbyControlNumber"); } diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index eab5e66838..36c5a9d715 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -157,6 +157,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DefaultLongOverdueDays', '', NULL, "Set the LOST value of an item when the item has been overdue for more than n days.", 'integer'), ('DefaultLongOverdueLostValue', '', NULL, "Set the LOST value of an item to n when the item has been overdue for more than defaultlongoverduedays days.", 'integer'), ('DefaultPatronSearchFields', 'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search using the "standard" option. If empty Koha will default to "surname,firstname,othernames,cardnumber,userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','free'), +('DefaultSaveRecordFileID','biblionumber','biblionumber|controlnumber','Defines whether the advanced cataloging editor will use the bibliographic record number or control number field to populate the name of the save file','Choice') ('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'), ('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'), ('DefaultToLoggedInLibraryCircRules', '0', NULL , 'If enabled, circ rules editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.', 'YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index a869ab08ea..822f984e6f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -291,14 +291,14 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr save: function( id, record, done ) { var recname = 'record.mrc'; if(state.recordID) { - recname = state.recordID+'.mrc'; + recname = 'bib-'+state.recordID+'.mrc'; } - [% IF (Koha.Preference('SaveRecordbyControlNumber') == '1') %] - var controlnumfield = record.field('001'); - if(controlnumfield) { - recname = controlnumfield.subfield('@')+'.mrc'; - } + [% IF (Koha.Preference('DefaultSaveRecordFileID') == 'controlnumber') %] + var controlnumfield = record.field('001'); + if(controlnumfield) { + recname = 'record-'+controlnumfield.subfield('@')+'.mrc'; + } [% END %] saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), recname ); @@ -310,14 +310,14 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr save: function( id, record, done ) { var recname = 'record.xml'; if(state.recordID) { - recname = state.recordID+'.xml'; + recname = 'bib-'+state.recordID+'.xml'; } - [% IF (Koha.Preference('SaveRecordbyControlNumber') == '1') %] - var controlnumfield = record.field('001'); - if(controlnumfield) { - recname = controlnumfield.subfield('@')+'.xml'; - } + [% IF (Koha.Preference('DefaultSaveRecordFileID') == 'controlnumber') %] + var controlnumfield = record.field('001'); + if(controlnumfield) { + recname = 'record-'+controlnumfield.subfield('@')+'.xml'; + } [% END %] saveAs( new Blob( [record.toXML()], { 'type': 'application/octe t-stream;charset=utf-8' } ), recname ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 9514784262..bec1975a20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -29,13 +29,12 @@ Cataloging: - Currently does not include support for UNIMARC or NORMARC fixed fields. - - "When saving in a MARC/MARCXML file in the advanced cataloging editor, use the" - - pref: SaveRecordbyControlNumber - default: 0 + - pref: DefaultSaveRecordFileID + default: biblionumber choices: - yes: Enable - yes: "control number" - no: "record number" - - "in the file name. The default is to use the bibliographic record number." + controlnumber: "control number" + biblionumber: "bibliographic record number" + - "in the file name." Spine labels: - - When using the quick spine label printer, diff --git a/opac/opac-export.pl b/opac/opac-export.pl index 402d1fee0d..82954d660f 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -61,6 +61,17 @@ if(!$marc) { exit; } +my $file_id = $biblionumber; +my $file_pre = "bib-"; +if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ + my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour + my $control_num = GetMarcControlnumber( $marc, $marcflavour ); + if( $control_num ){ + $file_id = $control_num; + $file_pre = "record-"; + } +} + # ASSERT: There is a biblionumber, because GetMarcBiblio returned something. my $framework = GetFrameworkCode( $biblionumber ); my $record_processor = Koha::RecordProcessor->new({ @@ -136,27 +147,27 @@ else { print $query->header( -type => 'application/marc', -charset=>'ISO-2022', - -attachment=>"bib-$biblionumber.$format"); + -attachment=>"$file_pre$file_id.$format"); } elsif ( $format eq 'isbd' ) { print $query->header( -type => 'text/plain', -charset => 'utf-8', - -attachment => "bib-$biblionumber.txt" + -attachment => "$file_pre$file_id.txt" ); } elsif ( $format eq 'ris' ) { print $query->header( -type => 'text/plain', -charset => 'utf-8', - -attachment => "bib-$biblionumber.$format" + -attachment => "$file_pre$file_id.$format" ); } else { binmode STDOUT, ':encoding(UTF-8)'; print $query->header( -type => 'application/octet-stream', -charset => 'utf-8', - -attachment => "bib-$biblionumber.$format" + -attachment => "$file_pre$file_id.$format" ); } print $marc; -- 2.39.5