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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class contains scheduled jobs related functions.
39 class CRM_Core_BAO_Job
extends CRM_Core_DAO_Job
{
44 function __construct() {
45 parent
::__construct();
48 * Function to add the payment-processor type in the db
50 * @param array $params (reference ) an assoc array of name/value pairs
51 * @param array $ids the array that holds all the db ids
53 * @return object CRM_Financial_DAO_PaymentProcessorType
58 static function create($params) {
59 $job = new CRM_Core_DAO_Job();
60 $job->copyValues($params);
65 * Takes a bunch of params that are needed to match certain criteria and
66 * retrieves the relevant objects. It also stores all the retrieved
67 * values in the default array
69 * @param array $params (reference ) an assoc array of name/value pairs
70 * @param array $defaults (reference ) an assoc array to hold the flattened values
72 * @return object CRM_Core_DAO_Job object on success, null otherwise
76 static function retrieve(&$params, &$defaults) {
77 $job = new CRM_Core_DAO_Job();
78 $job->copyValues($params);
79 if ($job->find(TRUE)) {
80 CRM_Core_DAO
::storeValues($job, $defaults);
87 * update the is_active flag in the db
89 * @param int $id id of the database record
90 * @param boolean $is_active value we want to set the is_active field
92 * @return Object DAO object on sucess, null otherwise
97 static function setIsActive($id, $is_active) {
98 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_Job', $id, 'is_active', $is_active);
102 * Function to delete scheduled job
104 * @param int $jobId ID of the job to be deleted.
109 static function del($jobID) {
111 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function'));
114 $dao = new CRM_Core_DAO_Job();
116 if (!$dao->find(TRUE)) {
120 if ($dao->delete()) {
126 * Trim job table on a regular basis to keep it at a good size
130 static function cleanup($maxEntriesToKeep = 1000, $minDaysToKeep = 30) {
131 // Prevent the job log from getting too big
132 // For now, keep last minDays days and at least maxEntries records
133 $query = 'SELECT COUNT(*) FROM civicrm_job_log';
134 $count = CRM_Core_DAO
::singleValueQuery($query);
136 if ( $count <= $maxEntriesToKeep) {
140 $count = $count - $maxEntriesToKeep;
142 $query = "DELETE FROM civicrm_job_log WHERE run_time < SUBDATE(NOW(), $minDaysToKeep) LIMIT $count";
143 CRM_Core_DAO
::executeQuery($query);