Merge pull request #22484 from civicrm/5.46
[civicrm-core.git] / CRM / Admin / Page / JobLog.php
CommitLineData
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 */
21class CRM_Admin_Page_JobLog 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 return self::$_links;
48 }
49
50 /**
51 * Run the page.
52 *
53 * This method is called after the page is created. It checks for the
54 * type of action and executes that action.
55 * Finally it calls the parent's run method.
6a488035 56 */
00be9182 57 public function run() {
6a488035
TO
58 // set title and breadcrumb
59 CRM_Utils_System::setTitle(ts('Settings - Scheduled Jobs Log'));
353ffa53
TO
60 $breadCrumb = array(
61 array(
62 'title' => ts('Administration'),
6a488035
TO
63 'url' => CRM_Utils_System::url('civicrm/admin',
64 'reset=1'
65 ),
389bcebf 66 ),
353ffa53 67 );
6a488035
TO
68 CRM_Utils_System::appendBreadCrumb($breadCrumb);
69 return parent::run();
70 }
71
72 /**
73 * Browse all jobs.
6a488035 74 */
41b74a9c 75 public function browse() {
ed2ee15a 76 $jid = CRM_Utils_Request::retrieve('jid', 'Positive');
6a488035
TO
77
78 $sj = new CRM_Core_JobManager();
79
5e99888b 80 if ($jid) {
389bcebf 81 $jobName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Job', $jid);
ed2ee15a
MW
82 $this->assign('jobName', $jobName);
83 $jobRunUrl = CRM_Utils_System::url('civicrm/admin/job', 'action=view&reset=1&context=joblog&id=' . $jid);
84 $this->assign('jobRunUrl', $jobRunUrl);
6a488035
TO
85 }
86
6a488035
TO
87 $dao = new CRM_Core_DAO_JobLog();
88 $dao->orderBy('id desc');
5e99888b
DL
89
90 // limit to last 1000 records
91 $dao->limit(1000);
92
93 if ($jid) {
6a488035
TO
94 $dao->job_id = $jid;
95 }
96 $dao->find();
5e99888b 97
affcc9d2 98 $rows = [];
6a488035
TO
99 while ($dao->fetch()) {
100 unset($row);
101 CRM_Core_DAO::storeValues($dao, $row);
102 $rows[$dao->id] = $row;
103 }
104 $this->assign('rows', $rows);
105
106 $this->assign('jobId', $jid);
107 }
108
109 /**
eceb18cc 110 * Get name of edit form.
6a488035 111 *
a6c01b45
CW
112 * @return string
113 * Classname of edit form.
6a488035 114 */
00be9182 115 public function editForm() {
6a488035
TO
116 return 'CRM_Admin_Form_Job';
117 }
118
119 /**
eceb18cc 120 * Get edit form name.
6a488035 121 *
a6c01b45
CW
122 * @return string
123 * name of this page.
6a488035 124 */
00be9182 125 public function editName() {
6a488035
TO
126 return 'Scheduled Jobs';
127 }
128
129 /**
130 * Get user context.
131 *
da6b46f4
EM
132 * @param null $mode
133 *
a6c01b45
CW
134 * @return string
135 * user context.
6a488035 136 */
00be9182 137 public function userContext($mode = NULL) {
6a488035
TO
138 return 'civicrm/admin/job';
139 }
96025800 140
6a488035 141}