https://www.mediawiki.org/wiki/Special:Code/MediaWiki/103491
Revision: 103491
Author: khorn
Date: 2011-11-17 18:57:29 +0000 (Thu, 17 Nov 2011)
Log Message:
-----------
GlobalCollect command-line orphan rectifier: Adding in yet more data from the
contribution_tracking table (including timestamp).
Modified Paths:
--------------
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
2011-11-17 18:54:52 UTC (rev 103490)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphan_adapter.php
2011-11-17 18:57:29 UTC (rev 103491)
@@ -2,7 +2,9 @@
class GlobalCollectOrphanAdapter extends GlobalCollectAdapter {
- protected $utm_source;
+ //Data we know to be good, that we always want to re-assert after a
load or an addData.
+ //so far: order_id, i_order_id, and the utm data we pull from
contribution tracking.
+ protected $hard_data = array();
public function unstage_data( $data = array(), $final = true ){
$unstaged = array();
@@ -32,16 +34,24 @@
public function loadDataAndReInit( $data ){
$this->batch = true; //or the hooks will accumulate badness.
+ //re-init all these arrays, because this is a batch thing.
+ $this->hard_data = array();
+ $this->transaction_results = array();
+ $this->raw_data = array();
+ $this->staged_data = array();
+
+ $this->hard_data['order_id'] = $data['order_id'];
+ $this->hard_data['i_order_id'] = $data['order_id'];
+
$this->dataObj = new DonationData( get_called_class(), false,
$data );
$this->raw_data = $this->dataObj->getData();
- //this would be VERY BAD anywhere else.
- $this->raw_data['order_id'] = $this->raw_data['i_order_id'];
+ $this->hard_data = array_merge( $this->hard_data,
$this->getUTMInfoFromDB() );
+ $this->reAddHardData();
+
$this->staged_data = $this->raw_data;
- $this->transaction_results = array();
-
$this->setPostDefaults();
$this->defineTransactions();
$this->defineErrorMap();
@@ -52,23 +62,24 @@
$this->stageData();
- //have to do this here, or else.
- $this->utm_source = $this->getUTMSourceFromDB();
- $this->raw_data['utm_source'] = $this->utm_source;
- $this->staged_data['utm_source'] = $this->utm_source;
+ //have to do this again here.
+ $this->reAddHardData();
}
public function addData($dataArray){
- $order_id = $this->raw_data['i_order_id'];
parent::addData($dataArray);
- $this->raw_data['order_id'] = $order_id;
- $this->raw_data['i_order_id'] = $order_id;
- $this->staged_data['order_id'] = $order_id;
- $this->staged_data['i_order_id'] = $order_id;
- $this->raw_data['utm_source'] = $this->utm_source;
- $this->staged_data['utm_source'] = $this->utm_source;
+ $this->reAddHardData();
}
+ private function reAddHardData(){
+ //anywhere else, and this would constitute abuse of the system.
+ //so don't do it.
+ foreach ($this->hard_data as $key => $val){
+ $this->raw_data[$key] = $val;
+ $this->staged_data[$key] = $val;
+ }
+ }
+
public function do_transaction($transaction){
switch ($transaction){
case 'SET_PAYMENT':
@@ -98,7 +109,7 @@
closelog();
}
- public function getUTMSourceFromDB(){
+ public function getUTMInfoFromDB(){
$db =
ContributionTrackingProcessor::contributionTrackingConnection();
@@ -108,25 +119,87 @@
}
$ctid = $this->getData_Raw('contribution_tracking_id');
+
+ $data = array();
// if contrib tracking id is not already set, we need to insert
the data, otherwise update
if ( $ctid ) {
$res = $db->select( 'contribution_tracking',
array(
- 'utm_source'
+ 'utm_source',
+ 'utm_campaign',
+ 'utm_medium',
+ 'ts'
),
array('id' => $ctid)
);
foreach ($res as $thing){
- $this->log("$ctid: Found UTM Source value
$thing->utm_source");
- return $thing->utm_source;
+ $data['utm_source'] = $thing->utm_source;
+ $data['utm_campaign'] = $thing->utm_campaign;
+ $data['utm_medium'] = $thing->utm_medium;
+ $data['ts'] = $thing->ts;
+ $msg = '';
+ foreach ($data as $key => $val){
+ $msg .= "$key = $val ";
+ }
+ $this->log("$ctid: Found UTM Data. $msg");
+ echo $msg;
+ return $data;
}
}
//if we got here, we can't find anything else...
$this->log("$ctid: FAILED to find UTM Source value. Using
default.");
- return $this->getData_Raw('utm_source');
+ return $data;
+ }
+
+
+ /**
+ * Copying this here because it's the fastest way to bring in an actual
timestamp.
+ */
+ protected function doStompTransaction() {
+ if ( !$this->getGlobal( 'EnableStomp' ) ){
+ return;
+ }
+ $this->debugarray[] = "Attempting Stomp Transaction!";
+ $hook = '';
+
+ $status = $this->getTransactionWMFStatus();
+ switch ( $status ) {
+ case 'complete':
+ $hook = 'gwStomp';
+ break;
+ case 'pending':
+ case 'pending-poke':
+ $hook = 'gwPendingStomp';
+ break;
+ }
+ if ( $hook === '' ) {
+ $this->debugarray[] = "No Stomp Hook Found for
WMF_Status $status";
+ return;
+ }
+
+ if (!is_null($this->getData_Raw('ts'))){
+ $timestamp = strtotime($this->getData_Raw('ts')); //I
hate that this works.
+ } else {
+ $timestamp = time();
+ }
+
+ // send the thing.
+ $transaction = array(
+ 'response' => $this->getTransactionMessage(),
+ 'date' => $timestamp,
+ 'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
+ //'language' => '',
+ );
+ $transaction += $this->getData_Raw();
+
+ try {
+ wfRunHooks( $hook, array( $transaction ) );
+ } catch ( Exception $e ) {
+ self::log( "STOMP ERROR. Could not add message. " .
$e->getMessage() , LOG_CRIT );
+ }
}
}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
2011-11-17 18:54:52 UTC (rev 103490)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/scripts/orphans.php
2011-11-17 18:57:29 UTC (rev 103491)
@@ -90,11 +90,11 @@
$results =
$adapter->do_transaction('Confirm_CreditCard');
if ($results['status'] == true){
$adapter->log(
$payment_data['unstaged']['contribution_tracking_id'] . ": FINAL: " .
$results['action']);
-
unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
+
unset($this->order_ids[$payment_data['unstaged']['order_id']]);
} else {
$adapter->log(
$payment_data['unstaged']['contribution_tracking_id'] . ": ERROR: " .
$results['message']);
if (strpos($results['message'],
"GET_ORDERSTATUS reports that the payment is already complete.")){
-
unset($this->order_ids[$payments[$key]['unstaged']['order_id']]);
+
unset($this->order_ids[$payment_data['unstaged']['order_id']]);
}
}
echo $results['message'] . "\n";
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs