Merge pull request #8980 from ergonlogic/dev/CRM-19308
[civicrm-core.git] / CRM / Admin / Page / Job.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
32 */
33
34/**
ce064e4f 35 * Page for displaying list of jobs.
6a488035
TO
36 */
37class CRM_Admin_Page_Job extends CRM_Core_Page_Basic {
38
39 /**
eceb18cc 40 * The action links that we need to display for the browse screen.
6a488035
TO
41 *
42 * @var array
6a488035
TO
43 */
44 static $_links = NULL;
45
46 /**
eceb18cc 47 * Get BAO Name.
6a488035 48 *
a6c01b45
CW
49 * @return string
50 * Classname of BAO.
6a488035 51 */
00be9182 52 public function getBAOName() {
6a488035
TO
53 return 'CRM_Core_BAO_Job';
54 }
55
56 /**
eceb18cc 57 * Get action Links.
6a488035 58 *
a6c01b45
CW
59 * @return array
60 * (reference) of action links
6a488035 61 */
00be9182 62 public function &links() {
6a488035
TO
63 if (!(self::$_links)) {
64 self::$_links = array(
65 CRM_Core_Action::FOLLOWUP => array(
66 'name' => ts('View Job Log'),
67 'url' => 'civicrm/admin/joblog',
68 'qs' => 'jid=%%id%%&reset=1',
69 'title' => ts('See log entries for this Scheduled Job'),
70 ),
71 CRM_Core_Action::UPDATE => array(
72 'name' => ts('Edit'),
73 'url' => 'civicrm/admin/job',
74 'qs' => 'action=update&id=%%id%%&reset=1',
75 'title' => ts('Edit Scheduled Job'),
76 ),
77 CRM_Core_Action::EXPORT => array(
78 'name' => ts('Execute Now'),
79 'url' => 'civicrm/admin/job',
80 'qs' => 'action=export&id=%%id%%&reset=1',
81 'title' => ts('Execute Scheduled Job Now'),
82 ),
83 CRM_Core_Action::DISABLE => array(
84 'name' => ts('Disable'),
4d17a233 85 'ref' => 'crm-enable-disable',
6a488035
TO
86 'title' => ts('Disable Scheduled Job'),
87 ),
88 CRM_Core_Action::ENABLE => array(
89 'name' => ts('Enable'),
4d17a233 90 'ref' => 'crm-enable-disable',
6a488035
TO
91 'title' => ts('Enable Scheduled Job'),
92 ),
93 CRM_Core_Action::DELETE => array(
94 'name' => ts('Delete'),
95 'url' => 'civicrm/admin/job',
96 'qs' => 'action=delete&id=%%id%%',
97 'title' => ts('Delete Scheduled Job'),
98 ),
99 );
100 }
101 return self::$_links;
102 }
103
104 /**
105 * Run the page.
106 *
107 * This method is called after the page is created. It checks for the
108 * type of action and executes that action.
109 * Finally it calls the parent's run method.
6a488035 110 */
00be9182 111 public function run() {
6a488035
TO
112 // set title and breadcrumb
113 CRM_Utils_System::setTitle(ts('Settings - Scheduled Jobs'));
353ffa53
TO
114 $breadCrumb = array(
115 array(
116 'title' => ts('Scheduled Jobs'),
6a488035
TO
117 'url' => CRM_Utils_System::url('civicrm/admin',
118 'reset=1'
119 ),
bed98343 120 ),
353ffa53 121 );
6a488035
TO
122 CRM_Utils_System::appendBreadCrumb($breadCrumb);
123
124 $this->_id = CRM_Utils_Request::retrieve('id', 'String',
125 $this, FALSE, 0
126 );
127 $this->_action = CRM_Utils_Request::retrieve('action', 'String',
128 $this, FALSE, 0
129 );
130
131 if ($this->_action == 'export') {
132 $session = CRM_Core_Session::singleton();
133 $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/job', 'reset=1'));
134 }
135
6a488035
TO
136 return parent::run();
137 }
138
139 /**
140 * Browse all jobs.
141 *
da6b46f4 142 * @param null $action
6a488035 143 */
00be9182 144 public function browse($action = NULL) {
6a488035
TO
145
146 // using Export action for Execute. Doh.
147 if ($this->_action & CRM_Core_Action::EXPORT) {
148 $jm = new CRM_Core_JobManager();
149 $jm->executeJobById($this->_id);
150
151 CRM_Core_Session::setStatus(ts('Selected Scheduled Job has been executed. See the log for details.'), ts("Executed"), "success");
152 }
153
154 $sj = new CRM_Core_JobManager();
155 $rows = $temp = array();
156 foreach ($sj->jobs as $job) {
157 $action = array_sum(array_keys($this->links()));
158
159 // update enable/disable links.
160 // CRM-9868- remove enable action for jobs that should never be run automatically via execute action or runjobs url
161 if ($job->api_action == 'process_membership_reminder_date' || $job->api_action == 'update_greeting') {
162 $action -= CRM_Core_Action::ENABLE;
163 $action -= CRM_Core_Action::DISABLE;
164 }
165 elseif ($job->is_active) {
166 $action -= CRM_Core_Action::ENABLE;
167 }
168 else {
169 $action -= CRM_Core_Action::DISABLE;
170 }
171
172 $job->action = CRM_Core_Action::formLink(self::links(), $action,
87dab4a4
AH
173 array('id' => $job->id),
174 ts('more'),
175 FALSE,
176 'job.manage.action',
177 'Job',
178 $job->id
6a488035
TO
179 );
180 $rows[] = get_object_vars($job);
181 }
182 $this->assign('rows', $rows);
183 }
184
185 /**
eceb18cc 186 * Get name of edit form.
6a488035 187 *
a6c01b45
CW
188 * @return string
189 * Classname of edit form.
6a488035 190 */
00be9182 191 public function editForm() {
6a488035
TO
192 return 'CRM_Admin_Form_Job';
193 }
194
195 /**
eceb18cc 196 * Get edit form name.
6a488035 197 *
a6c01b45
CW
198 * @return string
199 * name of this page.
6a488035 200 */
00be9182 201 public function editName() {
6a488035
TO
202 return 'Scheduled Jobs';
203 }
204
205 /**
206 * Get user context.
207 *
77b97be7
EM
208 * @param null $mode
209 *
a6c01b45
CW
210 * @return string
211 * user context.
6a488035 212 */
00be9182 213 public function userContext($mode = NULL) {
6a488035
TO
214 return 'civicrm/admin/job';
215 }
96025800 216
6a488035 217}