From 8e246c387a72051b99044e079f081ebabf003c61 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 24 May 2010 05:12:43 +0000 Subject: [PATCH] ENHANCEMENT Fixed ContentReviewTest to work with SQLite3, MSSQL and Postgres database drivers --- code/ContentReviewEmails.php | 2 +- code/PagesDueForReviewReport.php | 18 +++++++++++------- tests/ContentReviewTest.php | 4 +--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/code/ContentReviewEmails.php b/code/ContentReviewEmails.php index 0b05b9d..534df1f 100644 --- a/code/ContentReviewEmails.php +++ b/code/ContentReviewEmails.php @@ -15,7 +15,7 @@ class ContentReviewEmails extends DailyTask { Subsite::$disable_subsite_filter = true; } - $pages = DataObject::get('Page', "SiteTree.NextReviewDate = '".(class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate())."' AND SiteTree.OwnerID != 0"); + $pages = DataObject::get('Page', "\"SiteTree\".\"NextReviewDate\" = '".(class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate())."' AND \"SiteTree\".\"OwnerID\" != 0"); if ($pages && $pages->Count()) { foreach($pages as $page) { $owner = $page->Owner(); diff --git a/code/PagesDueForReviewReport.php b/code/PagesDueForReviewReport.php index 6dcb0f7..451be74 100644 --- a/code/PagesDueForReviewReport.php +++ b/code/PagesDueForReviewReport.php @@ -1,4 +1,5 @@ URLDate() : SSDatetime::now()->URLDate()) . '\' + INTERVAL 1 DAY'; + $reviewDate = new Zend_Date(SS_Datetime::now()->getValue()); + $reviewDate->add(1, Zend_Date::DAY); + $wheres[] = sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')); } else { // Review date before if(!empty($params['ReviewDateBefore'])) { list($day, $month, $year) = explode('/', $params['ReviewDateBefore']); - $reviewDate = "$year-$month-$day"; - $wheres[] = 'NextReviewDate < \'' . Convert::raw2sql($reviewDate) . '\' + INTERVAL 1 DAY'; + $reviewDate = new Zend_Date("$year-$month-$day"); + $reviewDate->add(1, Zend_Date::DAY); + $wheres[] = sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')); } // Review date after if(!empty($params['ReviewDateAfter'])) { list($day, $month, $year) = explode('/', $params['ReviewDateAfter']); - $reviewDate = "$year-$month-$day"; - $wheres[] = 'NextReviewDate >= \'' . Convert::raw2sql($reviewDate) . '\''; + $reviewDate = new Zend_Date("$year-$month-$day"); + $wheres[] = sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd')); } } @@ -119,7 +123,7 @@ class PagesDueForReviewReport extends SS_Report { $ownerID = (int)$params[$ownerIdParam]; // We use -1 here to distinguish between No Owner and Any if($ownerID == -1) $ownerID = 0; - $wheres[] = 'OwnerID = ' . $ownerID; + $wheres[] = '"OwnerID" = ' . $ownerID; } $query = singleton("SiteTree")->extendedSQL(join(' AND ', $wheres)); @@ -134,7 +138,7 @@ class PagesDueForReviewReport extends SS_Report { $direction = $parts[1]; if($field == 'AbsoluteLink') { - $sort = 'URLSegment ' . $direction; + $sort = '"URLSegment" ' . $direction; } elseif($field == 'Subsite.Title') { $query->from[] = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"'; } diff --git a/tests/ContentReviewTest.php b/tests/ContentReviewTest.php index 169f968..f5c1468 100644 --- a/tests/ContentReviewTest.php +++ b/tests/ContentReviewTest.php @@ -67,11 +67,9 @@ class ContentReviewTest extends FunctionalTest { 'Contact Us' )); - SS_Datetime::set_mock_now('2010-02-13 12:00:00'); - + SS_Datetime::set_mock_now('2010-02-13 00:00:00'); $results = $report->sourceRecords(array( ), 'NextReviewDate ASC', false); - $this->assertEquals($results->column('Title'), array( 'Home', 'About Us'