From b3eee9c65f40fec5223760effeb7ba78d2f24078 Mon Sep 17 00:00:00 2001 From: Jonathan Ernst Date: Wed, 19 Jan 2005 05:03:07 +0000 Subject: [PATCH] - cron job to delete inactive users - improved statistics --- TODO | 7 -- appdbStats.php | 42 +++++++----- cron/.htaccess | 1 + cron/cleanup.php | 173 +++++++++++++++++++++++++++++++++++++++++++++++ cron/path.php | 3 + 5 files changed, 201 insertions(+), 25 deletions(-) create mode 100644 cron/.htaccess create mode 100644 cron/cleanup.php create mode 100644 cron/path.php diff --git a/TODO b/TODO index 3dfd12e..2f10752 100644 --- a/TODO +++ b/TODO @@ -9,13 +9,6 @@ borrow from lostwages(winehq.org/cvsweb/lostwages) for this # check for existing email when user is creating a new account -# setup a cron job in a new /bin directory, put a deny all .htaccess -file in there and purge all inactive accounts after 6 months of inactivity - -# RELATED TODO: how to handle deleting accounts that have comments ? go through -and assign them to a special account number that prints (account deleted due -to inactivity) - # when deleting an application or version we should delete linked entries (screenshots, comments, etc.) # when deleting a screenshot we should delete the image file as well diff --git a/appdbStats.php b/appdbStats.php index 148241e..a31f82d 100644 --- a/appdbStats.php +++ b/appdbStats.php @@ -19,6 +19,30 @@ echo " Users:\n"; echo " ".getNumberOfUsers()."\n"; echo "\n\n"; +/* Display the active users in the last 30 days */ +echo "\n"; +echo " Users active within the last 30 days:\n"; +echo " ".getActiveUsersWithinDays(30)."\n"; +echo "\n\n"; + +/* Display the active users in the last 60 days */ +echo "\n"; +echo " Users active within the last 60 days:\n"; +echo " ".getActiveUsersWithinDays(60)."\n"; +echo "\n\n"; + +/* Display the active users in the last 90 days */ +echo "\n"; +echo " Users active within the last 90 days:\n"; +echo " ".getActiveUsersWithinDays(90)."\n"; +echo "\n\n"; + +/* Display the inactive users */ +echo "\n"; +echo " Inactive users (not logged in since six months):\n"; +echo " ".(getNumberOfUsers()-getActiveUsersWithinDays(183))."\n"; +echo "\n\n"; + /* Display the number of comments */ echo "\n"; echo " Comments:\n"; @@ -49,24 +73,6 @@ echo " Images:\n"; echo " ".getNumberOfImages()."\n"; echo "\n\n"; -/* Display the active users in the last 30 days */ -echo "\n"; -echo " Users active within the last 30 days:\n"; -echo " ".getActiveUsersWithinDays(30)."\n"; -echo "\n\n"; - -/* Display the active users in the last 60 days */ -echo "\n"; -echo " Users active within the last 60 days:\n"; -echo " ".getActiveUsersWithinDays(60)."\n"; -echo "\n\n"; - -/* Display the active users in the last 90 days */ -echo "\n"; -echo " Users active within the last 90 days:\n"; -echo " ".getActiveUsersWithinDays(90)."\n"; -echo "\n\n"; - echo "\n\n"; echo html_frame_end(" "); diff --git a/cron/.htaccess b/cron/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/cron/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/cron/cleanup.php b/cron/cleanup.php new file mode 100644 index 0000000..064ec59 --- /dev/null +++ b/cron/cleanup.php @@ -0,0 +1,173 @@ +#!/usr/bin/php +userid)) + warnMaintainer(lookupEmail($oRow->userid)); + elseif(!hasDataAssociated($oRow->userid)) + warnUser(lookupEmail($oRow->userid)); +} + +$hSevenMonth = inactiveSince(7); +while($oRow = mysql_fetch_object($hSevenMonth)) +{ + if(isMaintainer($oRow->userid)) + deleteMaintainer($oRow->userid); + elseif(!hasDataAssociated($oRow->userid)) + deleteUser($oRow->userid); +} + + +function inactiveSince($iMonths) +{ + $sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= stamp"; + $hResult = query_appdb($sQuery); + return $hResult; +} + +function hasDataAssociated($iUserId) +{ + $sQuery = "SELECT * FROM appComments WHERE userId = $iUserId"; + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult)) return true; + + $sQuery = "SELECT * FROM appDataQueue WHERE userId = $iUserId"; + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult)) return true; + + $sQuery = "SELECT * FROM appMaintainerQueue WHERE userId = $iUserId"; + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult)) return true; + + $sQuery = "SELECT * FROM appOwners WHERE ownerId = $iUserId"; + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult)) return true; + + $sQuery = "SELECT * FROM appVotes WHERE userId = $iUserId"; + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult)) return true; + + return false; +} + + +function deleteUser($iUserId) +{ + warnUserDeleted(lookupEmail($iUserId)); + echo "user ".lookupEmail($iUserId)." deleted.\n"; + $sQuery = "DELETE FROM user_list WHERE userid = $iUserId"; + $hResult = query_appdb($sQuery); + $sQuery = "DELETE FROM user_prefs WHERE userid = $iUserId"; + $hResult = query_appdb($sQuery); +} + +function deleteMaintainer() +{ + $sQuery = "DELETE FROM appMaintainers WHERE userId = $iUserId"; + $hResult = query_appdb($sQuery); + warnMaintainerDeleted(lookupEmail($iUserId)); + echo "user ".lookupEmail($iUserId)." is not a maintainer anymore.\n"; +} + +function warnUser($sEmail) +{ + $sHeaders = "MIME-Version: 1.0\r\n"; + $sHeaders .= "From: AppDB \r\n"; + $sHeaders .= "Reply-to: AppDB \r\n"; + $sHeaders .= "X-Priority: 3\r\n"; + $sHeaders .= "X-Mailer: ".APPDB_OWNER." mailer\r\n"; + + $sMsg = "AppDB Warning: inactivity detected\r\n"; + $sMsg .= "-----------------------------------\r\n"; + $sMsg .= "You didn't log in in the past six month to the AppDB (".APPDB_OWNER_URL.")\r\n"; + $sMsg .= "Please log in or your account will automatically be deleted in one month.\r\n\r\n"; + $sMsg .= "Best regards.\r\n"; + $sMsg .= "The AppDB team.\r\n"; + + mail($sEmail, "[AppDB] Warning: inactivity detected", $sMsg, $sHeaders, "-fappdb@winehq.org"); +} + +function warnMaintainer($sEmail) +{ + $sHeaders = "MIME-Version: 1.0\r\n"; + $sHeaders .= "From: AppDB \r\n"; + $sHeaders .= "Reply-to: AppDB \r\n"; + $sHeaders .= "X-Priority: 3\r\n"; + $sHeaders .= "X-Mailer: ".APPDB_OWNER." mailer\r\n"; + + $sMsg = "AppDB Warning: inactivity detected\r\n"; + $sMsg .= "-----------------------------------\r\n"; + $sMsg .= "You didn't log in in the past six month to the AppDB (".APPDB_OWNER_URL.")\r\n"; + $sMsg .= "As a maintainer we would be pleased to see you once in a while\r\n"; + $sMsg .= "Please log in or you will lose your maintainer's abilities in one month.\r\n\r\n"; + $sMsg .= "Best regards.\r\n"; + $sMsg .= "The AppDB team.\r\n"; + + mail($sEmail, "[AppDB] Warning: inactivity detected", $sMsg, $sHeaders, "-fappdb@winehq.org"); +} + +function warnUserDeleted($sEmail) +{ + $sHeaders = "MIME-Version: 1.0\r\n"; + $sHeaders .= "From: AppDB \r\n"; + $sHeaders .= "Reply-to: AppDB \r\n"; + $sHeaders .= "X-Priority: 3\r\n"; + $sHeaders .= "X-Mailer: ".APPDB_OWNER." mailer\r\n"; + + $sMsg = "AppDB Warning: account removed\r\n"; + $sMsg .= "-----------------------------------\r\n"; + $sMsg .= "You didn't log in in the past seven month to the AppDB (".APPDB_OWNER_URL.")\r\n"; + $sMsg .= "As you don't have any data associated to your account we have removed it.\r\n\r\n"; + $sMsg .= "Please feel free to recreate an account anytime.\r\n\r\n"; + $sMsg .= "Best regards.\r\n"; + $sMsg .= "The AppDB team.\r\n"; + + mail($sEmail, "[AppDB] Warning: account removed", $sMsg, $sHeaders, "-fappdb@winehq.org"); +} + +function warnMaintainerDeleted($sEmail) +{ + $sHeaders = "MIME-Version: 1.0\r\n"; + $sHeaders .= "From: AppDB \r\n"; + $sHeaders .= "Reply-to: AppDB \r\n"; + $sHeaders .= "X-Priority: 3\r\n"; + $sHeaders .= "X-Mailer: ".APPDB_OWNER." mailer\r\n"; + + $sMsg = "AppDB Warning: maintainer rights revoked\r\n"; + $sMsg .= "----------------------------------------\r\n"; + $sMsg .= "You didn't log in in the past seven month to the AppDB (".APPDB_OWNER_URL.")\r\n"; + $sMsg .= "As a result, you are not a maintainer anymore.\r\n\r\n"; + $sMsg .= "Please feel free to enroll again as a maintainer anytime.\r\n\r\n"; + $sMsg .= "Best regards.\r\n"; + $sMsg .= "The AppDB team.\r\n"; + + mail($sEmail, "[AppDB] Warning: maintainer rights revoked", $sMsg, $sHeaders, "-fappdb@winehq.org"); +} +?> diff --git a/cron/path.php b/cron/path.php new file mode 100644 index 0000000..4ae17f9 --- /dev/null +++ b/cron/path.php @@ -0,0 +1,3 @@ +