This subroutine returned the export_format_id for a given profile name.
This can be done easily with the Koha::CsvProfiles->search method.
Test plan:
Export records using the misc/export_records.pl script and the
export tool.
If you are exporting using the MARC format, the profile filled in the pref
ExportWithCsvProfile will be used (or the one passed in parameter of
misc/export_records.pl).
If you are exporting using the CSV format, you can choose a profile in
the dropdown list.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Exported using tool & cmd, marc & csv. Pref is used.
No errors
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
@EXPORT = qw(
&GetCsvProfile
@EXPORT = qw(
&GetCsvProfile
return ($sth->fetchrow_hashref);
}
return ($sth->fetchrow_hashref);
}
-# Returns id of csv profile about a given csv profile name
-sub GetCsvProfileId {
- my ($name) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "SELECT export_format_id FROM export_format WHERE profile=?";
-
- $sth = $dbh->prepare($query);
- $sth->execute($name);
-
- return ( $sth->fetchrow );
-}
-
# Returns fields to extract for the given csv profile
sub GetMarcFieldsForCsv {
# Returns fields to extract for the given csv profile
sub GetMarcFieldsForCsv {
use C4::AuthoritiesMarc;
use C4::Biblio;
use C4::Record;
use C4::AuthoritiesMarc;
use C4::Biblio;
use C4::Record;
sub _get_record_for_export {
my ($params) = @_;
sub _get_record_for_export {
my ($params) = @_;
print MARC::File::XML::footer();
print "\n";
} elsif ( $format eq 'csv' ) {
print MARC::File::XML::footer();
print "\n";
} elsif ( $format eq 'csv' ) {
- $csv_profile_id ||= C4::Csv::GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') );
+ $csv_profile_id ||= Koha::CsvProfiles->search({ profile => C4::Context->preference('ExportWithCsvProfile') })->export_format_id;
print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
}
print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
}
use Koha::Biblioitems;
use Koha::Database;
use Koha::Biblioitems;
use Koha::Database;
use Koha::Exporter::Record;
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Exporter::Record;
use Koha::DateUtils qw( dt_from_string output_pref );
+ unless ( $csv_profile_id ) {
+ my $default_csv_profile = Koha::CsvProfiles->search({ profile => C4::Context->preference('ExportWithCsvProfile') });
+ $csv_profile_id = $default_csv_profile ? $default_csv_profile->export_format_id : undef;
+ }
Koha::Exporter::Record::export(
{ record_type => $record_type,
record_ids => \@record_ids,
format => $output_format,
Koha::Exporter::Record::export(
{ record_type => $record_type,
record_ids => \@record_ids,
format => $output_format,
- csv_profile_id => ( $csv_profile_id || GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ) || undef ),
+ csv_profile_id => $csv_profile_id,
export_items => (not $dont_export_items),
clean => $clean || 0,
}
export_items => (not $dont_export_items),
clean => $clean || 0,
}
-attachment => $filename,
);
-attachment => $filename,
);
+ my $csv_profile_id = $query->param('csv_profile_id');
+ unless ( $csv_profile_id ) {
+ my $default_csv_profile = Koha::CsvProfiles->search({ profile => C4::Context->preference('ExportWithCsvProfile') });
+ $csv_profile_id = $default_csv_profile ? $default_csv_profile->export_format_id : undef;
+ }
+
Koha::Exporter::Record::export(
{ record_type => $record_type,
record_ids => \@record_ids,
Koha::Exporter::Record::export(
{ record_type => $record_type,
record_ids => \@record_ids,
filename => $filename,
itemnumbers => \@itemnumbers,
dont_export_fields => $export_remove_fields,
filename => $filename,
itemnumbers => \@itemnumbers,
dont_export_fields => $export_remove_fields,
- csv_profile_id => ( $query->param('csv_profile_id') || GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ) || undef ),
+ csv_profile_id => $csv_profile_id,
export_items => (not $dont_export_items),
}
);
export_items => (not $dont_export_items),
}
);
itemtypeloop => \@itemtypesloop,
authority_types => $authority_types,
export_remove_fields => C4::Context->preference("ExportRemoveFields"),
itemtypeloop => \@itemtypesloop,
authority_types => $authority_types,
export_remove_fields => C4::Context->preference("ExportRemoveFields"),
- csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }),
+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
);
output_html_with_http_headers $query, $cookie, $template->output;
);
output_html_with_http_headers $query, $cookie, $template->output;