r75050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75049‎ | r75050 | r75051 >
Date:22:09, 19 October 2010
Author:nimishg
Status:deferred
Tags:
Comment:
added if not exist to sql
Modified paths:
  • /trunk/extensions/ContributionTracking/ContributionTracking.php (modified) (history)
  • /trunk/extensions/ContributionTracking/ContributionTracking.sql (modified) (history)
  • /trunk/extensions/ContributionTracking/ContributionTracking_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionTracking/ContributionTracking.sql
@@ -1,4 +1,4 @@
2 -CREATE TABLE `contribution_tracking` (
 2+CREATE TABLE IF NOT EXISTS /*_*/`contribution_tracking` (
33 `id` int(10) unsigned NOT NULL auto_increment,
44 `contribution_id` int(10) unsigned default NULL,
55 `note` text,
Index: trunk/extensions/ContributionTracking/ContributionTracking_body.php
@@ -5,6 +5,28 @@
66 parent::__construct( 'ContributionTracking' );
77 }
88
 9+ function get_owa_ref_id($ref){
 10+ // Replication lag means sometimes a new event will not exist in the table yet
 11+ $dbw = wfGetDB( DB_MASTER );
 12+ $id_num = $dbw->selectField(
 13+ 'contribution_tracking_owa_ref',
 14+ 'id',
 15+ array( 'url' => $ref ),
 16+ __METHOD__
 17+ );
 18+ // Once we're on mysql 5, we can use replace() instead of this selectField --> insert or update hooey
 19+ if ( $id_num === false ) {
 20+ $dbw->insert(
 21+ 'contribution_tracking_owa_ref',
 22+ array( 'url' => (string) $event_name ),
 23+ __METHOD__
 24+ );
 25+ $id_num = $dbw->insertId();
 26+ }
 27+ return $id_num === false ? 0 : $id_num;
 28+ }
 29+
 30+
931 function execute( $language ) {
1032 global $wgRequest, $wgOut;
1133 wfLoadExtensionMessages( 'ContributionTracking' );
@@ -28,6 +50,11 @@
2951
3052 $ts = $db->timestamp();
3153
 54+ $owa_ref = $wgRequest->getText('owa_ref', null);
 55+ if($owa_ref != null && !is_numeric($owa_ref)){
 56+ $owa_ref = $this->get_owa_ref_id($owa_ref);
 57+ }
 58+
3259 $tracked_contribution = array(
3360 'note' => $wgRequest->getText('comment', null),
3461 'referrer' => $wgRequest->getText('referrer', null),
@@ -38,7 +65,7 @@
3966 'optout' => ($wgRequest->getCheck('email-opt', 0) ? 0 : 1),
4067 'language' => $wgRequest->getText('language', null),
4168 'owa_session' => $wgRequest->getText('owa_session', null),
42 - 'owa_ref' => $wgRequest->getText('owa_ref', null),
 69+ 'owa_ref' => $owa_ref,
4370 'ts' => $ts,
4471 );
4572
@@ -141,6 +168,7 @@
142169 return wfMsgExt( $key, array( 'escape', 'language' => $this->lang ) );
143170 }
144171
 172+
145173 function msgWiki( $key ) {
146174 return wfMsgExt( $key, array( 'parse', 'language' => $this->lang ) );
147175 }
Index: trunk/extensions/ContributionTracking/ContributionTracking.php
@@ -46,6 +46,28 @@
4747
4848 }
4949
 50+ //convert a referrer URL to an index in the owa_ref table
 51+function ef_contribution_tracking_owa_get_ref_id($ref){
 52+ // Replication lag means sometimes a new event will not exist in the table yet
 53+ $dbw = wfGetDB( DB_MASTER );
 54+ $id_num = $dbw->selectField(
 55+ 'contribution_tracking_owa_ref',
 56+ 'id',
 57+ array( 'url' => $ref ),
 58+ __METHOD__
 59+ );
 60+ // Once we're on mysql 5, we can use replace() instead of this selectField --> insert or update hooey
 61+ if ( $id_num === false ) {
 62+ $dbw->insert(
 63+ 'contribution_tracking_owa_ref',
 64+ array( 'url' => (string) $event_name ),
 65+ __METHOD__
 66+ );
 67+ $id_num = $dbw->insertId();
 68+ }
 69+ return $id_num === false ? 0 : $id_num;
 70+ }
 71+
5072 function contributionTrackingConnection() {
5173 global $wgContributionTrackingDBserver, $wgContributionTrackingDBname;
5274 global $wgContributionTrackingDBuser, $wgContributionTrackingDBpassword;

Status & tagging log