r106362 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106361‎ | r106362 | r106363 >
Date:20:04, 15 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
reorganizing how were connecting to the databases, fixing spelling of emergency
Modified paths:
  • /trunk/extensions/ContributionReporting/ContributionHistory_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionReporting.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/DailyTotal_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/ContributionReporting.php
@@ -11,12 +11,18 @@
1212
1313 $wgContributionReportingBaseURL = "http://meta.wikimedia.org/w/index.php?title=Special:NoticeTemplate/view&template=";
1414
15 -// Override these with appropriate DB settings for the CiviCRM database...
 15+// Override these with appropriate DB settings for the CiviCRM master database...
1616 $wgContributionReportingDBserver = $wgDBserver;
1717 $wgContributionReportingDBuser = $wgDBuser;
1818 $wgContributionReportingDBpassword = $wgDBpassword;
1919 $wgContributionReportingDBname = $wgDBname;
2020
 21+// Override these with appropriate DB settings for the CiviCRM slave database...
 22+$wgContributionReportingReadDBserver = $wgDBserver;
 23+$wgContributionReportingReadDBuser = $wgDBuser;
 24+$wgContributionReportingReadDBpassword = $wgDBpassword;
 25+$wgContributionReportingReadDBname = $wgDBname;
 26+
2127 // And now the tracking database
2228 $wgContributionTrackingDBserver = $wgDBserver;
2329 $wgContributionTrackingDBuser = $wgDBuser;
@@ -163,6 +169,7 @@
164170
165171 /**
166172 * Automatically use a local or special database connection for reporting
 173+ * This connection will typically be to the CiviCRM master database
167174 * @return DatabaseMysql
168175 */
169176 function efContributionReportingConnection() {
@@ -184,6 +191,29 @@
185192 }
186193
187194 /**
 195+ * Automatically use a local or special database connection for reporting
 196+ * This connection will typically be to a CiviCRM slave database
 197+ * @return DatabaseMysql
 198+ */
 199+function efContributionReportingReadConnection() {
 200+ global $wgContributionReportingReadDBserver, $wgContributionReportingReadDBname;
 201+ global $wgContributionReportingReadDBuser, $wgContributionReportingReadDBpassword;
 202+
 203+ static $db;
 204+
 205+ if ( !$db ) {
 206+ $db = new DatabaseMysql(
 207+ $wgContributionReportingReadDBserver,
 208+ $wgContributionReportingReadDBuser,
 209+ $wgContributionReportingReadDBpassword,
 210+ $wgContributionReportingReadDBname );
 211+ $db->query( "SET names utf8" );
 212+ }
 213+
 214+ return $db;
 215+}
 216+
 217+/**
188218 * Automatically use a local or special database connection for tracking
189219 * @return DatabaseMysql
190220 */
@@ -221,7 +251,7 @@
222252 return $cache;
223253 }
224254
225 - $dbr = efContributionReportingConnection();
 255+ $dbr = wfGetDB( DB_SLAVE );
226256
227257 // Find the index number for the requested fundraiser
228258 $myFundraiserIndex = false;
Index: trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
@@ -20,7 +20,7 @@
2121 public function execute( $sub ) {
2222 global $wgOut, $wgRequest;
2323
24 - # Emergecny short cut until this is back in working order
 24+ # Emergency short cut until this is back in working order
2525 $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() );
2626 return;
2727
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
@@ -323,8 +323,8 @@
324324 return $cache;
325325 }
326326
327 - // Use database
328 - $dbr = efContributionReportingConnection();
 327+ // Use MediaWiki slave database
 328+ $dbr = wfGetDB( DB_SLAVE );
329329 // Set timezone to UTC (contribution data will always be in UTC)
330330 date_default_timezone_set( 'UTC' );
331331
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php
@@ -7,7 +7,7 @@
88 function execute( $language ) {
99 global $wgRequest, $wgOut, $wgLang;
1010
11 - # Emergecny short cut until post donation comments are enabled
 11+ # Emergency short cut until post donation comments are enabled
1212 $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() );
1313 return;
1414
Index: trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
@@ -67,6 +67,7 @@
6868 // Set database objects
6969 $this->dbr = wfGetDB( DB_SLAVE );
7070 $this->dbw = wfGetDB( DB_MASTER );
 71+ $this->dbpr = efContributionReportingReadConnection();
