Added group expiration notifications.

This commit is contained in:
JT Smith 2003-02-02 03:43:45 +00:00
parent 3f2d2c63f9
commit 226ed9abcf
10 changed files with 241 additions and 31 deletions

View file

@ -17,9 +17,14 @@ use WebGUI::SQL;
#-----------------------------------------
sub process {
if ($session{config}{DeleteExpiredGroupings_offset} ne "") {
WebGUI::SQL->write("delete from groupings where expireDate < "
.(time()-(86400*$session{config}{DeleteExpiredGroupings_offset})));
my @date = WebGUI::DateTime::localtime();
if ($date[4] == 3) { # only occurs at 3am on the day in question.
my $sth = WebGUI::SQL->read("select groupId,deleteOffset from groups");
while (my $data = $sth->hashRef) {
WebGUI::SQL->write("delete from groupings where groupId=$data->{groupId} and expireDate < "
.(time()-(86400*$data->{deleteOffset})));
}
$sth->finish;
}
}

View file

@ -0,0 +1,41 @@
package Hourly::NotifyExpiredGroupings;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::DateTime;
use WebGUI::International;
use WebGUI::MessageLog;
use WebGUI::Session;
use WebGUI::SQL;
#-----------------------------------------
sub process {
my @date = WebGUI::DateTime::localtime();
if ($date[4] == 1) { # only occurs at 1am on the day in question.
my $now = time();
my $a = WebGUI::SQL->read("select groupId,expireNotifyOffset,expireNotifyMessage from groups
where expireNotify=1");
while (my $group = $a->hashRef) {
my $start = $now + (86400 * $group->{expireNotifyOffset});
my $end = $start + 86400;
my $b = WebGUI::SQL->read("select userId from groupings where expireDate>=".$start." and expireDate<=".$end);
while (my ($userId) = $b->array) {
WebGUI::MessageLog::addEntry($userId,"",WebGUI::International::get(867),$group->{expireNotifyMessage});
}
$b->finish;
}
$a->finish;
}
}
1;

View file

@ -56,7 +56,7 @@ $|=1;
print "Starting...\n";
my ($i, $dbh, @row, %user, @field, $userId, $first, $dup, $lineNumber, $expireAfter, @group);
my ($i, $dbh, @row, %user, @field, $userId, $first, $dup, $lineNumber, $expireOffset, @group);
$first = 1;
$dbh = connectToDb();
open(FILE,"<".$usersFile);
@ -109,13 +109,13 @@ while(<FILE>) {
values ($user{userId},'LDAP','$_',".$dbh->quote($user{$_}).")");
}
}
($expireAfter) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=2",$dbh);
($expireOffset) = WebGUI::SQL->quickArray("select expireOffset from groups where groupId=2",$dbh);
$user{groups} =~ s/ //g;
@group = split(/,/,$user{groups});
foreach (@group) {
($expireAfter) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=$_",$dbh);
($expireOffset) = WebGUI::SQL->quickArray("select expireOffset from groups where groupId=$_",$dbh);
WebGUI::SQL->write("insert into groupings (groupId,userId,expireDate) values
($user{userId},$_,".(time()+$expireAfter).")",$dbh);
($user{userId},$_,".(time()+$expireOffset).")",$dbh);
}
}
}