View | Details | Raw Unified | Return to bug 36770
Collapse All | Expand All

(-)a/misc/export_records.pl (-2 / +56 lines)
Lines 26-37 use Koha::Script; Link Here
26
use C4::Auth;
26
use C4::Auth;
27
use C4::Context;
27
use C4::Context;
28
use C4::Record;
28
use C4::Record;
29
use C4::Reports::Guided qw( execute_query );
29
30
30
use Koha::Biblioitems;
31
use Koha::Biblioitems;
31
use Koha::Database;
32
use Koha::Database;
32
use Koha::CsvProfiles;
33
use Koha::CsvProfiles;
33
use Koha::Exporter::Record;
34
use Koha::Exporter::Record;
34
use Koha::DateUtils qw( dt_from_string output_pref );
35
use Koha::DateUtils qw( dt_from_string output_pref );
36
use Koha::Reports;
35
37
36
my (
38
my (
37
    $output_format,
39
    $output_format,
Lines 55-60 my ( Link Here
55
    $end_accession,
57
    $end_accession,
56
    $marc_conditions,
58
    $marc_conditions,
57
    $embed_see_from_headings,
59
    $embed_see_from_headings,
60
    $report_id,
61
    @report_params,
62
    $report,
63
    $sql,
64
    $params_needed,
58
    $help
65
    $help
59
);
66
);
60
67
Lines 80-85 GetOptions( Link Here
80
    'end_accession=s'         => \$end_accession,
87
    'end_accession=s'         => \$end_accession,
81
    'marc_conditions=s'       => \$marc_conditions,
88
    'marc_conditions=s'       => \$marc_conditions,
82
    'embed_see_from_headings' => \$embed_see_from_headings,
89
    'embed_see_from_headings' => \$embed_see_from_headings,
90
    'report_id=s'             => \$report_id,
91
    'report_param=s'          => \@report_params,
83
    'h|help|?'                => \$help
92
    'h|help|?'                => \$help
84
) || pod2usage(1);
93
) || pod2usage(1);
85
94
Lines 111-116 if ( $deleted_barcodes and $record_type ne 'bibs' ) { Link Here
111
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
120
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
112
}
121
}
113
122
123
if ( $report_id ) {
124
125
    # Check report exists
126
    $report = Koha::Reports->find( $report_id );
127
    unless ( $report ) {
128
        pod2usage( sprintf( "No saved report (%s) found", $report_id ) );
129
    }
130
131
    # Check report can be used to export records
132
    unless ( $sql =~ /biblionumber/ || $sql =~ /authid/) {
133
        pod2usage(q|The --report_id you specified does not fetch a biblionumber or authid|);
134
    }
135
    $sql = $report->savedsql;
136
137
    # convert SQL parameters to placeholders
138
    my $params_needed = ( $sql =~ s/(<<[^>]+>>)/\?/g );
139
    die("You supplied ". scalar @report_params . " parameter(s) and $params_needed are required by the report") if scalar @report_params != $params_needed;
140
141
}
142
114
$start_accession = dt_from_string( $start_accession ) if $start_accession;
143
$start_accession = dt_from_string( $start_accession ) if $start_accession;
115
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
144
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
116
145
Lines 141-147 my @record_ids; Link Here
141
$timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), dateformat => 'iso', dateonly => 0, }): '';
170
$timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), dateformat => 'iso', dateonly => 0, }): '';
142
171
143
if ( $record_type eq 'bibs' ) {
172
if ( $record_type eq 'bibs' ) {
144
    if ( $timestamp ) {
173
    
174
    if ( $report ) {
175
        my ($sth) = execute_query(
176
            {
177
                sql        => $sql,
178
                sql_params => \@report_params,
179
                report_id  => $report_id,
180
            }
181
        );
182
        my $count = scalar($sth->rows);
183
184
        while ( my $row = $sth->fetchrow_hashref() ) {
185
            push @record_ids, $row->{biblionumber};
186
        }
187
188
    } elsif ( $timestamp ) {
145
        if (!$dont_export_items) {
189
        if (!$dont_export_items) {
146
            push @record_ids, $_->{biblionumber} for @{
190
            push @record_ids, $_->{biblionumber} for @{
147
                $dbh->selectall_arrayref(q| (
191
                $dbh->selectall_arrayref(q| (
Lines 402-407 Print a brief help message. Link Here
402
446
403
 --embed_see_from_headings      Embed see from (non-preferred form) headings in bibliographic record.
447
 --embed_see_from_headings      Embed see from (non-preferred form) headings in bibliographic record.
404
448
449
=item B<--report_id>
450
451
--report_id=ID                  Export biblionumbers or authids from a given saved report output.
452
453
=item B<--report_param>
454
455
--report_param=PARAM            Repeatable, should provide one param per param requested for the 
456
                                report.
457
                                Report params are not combined as on the staff side, so you may 
458
                                need to repeat params.
459
405
=back
460
=back
406
461
407
=head1 AUTHOR
462
=head1 AUTHOR
408
- 

Return to bug 36770