Ken Muldrew

Starter
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

1 Neutral

About Ken Muldrew

  • Rank
    Newbie
  1. That did the trick, psy. Thank you for your help.
  2. This is the line where it crashes: $transport_pages = $pages->find("template=aggregate-entry, aggregate_type.title='Transport'"); Do you mean it should be this instead?: $transport_pages = wire('$pages')->find("template=aggregate-entry, aggregate_type.title='Transport'");
  3. I'm trying to get a short routine to run once per day that will look at some pages and send a reminder email when that customer's subscription (yearly) is about to expire. When I run the code in a template then it works without issue, but inside my lazycron service routine, I get an "Error: Uncaught Error: Call to a member function get() on null" as if the database cannot be found. My autoload module is just the sample HelloWorld module included with ProcessWire, editted to perform this task. The whole of it is included below (I've stripped out the code that generates the email because it never gets past $pages->find): <?php namespace ProcessWire; /** * ProcessWire 'LazyCronLoad' module * */ class LazyCronLoad extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'LazyCronLoad', 'version' => 1, 'summary' => 'Just loads a lazy cron callback.', 'singular' => true, 'autoload' => true, ); } public function init() { // initialize the hook in the AutoLoad module $this->addHook('LazyCron::everyDay', $this, 'myHook'); } public function myHook(HookEvent $e) { // called once per day wire('log')->save('user_activities',' lazy cron service routine'); $transport_pages = $pages->find("template=aggregate-entry, aggregate_type.title='Transport'"); foreach ($transport_pages as $page) { if (($page->purchase_date + 30325800 < time()) && ($page->purchase_date + 30412600 > time())) { // between 351 and 352 days wire('log')->save('user_activities', $page->id . ' email reminder sent'); // send email } } } } The first wire('log') shows up but the second one doesn't (the purchase_date condition is met (as demonstrated by running the code in a template close in time to when the lazycron routine executes)). The error log gives the Uncaught Error shown above. I think this is a beginner's mistake with something obvious being missed and would be grateful for any assistance in fixing it.