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

(-)a/C4/Reports/Guided.pm (-5 / +21 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 LIKE ?";
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
        }
626
    } else {
627
        return;
628
    }
629
    $sth   = $dbh->prepare($query);
630
    $sth->execute($report_arg);
615
    my $data = $sth->fetchrow_hashref();
631
    my $data = $sth->fetchrow_hashref();
616
    return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'}, $data->{'cache_expiry'}, $data->{'public'} );
632
    return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'}, $data->{'cache_expiry'}, $data->{'public'}, $data->{'id'} );
617
}
633
}
618
634
619
=item create_compound($masterID,$subreportID)
635
=item create_compound($masterID,$subreportID)
(-)a/opac/svc/report (-5 / +6 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 56-60 my $json_text = to_json($lines); Link Here
56
print $json_text;
57
print $json_text;
57
58
58
if (Koha::Cache->is_cache_active) {
59
if (Koha::Cache->is_cache_active) {
59
    $cache->set_in_cache( "opac:report:$report", $json_text, $cache_expiry );
60
    $cache->set_in_cache( "opac:report:$report_id", $json_text, $cache_expiry );
60
}
61
}
(-)a/svc/report (-6 / +20 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-64 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 ) =
75
        get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
76
}
62
my $offset = 0;
77
my $offset = 0;
63
my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
78
my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
64
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
79
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
Lines 67-71 my $json_text = to_json($lines); Link Here
67
print $json_text;
82
print $json_text;
68
83
69
if (Koha::Cache->is_cache_active) {
84
if (Koha::Cache->is_cache_active) {
70
    $cache->set_in_cache( "intranet:report:$report", $json_text, $cache_expiry );
85
    $cache->set_in_cache( "intranet:report:$report_id", $json_text, $cache_expiry );
71
}
86
}
72
- 

Return to bug 8256