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

(-)a/Koha/BackgroundJobs.pm (+45 lines)
Lines 72-77 sub filter_by_current { Link Here
72
    );
72
    );
73
}
73
}
74
74
75
=head3 purge
76
77
    my $params = { job_types => ('all') , # Arrayref of jobtypes to be purged
78
                   days      => 1,        # Age in days of jobs to be purged
79
                   confirm   => 1,        # Confirm deletion
80
                };
81
    my $count = Koha::BackgroundJobs->purge( $params );
82
83
Deletes finished background jobs. Returns the number of jobs that was / would've been deleted.
84
85
=cut
86
87
sub purge {
88
    my ( $self, $params) = @_;
89
90
    return 0 unless ( exists $params->{job_types} && scalar @{ $params->{job_types} }  >= 1 );
91
    return 0 unless ( exists $params->{days} );
92
93
    my $types = $params->{job_types};
94
    my $days  = $params->{days};
95
96
    my $confirm = exists $params->{confirm} ? $params->{confirm} : 0;
97
98
    my $rs;
99
    if ( $types->[0] eq 'all' ){
100
        $rs = $self->search(
101
            {
102
                ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] },
103
                status   => 'finished',
104
            });
105
106
    } else {
107
        $rs = $self->search(
108
            {
109
                ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] },
110
                type     => $types,
111
                status   => 'finished',
112
            });
113
    }
114
    my $count = $rs->count();
115
    $rs->delete if $confirm;
116
117
    return $count;
118
}
119
75
=head2 Internal methods
120
=head2 Internal methods
76
121
77
=head3 _type
122
=head3 _type
(-)a/misc/cronjobs/cleanup_database.pl (-26 / +5 lines)
Lines 690-696 if ($cards) { Link Here
690
690
691
if ($background_days) {
691
if ($background_days) {
692
    print "Purging background jobs more than $background_days days ago.\n" if $verbose;
692
    print "Purging background jobs more than $background_days days ago.\n" if $verbose;
693
    my $count = PurgeBackgroundJobs($background_days, \@background_types, $confirm);
693
    my $params = { job_types => \@background_types ,
694
                   days      => $background_days,
695
                   confirm   => $confirm,
696
                };
697
    my $count = Koha::BackgroundJobs->purge( $params );
694
    if ($verbose) {
698
    if ($verbose) {
695
        say $confirm
699
        say $confirm
696
          ? sprintf "Done with purging %d background jobs of type(s): %s added more than %d days ago.\n", $count, join(',', @background_types), $background_days
700
          ? sprintf "Done with purging %d background jobs of type(s): %s added more than %d days ago.\n", $count, join(',', @background_types), $background_days
Lines 836-862 sub DeleteSpecialHolidays { Link Here
836
    print "Removed $count unique holidays\n" if $verbose;
840
    print "Removed $count unique holidays\n" if $verbose;
837
}
841
}
838
842
839
sub PurgeBackgroundJobs {
840
    my ( $days, $types, $confirm ) = @_;
841
842
    my $rs;
843
    if ( $types->[0] eq 'all' ){
844
        $rs = Koha::BackgroundJobs->search(
845
            {
846
                ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] },
847
                status   => 'finished',
848
            });
849
850
    } else {
851
        $rs = Koha::BackgroundJobs->search(
852
            {
853
                ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] },
854
                type     => \@{$types},
855
                status   => 'finished',
856
            });
857
    }
858
    my $count = $rs->count();
859
    $rs->delete if $confirm;
860
861
    return $count;
862
}
863
- 

Return to bug 31969