civicrm/queue/monitor - Add skeletal page for monitoring status
authorTim Otten <totten@civicrm.org>
Sat, 4 Jun 2022 08:09:42 +0000 (01:09 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 9 Jun 2022 23:40:57 +0000 (16:40 -0700)
CRM/Queue/Menu.php
CRM/Queue/Page/Monitor.php [new file with mode: 0644]
templates/CRM/Queue/Page/Monitor.tpl [new file with mode: 0644]

index b3883e569dda205ce61869a81309c2a6586e844f..c33e0e11e9b405e51fd00535ea78178f11d12f99 100644 (file)
@@ -65,6 +65,15 @@ class CRM_Queue_Menu {
         $menuPath['access_callback'] = ['CRM_Core_Permission', 'checkMenu'];
         break;
 
+      case 'civicrm/queue/monitor':
+        // Not supported: case 'civicrm/upgrade/queue/monitor':
+        $menuPath['path'] = $path;
+        $menuPath['title'] = 'Queue Monitor';
+        $menuPath['page_callback'] = 'CRM_Queue_Page_Monitor';
+        $menuPath['access_arguments'][0][] = 'access CiviCRM';
+        $menuPath['access_callback'] = ['CRM_Core_Permission', 'checkMenu'];
+        break;
+
       default:
         // unrecognized
     }
diff --git a/CRM/Queue/Page/Monitor.php b/CRM/Queue/Page/Monitor.php
new file mode 100644 (file)
index 0000000..d0ea387
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * The queue-monitor page provides an interactive, web-based system
+ * running the tasks in a queue and monitoring its progression.
+ *
+ * Do not link or redirect to this page directly -- go through
+ * CRM_Queue_Runner::runAllViaWeb().
+ *
+ * Note: The queue monitor only requires 'access CiviCRM' permission.
+ * It fetches all other data via APIv4 (Queue) and respects the
+ * permissions thereof.
+ */
+class CRM_Queue_Page_Monitor extends CRM_Core_Page {
+
+  /**
+   *
+   * GET Param 'qrid': string, usually the name of the queue
+   */
+  public function run() {
+    $queueName = CRM_Utils_Request::retrieve('name', 'String');
+    $queue = \Civi\Api4\Queue::get()->addWhere('name', '=', $queueName)->execute()->first();
+
+    if (!$queue) {
+      header("HTTP/1.0 404 Not found or not visible");
+      CRM_Utils_System::civiExit();
+      return;
+    }
+
+    // If this queue was created for a user-job, then use the title.
+    $userJob = \Civi\Api4\UserJob::get()->addWhere('queue_id.name', '=', $queueName)->execute()->first();
+    $runnerOptions = $userJob['metadata']['runner'] ?? [];
+
+    Civi::service('angularjs.loader')->addModules('crmQueueMonitor');
+    CRM_Utils_System::setTitle($runnerOptions['title'] ?? ts('Queue Monitor "%1"', [
+      1 => htmlentities($queueName),
+    ]));
+    $this->assign('queueNameJS', CRM_Utils_JS::encode($queueName));
+    parent::run();
+  }
+
+}
diff --git a/templates/CRM/Queue/Page/Monitor.tpl b/templates/CRM/Queue/Page/Monitor.tpl
new file mode 100644 (file)
index 0000000..aa53bce
--- /dev/null
@@ -0,0 +1,3 @@
+<crm-angular-js modules="crmQueueMonitor">
+  <crm-queue-monitor queue="{$queueNameJS|escape}"></crm-queue-monitor>
+</crm-angular-js>