r91682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91681‎ | r91682 | r91683 >
Date:20:50, 7 July 2011
Author:reedy
Status:ok
Tags:
Comment:
Add seemingly missing transaction $db-begin() noticed in r91664
Modified paths:
  • /trunk/extensions/ClickTracking/ClickTracking.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php
@@ -94,7 +94,7 @@
9595 //adds a bucket-testing campaign to the active campaigns
9696 public static function addCampaign($localBasePath, $remoteExtPath, $name ){
9797 global $wgResourceModules;
98 -
 98+
9999 $cusResourceTemplate = array(
100100 'localBasePath' => $localBasePath,
101101 'remoteExtPath' => $remoteExtPath,
@@ -103,7 +103,7 @@
104104 'scripts' => "$name.js",
105105 'dependencies' => 'jquery.clickTracking',
106106 ) + $cusResourceTemplate;
107 - $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge(
 107+ $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge(
108108 ( array ) $wgResourceModules['ext.UserBuckets']['dependencies'],
109109 array("ext.UserBuckets.$name"));
110110 }
@@ -143,11 +143,11 @@
144144 */
145145 public static function unpackBucketInfo(){
146146 global $wgRequest;
147 -
 147+
148148 //JSON-encoded because it's simple, can be replaced with any other encoding scheme
149149 return FormatJson::decode( $wgRequest->getCookie( 'userbuckets', "" ), true );
150150 }
151 -
 151+
152152 /**
153153 * Takes in an array of buckets
154154 * @param unknown_type $buckets
@@ -157,12 +157,12 @@
158158 global $wgRequest;
159159 //Can be another encoding scheme, just needs to match unpackBucketInfo
160160 $packedBuckets = FormatJson::encode( $buckets );
161 -
 161+
162162 //NOTE: $wgRequest->response setCookie sets it with a prefix and httponly by default
163 - setcookie( 'userbuckets' , $packedBuckets ,
 163+ setcookie( 'userbuckets' , $packedBuckets ,
164164 time() + 60 * 60 * 24 * 90 , '/' ); //expire in 90 days
165165 }
166 -
 166+
167167 /**
168168 * Track particular event
169169 *
@@ -177,13 +177,13 @@
178178 * (defined by ClickTracking/$wgClickTrackContribGranularity2)
179179 * @param $contribs_in_timespan3 Integer: number of contributions user has made in timespan of granularity 3
180180 * (defined by ClickTracking/$wgClickTrackContribGranularity3)
181 - * @param $additional String: catch-all for any additional information we want to record about this click
 181+ * @param $additional String: catch-all for any additional information we want to record about this click
182182 * @param $relevantBucket String: name/index of the particular bucket we're concerned with for this event
183183 * @return Boolean: true if the event was stored in the DB
184184 */
185185 public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventName, $contribs = 0,
186186 $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0, $additional = null, $recordBucketInfo = true ) {
187 -
 187+
188188 global $wgClickTrackingDatabase, $wgClickTrackingLog;
189189 $retval = true;
190190 if ( $wgClickTrackingDatabase ) {
@@ -207,11 +207,12 @@
208208 $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ );
209209 $dbw->commit();
210210
211 - if( $recordBucketInfo && $db_status ){
 211+ if( $recordBucketInfo && $db_status ) {
212212 $buckets = self::unpackBucketInfo();
213 - if( $buckets ){
 213+ $dbw->begin();
 214+ if( $buckets ) {
214215 foreach( $buckets as $bucketName => $bucketValue ){
215 - $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties',
 216+ $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties',
216217 array(
217218 'session_id' => (string) $sessionId,
218219 'property_name' => (string) $bucketName,
@@ -225,7 +226,7 @@
226227 }
227228 }//ifbuckets
228229 }//ifrecord
229 -
 230+
230231 $dbw->commit();
231232 $retval = $db_status && $db_status_buckets;
232233 }
@@ -244,16 +245,16 @@
245246 str_replace( "\t", ' ', $additional ),
246247 ) );
247248 wfErrorLog( $msg, $wgClickTrackingLog );
248 -
 249+
249250 // No need to mess with $retval here, doing
250251 // $retval == $retval && true is useless
251252 }
252253 return $retval;
253254 }
254 -
 255+
255256 public static function editPageShowEditFormFields( $editPage, $output ) {
256257 global $wgRequest;
257 -
 258+
258259 // Add clicktracking fields to form, if given
259260 $session = $wgRequest->getVal( 'clicktrackingsession' );
260261 $event = $wgRequest->getVal( 'clicktrackingevent' );
@@ -263,24 +264,24 @@
264265 $editPage->editFormTextAfterContent .= Html::hidden( 'clicktrackingevent', $event );
265266 $editPage->editFormTextAfterContent .= Html::hidden( 'clicktrackinginfo', $info );
266267 }
267 -
 268+
268269 return true;
269270 }
270 -
 271+
271272 public static function articleSave( $editpage ) {
272273 self::trackRequest( '-save-attempt' );
273274 return true;
274275 }
275 -
 276+
276277 public static function articleSaveComplete( $article, $user, $text, $summary, $minoredit,
277278 $watchthis, $sectionanchor, $flags, $revision, $baseRevId ) {
278279 self::trackRequest( '-save-complete' );
279280 return true;
280281 }
281 -
 282+
282283 protected static function trackRequest( $suffix ) {
283284 global $wgRequest, $wgTitle;
284 -
 285+
285286 $session = $wgRequest->getVal( 'clicktrackingsession' );
286287 $event = $wgRequest->getVal( 'clicktrackingevent' );
287288 $info = $wgRequest->getVal( 'clicktrackinginfo' );
@@ -295,7 +296,7 @@
296297 $api = new ApiMain( $params, true );
297298 $api->execute();
298299 }
299 -
 300+
300301 return true;
301302 }
302303 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91664ClickTracking: Add support for logging events to files or UDP through $wgClic...catrope18:30, 7 July 2011

Status & tagging log