- cron job to delete inactive users
- improved statistics
This commit is contained in:
7
TODO
7
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
|
# 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 an application or version we should delete linked entries (screenshots, comments, etc.)
|
||||||
|
|
||||||
# when deleting a screenshot we should delete the image file as well
|
# when deleting a screenshot we should delete the image file as well
|
||||||
|
|||||||
@@ -19,6 +19,30 @@ echo " <td>Users:</td>\n";
|
|||||||
echo " <td>".getNumberOfUsers()."</td>\n";
|
echo " <td>".getNumberOfUsers()."</td>\n";
|
||||||
echo "</tr>\n\n";
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
|
/* Display the active users in the last 30 days */
|
||||||
|
echo "<tr class=color4>\n";
|
||||||
|
echo " <td>Users active within the last 30 days:</td>\n";
|
||||||
|
echo " <td>".getActiveUsersWithinDays(30)."</td>\n";
|
||||||
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
|
/* Display the active users in the last 60 days */
|
||||||
|
echo "<tr class=color4>\n";
|
||||||
|
echo " <td>Users active within the last 60 days:</td>\n";
|
||||||
|
echo " <td>".getActiveUsersWithinDays(60)."</td>\n";
|
||||||
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
|
/* Display the active users in the last 90 days */
|
||||||
|
echo "<tr class=color4>\n";
|
||||||
|
echo " <td>Users active within the last 90 days:</td>\n";
|
||||||
|
echo " <td>".getActiveUsersWithinDays(90)."</td>\n";
|
||||||
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
|
/* Display the inactive users */
|
||||||
|
echo "<tr class=color4>\n";
|
||||||
|
echo " <td>Inactive users (not logged in since six months):</td>\n";
|
||||||
|
echo " <td>".(getNumberOfUsers()-getActiveUsersWithinDays(183))."</td>\n";
|
||||||
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
/* Display the number of comments */
|
/* Display the number of comments */
|
||||||
echo "<tr class=color4>\n";
|
echo "<tr class=color4>\n";
|
||||||
echo " <td>Comments:</td>\n";
|
echo " <td>Comments:</td>\n";
|
||||||
@@ -49,24 +73,6 @@ echo " <td>Images:</td>\n";
|
|||||||
echo " <td>".getNumberOfImages()."</td>\n";
|
echo " <td>".getNumberOfImages()."</td>\n";
|
||||||
echo "</tr>\n\n";
|
echo "</tr>\n\n";
|
||||||
|
|
||||||
/* Display the active users in the last 30 days */
|
|
||||||
echo "<tr class=color4>\n";
|
|
||||||
echo " <td>Users active within the last 30 days:</td>\n";
|
|
||||||
echo " <td>".getActiveUsersWithinDays(30)."</td>\n";
|
|
||||||
echo "</tr>\n\n";
|
|
||||||
|
|
||||||
/* Display the active users in the last 60 days */
|
|
||||||
echo "<tr class=color4>\n";
|
|
||||||
echo " <td>Users active within the last 60 days:</td>\n";
|
|
||||||
echo " <td>".getActiveUsersWithinDays(60)."</td>\n";
|
|
||||||
echo "</tr>\n\n";
|
|
||||||
|
|
||||||
/* Display the active users in the last 90 days */
|
|
||||||
echo "<tr class=color4>\n";
|
|
||||||
echo " <td>Users active within the last 90 days:</td>\n";
|
|
||||||
echo " <td>".getActiveUsersWithinDays(90)."</td>\n";
|
|
||||||
echo "</tr>\n\n";
|
|
||||||
|
|
||||||
echo "</table>\n\n";
|
echo "</table>\n\n";
|
||||||
echo html_frame_end(" ");
|
echo html_frame_end(" ");
|
||||||
|
|
||||||
|
|||||||
1
cron/.htaccess
Normal file
1
cron/.htaccess
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Deny from all
|
||||||
173
cron/cleanup.php
Normal file
173
cron/cleanup.php
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
##################################################
|
||||||
|
# this script has to be run once a month by cron #
|
||||||
|
# it's purpose is to clean the user's table. #
|
||||||
|
##################################################
|
||||||
|
|
||||||
|
include("path.php");
|
||||||
|
include(BASE."include/"."incl.php");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Let:
|
||||||
|
* 1) you did not log in for six month
|
||||||
|
* 2) you don't have any data associated
|
||||||
|
* 3) you are a maintainer
|
||||||
|
* 4) you receive a warning e-mail
|
||||||
|
* 5) you did not log in for seven month
|
||||||
|
* 6) your account is deleted
|
||||||
|
* 7) you are not a maintainer anymore
|
||||||
|
*
|
||||||
|
* The rules are the following:
|
||||||
|
* if(1 AND 2) then 4
|
||||||
|
* if(1 AND 3) then 4
|
||||||
|
* if(5 AND 2) then 6
|
||||||
|
* if(5 AND 3) then 7
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
$hSixMonth = inactiveSince(6);
|
||||||
|
while($oRow = mysql_fetch_object($hSixMonth))
|
||||||
|
{
|
||||||
|
if(isMaintainer($oRow->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 <appdb@winehq.org>\r\n";
|
||||||
|
$sHeaders .= "Reply-to: AppDB <appdb@winehq.orgl>\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 <appdb@winehq.org>\r\n";
|
||||||
|
$sHeaders .= "Reply-to: AppDB <appdb@winehq.orgl>\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 <appdb@winehq.org>\r\n";
|
||||||
|
$sHeaders .= "Reply-to: AppDB <appdb@winehq.orgl>\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 <appdb@winehq.org>\r\n";
|
||||||
|
$sHeaders .= "Reply-to: AppDB <appdb@winehq.orgl>\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");
|
||||||
|
}
|
||||||
|
?>
|
||||||
3
cron/path.php
Normal file
3
cron/path.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
define("BASE","../");
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user