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.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
# 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 {
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);
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" }
$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);
use C4::Acquisition;
use C4::Output;
use C4::Context;
-use C4::Csv qw( GetCsvProfile );
+use C4::Csv;
+
+use Koha::CsvProfiles;
use Text::CSV_XS;
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
-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);