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

(-)a/C4/Reports/Guided.pm (-13 / +31 lines)
Lines 599-615 sub save_report { Link Here
599
    my $area = $fields->{area};
599
    my $area = $fields->{area};
600
    my $group = $fields->{group};
600
    my $group = $fields->{group};
601
    my $subgroup = $fields->{subgroup};
601
    my $subgroup = $fields->{subgroup};
602
    my $cache_expiry = $fields->{cache_expiry} || 300;
602
    my $cache_expiry = $fields->{cache_expiry};
603
    my $public = $fields->{public};
603
    my $public = $fields->{public};
604
604
605
    my $dbh = C4::Context->dbh();
606
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
605
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
607
    my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public)  VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?)";
606
    my $now = dt_from_string;
608
    $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public);
607
    my $report = Koha::Report->new(
608
        {
609
            borrowernumber  => $borrowernumber,
610
            date_created    => $now, # Must be moved to Koha::Report->store
611
            last_modified   => $now, # Must be moved to Koha::Report->store
612
            savedsql        => $sql,
613
            report_name     => $name,
614
            report_area     => $area,
615
            report_group    => $group,
616
            report_subgroup => $subgroup,
617
            type            => $type,
618
            notes           => $notes,
619
            cache_expiry    => $cache_expiry,
620
            public          => $public,
621
        }
622
    )->store;
609
623
610
    my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
624
    return $report->id;
611
                                   $borrowernumber, $name);
612
    return $id;
613
}
625
}
614
626
615
sub update_sql {
627
sub update_sql {
Lines 623-636 sub update_sql { Link Here
623
    my $cache_expiry = $fields->{cache_expiry};
635
    my $cache_expiry = $fields->{cache_expiry};
624
    my $public = $fields->{public};
636
    my $public = $fields->{public};
625
637
638
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
639
    my $report = Koha::Reports->find($id);
640
    $report->last_modified(dt_from_string);
641
    $report->savedsql($sql);
642
    $report->report_name($name);
643
    $report->notes($notes);
644
    $report->report_group($group);
645
    $report->report_subgroup($subgroup);
646
    $report->cache_expiry($cache_expiry) if defined $cache_expiry;
647
    $report->public($public);
626
    if( $cache_expiry >= 2592000 ){
648
    if( $cache_expiry >= 2592000 ){
627
      die "Please specify a cache expiry less than 30 days\n";
649
      die "Please specify a cache expiry less than 30 days\n"; # That's a bit harsh
628
    }
650
    }
629
651
630
    my $dbh        = C4::Context->dbh();
652
    return $report;
631
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
632
    my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, report_group = ?, report_subgroup = ?, notes = ?, cache_expiry = ?, public = ? WHERE id = ? ";
633
    $dbh->do($query, undef, $sql, $name, $group, $subgroup, $notes, $cache_expiry, $public, $id );
634
}
653
}
635
654
636
sub store_results {
655
sub store_results {
637
- 

Return to bug 24614