7172
7273 // Set timezone to UTC (contribution data will always be in UTC)
7374 date_default_timezone_set( 'UTC' );
@@ -122,7 +123,7 @@
123124 );
124125
125126 // Get the data for a fundraiser
126 - $result = $this->dbr->select( 'public_reporting',
 127+ $result = $this->dbpr->select( 'public_reporting',
127128 array(
128129 "DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' ) AS date",
129130 'sum( converted_amount ) AS total',
@@ -138,7 +139,7 @@
139140 )
140141 );
141142
142 - while ( $row = $this->dbr->fetchRow( $result ) ) {
 143+ while ( $row = $this->dbpr->fetchRow( $result ) ) {
143144 // Add it to the insert array
144145 $insertArray[] = array(
145146 'prd_date' => $row['date'],
@@ -181,12 +182,12 @@
182183 foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) {
183184
184185 $conditions = array(
185 - 'received >= ' . $this->dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $fundraiser['start'] ) ) ),
186 - 'received <= ' . $this->dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $fundraiser['end'] ) + 24 * 60 * 60 ) ),
 186+ 'received >= ' . $this->dbpr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $fundraiser['start'] ) ) ),
 187+ 'received <= ' . $this->dbpr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $fundraiser['end'] ) + 24 * 60 * 60 ) ),
187188 );
188189
189190 // Get the total for a fundraiser
190 - $result = $this->dbr->select(
 191+ $result = $this->dbpr->select(
191192 'public_reporting',
192193 array(
193194 'sum( converted_amount ) AS total',
@@ -197,7 +198,7 @@
198199 $conditions,
199200 __METHOD__
200201 );
201 - $row = $this->dbr->fetchRow( $result );
 202+ $row = $this->dbpr->fetchRow( $result );
202203
203204 // Add it to the insert array
204205 $insertArray[] = array(
@@ -245,14 +246,14 @@
246247 $this->output( "Writing data to public_reporting_days...\n" );
247248
248249 $conditions = array(
249 - 'received >= ' . $this->dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ),
250 - 'received <= ' . $this->dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ),
 250+ 'received >= ' . $this->dbpr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ),
 251+ 'received <= ' . $this->dbpr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ),
251252 'converted_amount >= ' . $egFundraiserStatisticsMinimum,
252253 'converted_amount <= ' . $egFundraiserStatisticsMaximum
253254 );
254255
255256 // Get the data for a fundraiser
256 - $result = $this->dbr->select( 'public_reporting',
 257+ $result = $this->dbpr->select( 'public_reporting',
257258 array(
258259 "DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' ) AS date",
259260 'sum( converted_amount ) AS total',
@@ -268,7 +269,7 @@
269270 )
270271 );
271272
272 - while ( $row = $this->dbr->fetchRow( $result ) ) {
 273+ while ( $row = $this->dbpr->fetchRow( $result ) ) {
273274 // Add it to the insert array
274275 $insertArray[] = array(
275276 'prd_date' => $row['date'],
@@ -286,8 +287,8 @@
287288 $res = $this->dbw->delete(
288289 'public_reporting_days',
289290 array(
290 - 'prd_date >= ' . $this->dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ),
291 - 'prd_date <= ' . $this->dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ),
 291+ 'prd_date >= ' . $this->dbpr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ),
 292+ 'prd_date <= ' . $this->dbpr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ),
292293 )
293294 );
294295 // Insert the new totals
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php
@@ -112,8 +112,8 @@
113113 return $cache;
114114 }
115115
116 - // Use database
117 - $dbr = efContributionReportingConnection();
 116+ // Use MediaWiki slave database
 117+ $dbr = wfGetDB( DB_SLAVE );
118118
119119 $result = $dbr->select(
120120 'public_reporting_days',
Index: trunk/extensions/ContributionReporting/ContributionStatistics_body.php
@@ -25,7 +25,7 @@
2626 public function execute( $sub ) {
2727 global $wgOut,$egContributionStatisticsViewDays;
2828
29 - # Emergecny short cut until this can be changed to use cron-generated data
 29+ # Emergency short cut until this can be changed to use cron-generated data
3030 # These queries are too expensive to run on demand.
3131 $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() );
3232 return;

Follow-up revisions

RevisionCommit summaryAuthorDate
r106696MFT r105145, r105454, r105641, r105657, r105659, r105757, r105916, r105965, r...awjrichards20:59, 19 December 2011

Status & tagging log