Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/247765

Change subject: Queue consumer can import multiple messages from JSON
......................................................................

Queue consumer can import multiple messages from JSON

drush donations-process-messagefile can now handle a file with
either a single message or an array of messages.

Bug: T114466
Change-Id: I1938caf2c2f4ebdf2631a5b64b1ac909e9bedcf7
---
M sites/all/modules/queue2civicrm/queue_consume.drush.inc
1 file changed, 11 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/65/247765/1

diff --git a/sites/all/modules/queue2civicrm/queue_consume.drush.inc 
b/sites/all/modules/queue2civicrm/queue_consume.drush.inc
index 3e21b20..123da0f 100644
--- a/sites/all/modules/queue2civicrm/queue_consume.drush.inc
+++ b/sites/all/modules/queue2civicrm/queue_consume.drush.inc
@@ -20,9 +20,9 @@
   );
   $items['donations-process-messagefile'] = array(
     'description' => 
-      'Feeds a single message directly into the import pipeline, bypassing the 
queue.',
+      'Feeds messages directly into the import pipeline, bypassing the queue.',
     'arguments' => array(
-        'path' => 'The JSON file containing the message'
+        'path' => 'The JSON file containing the message(s)'
     ),
     'required-arguments' => true,
     'examples' => array( 'drush dpm /tmp/blurr.json' => '# process the file' 
), 
@@ -40,7 +40,7 @@
     case 'drush:queue-consume':
       return dt( "Pulls items from an ActiveMQ queue and processes them into 
CiviCRM" );
     case 'drush:donations-process-messagefile':
-      return dt( "Feeds a single message directly into the import pipeline, 
bypassing the queue." );
+      return dt( "Feeds messages directly into the import pipeline, bypassing 
the queue." );
   }
 }
 
@@ -70,9 +70,14 @@
     watchdog( 'queue2civicrm', "Processing input file @path and feeding to 
queue2civicrm_import.",
         array( '@path' => realpath( $path ) ), WATCHDOG_INFO );
     $contents = file_get_contents( $path );
-    $msg = json_decode( $contents, true );
-    if ($msg === NULL) {
+    $messages = json_decode( $contents, true );
+    if ( !is_array( $messages ) ) {
       throw new Exception("Error decoding JSON in '$path'.");
     }
-    module_invoke( 'queue2civicrm', 'import', $msg );
+    if ( !isset( $messages[0] ) || !is_array( $messages[0] ) ) {
+      $messages = array( $messages );
+    }
+    foreach( $messages as $msg ) {
+      module_invoke( 'queue2civicrm', 'import', $msg );
+    }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1938caf2c2f4ebdf2631a5b64b1ac909e9bedcf7
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to