From 6ae7e3577853a6fd663372e79fcb08bc8d29896c Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 2 Mar 2013 05:37:52 +0100 Subject: [PATCH] Only attempt to update statistics for all campaigns if there actually are any campaigns --- public_html/cron.daily.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/public_html/cron.daily.php b/public_html/cron.daily.php index a553429..586a608 100644 --- a/public_html/cron.daily.php +++ b/public_html/cron.daily.php @@ -48,9 +48,23 @@ foreach($sSubscriptions as $sSubscription) /* Now, we'll log a historical statistics snapshot for every campaign. */ -foreach(Campaign::CreateFromQuery("SELECT * FROM campaigns") as $sCampaign) +try +{ + $sCampaigns = Campaign::CreateFromQuery("SELECT * FROM campaigns"); + $found = true; +} +catch (NotFoundException $e) +{ + /* No campaigns are in the database yet. */ + $found = false; +} + +if($found) { - $sCampaign->UpdateStatistics(); - $sStatisticsEntry = $sCampaign->CreateStatisticsEntry(); - $sStatisticsEntry->InsertIntoDatabase(); + foreach($sCampaigns as $sCampaign) + { + $sCampaign->UpdateStatistics(); + $sStatisticsEntry = $sCampaign->CreateStatisticsEntry(); + $sStatisticsEntry->InsertIntoDatabase(); + } }