Index: trunk/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.hooks.php |
— | — | @@ -29,18 +29,20 @@ |
30 | 30 | global $wgUser; |
31 | 31 | $today = gmdate( 'Ymd', time() ); |
32 | 32 | $dbw = wfGetDB( DB_MASTER ); |
33 | | - /* |
34 | | - //there seems no way to set contribs to contribs+1 in a reasonably fast manner in this framework |
35 | | - try{ |
36 | | - $dbw->insert("user_daily_contribs", array("user_id" => $wgUser->getId(), "day" => $today, "contribs" => 1), __METHOD__); |
| 33 | + |
| 34 | + //writes only return true/false and an update on 0 rows is true, so try insert, on fail, update |
| 35 | + try |
| 36 | + { |
| 37 | + $dbw->insert("user_daily_contribs", array("user_id" => $wgUser->getId(), "day" => $today, "contribs" => 1), __METHOD__); |
37 | 38 | } |
38 | | - catch(Exception $e){ |
39 | | - $dbw->update( "user_daily_contribs", array( "contribs" => "contribs+1"), array("user_id" => $wgUser->getId(), "day" => $today), __METHOD__); |
| 39 | + catch(Exception $e) |
| 40 | + { |
| 41 | + //normal $db->update doesn't support SQL variables yet |
| 42 | + $sql = "UPDATE user_daily_contribs SET contribs=contribs+1 WHERE day = $today AND user_id = {$wgUser->getId()}"; |
| 43 | + $dbw->query($sql, __METHOD__); |
40 | 44 | } |
41 | | - */ |
42 | | - $sql = |
43 | | - "INSERT INTO user_daily_contribs (user_id,day,contribs) VALUES ({$wgUser->getId()},$today,1) ON DUPLICATE KEY UPDATE contribs=contribs+1;"; |
44 | | - $dbw->query($sql, __METHOD__); |
| 45 | + |
| 46 | + |
45 | 47 | return true; |
46 | 48 | } |
47 | 49 | |