3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This interface defines methods that need to be implemented
30 * by every scheduled job (cron task) in CiviCRM.
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Core_ScheduledJob
{
43 var $apiParams = array();
45 var $remarks = array();
50 * @param string $namespace namespace prefix for component's files
55 public function __construct($params) {
56 foreach ($params as $name => $param) {
57 $this->$name = $param;
60 // version is set to 3 by default - if different number
61 // defined in params, it's replaced later on, however,
62 // it's practically useles, since it seems none of api v2
63 // will work properly in cron job setup. It might become
64 // useful when/if api v4 starts to emerge and will need
65 // testing in the cron job setup. To permanenty require
66 // hardcoded api version, it's enough to move below line
67 // under following if block.
68 $this->apiParams
= array('version' => $this->version
);
70 if (!empty($this->parameters
)) {
71 $lines = explode("\n", $this->parameters
);
73 foreach ($lines as $line) {
74 $pair = explode("=", $line);
75 if (empty($pair[0]) ||
empty($pair[1])) {
76 $this->remarks
[] .= 'Malformed parameters!';
79 $this->apiParams
[trim($pair[0])] = trim($pair[1]);
84 public function saveLastRun($date = NULL) {
85 $dao = new CRM_Core_DAO_Job();
87 $dao->last_run
= ($date == NULL) ? CRM_Utils_Date
::currentDBDate() : CRM_Utils_Date
::currentDBDate($date);
91 public function needsRunning() {
92 // run if it was never run
93 if (empty($this->last_run
)) {
97 // run_frequency check
98 switch ($this->run_frequency
) {
103 $now = CRM_Utils_Date
::currentDBDate();
104 $hourAgo = strtotime('-1 hour', strtotime($now));
105 $lastRun = strtotime($this->last_run
);
106 if ($lastRun < $hourAgo) {
111 $now = CRM_Utils_Date
::currentDBDate();
112 $dayAgo = strtotime('-1 day', strtotime($now));
113 $lastRun = strtotime($this->last_run
);
114 if ($lastRun < $dayAgo) {
122 public function __destruct() {}