$param) { $this->$name = $param; } // version is set to 3 by default - if different number // defined in params, it's replaced later on, however, // it's practically useles, since it seems none of api v2 // will work properly in cron job setup. It might become // useful when/if api v4 starts to emerge and will need // testing in the cron job setup. To permanenty require // hardcoded api version, it's enough to move below line // under following if block. $this->apiParams = array('version' => $this->version); if (!empty($this->parameters)) { $lines = explode("\n", $this->parameters); foreach ($lines as $line) { $pair = explode("=", $line); if (empty($pair[0]) || empty($pair[1])) { $this->remarks[] .= 'Malformed parameters!'; break; } $this->apiParams[trim($pair[0])] = trim($pair[1]); } } } /** * @param null $date */ public function saveLastRun($date = NULL) { $dao = new CRM_Core_DAO_Job(); $dao->id = $this->id; $dao->last_run = ($date == NULL) ? CRM_Utils_Date::currentDBDate() : CRM_Utils_Date::currentDBDate($date); $dao->save(); } /** * @return bool */ public function needsRunning() { // run if it was never run if (empty($this->last_run)) { return TRUE; } // run_frequency check switch ($this->run_frequency) { case 'Always': return TRUE; case 'Hourly': $format = 'YmdH'; break; case 'Daily': $format = 'Ymd'; break; } $now = CRM_Utils_Date::currentDBDate(); $lastTime = date($format, strtotime($this->last_run)); $thisTime = date($format, strtotime($now)); return ($lastTime <> $thisTime); } public function __destruct() { } }