// called by iframe
$ajax=true;
require 'res/lib2.php';
ensureonline(); // sets $nightly
sql("update SysStatus set nightly='$today'");
if(!$qrows) {hotlogit("ignore redundant call"); exit;}
logerr("watch nightly",4);
// PURGE BUGS
$d7=date('Y-m-d',strtotime('-7 days'));
sql("delete from Bugs where status in('trash','watch','cron') && lastmod<'$d7'", 'Purge Bugs');
if($qrows)
sql("alter table Bugs engine=innodb");
// PURGE QUESTIONS
$d2=date('Y-m-d',strtotime('-2 day'));
$qid=sql("select distinct quest from QuestionKey where deleted between '$d7' and '$d2'"); // unindexed; check five extra times in case script was down
while($q=$qid->fetch_assoc()) {
extract($q);
if(getsql("select 1 from Responses where quest=$quest", 'used?')) continue; // unindexed
sql("delete from Questions where quest=$quest");
sql("delete from QuestionKey where quest=$quest");
}
$qid->free();
// NOTIFY BUGS
$foolbugs = getsql("select count(*) from Foolacy.Bugs where status='new' && date>='$nightly 00:00:00'", 'New bugs?');
$factbugs = getsql("select count(*) from FactOpy.Bugs where status='new' && date>='$nightly 00:00:00'", 'New bugs?');
$thinkbugs = getsql("select count(*) from ThinkKeen.Bugs where status='new' && date>='$nightly 00:00:00'", 'New bugs?');
$totalbugs=$foolbugs+$factbugs+$thinkbugs;
if($totalbugs) {
$toemail='dhundsness@gmail.com';
$subject="$totalbugs Bugs";
if(!$live) $subject.=" (dev)";
$html="$nightly to $now recent bugs:";
if($foolbugs) $html.="
$foolbugs Foolacy";
if($factbugs) $html.="
$factbugs FactOpy";
if($thinkbugs) $html.="
$thinkbugs ThinkKeen";
if($live) mailit($toemail,$subject,$html);
else logit("mail $toemail\n$subject\n$html");
}
?>