3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Page for displaying list of jobs.
21 class CRM_Admin_Page_Job
extends CRM_Core_Page_Basic
{
24 * The action links that we need to display for the browse screen.
28 public static $_links = NULL;
36 public function getBAOName() {
37 return 'CRM_Core_BAO_Job';
44 * (reference) of action links
46 public function &links() {
47 if (!(self
::$_links)) {
48 self
::$_links = array(
49 CRM_Core_Action
::FOLLOWUP
=> array(
50 'name' => ts('View Job Log'),
51 'url' => 'civicrm/admin/joblog',
52 'qs' => 'jid=%%id%%&reset=1',
53 'title' => ts('See log entries for this Scheduled Job'),
55 CRM_Core_Action
::UPDATE
=> array(
57 'url' => 'civicrm/admin/job',
58 'qs' => 'action=update&id=%%id%%&reset=1',
59 'title' => ts('Edit Scheduled Job'),
61 CRM_Core_Action
::VIEW
=> array(
62 'name' => ts('Execute Now'),
63 'url' => 'civicrm/admin/job',
64 'qs' => 'action=view&id=%%id%%&reset=1',
65 'title' => ts('Execute Scheduled Job Now'),
67 CRM_Core_Action
::DISABLE
=> array(
68 'name' => ts('Disable'),
69 'ref' => 'crm-enable-disable',
70 'title' => ts('Disable Scheduled Job'),
72 CRM_Core_Action
::ENABLE
=> array(
73 'name' => ts('Enable'),
74 'ref' => 'crm-enable-disable',
75 'title' => ts('Enable Scheduled Job'),
77 CRM_Core_Action
::DELETE
=> array(
78 'name' => ts('Delete'),
79 'url' => 'civicrm/admin/job',
80 'qs' => 'action=delete&id=%%id%%',
81 'title' => ts('Delete Scheduled Job'),
83 CRM_Core_Action
::COPY
=> array(
85 'url' => 'civicrm/admin/job',
86 'qs' => 'action=copy&id=%%id%%',
87 'title' => ts('Copy Scheduled Job'),
97 * This method is called after the page is created. It checks for the
98 * type of action and executes that action.
99 * Finally it calls the parent's run method.
101 public function run() {
102 // set title and breadcrumb
103 CRM_Utils_System
::setTitle(ts('Settings - Scheduled Jobs'));
106 'title' => ts('Scheduled Jobs'),
107 'url' => CRM_Utils_System
::url('civicrm/admin',
112 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
114 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String',
117 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
120 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String',
124 if (($this->_action
& CRM_Core_Action
::COPY
) && (!empty($this->_id
))) {
126 $jobResult = civicrm_api3('Job', 'clone', array('id' => $this->_id
));
127 if ($jobResult['count'] > 0) {
128 CRM_Core_Session
::setStatus($jobResult['values'][$jobResult['id']]['name'], ts('Job copied successfully'), 'success');
130 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/job', 'reset=1'));
132 catch (Exception
$e) {
133 CRM_Core_Session
::setStatus(ts('Failed to copy job'), 'Error');
137 return parent
::run();
143 public function browse() {
144 // check if non-prod mode is enabled.
145 if (CRM_Core_Config
::environment() != 'Production') {
146 CRM_Core_Session
::setStatus(ts('Execution of scheduled jobs has been turned off by default since this is a non-production environment. You can override this for particular jobs by adding runInNonProductionEnvironment=TRUE as a parameter.'), ts("Non-production Environment"), "warning", array('expires' => 0));
149 $cronError = Civi\Api4\System
::check(FALSE)
150 ->addWhere('name', '=', 'checkLastCron')
151 ->addWhere('severity_id', '>', 1)
152 ->setIncludeDisabled(TRUE)
156 CRM_Core_Session
::setStatus($cronError['message'], $cronError['title'], 'alert', ['expires' => 0]);
160 $sj = new CRM_Core_JobManager();
162 foreach ($sj->jobs
as $job) {
163 $action = array_sum(array_keys($this->links()));
165 // update enable/disable links.
166 // CRM-9868- remove enable action for jobs that should never be run automatically via execute action or runjobs url
167 if ($job->api_action
=== 'process_membership_reminder_date' ||
$job->api_action
=== 'update_greeting') {
168 $action -= CRM_Core_Action
::ENABLE
;
169 $action -= CRM_Core_Action
::DISABLE
;
171 elseif ($job->is_active
) {
172 $action -= CRM_Core_Action
::ENABLE
;
175 $action -= CRM_Core_Action
::DISABLE
;
178 $job->action
= CRM_Core_Action
::formLink($this->links(), $action,
186 $rows[] = get_object_vars($job);
188 $this->assign('rows', $rows);
192 * Get name of edit form.
195 * Classname of edit form.
197 public function editForm() {
198 return 'CRM_Admin_Form_Job';
202 * Get edit form name.
207 public function editName() {
208 return 'Scheduled Jobs';
219 public function userContext($mode = NULL) {
220 return 'civicrm/admin/job';