Jump to content

trouble triggering lazycron hook


benbyf
 Share

Recommended Posts

Hi, I'm trying to add a hook to lazycron in my module that finds all pages with a checkbox and then sets less the seconds passed to another field, but as yet have seen anything happen.
 

public function init() {
	$this->checkboxName = "pdp_pub_later_check";
	$this->fieldName = "pdp_pub_later";

	$this->addHook("LazyCron::everyMinute", $this, 'publishDefferedPages');
}
public function ___publishDefferedPages(HookEvent $e){
		// seconds since last lazycron
		$seconds = $e->arguments[0];

		// find all pages with deffered field
		$defferedPages = $this->pages->find("{$this->checkboxName}=true");

		// for each page decrease time for deffered field
		foreach ($defferedPages as $page) {

			// get current page time
			$timeTillPublish = $page->get($this->fieldName);

			// set time to time minus time past
			$timeLeft = $timeTillPublish - $seconds;

			// if time passed 0 or less then publish page
			$page->of(false);
			if($timeLeft <= 0){
				// remove flags and save
				$this->publish();

				$page->set($this->fieldName, 0);
			}else{
				$page->set($this->fieldName, $timeLeft);
			}
			$page->Save();
			$page->of(true);
		}
	}

 

Link to comment
Share on other sites

AAAHAHAHHAAHAAHHAH i think i know what it is, and boy is it annoying!!!! the pages im looking to target a UNPUBLISHED and therefore I cant grab them in $pages, any way of seraching for unpublished pages too? grrrrrrrrr

Link to comment
Share on other sites

Working, legend! It was the old Unpublished pages thing again (something that tripped me up when I first start learning PW), thanks again everything seems to be working and will be releasing deffered pages module soon. (wish the forum still made solved buttons)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...