Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * Page for displaying list of jobs. |
6a488035 TO |
20 | */ |
21 | class CRM_Admin_Page_Job extends CRM_Core_Page_Basic { | |
22 | ||
23 | /** | |
eceb18cc | 24 | * The action links that we need to display for the browse screen. |
6a488035 TO |
25 | * |
26 | * @var array | |
6a488035 | 27 | */ |
62d3ee27 | 28 | public static $_links = NULL; |
6a488035 TO |
29 | |
30 | /** | |
eceb18cc | 31 | * Get BAO Name. |
6a488035 | 32 | * |
a6c01b45 CW |
33 | * @return string |
34 | * Classname of BAO. | |
6a488035 | 35 | */ |
00be9182 | 36 | public function getBAOName() { |
6a488035 TO |
37 | return 'CRM_Core_BAO_Job'; |
38 | } | |
39 | ||
40 | /** | |
eceb18cc | 41 | * Get action Links. |
6a488035 | 42 | * |
a6c01b45 CW |
43 | * @return array |
44 | * (reference) of action links | |
6a488035 | 45 | */ |
00be9182 | 46 | public function &links() { |
6a488035 TO |
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'), | |
54 | ), | |
55 | CRM_Core_Action::UPDATE => array( | |
56 | 'name' => ts('Edit'), | |
57 | 'url' => 'civicrm/admin/job', | |
58 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
59 | 'title' => ts('Edit Scheduled Job'), | |
60 | ), | |
a098caf2 | 61 | CRM_Core_Action::VIEW => array( |
6a488035 TO |
62 | 'name' => ts('Execute Now'), |
63 | 'url' => 'civicrm/admin/job', | |
a098caf2 | 64 | 'qs' => 'action=view&id=%%id%%&reset=1', |
6a488035 TO |
65 | 'title' => ts('Execute Scheduled Job Now'), |
66 | ), | |
67 | CRM_Core_Action::DISABLE => array( | |
68 | 'name' => ts('Disable'), | |
4d17a233 | 69 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
70 | 'title' => ts('Disable Scheduled Job'), |
71 | ), | |
72 | CRM_Core_Action::ENABLE => array( | |
73 | 'name' => ts('Enable'), | |
4d17a233 | 74 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
75 | 'title' => ts('Enable Scheduled Job'), |
76 | ), | |
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'), | |
82 | ), | |
7a6059c2 MW |
83 | CRM_Core_Action::COPY => array( |
84 | 'name' => ts('Copy'), | |
85 | 'url' => 'civicrm/admin/job', | |
86 | 'qs' => 'action=copy&id=%%id%%', | |
87 | 'title' => ts('Copy Scheduled Job'), | |
88 | ), | |
6a488035 TO |
89 | ); |
90 | } | |
91 | return self::$_links; | |
92 | } | |
93 | ||
94 | /** | |
95 | * Run the page. | |
96 | * | |
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. | |
6a488035 | 100 | */ |
00be9182 | 101 | public function run() { |
6a488035 TO |
102 | // set title and breadcrumb |
103 | CRM_Utils_System::setTitle(ts('Settings - Scheduled Jobs')); | |
353ffa53 TO |
104 | $breadCrumb = array( |
105 | array( | |
106 | 'title' => ts('Scheduled Jobs'), | |
6a488035 TO |
107 | 'url' => CRM_Utils_System::url('civicrm/admin', |
108 | 'reset=1' | |
109 | ), | |
bed98343 | 110 | ), |
353ffa53 | 111 | ); |
6a488035 TO |
112 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
113 | ||
d71d4aae SL |
114 | $this->_id = CRM_Utils_Request::retrieve('id', 'String', |
115 | $this, FALSE, 0 | |
116 | ); | |
117 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', | |
118 | $this, FALSE, 0 | |
119 | ); | |
120 | ||
7a6059c2 MW |
121 | if (($this->_action & CRM_Core_Action::COPY) && (!empty($this->_id))) { |
122 | try { | |
123 | $jobResult = civicrm_api3('Job', 'clone', array('id' => $this->_id)); | |
124 | if ($jobResult['count'] > 0) { | |
125 | CRM_Core_Session::setStatus($jobResult['values'][$jobResult['id']]['name'], ts('Job copied successfully'), 'success'); | |
126 | } | |
127 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/job', 'reset=1')); | |
128 | } | |
129 | catch (Exception $e) { | |
130 | CRM_Core_Session::setStatus(ts('Failed to copy job'), 'Error'); | |
131 | } | |
132 | } | |
133 | ||
6a488035 TO |
134 | return parent::run(); |
135 | } | |
136 | ||
137 | /** | |
138 | * Browse all jobs. | |
6a488035 | 139 | */ |
41b74a9c | 140 | public function browse() { |
f008885c E |
141 | // check if non-prod mode is enabled. |
142 | if (CRM_Core_Config::environment() != 'Production') { | |
143 | 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)); | |
144 | } | |
6a488035 | 145 | |
6a488035 TO |
146 | $sj = new CRM_Core_JobManager(); |
147 | $rows = $temp = array(); | |
148 | foreach ($sj->jobs as $job) { | |
149 | $action = array_sum(array_keys($this->links())); | |
150 | ||
151 | // update enable/disable links. | |
152 | // CRM-9868- remove enable action for jobs that should never be run automatically via execute action or runjobs url | |
153 | if ($job->api_action == 'process_membership_reminder_date' || $job->api_action == 'update_greeting') { | |
154 | $action -= CRM_Core_Action::ENABLE; | |
155 | $action -= CRM_Core_Action::DISABLE; | |
156 | } | |
157 | elseif ($job->is_active) { | |
158 | $action -= CRM_Core_Action::ENABLE; | |
159 | } | |
160 | else { | |
161 | $action -= CRM_Core_Action::DISABLE; | |
162 | } | |
163 | ||
164 | $job->action = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
165 | array('id' => $job->id), |
166 | ts('more'), | |
167 | FALSE, | |
168 | 'job.manage.action', | |
169 | 'Job', | |
170 | $job->id | |
6a488035 TO |
171 | ); |
172 | $rows[] = get_object_vars($job); | |
173 | } | |
174 | $this->assign('rows', $rows); | |
175 | } | |
176 | ||
177 | /** | |
eceb18cc | 178 | * Get name of edit form. |
6a488035 | 179 | * |
a6c01b45 CW |
180 | * @return string |
181 | * Classname of edit form. | |
6a488035 | 182 | */ |
00be9182 | 183 | public function editForm() { |
6a488035 TO |
184 | return 'CRM_Admin_Form_Job'; |
185 | } | |
186 | ||
187 | /** | |
eceb18cc | 188 | * Get edit form name. |
6a488035 | 189 | * |
a6c01b45 CW |
190 | * @return string |
191 | * name of this page. | |
6a488035 | 192 | */ |
00be9182 | 193 | public function editName() { |
6a488035 TO |
194 | return 'Scheduled Jobs'; |
195 | } | |
196 | ||
197 | /** | |
198 | * Get user context. | |
199 | * | |
77b97be7 EM |
200 | * @param null $mode |
201 | * | |
a6c01b45 CW |
202 | * @return string |
203 | * user context. | |
6a488035 | 204 | */ |
00be9182 | 205 | public function userContext($mode = NULL) { |
6a488035 TO |
206 | return 'civicrm/admin/job'; |
207 | } | |
96025800 | 208 | |
6a488035 | 209 | } |