Add an 'Execute Now' button to the job log
[civicrm-core.git] / CRM / Admin / Form / Job.php
index e304420e0cd232db2afe9a60e596163dda643b95..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'));
 
@@ -56,7 +57,7 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
     }
 
     if ($this->_action & CRM_Core_Action::VIEW) {
-      $this->assign('jobName', self::getJobName($this->_id)); 
+      $this->assign('jobName', self::getJobName($this->_id));
       $this->addButtons([
         [
           'type' => 'submit',
@@ -70,7 +71,6 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
       ]);
       return;
     }
-        
 
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Job');
 
@@ -98,7 +98,7 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
     $this->add('select', 'run_frequency', ts('Run frequency'), CRM_Core_SelectValues::getJobFrequency());
 
     // CRM-17686
-    $this->add('datepicker', 'scheduled_run_date', ts('Scheduled Run Date'), NULL, FALSE, ['minDate' => time()]);
+    $this->add('datepicker', 'scheduled_run_date', ts('Scheduled Run Date'), NULL, FALSE, ['minDate' => date('Y-m-d')]);
 
     $this->add('textarea', 'parameters', ts('Command parameters'),
       "cols=50 rows=6"
@@ -195,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;
     }
 
@@ -242,8 +250,7 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
 
     // CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url.
     if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array::value('is_active', $values) == 1) {
-      // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
-      $docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
+      $docLink = CRM_Utils_System::docURL2("user/initial-set-up/scheduled-jobs/#job_update_greeting");
       $msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', [1 => $docLink]);
       CRM_Core_Session::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert');
     }