From f60995d78ed1d4931e033bb5d69528b038ecef30 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 30 Dec 2015 18:26:17 +0000 Subject: [PATCH] Bug 15451: Koha::CsvProfiles - Remove GetCsvProfile This subroutine just returned a csv profile for a given id. It is replaced in this patch by a call to Koha::CsvProfiles->find. There is nothing to test here, these changes have been tested in previous patches. --- C4/Csv.pm | 13 ------------- C4/Record.pm | 13 +++++++------ serials/lateissues-export.pl | 12 +++++++----- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/C4/Csv.pm b/C4/Csv.pm index cc88c01..2cd6430 100644 --- a/C4/Csv.pm +++ b/C4/Csv.pm @@ -31,23 +31,10 @@ use vars qw(@ISA @EXPORT); # only export API methods @EXPORT = qw( - &GetCsvProfile &GetMarcFieldsForCsv ); -# Returns all informations about a given csv profile -sub GetCsvProfile { - my ($id) = @_; - my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM export_format WHERE export_format_id=?"; - - $sth = $dbh->prepare($query); - $sth->execute($id); - - return ($sth->fetchrow_hashref); -} - # Returns fields to extract for the given csv profile sub GetMarcFieldsForCsv { diff --git a/C4/Record.pm b/C4/Record.pm index a3c1e8e..dbbde57 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -37,6 +37,7 @@ use Template; use Text::CSV::Encoded; #marc2csv use Koha::SimpleMARC qw(read_field); use Koha::XSLT_Handler; +use Koha::CsvProfiles; use Carp; use vars qw(@ISA @EXPORT); @@ -475,14 +476,14 @@ sub marcrecord2csv { my $frameworkcode = GetFrameworkCode($biblio); # Getting information about the csv profile - my $profile = GetCsvProfile($id); + my $profile = Koha::CsvProfiles->find($id); # Getting output encoding - my $encoding = $profile->{encoding} || 'utf8'; + my $encoding = $profile->encoding || 'utf8'; # Getting separators - my $csvseparator = $profile->{csv_separator} || ','; - my $fieldseparator = $profile->{field_separator} || '#'; - my $subfieldseparator = $profile->{subfield_separator} || '|'; + my $csvseparator = $profile->csv_separator || ','; + my $fieldseparator = $profile->field_separator || '#'; + my $subfieldseparator = $profile->subfield_separator || '|'; # TODO: Be more generic (in case we have to handle other protected chars or more separators) if ($csvseparator eq '\t') { $csvseparator = "\t" } @@ -496,7 +497,7 @@ sub marcrecord2csv { $csv->sep_char($csvseparator); # Getting the marcfields - my $marcfieldslist = $profile->{content}; + my $marcfieldslist = $profile->content; # Getting the marcfields as an array my @marcfieldsarray = split('\|', $marcfieldslist); diff --git a/serials/lateissues-export.pl b/serials/lateissues-export.pl index a75b21c..00804ca 100755 --- a/serials/lateissues-export.pl +++ b/serials/lateissues-export.pl @@ -22,7 +22,9 @@ use C4::Serials; use C4::Acquisition; use C4::Output; use C4::Context; -use C4::Csv qw( GetCsvProfile ); +use C4::Csv; + +use Koha::CsvProfiles; use Text::CSV_XS; @@ -32,17 +34,17 @@ my @serialids = $query->param('serialid'); my $op = $query->param('op') || q{}; my $csv_profile_id = $query->param('csv_profile'); -my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id ); +my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id ); die "There is no valid csv profile given" unless $csv_profile; my $csv = Text::CSV_XS->new({ 'quote_char' => '"', 'escape_char' => '"', - 'sep_char' => $csv_profile->{csv_separator}, + 'sep_char' => $csv_profile->csv_separator, 'binary' => 1 }); -my $content = $csv_profile->{content}; +my $content = $csv_profile->content; my ( @headers, @fields ); while ( $content =~ / ([^=]+) # header @@ -75,7 +77,7 @@ print $query->header( -attachment => "serials-claims.csv", ); -print join( $csv_profile->{csv_separator}, @headers ) . "\n"; +print join( $csv_profile->csv_separator, @headers ) . "\n"; for my $row ( @rows ) { $csv->combine(@$row); -- 2.7.0