Ejegg has submitted this change and it was merged.
Change subject: Add banner_history module to consume BH log id associations
......................................................................
Add banner_history module to consume BH log id associations
Creates the new table, 'banner_history_contribution_associations'.
Bug: T112022
Change-Id: I9638df7b75add7408d1dc0ed0e54e1341e604721
---
A sites/all/modules/queue2civicrm/banner_history/banner_history.info
A sites/all/modules/queue2civicrm/banner_history/banner_history.install
A sites/all/modules/queue2civicrm/banner_history/banner_history.module
A
sites/all/modules/queue2civicrm/banner_history/banner_history_queue_consume.drush.inc
M sites/all/modules/wmf_common/WmfException.php
5 files changed, 242 insertions(+), 0 deletions(-)
Approvals:
Ejegg: Looks good to me, approved
diff --git a/sites/all/modules/queue2civicrm/banner_history/banner_history.info
b/sites/all/modules/queue2civicrm/banner_history/banner_history.info
new file mode 100644
index 0000000..0b46909
--- /dev/null
+++ b/sites/all/modules/queue2civicrm/banner_history/banner_history.info
@@ -0,0 +1,6 @@
+name = Banner history
+description = Imports associated banner history log IDs and contribution
tracking IDs.
+core = 7.x
+package = queue2civicrm
+configure = admin/config/queue2civicrm/banner_history
+dependencies[] = queue2civicrm
\ No newline at end of file
diff --git
a/sites/all/modules/queue2civicrm/banner_history/banner_history.install
b/sites/all/modules/queue2civicrm/banner_history/banner_history.install
new file mode 100644
index 0000000..af04b25
--- /dev/null
+++ b/sites/all/modules/queue2civicrm/banner_history/banner_history.install
@@ -0,0 +1,40 @@
+<?php
+
+function banner_history_schema() {
+
+ $schema['banner_history_contribution_associations'] = array(
+ 'description' => 'Associations of banner history log IDs and
contribution tracking IDs',
+ 'fields' => array(
+ 'id' => array(
+ 'type' => 'serial',
+ 'size' => 'normal',
+ 'unsigned' => true,
+ 'not null' => true,
+ ),
+ 'contribution_tracking_id' => array(
+ 'type' => 'int',
+ 'size' => 'normal',
+ 'unsigned' => true,
+ 'not null' => true,
+ 'description' => 'Expected to correspond to the
id column of the contribution_tracking table.',
+ ),
+ 'banner_history_log_id' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => true,
+ 'description' => 'Temporary banner history log
ID to associate banner history EventLogging events.'
+ ),
+ ),
+ 'indexes' => array(
+ 'contribution_tracking_id' => array(
'contribution_tracking_id' ),
+ 'banner_history_log_id' => array(
'banner_history_log_id' ),
+ ),
+ 'unique keys' => array(
+ 'ct_id_bh_id_unique' =>
+ array( 'contribution_tracking_id',
'banner_history_log_id' ),
+ ),
+ 'primary key' => array( 'id' ),
+ );
+
+ return $schema;
+}
\ No newline at end of file
diff --git
a/sites/all/modules/queue2civicrm/banner_history/banner_history.module
b/sites/all/modules/queue2civicrm/banner_history/banner_history.module
new file mode 100644
index 0000000..950a614
--- /dev/null
+++ b/sites/all/modules/queue2civicrm/banner_history/banner_history.module
@@ -0,0 +1,124 @@
+<?php
+
+
+/**
+ * Implements hook_menu
+ */
+function banner_history_menu() {
+ $items[ 'admin/config/queue2civicrm/banner_history' ] = array(
+ 'title' => 'Banner history',
+ 'description' => t( 'Configure banner history queue' ),
+ 'access arguments' => array( 'administer queue2civicrm' ),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array( 'banner_history_settings_page_args'
),
+ );
+ return $items;
+}
+
+/**
+ * Constructs the settings page for this module.
+ * @return array Of form components.
+ */
+function banner_history_settings_page_args() {
+ $form = array();
+
+ $form['description'] = array(
+ '#type' => 'markup',
+ '#description' =>
+ t( '<p>Banner history log ID associations are consumed
from a' .
+ ' queue and placed in a table.</p>' ),
+ );
+
+ $form['banner_history_queue'] = array(
+ '#type' => 'textfield',
+ '#title' => t( 'Subscription path' ),
+ '#required' => true,
+ '#default_value' => variable_get(
+ 'banner_history_queue', '/queue/banner-history-test' ),
+ '#description' => t( 'Queue for banner history log ID
associations' ),
+ );
+
+ $form['banner_history_batch'] = array(
+ '#type' => 'textfield',
+ '#title' => t( 'Batch size' ),
+ '#description' => t(
+ 'Maximum number of items processed by a banner history
job. Use ' .
+ '0 for no limit.'
+ ),
+ '#default_value' => variable_get( 'banner_history_batch', 0 ),
+ );
+
+ $form['banner_history_batch_time'] = array(
+ '#type' => 'textfield',
+ '#title' => t( 'Job time limit (in seconds)' ),
+ '#description' => t(
+ 'Maximum elapsed duration of an banner history job,
after which ' .
+ 'we will abort from the loop. This can be used to set a
reliable ' .
+ 'duty cycle for the job. Use 0 for no limit. Either a
time limit ' .
+ 'or batch size limit is required.'
+ ),
+ '#required' => true,
+ '#default_value' => variable_get( 'banner_history_batch_time',
0 ),
+ );
+
+ return system_settings_form( $form );
+}
+
+/**
+ * Entry point from banner-history-queue-consume drush command
+ */
+function banner_history_queue_consume() {
+ watchdog( 'banner_history', 'Executing: banner_history_queue_consume' );
+
+ civicrm_initialize();
+
+ $processed = queue2civicrm_stomp()->dequeue_loop(
+ variable_get( 'banner_history_queue',
'/queue/banner-history-test' ) ,
+ variable_get( 'banner_history_batch', 0 ),
+ variable_get( 'banner_history_batch_time', 0 ),
+ 'banner_history_process_message'
+ );
+
+ if ( $processed > 0 ) {
+ watchdog( 'banner_history',
+ "Processed $processed banner_history log ID
association(s)." );
+
+ } else {
+ 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.' );
+ }
+
+ 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" );
+}
\ No newline at end of file
diff --git
a/sites/all/modules/queue2civicrm/banner_history/banner_history_queue_consume.drush.inc
b/sites/all/modules/queue2civicrm/banner_history/banner_history_queue_consume.drush.inc
new file mode 100644
index 0000000..54982cf
--- /dev/null
+++
b/sites/all/modules/queue2civicrm/banner_history/banner_history_queue_consume.drush.inc
@@ -0,0 +1,68 @@
+<?php
+/**
+ * @file banner_history.drush.inc
+ *
+ * Consumes associations of banner history log IDs and contribution tracking
IDs
+ * from a remote queue, then stores them in a table.
+ *
+ * @author Andrew Green <[email protected]>
+ */
+
+/**
+ * Implementation of hook_drush_command()
+ */
+function banner_history_queue_consume_drush_command() {
+ $items = array();
+
+ $items['banner-history-queue-consume'] = array(
+ 'description' => 'Consume associations of banner history log
IDs and ' .
+ 'contribution tracking IDs.',
+ 'aliases' => array( 'bhqc' ),
+ );
+ return $items;
+}
+
+/**
+ * Implementation of hook_drush_help()
+ * @param $section
+ * @return mixed
+ */
+function banner_history_queue_consume_drush_help( $section ) {
+ switch ( $section ) {
+ case 'drush:banner-history-queue-consume':
+ return dt( "Consume associations of banner history log
IDs and " .
+ "contribution tracking IDs from a remote queue,
then store " .
+ "them in a table." );
+ }
+}
+
+/**
+ * Implements the drush comand banner-history-queue consume; consumes
+ * associations of banner history log IDs and contribution tracking IDs and
puts
+ * them in a table.
+ */
+function drush_banner_history_queue_consume() {
+
+ watchdog( 'banner_history', 'Executing:
drush_banner_history_queue_consume' );
+ module_invoke( 'banner_history', 'queue_consume' );
+
+ // TODO Copypasta from error handling in
unsubscribe_queue_consume.drush.inc
+ // Should be consolidated somewhere
+
+ $errors = drush_get_error_log();
+
+ if ( !empty( $errors ) ){
+
+ echo "\n***ERRORS***";
+
+ foreach( $errors as $error => $msgarray ){
+ echo "\n$error: ";
+ foreach ( $msgarray as $count => $message ){
+ echo "\n\t$message";
+ }
+ }
+
+ echo "\n\n";
+ exit( drush_get_error() );
+ }
+}
\ No newline at end of file
diff --git a/sites/all/modules/wmf_common/WmfException.php
b/sites/all/modules/wmf_common/WmfException.php
index f76136c..4da6bbc 100644
--- a/sites/all/modules/wmf_common/WmfException.php
+++ b/sites/all/modules/wmf_common/WmfException.php
@@ -20,6 +20,7 @@
const fredge = 17;
const MISSING_MANDATORY_DATA = 18;
const DATA_INCONSISTENT = 19;
+ const BANNER_HISTORY = 20;
//XXX shit we aren't using the 'rollback' attribute
// and it's not correct in most of these cases
@@ -68,6 +69,9 @@
'requeue' => TRUE,
'no-email' => TRUE,
),
+ 'BANNER_HISTORY' => array(
+ 'reject' => TRUE,
+ ),
// other errors
'FILE_NOT_FOUND' => array(
--
To view, visit https://gerrit.wikimedia.org/r/246425
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9638df7b75add7408d1dc0ed0e54e1341e604721
Gerrit-PatchSet: 9
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
Gerrit-Reviewer: AndyRussG <[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