| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Page for displaying list of jobs. |
| 20 | */ |
| 21 | class CRM_Admin_Page_JobLog extends CRM_Core_Page_Basic { |
| 22 | |
| 23 | /** |
| 24 | * The action links that we need to display for the browse screen. |
| 25 | * |
| 26 | * @var array |
| 27 | */ |
| 28 | public static $_links = NULL; |
| 29 | |
| 30 | /** |
| 31 | * Get BAO Name. |
| 32 | * |
| 33 | * @return string |
| 34 | * Classname of BAO. |
| 35 | */ |
| 36 | public function getBAOName() { |
| 37 | return 'CRM_Core_BAO_Job'; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Get action Links. |
| 42 | * |
| 43 | * @return array |
| 44 | * (reference) of action links |
| 45 | */ |
| 46 | public function &links() { |
| 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. |
| 56 | */ |
| 57 | public function run() { |
| 58 | // set title and breadcrumb |
| 59 | CRM_Utils_System::setTitle(ts('Settings - Scheduled Jobs Log')); |
| 60 | $breadCrumb = array( |
| 61 | array( |
| 62 | 'title' => ts('Administration'), |
| 63 | 'url' => CRM_Utils_System::url('civicrm/admin', |
| 64 | 'reset=1' |
| 65 | ), |
| 66 | ), |
| 67 | ); |
| 68 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
| 69 | return parent::run(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Browse all jobs. |
| 74 | */ |
| 75 | public function browse() { |
| 76 | $jid = CRM_Utils_Request::retrieve('jid', 'Positive'); |
| 77 | |
| 78 | $sj = new CRM_Core_JobManager(); |
| 79 | |
| 80 | if ($jid) { |
| 81 | $jobName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Job', $jid); |
| 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); |
| 85 | } |
| 86 | |
| 87 | $dao = new CRM_Core_DAO_JobLog(); |
| 88 | $dao->orderBy('id desc'); |
| 89 | |
| 90 | // limit to last 1000 records |
| 91 | $dao->limit(1000); |
| 92 | |
| 93 | if ($jid) { |
| 94 | $dao->job_id = $jid; |
| 95 | } |
| 96 | $dao->find(); |
| 97 | |
| 98 | $rows = []; |
| 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 | /** |
| 110 | * Get name of edit form. |
| 111 | * |
| 112 | * @return string |
| 113 | * Classname of edit form. |
| 114 | */ |
| 115 | public function editForm() { |
| 116 | return 'CRM_Admin_Form_Job'; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Get edit form name. |
| 121 | * |
| 122 | * @return string |
| 123 | * name of this page. |
| 124 | */ |
| 125 | public function editName() { |
| 126 | return 'Scheduled Jobs'; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get user context. |
| 131 | * |
| 132 | * @param null $mode |
| 133 | * |
| 134 | * @return string |
| 135 | * user context. |
| 136 | */ |
| 137 | public function userContext($mode = NULL) { |
| 138 | return 'civicrm/admin/job'; |
| 139 | } |
| 140 | |
| 141 | } |