From 2bcbb8ee7dd7b6ae6b6cf709c1f6eb565586d551 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 16 Dec 2008 04:35:28 +0000 Subject: [PATCH] BUGFIX: #1709 - Archive widgets shows months and years for unpublished posts --- code/ArchiveWidget.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/ArchiveWidget.php b/code/ArchiveWidget.php index f5cb756..93227b4 100644 --- a/code/ArchiveWidget.php +++ b/code/ArchiveWidget.php @@ -52,10 +52,14 @@ class ArchiveWidget extends Widget { $blogHolder = $this->getBlogHolder(); $id = $blogHolder->ID; + $stage = Versioned::current_stage(); + $suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage"; + + if($this->DisplayMode == 'month') { - $sqlResults = DB::query("SELECT DISTINCT MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year` FROM `SiteTree` NATURAL JOIN `BlogEntry` WHERE `ParentID` = $id ORDER BY `Date` DESC"); + $sqlResults = DB::query("SELECT DISTINCT MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year` FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` WHERE `ParentID` = $id ORDER BY `Date` DESC"); } else { - $sqlResults = DB::query("SELECT DISTINCT YEAR(`Date`) AS `Year` FROM `SiteTree` NATURAL JOIN `BlogEntry` WHERE `ParentID` = $id ORDER BY `Date` DESC"); + $sqlResults = DB::query("SELECT DISTINCT YEAR(`Date`) AS `Year` FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` WHERE `ParentID` = $id ORDER BY `Date` DESC"); } if(!$sqlResults) return new DataObjectSet();