17f090e8f6f572f330cb3c87e4808b303353cf59
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
39 class CRM_Admin_Form_Job
extends CRM_Admin_Form
{
40 protected $_id = NULL;
42 function preProcess() {
46 CRM_Utils_System
::setTitle(ts('Manage - Scheduled Jobs'));
49 $refreshURL = CRM_Utils_System
::url('civicrm/admin/job',
50 "reset=1&action=update&id={$this->_id}",
55 $refreshURL = CRM_Utils_System
::url('civicrm/admin/job',
61 $this->assign('refreshURL', $refreshURL);
65 * Function to build the form
70 public function buildQuickForm($check = FALSE) {
71 parent
::buildQuickForm();
73 if ($this->_action
& CRM_Core_Action
::DELETE
) {
77 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Job');
79 $this->add('text', 'name', ts('Name'),
80 $attributes['name'], TRUE
83 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_Job', $this->_id
));
85 $this->add('text', 'description', ts('Description'),
86 $attributes['description']
89 $this->add('text', 'api_entity', ts('API Call Entity'),
90 $attributes['api_entity'], TRUE
93 $this->add('text', 'api_action', ts('API Call Action'),
94 $attributes['api_action'], TRUE
97 $this->add('select', 'run_frequency', ts('Run frequency'),
98 array('Daily' => ts('Daily'), 'Hourly' => ts('Hourly'), 'Always' => ts('Every time cron job is run'))
102 $this->add('textarea', 'parameters', ts('Command parameters'),
106 // is this job active ?
107 $this->add('checkbox', 'is_active', ts('Is this Scheduled Job active?'));
109 $this->addFormRule(array('CRM_Admin_Form_Job', 'formRule'));
112 static function formRule($fields) {
116 require_once 'api/api.php';
118 $apiRequest = array();
119 $apiRequest['entity'] = CRM_Utils_String
::munge($fields['api_entity']);
120 $apiRequest['action'] = CRM_Utils_String
::munge($fields['api_action']);
121 $apiRequest['version'] = 3;
122 $apiRequest +
= _civicrm_api_resolve($apiRequest); // look up function, file, is_generic
124 if( !$apiRequest['function'] ) {
125 $errors['api_action'] = ts('Given API command is not defined.');
128 if (!empty($errors)) {
132 return empty($errors) ?
TRUE : $errors;
135 function setDefaultValues() {
139 $defaults['is_active'] = $defaults['is_default'] = 1;
142 $domainID = CRM_Core_Config
::domainID();
144 $dao = new CRM_Core_DAO_Job();
145 $dao->id
= $this->_id
;
146 $dao->domain_id
= $domainID;
147 if (!$dao->find(TRUE)) {
151 CRM_Core_DAO
::storeValues($dao, $defaults);
154 // job entity thats shipped with core is all lower case.
155 // this makes sure camel casing is followed for proper working of default population.
156 if (!empty($defaults['api_entity'])) {
157 $defaults['api_entity'] = ucfirst($defaults['api_entity']);
164 * Function to process the form
170 public function postProcess() {
172 CRM_Utils_System
::flushCache('CRM_Core_DAO_Job');
174 if ($this->_action
& CRM_Core_Action
::DELETE
) {
175 CRM_Core_BAO_Job
::del($this->_id
);
176 CRM_Core_Session
::setStatus("", ts('Scheduled Job Deleted.'), "success");
180 $values = $this->controller
->exportValues($this->_name
);
181 $domainID = CRM_Core_Config
::domainID();
183 $dao = new CRM_Core_DAO_Job();
185 $dao->id
= $this->_id
;
186 $dao->domain_id
= $domainID;
187 $dao->run_frequency
= $values['run_frequency'];
188 $dao->parameters
= $values['parameters'];
189 $dao->name
= $values['name'];
190 $dao->api_entity
= $values['api_entity'];
191 $dao->api_action
= $values['api_action'];
192 $dao->description
= $values['description'];
193 $dao->is_active
= CRM_Utils_Array
::value('is_active', $values, 0);
197 // CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url.
198 if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array
::value('is_active', $values) == 1) {
199 // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
200 $docLink = CRM_Utils_System
::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
201 $msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', array(1 => $docLink));
202 CRM_Core_Session
::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert');