From 0f2350d4c5ec0932ba48a65aaecad169ca89c00e Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 13 Oct 2002 19:55:39 +0000 Subject: [PATCH] Updated to take their configurable parameters from the config file. --- sbin/Hourly/CleanLoginHistory.pm | 7 +-- sbin/Hourly/DecayKarma.pm | 8 ++-- sbin/Hourly/DeleteExpiredEvents.pm | 7 +-- sbin/Hourly/DeleteExpiredGroupings.pm | 7 +-- sbin/Hourly/SyncProfilesToLDAP.pm | 62 +++++++++++++-------------- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/sbin/Hourly/CleanLoginHistory.pm b/sbin/Hourly/CleanLoginHistory.pm index 7d19db43e..d0a05458e 100644 --- a/sbin/Hourly/CleanLoginHistory.pm +++ b/sbin/Hourly/CleanLoginHistory.pm @@ -1,7 +1,5 @@ package Hourly::CleanLoginHistory; -my $ageToDelete = 90; # in days, time to wait before deleting from login log - #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black LLC. #------------------------------------------------------------------- @@ -19,7 +17,10 @@ use WebGUI::SQL; #----------------------------------------- sub process { - WebGUI::SQL->write("delete from userLoginLog where timeStamp<".(time()-(86400*$ageToDelete))); + if ($session{config}{CleanLoginHistory_ageToDelete}) { + WebGUI::SQL->write("delete from userLoginLog + where timeStamp < ".(time()-(86400*$session{config}{CleanLoginHistory_ageToDelete}))); + } } 1; diff --git a/sbin/Hourly/DecayKarma.pm b/sbin/Hourly/DecayKarma.pm index ce26980a2..16617ac83 100644 --- a/sbin/Hourly/DecayKarma.pm +++ b/sbin/Hourly/DecayKarma.pm @@ -1,8 +1,5 @@ package Hourly::DecayKarma; -my $minimumKarma = 0; # won't go below this number -my $decayFactor = 1; # amount to remove per hour - #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black LLC. #------------------------------------------------------------------- @@ -20,7 +17,10 @@ use WebGUI::SQL; #----------------------------------------- sub process { - WebGUI::SQL->write("update users set karma=karma-$decayFactor where karma>".$minimumKarma); + if ($session{config}{DecayKarma_minimumKarma} ne "" && $session{config}{DecayKarma_decayFactor}) { + WebGUI::SQL->write("update users set karma=".karma-$session{config}{DecayKarma_decayFactor} + ." where karma > ".$session{config}{DecayKarma_minimumKarma}); + } } 1; diff --git a/sbin/Hourly/DeleteExpiredEvents.pm b/sbin/Hourly/DeleteExpiredEvents.pm index 1d60fe6e9..7063afdbb 100644 --- a/sbin/Hourly/DeleteExpiredEvents.pm +++ b/sbin/Hourly/DeleteExpiredEvents.pm @@ -1,7 +1,5 @@ package Hourly::DeleteExpiredEvents; -my $offset = 0; # in days, time to wait before deleting - #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black LLC. #------------------------------------------------------------------- @@ -19,7 +17,10 @@ use WebGUI::SQL; #----------------------------------------- sub process { - WebGUI::SQL->write("delete from EventsCalendar_event where endDate<".(time()-(86400*$offset))); + if ($session{config}{DeleteExpiredEvents_offset} ne "") { + WebGUI::SQL->write("delete from EventsCalendar_event where endDate < " + .(time()-(86400*$session{config}{DeleteExpiredEvents}{offset}))); + } } 1; diff --git a/sbin/Hourly/DeleteExpiredGroupings.pm b/sbin/Hourly/DeleteExpiredGroupings.pm index b3613ac78..d352b8714 100644 --- a/sbin/Hourly/DeleteExpiredGroupings.pm +++ b/sbin/Hourly/DeleteExpiredGroupings.pm @@ -1,7 +1,5 @@ package Hourly::DeleteExpiredGroupings; -my $offset = 0; # in seconds, time to wait before deleting - #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black LLC. #------------------------------------------------------------------- @@ -18,7 +16,10 @@ use WebGUI::SQL; #----------------------------------------- sub process { - WebGUI::SQL->write("delete from groupings where expireDate<".(time()-(86400*$offset))); + if ($session{config}{DeleteExpiredGroupings_offset} ne "") { + WebGUI::SQL->write("delete from groupings where expireDate < " + .(time()-(86400*$session{config}{DeleteExpiredGroupings_offset}))); + } } 1; diff --git a/sbin/Hourly/SyncProfilesToLDAP.pm b/sbin/Hourly/SyncProfilesToLDAP.pm index 9de2ecad1..32970ed2b 100644 --- a/sbin/Hourly/SyncProfilesToLDAP.pm +++ b/sbin/Hourly/SyncProfilesToLDAP.pm @@ -31,43 +31,41 @@ sub _alias { sub process { my (@date, $userId, $u, $uri, $port, %args, $fieldName, $ldap, $search, $a, $b); @date = WebGUI::DateTime::localtime(); - if ($date[3] == 6) { # only do this at 6 am. - if ($session{config}{syncProfilesToLDAP} == 1) { - $a = WebGUI::SQL->read("select userId from users where authMethod='LDAP'"); - while (($userId) = $a->array) { - $u = WebGUI::User->new($userId); - $uri = URI->new($u->ldapURL); - if ($uri->port < 1) { - $port = 389; - } else { - $port = $uri->port; - } - %args = (port => $port); - $ldap = Net::LDAP->new($uri->host, %args); - if ($ldap) { - $ldap->bind; - $search = $ldap->search (base => $uri->dn, filter => $u->connectDN); - if (defined $search->entry(0)) { - $b = WebGUI::SQL->read("select fieldName from userProfileField where profileCategoryId<>4"); - while (($fieldName) = $b->array) { - if ($search->entry(0)->get_value(_alias($fieldName)) ne "") { - WebGUI::SQL->write("replace into userProfileData - (userId,fieldName,fieldData) values (" - .$userId."," - .quote($fieldName)."," - .quote($search->entry(0)->get_value(_alias($fieldName))) - .")"); - } + if ($date[3] == $session{config}{SyncProfilesToLDAP_hour}) { + $a = WebGUI::SQL->read("select userId from users where authMethod='LDAP'"); + while (($userId) = $a->array) { + $u = WebGUI::User->new($userId); + $uri = URI->new($u->ldapURL); + if ($uri->port < 1) { + $port = 389; + } else { + $port = $uri->port; + } + %args = (port => $port); + $ldap = Net::LDAP->new($uri->host, %args); + if ($ldap) { + $ldap->bind; + $search = $ldap->search (base => $uri->dn, filter => $u->connectDN); + if (defined $search->entry(0)) { + $b = WebGUI::SQL->read("select fieldName from userProfileField where profileCategoryId<>4"); + while (($fieldName) = $b->array) { + if ($search->entry(0)->get_value(_alias($fieldName)) ne "") { + WebGUI::SQL->write("replace into userProfileData + (userId,fieldName,fieldData) values (" + .$userId."," + .quote($fieldName)."," + .quote($search->entry(0)->get_value(_alias($fieldName))) + .")"); } - $b->finish; - $ldap->unbind; - } else { - print "Couldn't connect to LDAP host ".$uri->host." to find user ".$u->username." (".$userId.").\n"; } + $b->finish; + $ldap->unbind; + } else { + print "Couldn't connect to LDAP host ".$uri->host." to find user ".$u->username." (".$userId.").\n"; } } - $a->finish; } + $a->finish; } }