Bug 19008: More database cleanups - old issues

misc/cronjobs/cleanup_database.pl provides some database cleanup.
Yet some tables that could need cleanup are not in this script.

This patch adds cleanup for old_issues table.

Test plan :
- Count : select count(*),date(timestamp) from old_issues group by date(timestamp);
- Run cleanup : misc/cronjobs/cleanup_database.pl -v --old-issues 30
- Recount

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit ce96ed4336)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Fridolin Somers 2017-07-28 14:57:33 +02:00 committed by Lucas Gass
parent 6e0d48f14e
commit 2f869f288f
1 changed files with 17 additions and 1 deletions

View File

@ -45,7 +45,7 @@ use Koha::UploadedFiles;
sub usage {
print STDERR <<USAGE;
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS]
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS]
-h --help prints this help message, and exits, ignoring all
other options
@ -87,6 +87,7 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu
--deleted-catalog DAYS Purge deleted catalog older than DAYS
in tables deleteditems, deletedbiblioitems, deletedbiblio_metadata and deletedbiblio
--deleted-patrons DAYS Purge deleted patrons older than DAYS days.
--old-issues DAYS Purge old issues older than DAYS days.
USAGE
exit $_[0];
}
@ -116,6 +117,7 @@ my $oauth_tokens;
my $pStatistics;
my $pDeletedCatalog;
my $pDeletedPatrons;
my $pOldIssues;
GetOptions(
'h|help' => \$help,
@ -143,6 +145,7 @@ GetOptions(
'statistics:i' => \$pStatistics,
'deleted-catalog:i' => \$pDeletedCatalog,
'deleted-patrons:i' => \$pDeletedPatrons,
'old-issues:i' => \$pOldIssues,
) || usage(1);
# Use default values
@ -180,6 +183,7 @@ unless ( $sessions
|| $pStatistics
|| $pDeletedCatalog
|| $pDeletedPatrons
|| $pOldIssues
) {
print "You did not specify any cleanup work for the script to do.\n\n";
usage(1);
@ -432,6 +436,18 @@ if ($pDeletedPatrons) {
print "Done with purging deleted patrons.\n" if $verbose;
}
if ($pOldIssues) {
print "Purging old issues older than $pOldIssues days.\n" if $verbose;
$sth = $dbh->prepare(
q{
DELETE FROM old_issues
WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
}
);
$sth->execute($pOldIssues);
print "Done with purging old issues.\n" if $verbose;
}
exit(0);
sub RemoveOldSessions {