r86597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86596‎ | r86597 | r86598 >
Date:07:15, 21 April 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Converted drush script that allocates unallocated contris to appropriate countries to use a batching mechanism (currently configured to batch report runs in 7-day increments, this should become configurable in the future); Added total contrib counts for aggregate allocations
Modified paths:
  • /civicrm/trunk/sites/all/modules/contribution_audit/allocate_unallocated_contribs.drush.inc (modified) (history)
  • /civicrm/trunk/sites/all/modules/contribution_audit/contribution_audit.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/contribution_audit/contribution_audit.module
@@ -47,10 +47,10 @@
4848 }
4949
5050 function contribution_audit_allocate_unallocated_contribs( $start_date, $end_date ) {
 51+ watchdog( 'contribution_audit', 'Running contribution_audit_allocate_unallocated_contribs for time period from @start_date until @end_date', array( '@start_date' => $start_date, '@end_date' => $end_date ), WATCHDOG_DEBUG );
5152 $allocated = array(); // country => $
5253 // find the info from missing trxns
5354 $missing_trxns = contribution_audit_find_missing_trxns( $start_date, $end_date );
54 -
5555 foreach ( $missing_trxns as $missing_trxn ) {
5656 // what happens if we still dont have country data?
5757 if ( !strlen($missing_trxn[ 'country' ])) {
@@ -63,12 +63,14 @@
6464
6565 function _contribution_audit_aggregate_country_amounts( &$allocated, $trxn ) {
6666 // handle currency conversion, etc
67 - $trxn = _queue2civicrm_normalize_contrib_amnts( $missing_trxn );
 67+ $trxn = _queue2civicrm_normalize_contrib_amnts( $trxn );
6868
6969 if ( !in_array( $trxn[ 'country' ], array_keys( $allocated ))) {
70 - $allocated[ $trxn[ 'country' ]] = $trxn[ 'gross' ];
 70+ $allocated[ $trxn[ 'country' ]][ 'amnt' ] = $trxn[ 'gross' ];
 71+ $allocated[ $trxn[ 'country' ]][ 'count' ] = 1;
7172 } else {
72 - $allocated[ $trxn[ 'country' ]] += $trxn[ 'gross' ];
 73+ $allocated[ $trxn[ 'country' ]][ 'amnt' ] += $trxn[ 'gross' ];
 74+ $allocated[ $trxn[ 'country' ]][ 'count' ]++;
7375 }
7476 }
7577
@@ -77,8 +79,7 @@
7880 * @return array containing the missing transactions
7981 */
8082 function contribution_audit_find_missing_trxns( $start_date, $end_date ) {
81 - $missing_trxns = array();
82 - module_invoke_all( 'contribution_audit_find_missing_trxns', $missing_trxns, $start_date, $end_date );
 83+ $missing_trxns = module_invoke_all( 'contribution_audit_find_missing_trxns', $start_date, $end_date );
8384 return $missing_trxns;
8485 }
8586
Index: civicrm/trunk/sites/all/modules/contribution_audit/allocate_unallocated_contribs.drush.inc
@@ -41,10 +41,44 @@
4242 * Fires the 'contribution_audit_allocate_unallocated_contribs' method in the contribution_audit.
4343 */
4444 function drush_allocate_unallocated_contribs() {
45 - $start_date = drush_get_option( $start );
46 - $end_date = drush_get_option( $end );
47 - $allocated = module_invoke( 'contribution_audit', 'contribution_audit_allocate_unallocated_contribs', $start_date, $end_date );
48 - foreach( $allocated as $key => $value ) {
49 - print "'$key','$value'\n";
 45+ $start_date = drush_get_option( 'start' );
 46+ $end_date = drush_get_option( 'end' );
 47+ watchdog( 'contribution_audit_drush', 'Preparing to allocate unallocated contribs for timeframe between @start and @end', array('@start'=>$start_date, '@end'=>$end_date ));
 48+ $allocated = array();
 49+
 50+ // for memory purposes, we don't want startdate/enddate to be more than 7 days apart, this should be configurable.
 51+ while ( strtotime( $start_date ) < strtotime( $end_date )) {
 52+ $this_end_date = date( 'Y-m-d', strtotime( '+7 days', strtotime( $start_date )));
 53+ // if our increment goes beyond the original end date, reset it back to the original end date
 54+ if ( strtotime( $this_end_date ) > strtotime( $end_date )) {
 55+ $this_end_date = $end_date;
 56+ }
 57+
 58+ watchdog( 'contribution_audit_drush', 'Preparing to invoke contribution_audit allocate_unallocated_contribs() for timeframe between @start and @end', array('@start'=>$start_date, '@end'=>$end_date ));
 59+
 60+ $this_allocated = module_invoke( 'contribution_audit', 'allocate_unallocated_contribs', $start_date, $this_end_date );
 61+ allocate_unallocated_contribs_merge( $allocated, $this_allocated );
 62+
 63+ // move our start date up by 8 days for the next batch
 64+ $start_date = date( 'Y-m-d', strtotime( '+8 days', strtotime( $start_date )));
5065 }
 66+
 67+ if ( !count($allocated)) {
 68+ print "All contributions present and allocated.\n";
 69+ } else {
 70+ foreach( $allocated as $key => $val ) {
 71+ print "'$key','" . $val['amnt'] . "','" . $val['count'] . "'\n";
 72+ }
 73+ }
5174 }
 75+
 76+function allocate_unallocated_contribs_merge( &$allocated, $local_allocated ) {
 77+ foreach ( $local_allocated as $country => $data ) {
 78+ if ( !in_array( $country, array_keys( $allocated ))) {
 79+ $allocated = array_merge( $allocated, $local_allocated );
 80+ } else {
 81+ $allocated[ $country ][ 'amnt' ] += $local_allocated[ $country ][ 'amnt' ];
 82+ $allocated[ $country ][ 'count' ] += $local_allocated[ $country ][ 'count' ];
 83+ }
 84+ }
 85+}

Status & tagging log