From 95d93a09c2d7ae8a8c2f4f33e462c22ec9130048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Wed, 22 Jul 2009 17:07:35 +0200 Subject: [PATCH] cron: Add a script to remove votes for deleted versions --- cron/cleanup.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cron/cleanup.php b/cron/cleanup.php index 7c1fb25..79b7173 100644 --- a/cron/cleanup.php +++ b/cron/cleanup.php @@ -28,6 +28,9 @@ removeScreenshotsWithMissingFiles(); /* status since they aren't really maintaining the application/version */ maintainerCheck(); +/* remove votes for versions that have been deleted */ +cleanupVotes(); + /* Updates the rating info for all versions based on test results */ //updateRatings(); @@ -294,6 +297,45 @@ function maintainerCheck() maintainer::notifyMaintainersOfQueuedData(); } +/* remove votes for versions that have been deleted */ +function cleanupVotes() +{ + $hResult = mysql_query("SELECT appVotes.* FROM appVotes,appVersion WHERE + appVotes.versionId = appVersion.versionId + AND appVersion.state = 'deleted'"); + + if(!$hResult) + return; + + $iDeleted = 0; + $iFailed = 0; + + while($oRow = mysql_fetch_object($hResult)) + { + $oVote = new vote(null, $oRow); + if($oVote->delete()) + $iDeleted++; + else + $iFailed++; + } + + $sEmails = user::get_notify_email_address_list(null, null); // only admins + + if($sEmails) + { + global $sEmailSubject; + $sSubject = $sEmailSubject . 'Vote Cleanup'; + $sPlural = ($iDeleted == 1) ? '' : 's'; + $sMsg = "Removed $iDeleted vote$sPlural cast for deleted versions\n"; + if($iFailed) + { + $sPlural = ($iFailed == 1) ? '' : 's'; + $sMsg .= "WARNING: Failed to delete $iFailed vote$sPlural\n"; + } + mail_appdb($sEmails, $sSubject, $sMsg); + } +} + function updateRatings() { $hResult = query_parameters("SELECT * FROM appVersion");