Jump to content

Recommended Posts

Posted

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);
		}
	}

 

Posted

sorry my bad, i left out another function:

public function publish($page) {
		$page->removeStatus(Page::statusUnpublished);
		$page->removeStatus(Page::statusHidden);
		$page->Save();
	}

 

Screenshot 2016-08-11 15.37.15.png

Posted

now added the $page, but still cant seem to get cron to fire. is the a simple thing to do to check if LazyCron is even working? thanks

Posted

Yeah, just write something to the log in your method. I'm on mobile, so no example unforunately. You could even simply die(); the whole thing. Is your module autoloaded?

  • Like 1
Posted

Cron is working as it's printing to the logs :) so must be not finding the pages or something. Havent used $log before, and im an idiot for not, so thanks for the push in that direction for debugging.

Posted

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

Posted

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

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
×
×
  • Create New...