Add an 'Execute Now' button to the job log
authorMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 17 Jan 2020 19:04:00 +0000 (19:04 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Sat, 26 Sep 2020 18:15:39 +0000 (19:15 +0100)
CRM/Admin/Form/Job.php
CRM/Admin/Page/Job.php
CRM/Admin/Page/JobLog.php
templates/CRM/Admin/Page/JobLog.tpl

index 65bb09710e2ab6b2609258c8bada34cbe870435a..dec88aeeab13b922f399719a639cdceaf0b44866 100644 (file)
@@ -24,6 +24,7 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
   public function preProcess() {
 
     parent::preProcess();
+    $this->setContext();
 
     CRM_Utils_System::setTitle(ts('Manage - Scheduled Jobs'));
 
@@ -194,7 +195,15 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
       $jm->executeJobById($this->_id);
       $jobName = self::getJobName($this->_id);
       CRM_Core_Session::setStatus(ts('%1 Scheduled Job has been executed. See the log for details.', [1 => $jobName]), ts("Executed"), "success");
-      CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/job', 'reset=1'));
+
+      if ($this->getContext() === 'joblog') {
+        // If we were triggered via the joblog form redirect back there when we finish
+        $redirectUrl = CRM_Utils_System::url('civicrm/admin/joblog', 'reset=1&jid=' . $this->_id);
+      }
+      else {
+        $redirectUrl = CRM_Utils_System::url('civicrm/admin/job', 'reset=1');
+      }
+      CRM_Utils_System::redirect($redirectUrl);
       return;
     }
 
index 2164d2b7cefa57fd7c6531b9b6243d2933abf7cd..5a8d30767c570fcbc86885b991cd37f9abb7dfaf 100644 (file)
@@ -117,6 +117,9 @@ class CRM_Admin_Page_Job extends CRM_Core_Page_Basic {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String',
       $this, FALSE, 0
     );
+    $this->_context = CRM_Utils_Request::retrieve('context', 'String',
+      $this, FALSE, 0
+    );
 
     if (($this->_action & CRM_Core_Action::COPY) && (!empty($this->_id))) {
       try {
index c7b1226535f9274e0f4b7a328b529b5773e371eb..e31a52558d6fd66fbf18688adf44c0d25554f813 100644 (file)
@@ -73,17 +73,17 @@ class CRM_Admin_Page_JobLog extends CRM_Core_Page_Basic {
    * Browse all jobs.
    */
   public function browse() {
-    $jid = CRM_Utils_Request::retrieve('jid', 'Positive', $this);
+    $jid = CRM_Utils_Request::retrieve('jid', 'Positive');
 
     $sj = new CRM_Core_JobManager();
 
-    $jobName = NULL;
     if ($jid) {
       $jobName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Job', $jid);
+      $this->assign('jobName', $jobName);
+      $jobRunUrl = CRM_Utils_System::url('civicrm/admin/job', 'action=view&reset=1&context=joblog&id=' . $jid);
+      $this->assign('jobRunUrl', $jobRunUrl);
     }
 
-    $this->assign('jobName', $jobName);
-
     $dao = new CRM_Core_DAO_JobLog();
     $dao->orderBy('id desc');
 
index 367b0f5b1b113bd9d63029dcd56bc8dcb12cd4da..ca3bac9e5566ed4cc7032440f1396009fb6004a8 100644 (file)
@@ -19,6 +19,9 @@
 
   <div class="action-link">
     <a href="{crmURL p='civicrm/admin/job' q="reset=1"}" id="jobsList-top" class="button"><span><i class="crm-i fa-chevron-left" aria-hidden="true"></i> {ts}Back to Scheduled Jobs Listing{/ts}</span></a>
+    {if $jobRunUrl}
+      <a href="{$jobRunUrl}" id="jobsList-run-top" class="button"><span><i class="crm-i fa-play" aria-hidden="true"></i> {ts}Execute Now{/ts}</span></a>
+    {/if}
   </div>
 
 {if $rows}
@@ -60,5 +63,8 @@
 
   <div class="action-link">
     <a href="{crmURL p='civicrm/admin/job' q="reset=1"}" id="jobsList-bottom" class="button"><span><i class="crm-i fa-chevron-left" aria-hidden="true"></i> {ts}Back to Scheduled Jobs Listing{/ts}</span></a>
+    {if $jobRunUrl}
+      <a href="{$jobRunUrl}" id="jobsList-run-bottom" class="button"><span><i class="crm-i fa-play" aria-hidden="true"></i> {ts}Execute Now{/ts}</span></a>
+    {/if}
   </div>
 </div>