Mwalker has submitted this change and it was merged.

Change subject: (FR #1144) Damaged queue navigator
......................................................................


(FR #1144) Damaged queue navigator

Change-Id: I0aa2465cb945b3a5c13bdb5761a8b36a9b373a55
---
M sites/all/modules/wmf_common/Queue.php
M sites/all/modules/wmf_common/wmf_common.module
2 files changed, 70 insertions(+), 1 deletion(-)

Approvals:
  Mwalker: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/wmf_common/Queue.php 
b/sites/all/modules/wmf_common/Queue.php
index 3001f9c..ec79b1a 100644
--- a/sites/all/modules/wmf_common/Queue.php
+++ b/sites/all/modules/wmf_common/Queue.php
@@ -351,7 +351,11 @@
     function item_url( $msg ) {
         global $base_url;
         $queue = str_replace('/queue/', '', $msg->headers['destination'] );
-        $correlationId = $msg->headers['correlation-id'];
+        if ( !empty( $msg->headers['correlation-id'] ) ) {
+            $correlationId = $msg->headers['correlation-id'];
+        } else {
+            $correlationId = $msg->headers['message-id'];
+        }
         return "{$base_url}/queue/{$queue}/{$correlationId}";
     }
 
diff --git a/sites/all/modules/wmf_common/wmf_common.module 
b/sites/all/modules/wmf_common/wmf_common.module
index 808f707..6b4b8c6 100644
--- a/sites/all/modules/wmf_common/wmf_common.module
+++ b/sites/all/modules/wmf_common/wmf_common.module
@@ -69,6 +69,12 @@
     'page callback'    => 'drupal_get_form',
     'page arguments'   => array( 'wmf_common_settings' ),
   );
+  $items['queue/damaged'] = array(
+    'title' => 'Browse all damaged messages',
+    'access arguments' => array( 'manipulate queues' ),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array( 'wmf_common_queue_browser_form' ),
+  );
   $items['queue/%/%'] = array(
     'access arguments' => array( 'manipulate queues' ),
     'page callback' => 'drupal_get_form',
@@ -172,6 +178,65 @@
   return system_settings_form($form);
 }
 
+function wmf_common_queue_browser_form( $form, &$form_state ) {
+  $q = queue2civicrm_stomp();
+
+  # TODO: collect these using a hook
+  $queues = array(
+    variable_get( 'queue2civicrm_subscription' ),
+    variable_get( 'recurring_subscription' ),
+    variable_get( 'refund_queue' ),
+    variable_get( 'unsubscribe_queue' ),
+  );
+
+  # semi-FIXME: not actually paging
+  $allMsgs = array();
+  $pageSize = 100;
+  foreach ( $queues as $queue ) {
+    $msgs = $q->peekMultiple( "{$queue}-damaged", $pageSize );
+    $pageSize -= count( $msgs );
+    $allMsgs = array_merge( $allMsgs, $msgs );
+  }
+
+  $rows = array();
+  foreach ( $allMsgs as $msg ) {
+    $damaged_queue = str_replace( '/queue/', '', $msg->headers['destination'] 
);
+    $queue = str_replace( '-damaged', '', $damaged_queue );
+    if ( !empty( $msg->headers['correlation-id'] ) ) {
+      $id = $msg->headers['correlation-id'];
+    } else {
+      $id = $msg->headers['message-id'];
+    }
+
+    $rows[] = array(
+      $msg->headers['error'],
+      $queue,
+      l( $id, $q->item_url( $msg ) ),
+    );
+  }
+
+
+  $table_html = theme_table( array(
+    'header' => array(
+      'Error',
+      'Queue',
+      'ID',
+    ),
+    'rows' => $rows,
+    'empty' => 'Nothing in the damaged queues!  Be very suspicious...',
+    'attributes' => array(),
+    'caption' => t( 'Damaged messages' ),
+    'colgroups' => array(),
+    'sticky' => true,
+  ) ).theme( 'pager' );
+
+  $form['table'] = array(
+    '#markup' => $table_html,
+  );
+
+  return $form;
+}
+
 function wmf_common_queue_item_form( $form, &$form_state, $queue, 
$correlationId ) {
   $q = queue2civicrm_stomp();
 

-- 
To view, visit https://gerrit.wikimedia.org/r/96685
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0aa2465cb945b3a5c13bdb5761a8b36a9b373a55
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <awi...@wikimedia.org>
Gerrit-Reviewer: Adamw <awi...@wikimedia.org>
Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org>
Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to