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

(-)a/C4/Reports/Guided.pm (-2 / +7 lines)
Lines 496-502 sub strip_limit { Link Here
496
496
497
sub execute_query {
497
sub execute_query {
498
498
499
    my ( $sql, $offset, $limit, $sql_params ) = @_;
499
    my ( $sql, $offset, $limit, $sql_params, $report_id ) = @_;
500
500
501
    $sql_params = [] unless defined $sql_params;
501
    $sql_params = [] unless defined $sql_params;
502
502
Lines 531-538 sub execute_query { Link Here
531
    }
531
    }
532
    $sql .= " LIMIT ?, ?";
532
    $sql .= " LIMIT ?, ?";
533
533
534
    my $sth = C4::Context->dbh->prepare($sql);
534
    my $dbh = C4::Context->dbh;
535
536
    $dbh->do( 'UPDATE saved_sql SET last_run = NOW() WHERE id = ?', undef, $report_id ) if $report_id;
537
538
    my $sth = $dbh->prepare($sql);
535
    $sth->execute(@$sql_params, $offset, $limit);
539
    $sth->execute(@$sql_params, $offset, $limit);
540
536
    return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err);
541
    return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err);
537
    return ( $sth );
542
    return ( $sth );
538
}
543
}
(-)a/misc/cronjobs/runreport.pl (-2 / +1 lines)
Lines 249-256 foreach my $report_id (@ARGV) { Link Here
249
            $subject = 'Koha Saved Report';
249
            $subject = 'Koha Saved Report';
250
        }
250
        }
251
    }
251
    }
252
    # my $results = execute_query($sql, undef, 0, 99999, $format, $report_id);
252
    my ($sth) = execute_query( $sql, undef, undef, undef, $report_id );
253
    my ($sth) = execute_query($sql);
254
    my $count = scalar($sth->rows);
253
    my $count = scalar($sth->rows);
255
    unless ($count) {
254
    unless ($count) {
256
        print "NO OUTPUT: 0 results from execute_query\n";
255
        print "NO OUTPUT: 0 results from execute_query\n";
(-)a/opac/svc/report (-1 / +1 lines)
Lines 61-67 unless ($json_text) { Link Here
61
    $sql =~ s/(<<.*?>>)/\?/g;
61
    $sql =~ s/(<<.*?>>)/\?/g;
62
62
63
    my ( $sth, $errors ) =
63
    my ( $sth, $errors ) =
64
      execute_query( $sql, $offset, $limit, \@sql_params );
64
      execute_query( $sql, $offset, $limit, \@sql_params, $report_id );
65
    if ($sth) {
65
    if ($sth) {
66
        my $lines;
66
        my $lines;
67
        if ($report_annotation) {
67
        if ($report_annotation) {
(-)a/reports/guided_reports.pl (-1 / +1 lines)
Lines 772-778 elsif ($phase eq 'Run this report'){ Link Here
772
                $quoted = C4::Context->dbh->quote($quoted);
772
                $quoted = C4::Context->dbh->quote($quoted);
773
                $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
773
                $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
774
            }
774
            }
775
            my ($sth, $errors) = execute_query($sql, $offset, $limit);
775
            my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id );
776
            my $total = nb_rows($sql) || 0;
776
            my $total = nb_rows($sql) || 0;
777
            unless ($sth) {
777
            unless ($sth) {
778
                die "execute_query failed to return sth for report $report_id: $sql";
778
                die "execute_query failed to return sth for report $report_id: $sql";
(-)a/svc/report (-1 / +1 lines)
Lines 65-71 unless ($json_text) { Link Here
65
    # convert SQL parameters to placeholders
65
    # convert SQL parameters to placeholders
66
    $sql =~ s/(<<.*?>>)/\?/g;
66
    $sql =~ s/(<<.*?>>)/\?/g;
67
67
68
    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, \@sql_params );
68
    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, \@sql_params, $report_id );
69
    if ($sth) {
69
    if ($sth) {
70
        my $lines;
70
        my $lines;
71
        if ($report_annotation) {
71
        if ($report_annotation) {
(-)a/t/db_dependent/Reports/Guided.t (-2 / +29 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 7;
21
use Test::More tests => 8;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
Lines 260-265 subtest 'get_saved_reports' => sub { Link Here
260
        "get_report_areas returns the correct array of report areas");
260
        "get_report_areas returns the correct array of report areas");
261
};
261
};
262
262
263
subtest 'Ensure last_run is populated' => sub {
264
    plan tests => 3;
265
266
    my $rs = Koha::Database->new()->schema()->resultset('SavedSql');
267
268
    my $report = $rs->new(
269
        {
270
            report_name => 'Test Report',
271
            savedsql    => 'SELECT * FROM branches',
272
            notes       => undef,
273
        }
274
    )->insert();
275
276
    is( $report->last_run, undef, 'Newly created report has null last_run ' );
277
278
    execute_query( $report->savedsql, undef, undef, undef, $report->id );
279
    $report->discard_changes();
280
281
    isnt( $report->last_run, undef, 'First run of report populates last_run' );
282
283
    my $previous_last_run = $report->last_run;
284
    sleep(1); # last_run is stored to the second, so we need to ensure at least one second has passed between runs
285
    execute_query( $report->savedsql, undef, undef, undef, $report->id );
286
    $report->discard_changes();
287
288
    isnt( $report->last_run, $previous_last_run, 'Second run of report updates last_run' );
289
};
290
263
$schema->storage->txn_rollback;
291
$schema->storage->txn_rollback;
264
292
265
sub trim {
293
sub trim {
266
- 

Return to bug 14365