Ejegg has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374559 )
Change subject: WIP break up giant audit function
......................................................................
WIP break up giant audit function
Change-Id: Ib1a0f4bc16d393c33d4e695e63e9ecdd96a9c3c5
---
M sites/all/modules/wmf_audit/BaseAuditProcessor.php
1 file changed, 95 insertions(+), 77 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/59/374559/1
diff --git a/sites/all/modules/wmf_audit/BaseAuditProcessor.php
b/sites/all/modules/wmf_audit/BaseAuditProcessor.php
index ac49482..9d28c33 100644
--- a/sites/all/modules/wmf_audit/BaseAuditProcessor.php
+++ b/sites/all/modules/wmf_audit/BaseAuditProcessor.php
@@ -643,85 +643,20 @@
}
if ( $log ) {
- //check to see if the missing transactions
we're trying now, are in there.
- //Echochar with results for each one.
+ // check to see if the missing transactions
we're trying now, are in there.
+ // Echochar with results for each one.
foreach ( $tryme as $date => $missing ) {
if ( !empty( $missing ) ) {
- wmf_audit_echo( "Log Date:
$log_date: About to check " . count( $missing ) . " missing transactions from
$date", true );
- $checked = 0;
- $found = 0;
- foreach ( $missing as $id =>
$transaction ) {
- $checked += 1;
- //reset vars used
below, for extra safety
- $order_id = false;
- $data = false;
- $all_data = false;
-
$contribution_tracking_data = false;
- try {
- $order_id =
$this->get_order_id( $transaction );
- if ( !$order_id
) {
- throw
new WmfException(
-
'MISSING_MANDATORY_DATA',
-
'Could not get an order id for the following transaction ' . print_r(
$transaction, true )
- );
- }
- $data =
$this->get_log_data_by_order_id( $order_id, $log, $transaction );
-
- if ( !$data ) {
- //no
data found in this log, which is expected and normal and not a problem.
-
wmf_audit_echo( '.' );
-
continue;
- }
-
$data['order_id'] = $order_id;
- //if we have
data at this point, it means we have a match in the logs
- $found += 1;
-
- $all_data =
$this->merge_data( $data, $transaction );
- //lookup
contribution_tracking data, and fill it in with audit markers if there's
nothing there.
-
$contribution_tracking_data = wmf_audit_get_contribution_tracking_data(
$all_data );
-
- if (
!$contribution_tracking_data ) {
- throw
new WmfException(
-
'MISSING_MANDATORY_DATA',
-
'No contribution tracking data retrieved for transaction ' . print_r(
$all_data, true )
- );
- }
-
- //Now that
we've made it this far: Easy check to make sure we're even looking at the right
thing...
- //I'm not
totally sure this is going to be the right thing to do, though. Intended
fragility.
- if ( (
!$this->get_runtime_options( 'fakedb' ) ) &&
- ( !empty(
$contribution_tracking_data['utm_payment_method'] ) ) &&
- (
$contribution_tracking_data['utm_payment_method'] !==
$all_data['payment_method'] ) ) {
-
-
$message = 'Payment method mismatch between utm tracking data(' .
$contribution_tracking_data['utm_payment_method'];
-
$message .= ') and normalized log and recon data(' .
$all_data['payment_method'] . '). Investigation required.';
- throw
new WmfException(
-
'DATA_INCONSISTENT',
-
$message
- );
- }
- unset(
$contribution_tracking_data['utm_payment_method'] );
- // On the next
line, the date field from all_data will win, which we totally want.
- // I had
thought we'd prefer the contribution tracking date, but that's just silly.
- // However, I'd
just like to point out that it would be terribly enlightening for some gateways
to log the difference...
- // ...but not
inside the char block, because it'll break the pretty.
- $all_data =
array_merge( $contribution_tracking_data, $all_data );
-
- //Send to
queue. Or somewhere. Or don't (if it's test mode).
-
wmf_audit_send_transaction( $all_data, 'main' );
- unset(
$tryme[$date][$id] );
- wmf_audit_echo(
'!' );
- } catch ( WmfException
$ex ) {
- // End of the
transaction search/destroy loop. If we're here and have
- // an error, we
found something and the re-fusion didn't work.
- // Handle
consistently, and definitely don't try looking in other
- // logs.
-
wmf_audit_log_error( $ex->getMessage(), $ex->getErrorName() );
- unset(
$tryme[$date][$id] );
- wmf_audit_echo(
'X' );
- }
- }
- wmf_audit_echo( "Log Date:
$log_date: Checked $checked missing transactions from $date, and found
$found\n" );
+ // $tryme is passed by
reference. Found transactions
+ // are removed from the list.
+ // FIXME: don't mutate the
thing we're looping over
+ $this->checkOneLogFile(
+ $log_date,
+ $missing,
+ $date,
+ $log,
+ $tryme
+ );
}
}
}
@@ -761,6 +696,89 @@
}
/**
+ * @param string $log_date the date of the log to check, in YYYYMMDD
format
+ * @param array $missing
+ * @param string $date
+ * @param string $log The full path to the log we want to search
+ * @param array $tryme
+ */
+ protected function checkOneLogFile( $log_date, $missing, $date, $log,
&$tryme ) {
+ wmf_audit_echo(
+ "Log Date: $log_date: About to check " . count(
$missing ) . " missing transactions from $date",
+ true
+ );
+ $checked = 0;
+ $found = 0;
+ foreach ( $missing as $id => $transaction ) {
+ $checked += 1;
+ try {
+ $order_id = $this->get_order_id( $transaction );
+ if ( !$order_id ) {
+ throw new WmfException(
+ 'MISSING_MANDATORY_DATA',
+ 'Could not get an order id for
the following transaction ' . print_r( $transaction, true )
+ );
+ }
+ $data = $this->get_log_data_by_order_id(
$order_id, $log, $transaction );
+
+ if ( !$data ) {
+ //no data found in this log, which is
expected and normal and not a problem.
+ wmf_audit_echo( '.' );
+ continue;
+ }
+ $data['order_id'] = $order_id;
+ //if we have data at this point, it means we
have a match in the logs
+ $found += 1;
+
+ $all_data = $this->merge_data( $data,
$transaction );
+ //lookup contribution_tracking data, and fill
it in with audit markers if there's nothing there.
+ $contribution_tracking_data =
wmf_audit_get_contribution_tracking_data( $all_data );
+
+ if ( !$contribution_tracking_data ) {
+ throw new WmfException(
+ 'MISSING_MANDATORY_DATA',
+ 'No contribution tracking data
retrieved for transaction ' . print_r( $all_data, true )
+ );
+ }
+
+ //Now that we've made it this far: Easy check
to make sure we're even looking at the right thing...
+ //I'm not totally sure this is going to be the
right thing to do, though. Intended fragility.
+ if ( ( !$this->get_runtime_options( 'fakedb' )
) &&
+ ( !empty(
$contribution_tracking_data['utm_payment_method'] ) ) &&
+ (
$contribution_tracking_data['utm_payment_method'] !==
$all_data['payment_method'] ) ) {
+
+ $message = 'Payment method mismatch
between utm tracking data(' . $contribution_tracking_data['utm_payment_method'];
+ $message .= ') and normalized log and
recon data(' . $all_data['payment_method'] . '). Investigation required.';
+ throw new WmfException(
+ 'DATA_INCONSISTENT',
+ $message
+ );
+ }
+ unset(
$contribution_tracking_data['utm_payment_method'] );
+ // On the next line, the date field from
all_data will win, which we totally want.
+ // I had thought we'd prefer the contribution
tracking date, but that's just silly.
+ // However, I'd just like to point out that it
would be terribly enlightening for some gateways to log the difference...
+ // ...but not inside the char block, because
it'll break the pretty.
+ $all_data = array_merge(
$contribution_tracking_data, $all_data );
+
+ //Send to queue. Or somewhere. Or don't (if
it's test mode).
+ wmf_audit_send_transaction( $all_data, 'main' );
+ unset( $tryme[$date][$id] );
+ wmf_audit_echo( '!' );
+ } catch ( WmfException $ex ) {
+ // End of the transaction search/destroy loop.
If we're here and have
+ // an error, we found something and the
re-fusion didn't work.
+ // Handle consistently, and definitely don't
try looking in other
+ // logs.
+ wmf_audit_log_error( $ex->getMessage(),
$ex->getErrorName() );
+ unset( $tryme[$date][$id] );
+ wmf_audit_echo( 'X' );
+ }
+ }
+ wmf_audit_echo( "Log Date: $log_date: Checked $checked missing
transactions from $date, and found $found\n" );
+ }
+
+ /**
* Both groom and return a distilled working payments log ready to be
searched
* for missing transaction data
* @param string $date The date of the log we want to grab
--
To view, visit https://gerrit.wikimedia.org/r/374559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1a0f4bc16d393c33d4e695e63e9ecdd96a9c3c5
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