From d82458fc5d9b2b0807e4b31b533bdde433b3ed8a Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 3 Jul 2024 09:52:45 +0000 Subject: [PATCH] Bug 36831: Allow for multiple file types This patch allows the KBART import tool to accept different filetypes and then work out whether they are CSV or TSV files. Test plan: 1) Try to import the file attached to the bug using the KBART import tool (E-resource management > eHoldings > Local > Titles > Import from a KBART file) 2) It should return an error saying that the file must be .csv or .tsv 3) Apply patch 4) yarn build 5) restart_all 6) Repeat step 1 7) The file should now successfully import --- Koha/REST/V1/ERM/EHoldings/Titles/Local.pm | 13 +++++-------- .../ERM/EHoldingsLocalTitlesKBARTImport.vue | 17 +---------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm index c45d4d69140..20edd57df98 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm @@ -281,15 +281,12 @@ sub import_from_kbart_file { my @invalid_columns; my $max_allowed_packet = C4::Context->dbh->selectrow_array(q{SELECT @@max_allowed_packet}); - # Check if file is in TSV or CSV format and send an error back if not - if ( $file->{filename} !~ /\.csv$/ && $file->{filename} !~ /\.tsv$/ ) { - return $c->render( - status => 201, - openapi => { invalid_filetype => 1 } - ); - } + my ( $column_headers, $rows, $error ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); - my ( $column_headers, $rows ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); + return $c->render( + status => 201, + openapi => { invalid_filetype => 1 } + ) if $error eq 'unknown_delimiter'; # Check that the column headers in the file match the standardised KBART phase II columns # If not, return a warning diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue index 5049bf9cb09..5cb0081f6e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue @@ -2,21 +2,6 @@

{{ $__("Import from a KBART file") }}

-

{{ $__("Requirements:") }}

-
    -
  • {{ $__("The file must be in TSV or CSV format") }}
  • -
  • - {{ - $__( - "The file should not contain any additional information / header rows, e.g. a file with a single title would be structured as follows:" - ) - }} -
      -
    1. {{ $__("Column headings row") }}
    2. -
    3. {{ $__("Title data row") }}
    4. -
    -
  • -

{{ $__("Select file for upload") }}:

    @@ -173,7 +158,7 @@ export default { } if (success.invalid_filetype) { message += `

    ${this.$__( - "The file must be in .tsv or .csv format, please convert your file and try again." + "Could not detect whether the file is TSV or CSV, please check the file." )}

    ` setWarning(message) } -- 2.39.3 (Apple Git-146)