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

(-)a/C4/Reports/Guided.pm (-5 / +23 lines)
Lines 607-619 sub get_saved_reports { Link Here
607
}
607
}
608
608
609
sub get_saved_report {
609
sub get_saved_report {
610
    my ($id)  = @_;
611
    my $dbh   = C4::Context->dbh();
610
    my $dbh   = C4::Context->dbh();
612
    my $query = " SELECT * FROM saved_sql WHERE id = ?";
611
    my $query;
613
    my $sth   = $dbh->prepare($query);
612
    my $sth;
614
    $sth->execute($id);
613
    my $report_arg;
614
    if ($#_ == 0 && ref $_[0] eq 'SCALAR') {
615
        ($report_arg) = @_;
616
        $query = " SELECT * FROM saved_sql WHERE id = ?";
617
    } elsif (ref $_[0] eq 'HASH') {
618
        my ($selector) = @_;
619
        if ($selector->{name}) {
620
            $query = " SELECT * FROM saved_sql WHERE report_name = ?";
621
            $report_arg = $selector->{name};
622
        } elsif ($selector->{id} || $selector->{id} eq '0') {
623
            $query = " SELECT * FROM saved_sql WHERE id = ?";
624
            $report_arg = $selector->{id};
625
        } else {
626
            return;
627
        }
628
    } else {
629
        return;
630
    }
631
    $sth   = $dbh->prepare($query);
632
    $sth->execute($report_arg);
615
    my $data = $sth->fetchrow_hashref();
633
    my $data = $sth->fetchrow_hashref();
616
    return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'}, $data->{'cache_expiry'}, $data->{'public'} );
634
    return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'}, $data->{'cache_expiry'}, $data->{'public'}, $data->{'id'} );
617
}
635
}
618
636
619
=item create_compound($masterID,$subreportID)
637
=item create_compound($masterID,$subreportID)
(-)a/opac/svc/report (-13 / +16 lines)
Lines 28-45 use CGI; Link Here
28
use Koha::Cache;
28
use Koha::Cache;
29
29
30
my $query  = CGI->new();
30
my $query  = CGI->new();
31
my $report = $query->param('id');
31
my $report_id = $query->param('id');
32
my $report_name = $query->param('name');
32
33
33
my $cache;
34
my $cache;
34
35
35
my ( $sql, $type, $name, $notes, $cache_expiry, $public ) =
36
my ( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
36
  get_saved_report($report);
37
  get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
37
die "Sorry this report is not public\n" unless $public;
38
die "Sorry this report is not public\n" unless $public;
38
39
39
if (Koha::Cache->is_cache_active) {
40
if (Koha::Cache->is_cache_active) {
40
    $cache = Koha::Cache->new(
41
    $cache = Koha::Cache->new(
41
    );
42
    );
42
    my $page = $cache->get_from_cache("opac:report:$report");
43
    my $page = $cache->get_from_cache("opac:report:$report_id");
43
    if ($page) {
44
    if ($page) {
44
        print $query->header;
45
        print $query->header;
45
        print $page;
46
        print $page;
Lines 48-60 if (Koha::Cache->is_cache_active) { Link Here
48
}
49
}
49
50
50
print $query->header;
51
print $query->header;
51
my $offset = 0;
52
if ($sql) {
52
my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
53
    my $offset = 0;
53
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
54
    my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
54
my $lines     = $sth->fetchall_arrayref;
55
    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
55
my $json_text = to_json($lines);
56
    my $lines     = $sth->fetchall_arrayref;
56
print $json_text;
57
    my $json_text = to_json($lines);
57
58
    print $json_text;
58
if (Koha::Cache->is_cache_active) {
59
59
    $cache->set_in_cache( "opac:report:$report", $json_text, $cache_expiry );
60
    if (Koha::Cache->is_cache_active) {
61
        $cache->set_in_cache( "opac:report:$report_id", $json_text, $cache_expiry );
62
    }
60
}
63
}
(-)a/svc/report (-13 / +29 lines)
Lines 30-38 use Koha::Cache; Link Here
30
30
31
31
32
my $query  = CGI->new();
32
my $query  = CGI->new();
33
my $report = $query->param('id');
33
my $report_id = $query->param('id');
34
my $report_name = $query->param('name');
34
35
35
my $cache;
36
my $cache;
37
my $sql;
38
my $type;
39
my $notes;
40
my $cache_expiry;
41
my $public;
36
42
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
    {
44
    {
Lines 45-52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
45
);
51
);
46
52
47
if (Koha::Cache->is_cache_active) {
53
if (Koha::Cache->is_cache_active) {
54
    if ($report_name) { # When retrieving by name, we have to hit the
55
                        # database to get the ID before we can check
56
                        # the cache. Yuck.
57
        ( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
58
            get_saved_report( { 'name' => $report_name } );
59
    }
60
48
    $cache = Koha::Cache->new();
61
    $cache = Koha::Cache->new();
49
    my $page = $cache->get_from_cache("intranet:report:$report");
62
    my $page = $cache->get_from_cache("intranet:report:$report_id");
50
    if ($page) {
63
    if ($page) {
51
        print $query->header;
64
        print $query->header;
52
        print $page;
65
        print $page;
Lines 57-71 if (Koha::Cache->is_cache_active) { Link Here
57
print $query->header;
70
print $query->header;
58
71
59
# $public isnt used for intranet
72
# $public isnt used for intranet
60
my ( $sql, $type, $name, $notes, $cache_expiry, $public ) =
73
unless ($sql) {
61
  get_saved_report($report);
74
    ( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
62
my $offset = 0;
75
        get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
63
my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
76
}
64
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
77
if ($sql) {
65
my $lines     = $sth->fetchall_arrayref;
78
    my $offset = 0;
66
my $json_text = to_json($lines);
79
    my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
67
print $json_text;
80
    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
81
    my $lines     = $sth->fetchall_arrayref;
82
    my $json_text = to_json($lines);
83
    print $json_text;
68
84
69
if (Koha::Cache->is_cache_active) {
85
    if (Koha::Cache->is_cache_active) {
70
    $cache->set_in_cache( "intranet:report:$report", $json_text, $cache_expiry );
86
        $cache->set_in_cache( "intranet:report:$report_id", $json_text, $cache_expiry );
87
    }
71
}
88
}
72
- 

Return to bug 8256