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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

augmentSQL seems to empty fields from object


Go to End


1568 Views

Avatar
micschk

Community Member, 22 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()",
				));
		}
		
	}

}