jenkins-bot has submitted this change and it was merged.
Change subject: Move banner history off ActiveMQ
......................................................................
Move banner history off ActiveMQ
Required:
* mirror BH messages to Redis in front-end
* add data-store/banner-history entry in SmashPig.yaml pointing to
Predis backend
* ensure damaged-db is set up and configured in SmashPig.yaml
Bug: T141555
Change-Id: Ib48a02a26d6ba35064af8f7f1f840f5f222a0ed7
---
A sites/all/modules/queue2civicrm/banner_history/BannerHistoryQueueConsumer.php
M sites/all/modules/queue2civicrm/banner_history/banner_history.info
M sites/all/modules/queue2civicrm/banner_history/banner_history.module
M sites/all/modules/queue2civicrm/tests/phpunit/BannerHistoryTest.php
4 files changed, 118 insertions(+), 71 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git
a/sites/all/modules/queue2civicrm/banner_history/BannerHistoryQueueConsumer.php
b/sites/all/modules/queue2civicrm/banner_history/BannerHistoryQueueConsumer.php
new file mode 100644
index 0000000..f0957b9
--- /dev/null
+++
b/sites/all/modules/queue2civicrm/banner_history/BannerHistoryQueueConsumer.php
@@ -0,0 +1,65 @@
+<?php namespace queue2civicrm\banner_history;
+
+use wmf_common\WmfQueueConsumer;
+use WmfException;
+
+class BannerHistoryQueueConsumer extends WmfQueueConsumer {
+
+ /**
+ * Validate and store messages from the banner history queue
+ *
+ * @param array $message
+ * @throws WmfException
+ */
+ function processMessage( $message ) {
+ if ( empty( $message ) ) {
+ throw new WmfException(
+ 'BANNER_HISTORY',
+ 'Empty banner history message.'
+ );
+ }
+
+ if (
+ empty( $message['banner_history_id'] ) ||
+ empty( $message['contribution_tracking_id'] )
+ ) {
+ throw new WmfException(
+ 'BANNER_HISTORY',
+ 'Missing banner history or contribution
tracking ID.'
+ );
+ }
+
+ $bannerHistoryId = $message['banner_history_id'];
+ $contributionTrackingId = $message['contribution_tracking_id'];
+
+ if (
+ !is_numeric( $contributionTrackingId ) ||
+ !preg_match( '/^[0-9a-f]{16,20}$/', $bannerHistoryId )
+ ) {
+ throw new WmfException(
+ 'BANNER_HISTORY',
+ 'Invalid data in banner history message.'
+ );
+ }
+
+ watchdog(
+ 'banner_history',
+ "About to add row for $bannerHistoryId",
+ array(),
+ WATCHDOG_INFO
+ );
+
+ db_merge( 'banner_history_contribution_associations' )
+ ->key( array(
+ 'banner_history_log_id' => $bannerHistoryId,
+ 'contribution_tracking_id' =>
$contributionTrackingId
+ ) )
+ ->insertFields( array(
+ 'banner_history_log_id' => $bannerHistoryId,
+ 'contribution_tracking_id' =>
$contributionTrackingId
+ ) )
+ ->execute();
+
+ watchdog( 'banner_history', "Processed $bannerHistoryId" );
+ }
+}
diff --git a/sites/all/modules/queue2civicrm/banner_history/banner_history.info
b/sites/all/modules/queue2civicrm/banner_history/banner_history.info
index 0b46909..9a2604a 100644
--- a/sites/all/modules/queue2civicrm/banner_history/banner_history.info
+++ b/sites/all/modules/queue2civicrm/banner_history/banner_history.info
@@ -3,4 +3,5 @@
core = 7.x
package = queue2civicrm
configure = admin/config/queue2civicrm/banner_history
-dependencies[] = queue2civicrm
\ No newline at end of file
+dependencies[] = queue2civicrm
+files[] = BannerHistoryQueueConsumer.php
diff --git
a/sites/all/modules/queue2civicrm/banner_history/banner_history.module
b/sites/all/modules/queue2civicrm/banner_history/banner_history.module
index 52446d2..8492429 100644
--- a/sites/all/modules/queue2civicrm/banner_history/banner_history.module
+++ b/sites/all/modules/queue2civicrm/banner_history/banner_history.module
@@ -1,5 +1,8 @@
<?php
+use queue2civicrm\banner_history\BannerHistoryQueueConsumer;
+use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
/**
* Implements hook_menu
@@ -34,7 +37,7 @@
'#title' => t( 'Subscription path' ),
'#required' => true,
'#default_value' => variable_get(
- 'banner_history_queue', '/queue/banner-history' ),
+ 'banner_history_queue', 'banner-history' ),
'#description' => t( 'Queue for banner history log ID
associations' ),
);
@@ -71,13 +74,17 @@
watchdog( 'banner_history', 'Executing: banner_history_queue_consume' );
civicrm_initialize();
+ $config = new Configuration();
+ Context::initWithLogger( $config, 'banner_history' );
- $processed = queue2civicrm_stomp()->dequeue_loop(
- variable_get( 'banner_history_queue', '/queue/banner-history' )
,
- variable_get( 'banner_history_batch', 0 ),
+ $queue = variable_get( 'banner_history_queue', 'banner-history' );
+
+ $qc = new BannerHistoryQueueConsumer(
+ $queue,
variable_get( 'banner_history_batch_time', 0 ),
- 'banner_history_process_message'
+ variable_get( 'banner_history_batch', 0 )
);
+ $processed = $qc->dequeueMessages();
if ( $processed > 0 ) {
watchdog( 'banner_history',
@@ -87,46 +94,4 @@
watchdog( 'banner_history',
'No banner history log ID associations processed.' );
}
-}
-
-function banner_history_process_message( $msg ) {
-
- $body = json_decode( $msg->body, true );
-
- if ( is_null( $body ) ) {
- throw new WmfException( 'BANNER_HISTORY',
- 'Couldn\'t parse banner history message body.' );
- }
-
- $bannerHistoryId = $body['banner_history_id'];
- $contributionTrackingId = $body['contribution_tracking_id'];
-
- if ( !$bannerHistoryId || !$contributionTrackingId ) {
- throw new WmfException( 'BANNER_HISTORY',
- 'Missing banner history or contribution tracking ID.' );
- }
-
- if (
- !is_numeric( $contributionTrackingId ) ||
- !preg_match( '/^[0-9a-f]{16,20}$/', $bannerHistoryId )
- ) {
- throw new WmfException( 'BANNER_HISTORY',
- 'Invalid data in banner history message.' );
- }
-
- watchdog( 'banner_history', "About to add row for $bannerHistoryId",
- array(), WATCHDOG_INFO);
-
- db_merge( 'banner_history_contribution_associations' )
- ->key( array(
- 'banner_history_log_id' => $bannerHistoryId,
- 'contribution_tracking_id' => $contributionTrackingId
- ) )
- ->insertFields( array(
- 'banner_history_log_id' => $bannerHistoryId,
- 'contribution_tracking_id' => $contributionTrackingId
- ) )
- ->execute();
-
- watchdog( 'banner_history', "Processed $bannerHistoryId" );
}
diff --git
a/sites/all/modules/queue2civicrm/tests/phpunit/BannerHistoryTest.php
b/sites/all/modules/queue2civicrm/tests/phpunit/BannerHistoryTest.php
index 37f28a0..c81a856 100644
--- a/sites/all/modules/queue2civicrm/tests/phpunit/BannerHistoryTest.php
+++ b/sites/all/modules/queue2civicrm/tests/phpunit/BannerHistoryTest.php
@@ -1,19 +1,39 @@
<?php
+use queue2civicrm\banner_history\BannerHistoryQueueConsumer;
+
+use SmashPig\Core\Context;
+use SmashPig\Core\QueueConsumers\BaseQueueConsumer;
+use SmashPig\Tests\QueueTestConfiguration;
/**
* @group Queue2Civicrm
*/
class BannerHistoryTest extends BaseWmfDrupalPhpUnitTestCase {
- public function testValidMessage() {
- $msg = ( object ) array(
- 'body' => json_encode( array(
- 'banner_history_id' => substr(
- md5( mt_rand() . time() ), 0, 16
- ),
- 'contribution_tracking_id' => strval( mt_rand()
),
- ) ),
+
+ /**
+ * @var BannerHistoryQueueConsumer
+ */
+ protected $consumer;
+
+ public function setUp() {
+ parent::setUp();
+ $config = new QueueTestConfiguration();
+ Context::initWithLogger( $config );
+ $queue = BaseQueueConsumer::getQueue( 'test' );
+ $queue->createTable( 'test' );
+ $this->consumer = new BannerHistoryQueueConsumer(
+ 'test'
);
- banner_history_process_message( $msg );
+ }
+
+ public function testValidMessage() {
+ $msg = array(
+ 'banner_history_id' => substr(
+ md5( mt_rand() . time() ), 0, 16
+ ),
+ 'contribution_tracking_id' => strval( mt_rand() ),
+ );
+ $this->consumer->processMessage( $msg );
// check for thing in db
}
@@ -21,27 +41,23 @@
* @expectedException WmfException
*/
public function testBadContributionId() {
- $msg = ( object ) array(
- 'body' => json_encode( array(
- 'banner_history_id' => substr(
- md5( mt_rand() . time() ), 0, 16
- ),
- 'contribution_tracking_id' => '1=1; DROP TABLE
students;--',
- ) ),
+ $msg = array(
+ 'banner_history_id' => substr(
+ md5( mt_rand() . time() ), 0, 16
+ ),
+ 'contribution_tracking_id' => '1=1; DROP TABLE
students;--',
);
- banner_history_process_message( $msg );
+ $this->consumer->processMessage( $msg );
}
/**
* @expectedException WmfException
*/
public function testBadHistoryId() {
- $msg = ( object ) array(
- 'body' => json_encode( array(
- 'banner_history_id' => '\';GRANT ALL ON
drupal.* TO \'leet\'@\'haxx0r\'',
- 'contribution_tracking_id' => strval( mt_rand()
),
- ) ),
+ $msg = array(
+ 'banner_history_id' => '\';GRANT ALL ON drupal.* TO
\'leet\'@\'haxx0r\'',
+ 'contribution_tracking_id' => strval( mt_rand() ),
);
- banner_history_process_message( $msg );
+ $this->consumer->processMessage( $msg );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/301660
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib48a02a26d6ba35064af8f7f1f840f5f222a0ed7
Gerrit-PatchSet: 16
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits