ChangeSet ID: 31132 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2007/05/23 21:29:44
Modified files: cron : cleanup.php
Log message: Chris Morgan cmorgan@alum.wpi.edu Add removeScreenshotsWithMissingFiles() to the nightly cron script. This will close a hole where we could potentially have screenshots in the database that don't have thumbnails or images.
Patch: http://cvs.winehq.org/patch.py?id=31132
Old revision New revision Changes Path 1.32 1.33 +57 -0 appdb/cron/cleanup.php
Index: appdb/cron/cleanup.php diff -u -p appdb/cron/cleanup.php:1.32 appdb/cron/cleanup.php:1.33 --- appdb/cron/cleanup.php:1.32 24 May 2007 2:29:44 -0000 +++ appdb/cron/cleanup.php 24 May 2007 2:29:44 -0000 @@ -81,6 +81,8 @@ orphanSessionListCheck(); /* report error log entries to admins and flush the error log after doing so */ reportErrorLogEntries();
+/* remove screenshots that are missing their screenshot and thumbnail files */ +removeScreenshotsWithMissingFiles();
/* Users that are unwarned and inactive since $iMonths */ function unwarnedAndInactiveSince($iMonths) @@ -236,4 +238,59 @@ function reportErrorLogEntries() error_log::flush(); }
+// returns an array of iScreenshotIds of screenshots that are +// missing their files +function getMissingScreenshotArray() +{ + $aMissingScreenshotIds = array(); + + // retrieve all screenshots, not queued, not rejected + $hResult = Screenshot::objectGetEntries(false, false); + + // go through each screenshot + while($oRow = mysql_fetch_object($hResult)) + { + $iScreenshotId = $oRow->id; + $oScreenshot = new Screenshot($iScreenshotId); + + // load the screenshot and thumbnail + $oScreenshot->load_image(true); + $oScreenshot->load_image(false); + + // are the screenshot and thumbnail images not loaded? if so + // add this screenshot id to the array + if(!$oScreenshot->oScreenshotImage->isLoaded() && + !$oScreenshot->oThumbnailImage->isLoaded()) + { + // add the screenshot id to the array + $aMissingScreenshotIds[] = $iScreenshotId; + } + } + + return $aMissingScreenshotIds; +} + +function removeScreenshotsWithMissingFiles() +{ + $aMissingScreenshotIds = getMissingScreenshotArray(); + + // build the email to admins about what we are doing + $sMsg = "Found ".count($aMissingScreenshotIds)." screenshots with missing files.\r\n"; + //FIXME: uncomment the below line when we uncomment the below lines in the script + // $sMsg.= "Deleting these screenshots.\r\n"; + + $sSubject = "Screenshots deleted\r\n"; + + $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */ + if($sEmail) + mail_appdb($sEmail, $sSubject, $sMsg); + + //FIXME: activate this after we see the results from the nightly cron script email + // remove the screenshots with missing files + // foreach($aMissingScreenshotIds as $iScreenshotId) + // { + // $oScreenshot = new Screenshot($iScreenshotId); + // $oScreenshot->delete(true); // delete the screenshot silently + // } +} ?>