my ($shelfnumber, $key)= @_;
return if !$shelfnumber || !$key;
- my $sql;
my $dbh = C4::Context->dbh;
- $sql="DELETE FROM virtualshelfshares WHERE sharedate<NOW() LIMIT 10";
- #housekeeping: add one, remove max 10 expired ones
- $dbh->do($sql);
- $sql="INSERT INTO virtualshelfshares (shelfnumber, invitekey, sharedate) VALUES (?, ?, ADDDATE(NOW(),?))";
- $dbh->do($sql, undef, ($shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS));
+ my $sql = "INSERT INTO virtualshelfshares (shelfnumber, invitekey, sharedate) VALUES (?, ?, NOW())";
+ $dbh->do($sql, undef, ($shelfnumber, $key));
return !$dbh->err;
}
my $dbh = C4::Context->dbh;
$sql="
UPDATE virtualshelfshares
-SET invitekey=NULL, sharedate=NULL, borrowernumber=?
-WHERE shelfnumber=? AND invitekey=? AND sharedate>NOW()
+SET invitekey=NULL, sharedate=NOW(), borrowernumber=?
+WHERE shelfnumber=? AND invitekey=? AND (sharedate + INTERVAL ? DAY) >NOW()
";
- my $i= $dbh->do($sql, undef, ($borrowernumber, $shelfnumber, $key));
+ my $i= $dbh->do($sql, undef, ($borrowernumber, $shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS));
return if !defined($i) || !$i || $i eq '0E0'; #not found
return 1;
}
koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/advance_notices.pl -c
koha-foreach --enabled /usr/share/koha/bin/cronjobs/holds/cancel_expired_holds.pl >/dev/null 2>&1
koha-foreach --enabled /usr/share/koha/bin/cronjobs/services_throttle.pl > /dev/null 2>&1
-koha-foreach --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --sessions --zebraqueue 10
+koha-foreach --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --sessions --zebraqueue 10 --list-invites
koha-foreach --enabled --noemail /usr/share/koha/bin/cronjobs/cleanup_database.pl --mail
koha-foreach --enabled /usr/share/koha/bin/cronjobs/holds/auto_unsuspend_holds.pl > /dev/null 2>&1
koha-run-backups --days 2 --output /var/spool/koha
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
use constant DEFAULT_LOGS_PURGEDAYS => 180;
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30;
+use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
BEGIN {
# find Koha's Perl modules
Defaults to 180 days if no days specified.
--searchhistory DAYS purge entries from search_history older than DAYS days.
Defaults to 30 days if no days specified
+ --list-invites DAYS purge (unaccepted) list share invites older than DAYS
+ days. Defaults to 14 days if no days specified.
USAGE
exit $_[0];
}
my (
$help, $sessions, $sess_days, $verbose,
$zebraqueue_days, $mail, $purge_merged, $pImport,
- $pLogs, $pSearchhistory, $pZ3950
+ $pLogs, $pSearchhistory, $pZ3950,
+ $pListShareInvites,
);
GetOptions(
'z3950' => \$pZ3950,
'logs:i' => \$pLogs,
'searchhistory:i' => \$pSearchhistory,
+ 'list-invites:i' => \$pListShareInvites,
) || usage(1);
$sessions=1 if $sess_days && $sess_days>0;
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days==0;
$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0;
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0;
+$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0;
if ($help) {
usage(0);
|| $pImport
|| $pLogs
|| $pSearchhistory
- || $pZ3950 )
+ || $pZ3950
+ || $pListShareInvites )
{
print "You did not specify any cleanup work for the script to do.\n\n";
usage(1);
print "Done with purging search_history.\n" if $verbose;
}
+if ($pListShareInvites) {
+ print "Purging unaccepted list share invites older than $pListShareInvites days.\n" if $verbose;
+ $sth = $dbh->prepare("
+ DELETE FROM virtualshelfshares
+ WHERE invitekey IS NOT NULL
+ AND (sharedate + INTERVAL ? DAY) < NOW()
+ ");
+ $sth->execute($pListShareInvites);
+ print "Done with purging unaccepted list share invites.\n" if $verbose;
+}
+
exit(0);
sub RemoveOldSessions {
59 23 * * * __KOHA_USER__ $KOHA_CRON_PATH/services_throttle.pl > /dev/null 2>&1
# clean up databases nightly. Be sure not to run this with --sessions during a time when the system is in use!
-16 1 * * * __KOHA_USER__ $KOHA_CRON_PATH/cleanup_database.pl --sessions --zebraqueue 10
+16 1 * * * __KOHA_USER__ $KOHA_CRON_PATH/cleanup_database.pl --sessions --zebraqueue 10 --list-invites
# delete old purchase suggestions weekly. Replace XX with a number to define the age of suggestions to delete.
@weekly __KOHA_USER__ $KOHA_CRON_PATH/purge_suggestions.pl --days XX > /dev/null 2>&1
#----------------------- TEST AddShare ----------------------------------------#
-#first count the number of shares in the table; keep in mind that AddShare may
-#delete some expired records while housekeeping
-my $sql_sharecount="select count(*) from virtualshelfshares where DATEDIFF(sharedate, NOW())>0";
+#first count the number of shares in the table
+my $sql_sharecount="select count(*) from virtualshelfshares";
my $cnt1=$dbh->selectrow_array($sql_sharecount);
#try to add a share without shelfnumber: should fail