r75172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75171‎ | r75172 | r75173 >
Date:21:41, 21 October 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Renamed owa module files to fit convention
Modified paths:
  • /civicrm/trunk/sites/all/modules/wmf_owa/owa.info (deleted) (history)
  • /civicrm/trunk/sites/all/modules/wmf_owa/owa.module (deleted) (history)
  • /civicrm/trunk/sites/all/modules/wmf_owa/wmf_owa.info (added) (history)
  • /civicrm/trunk/sites/all/modules/wmf_owa/wmf_owa.module (added) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/wmf_owa/owa.info
@@ -1,3 +0,0 @@
2 -name = Open Web Analytics for Wikimedia Foundation
3 -description = Allows for tracking of WMF-specific events in Open Web Analytics
4 -core = 6.x
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/wmf_owa/owa.module
@@ -1,129 +0,0 @@
2 -<?php
3 -
4 -/** The default OWA log script location **/
5 -define( 'OWA_LOG_DEFAULT', 'http://analytics.tesla.usability.wikimedia.org/wiki/d/extensions/owa/log.php' );
6 -
7 -/**
8 - * Implementation of hook_perm().
9 - */
10 -function wmf_owa_perm() {
11 - return array('administer wmf_owa');
12 -}
13 -
14 -/**
15 - * Implementation of hook_menu()
16 - */
17 -function wmf_owa_menu() {
18 - $items = array();
19 -
20 - $items['admin/settings/wmf_owa'] = array(
21 - 'title' => 'Wikimedia Foundation OWA Configuration',
22 - 'description' => t('Configure OWA log script location.'),
23 - 'access arguments' => array('administer wmf_owa'),
24 - 'page callback' => 'drupal_get_form',
25 - 'page arguments' => array( 'wmf_owa_settings' ),
26 - );
27 -
28 - return $items;
29 -}
30 -
31 -/**
32 - * Callback for menu path "admin/settings/wmf_owa".
33 - */
34 -function wmf_owa_settings() {
35 - $form[ 'wmf_owa_log' ] = array(
36 - '#type' => 'textfield',
37 - '#title' => t( 'OWA log path' ),
38 - '#required' => TRUE,
39 - '#default_value' => variable_get('wmf_owa_log', OWA_LOG_DEFAULT ),
40 - );
41 - return system_settings_form( $form );
42 -}
43 -
44 -/**
45 - * Implementation of hook_civicrm_post
46 - *
47 - * @param unknown_type $op
48 - * @param unknown_type $objectName
49 - * @param unknown_type $objectId
50 - * @param unknown_type $objectRef
51 - */
52 -function wmf_owa_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
53 - // only continue if we're handling a new or updated contribution
54 - if ( $objectName != 'Contribution' && !in_array( $op, array( 'edit', 'create' )) ) {
55 - return;
56 - }
57 -
58 - // load the OWA-specific tracking data
59 - $contrib_tracking_data = wmf_owa_get_contribution_tracking_data( $objectId );
60 - if ( !$contrib_tracking_data ) {
61 - // log, don't post to OWA
62 - watchdog( 'wmf_owa', 'Could not load tracking data for contribution_id ' . $objectId, WATCHDOG_WARNING );
63 - return;
64 - }
65 -
66 - /**
67 - * pull the gateway out fo the trxn_id string
68 - * it is the element prior to the first space in the str
69 - */
70 - $gateway = substr( $objectRef->trxn_id, 0, strpos( $objectRef->trxn_id, "\s" ));
71 -
72 - // format the contribution tracking message
73 - $query_params = array(
74 - "owa_event_type" => "ecommerce.transaction",
75 - "owa_ct_order_id" => $contrib_tracking_data->contribution_tracking_id,
76 - "owa_ct_order_source" => $contrib_tracking_data->utm_campaign,
77 - "owa_ct_total" => $objectRef->total_amount,
78 - "owa_ct_tax" => 0,
79 - "owa_ct_shipping" => 0,
80 - "owa_ct_gateway" => $gateway,
81 - "owa_page_url" => $contrib_tracking_data->url,
82 - "owa_session_id"=> $contrib_tracking_data->owa_session,
83 - );
84 -
85 - // log the query params
86 - watchdog( 'wmf_owa', 'OWA tracking params for contribution_id ' . $objectId . ': ' . print_r( $query_params, true ), WATCHDOG_DEBUG );
87 -
88 - // sent the query to OWA
89 - wmf_owa_send_tracking( $query_params );
90 - return;
91 -
92 -}
93 -
94 -/**
95 - * Fetch info needed for OWA from contribution_tracking table
96 - * @param int $contribution_tracking_id
97 - * @return array
98 - */
99 -function wmf_owa_get_contribution_tracking_data( $contribution_id ) {
100 - $query = 'SELECT ct.id as "contribuion_tracking_id", ct.owa_session, ctor.url, ct.utm_campaign
101 - FROM contribution_tracking ct, contribution_tracking_owa_ref ctor
102 - WHERE ctor.id=ct.owa_ref && ct.contribution_id="%d"';
103 - $result = db_fetch_object( db_query( $query, $contribution_id ));
104 -
105 - // log $query and $result
106 - watchdog( 'wmf_owa', 'OWA query to contribution_tracking for contribution_id ' . $contribution_id . ': ' . $query, WATCHDOG_DEBUG );
107 - watchdog( 'wmf_owa', 'OWA query result from contribution_tracking for contribution_id ' . $contribution_id . ': ' . print_r( $result, true ), WATCHDOG_DEBUG );
108 -
109 - return $result;
110 -}
111 -
112 -/**
113 - * Send tracking data to OWA
114 - *
115 - * @param array $query_params The array of data for OWA to track
116 - */
117 -function wmf_owa_send_tracking( $query_params ) {
118 - $owa_log_url = variable_get( 'wmf_owa_log', OWA_LOG_DEFAULT );
119 - $ch = curl_init();
120 - curl_setopt( $ch, CURLOPT_URL, $owa_log_url . "?". http_build_query( $query_params ));
121 - curl_setopt( $ch, CURLOPT_USERAGENT, "WMF Ecommerce web service 1.0" );
122 -
123 - if ( !curl_exec( $ch )) {
124 - // log curl error curl_error( $ch );
125 - watchdog( 'wmf_owa', 'Error posting to OWA with query params: ' . print_r( $query_params, true ), WATCHDOG_ERROR );
126 - }
127 -
128 - curl_close( $ch );
129 - return;
130 -}
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/wmf_owa/wmf_owa.module
@@ -0,0 +1,129 @@
 2+<?php
 3+
 4+/** The default OWA log script location **/
 5+define( 'OWA_LOG_DEFAULT', 'http://analytics.tesla.usability.wikimedia.org/wiki/d/extensions/owa/log.php' );
 6+
 7+/**
 8+ * Implementation of hook_perm().
 9+ */
 10+function wmf_owa_perm() {
 11+ return array('administer wmf_owa');
 12+}
 13+
 14+/**
 15+ * Implementation of hook_menu()
 16+ */
 17+function wmf_owa_menu() {
 18+ $items = array();
 19+
 20+ $items['admin/settings/wmf_owa'] = array(
 21+ 'title' => 'Wikimedia Foundation OWA Configuration',
 22+ 'description' => t('Configure OWA log script location.'),
 23+ 'access arguments' => array('administer wmf_owa'),
 24+ 'page callback' => 'drupal_get_form',
 25+ 'page arguments' => array( 'wmf_owa_settings' ),
 26+ );
 27+
 28+ return $items;
 29+}
 30+
 31+/**
 32+ * Callback for menu path "admin/settings/wmf_owa".
 33+ */
 34+function wmf_owa_settings() {
 35+ $form[ 'wmf_owa_log' ] = array(
 36+ '#type' => 'textfield',
 37+ '#title' => t( 'OWA log path' ),
 38+ '#required' => TRUE,
 39+ '#default_value' => variable_get('wmf_owa_log', OWA_LOG_DEFAULT ),
 40+ );
 41+ return system_settings_form( $form );
 42+}
 43+
 44+/**
 45+ * Implementation of hook_civicrm_post
 46+ *
 47+ * @param unknown_type $op
 48+ * @param unknown_type $objectName
 49+ * @param unknown_type $objectId
 50+ * @param unknown_type $objectRef
 51+ */
 52+function wmf_owa_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
 53+ // only continue if we're handling a new or updated contribution
 54+ if ( $objectName != 'Contribution' && !in_array( $op, array( 'edit', 'create' )) ) {
 55+ return;
 56+ }
 57+
 58+ // load the OWA-specific tracking data
 59+ $contrib_tracking_data = wmf_owa_get_contribution_tracking_data( $objectId );
 60+ if ( !$contrib_tracking_data ) {
 61+ // log, don't post to OWA
 62+ watchdog( 'wmf_owa', 'Could not load tracking data for contribution_id ' . $objectId, WATCHDOG_WARNING );
 63+ return;
 64+ }
 65+
 66+ /**
 67+ * pull the gateway out fo the trxn_id string
 68+ * it is the element prior to the first space in the str
 69+ */
 70+ $gateway = substr( $objectRef->trxn_id, 0, strpos( $objectRef->trxn_id, "\s" ));
 71+
 72+ // format the contribution tracking message
 73+ $query_params = array(
 74+ "owa_event_type" => "ecommerce.transaction",
 75+ "owa_ct_order_id" => $contrib_tracking_data->contribution_tracking_id,
 76+ "owa_ct_order_source" => $contrib_tracking_data->utm_campaign,
 77+ "owa_ct_total" => $objectRef->total_amount,
 78+ "owa_ct_tax" => 0,
 79+ "owa_ct_shipping" => 0,
 80+ "owa_ct_gateway" => $gateway,
 81+ "owa_page_url" => $contrib_tracking_data->url,
 82+ "owa_session_id"=> $contrib_tracking_data->owa_session,
 83+ );
 84+
 85+ // log the query params
 86+ watchdog( 'wmf_owa', 'OWA tracking params for contribution_id ' . $objectId . ': ' . print_r( $query_params, true ), WATCHDOG_DEBUG );
 87+
 88+ // sent the query to OWA
 89+ wmf_owa_send_tracking( $query_params );
 90+ return;
 91+
 92+}
 93+
 94+/**
 95+ * Fetch info needed for OWA from contribution_tracking table
 96+ * @param int $contribution_tracking_id
 97+ * @return array
 98+ */
 99+function wmf_owa_get_contribution_tracking_data( $contribution_id ) {
 100+ $query = 'SELECT ct.id as "contribuion_tracking_id", ct.owa_session, ctor.url, ct.utm_campaign
 101+ FROM contribution_tracking ct, contribution_tracking_owa_ref ctor
 102+ WHERE ctor.id=ct.owa_ref && ct.contribution_id="%d"';
 103+ $result = db_fetch_object( db_query( $query, $contribution_id ));
 104+
 105+ // log $query and $result
 106+ watchdog( 'wmf_owa', 'OWA query to contribution_tracking for contribution_id ' . $contribution_id . ': ' . $query, WATCHDOG_DEBUG );
 107+ watchdog( 'wmf_owa', 'OWA query result from contribution_tracking for contribution_id ' . $contribution_id . ': ' . print_r( $result, true ), WATCHDOG_DEBUG );
 108+
 109+ return $result;
 110+}
 111+
 112+/**
 113+ * Send tracking data to OWA
 114+ *
 115+ * @param array $query_params The array of data for OWA to track
 116+ */
 117+function wmf_owa_send_tracking( $query_params ) {
 118+ $owa_log_url = variable_get( 'wmf_owa_log', OWA_LOG_DEFAULT );
 119+ $ch = curl_init();
 120+ curl_setopt( $ch, CURLOPT_URL, $owa_log_url . "?". http_build_query( $query_params ));
 121+ curl_setopt( $ch, CURLOPT_USERAGENT, "WMF Ecommerce web service 1.0" );
 122+
 123+ if ( !curl_exec( $ch )) {
 124+ // log curl error curl_error( $ch );
 125+ watchdog( 'wmf_owa', 'Error posting to OWA with query params: ' . print_r( $query_params, true ), WATCHDOG_ERROR );
 126+ }
 127+
 128+ curl_close( $ch );
 129+ return;
 130+}
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/wmf_owa/wmf_owa.info
@@ -0,0 +1,3 @@
 2+name = Open Web Analytics for Wikimedia Foundation
 3+description = Allows for tracking of WMF-specific events in Open Web Analytics
 4+core = 6.x
\ No newline at end of file

Status & tagging log