Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

augmentSQL seems to empty fields from object


Go to End
Reply


502 Views

Avatar
micschk

Community Member, 20 Posts

7 July 2014 at 8:51pm

I'm developing a simple module to provide 'soft' scheduling of pages (Embargo & Expire, I'm aware this is also provided by the workflow module). For this I wrote a SiteTreeExtension which adds Embargo & Expiry as Datetimefields.

I'm trying to implement augmentSQL on this in order to filter out pages that are under embargo/expiry. But any time I add an extra 'Where' clause to the augmentSQL method involving the Embargo or Expiry fields, the 'Embargo' and 'Expiry' fields of all resulting Pages appear unset. If I comment out the 'addWhere' lines, these fields load their data just fine.

Am I missing something?

 

class EmbargoExpirySchedulerExtension extends SiteTreeExtension {
	
	public static $db = array(
		'Embargo' => 'SS_Datetime', 
		'Expiry' => 'SS_Datetime'
	);

	...

	function augmentSQL(SQLQuery &$query) {
		
		$myclass = $this->owner->className;
		if (is_subclass_of(Controller::curr(), 'ContentController')) { // on frontend 
			$query
				->addWhere(array(		
					"\"{$myclass}\".\"Embargo\" IS NULL OR \"{$myclass}\".\"Embargo\" < NOW()",
					"\"{$myclass}\".\"Expiry\" IS NULL OR \"{$myclass}\".\"Expiry\" > NOW()",
				));
		}
		
	}

}