3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * Page for displaying list of jobs.
37 class CRM_Admin_Page_Job
extends CRM_Core_Page_Basic
{
40 * The action links that we need to display for the browse screen.
44 static $_links = NULL;
52 public function getBAOName() {
53 return 'CRM_Core_BAO_Job';
60 * (reference) of action links
62 public function &links() {
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'),
71 CRM_Core_Action
::UPDATE
=> array(
73 'url' => 'civicrm/admin/job',
74 'qs' => 'action=update&id=%%id%%&reset=1',
75 'title' => ts('Edit Scheduled Job'),
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'),
83 CRM_Core_Action
::DISABLE
=> array(
84 'name' => ts('Disable'),
85 'ref' => 'crm-enable-disable',
86 'title' => ts('Disable Scheduled Job'),
88 CRM_Core_Action
::ENABLE
=> array(
89 'name' => ts('Enable'),
90 'ref' => 'crm-enable-disable',
91 'title' => ts('Enable Scheduled Job'),
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'),
101 return self
::$_links;
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.
111 public function run() {
112 // set title and breadcrumb
113 CRM_Utils_System
::setTitle(ts('Settings - Scheduled Jobs'));
116 'title' => ts('Scheduled Jobs'),
117 'url' => CRM_Utils_System
::url('civicrm/admin',
122 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
124 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String',
127 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
131 if ($this->_action
== 'export') {
132 $session = CRM_Core_Session
::singleton();
133 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/job', 'reset=1'));
136 return parent
::run();
142 * @param null $action
144 public function browse($action = NULL) {
145 // check if non-prod mode is enabled.
146 if (CRM_Core_Config
::environment() != 'Production') {
147 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));
150 // using Export action for Execute. Doh.
151 if ($this->_action
& CRM_Core_Action
::EXPORT
) {
152 $jm = new CRM_Core_JobManager();
153 $jm->executeJobById($this->_id
);
155 CRM_Core_Session
::setStatus(ts('Selected Scheduled Job has been executed. See the log for details.'), ts("Executed"), "success");
158 $sj = new CRM_Core_JobManager();
159 $rows = $temp = array();
160 foreach ($sj->jobs
as $job) {
161 $action = array_sum(array_keys($this->links()));
163 // update enable/disable links.
164 // CRM-9868- remove enable action for jobs that should never be run automatically via execute action or runjobs url
165 if ($job->api_action
== 'process_membership_reminder_date' ||
$job->api_action
== 'update_greeting') {
166 $action -= CRM_Core_Action
::ENABLE
;
167 $action -= CRM_Core_Action
::DISABLE
;
169 elseif ($job->is_active
) {
170 $action -= CRM_Core_Action
::ENABLE
;
173 $action -= CRM_Core_Action
::DISABLE
;
176 $job->action
= CRM_Core_Action
::formLink(self
::links(), $action,
177 array('id' => $job->id
),
184 $rows[] = get_object_vars($job);
186 $this->assign('rows', $rows);
190 * Get name of edit form.
193 * Classname of edit form.
195 public function editForm() {
196 return 'CRM_Admin_Form_Job';
200 * Get edit form name.
205 public function editName() {
206 return 'Scheduled Jobs';
217 public function userContext($mode = NULL) {
218 return 'civicrm/admin/job';