Index: trunk/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -11,12 +11,18 @@ |
12 | 12 | |
13 | 13 | $wgContributionReportingBaseURL = "http://meta.wikimedia.org/w/index.php?title=Special:NoticeTemplate/view&template="; |
14 | 14 | |
15 | | -// Override these with appropriate DB settings for the CiviCRM database... |
| 15 | +// Override these with appropriate DB settings for the CiviCRM master database... |
16 | 16 | $wgContributionReportingDBserver = $wgDBserver; |
17 | 17 | $wgContributionReportingDBuser = $wgDBuser; |
18 | 18 | $wgContributionReportingDBpassword = $wgDBpassword; |
19 | 19 | $wgContributionReportingDBname = $wgDBname; |
20 | 20 | |
| 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 | + |
21 | 27 | // And now the tracking database |
22 | 28 | $wgContributionTrackingDBserver = $wgDBserver; |
23 | 29 | $wgContributionTrackingDBuser = $wgDBuser; |
— | — | @@ -163,6 +169,7 @@ |
164 | 170 | |
165 | 171 | /** |
166 | 172 | * Automatically use a local or special database connection for reporting |
| 173 | + * This connection will typically be to the CiviCRM master database |
167 | 174 | * @return DatabaseMysql |
168 | 175 | */ |
169 | 176 | function efContributionReportingConnection() { |
— | — | @@ -184,6 +191,29 @@ |
185 | 192 | } |
186 | 193 | |
187 | 194 | /** |
| 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 | +/** |
188 | 218 | * Automatically use a local or special database connection for tracking |
189 | 219 | * @return DatabaseMysql |
190 | 220 | */ |
— | — | @@ -221,7 +251,7 @@ |
222 | 252 | return $cache; |
223 | 253 | } |
224 | 254 | |
225 | | - $dbr = efContributionReportingConnection(); |
| 255 | + $dbr = wfGetDB( DB_SLAVE ); |
226 | 256 | |
227 | 257 | // Find the index number for the requested fundraiser |
228 | 258 | $myFundraiserIndex = false; |
Index: trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | public function execute( $sub ) { |
22 | 22 | global $wgOut, $wgRequest; |
23 | 23 | |
24 | | - # Emergecny short cut until this is back in working order |
| 24 | + # Emergency short cut until this is back in working order |
25 | 25 | $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() ); |
26 | 26 | return; |
27 | 27 | |
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php |
— | — | @@ -323,8 +323,8 @@ |
324 | 324 | return $cache; |
325 | 325 | } |
326 | 326 | |
327 | | - // Use database |
328 | | - $dbr = efContributionReportingConnection(); |
| 327 | + // Use MediaWiki slave database |
| 328 | + $dbr = wfGetDB( DB_SLAVE ); |
329 | 329 | // Set timezone to UTC (contribution data will always be in UTC) |
330 | 330 | date_default_timezone_set( 'UTC' ); |
331 | 331 | |
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | function execute( $language ) { |
9 | 9 | global $wgRequest, $wgOut, $wgLang; |
10 | 10 | |
11 | | - # Emergecny short cut until post donation comments are enabled |
| 11 | + # Emergency short cut until post donation comments are enabled |
12 | 12 | $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() ); |
13 | 13 | return; |
14 | 14 | |
Index: trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php |
— | — | @@ -67,6 +67,7 @@ |
68 | 68 | // Set database objects |
69 | 69 | $this->dbr = wfGetDB( DB_SLAVE ); |
70 | 70 | $this->dbw = wfGetDB( DB_MASTER ); |
| 71 | + $this->dbpr = efContributionReportingReadConnection(); |
71 | 72 | |
72 | 73 | // Set timezone to UTC (contribution data will always be in UTC) |
73 | 74 | date_default_timezone_set( 'UTC' ); |
— | — | @@ -122,7 +123,7 @@ |
123 | 124 | ); |
124 | 125 | |
125 | 126 | // Get the data for a fundraiser |
126 | | - $result = $this->dbr->select( 'public_reporting', |
| 127 | + $result = $this->dbpr->select( 'public_reporting', |
127 | 128 | array( |
128 | 129 | "DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' ) AS date", |
129 | 130 | 'sum( converted_amount ) AS total', |
— | — | @@ -138,7 +139,7 @@ |
139 | 140 | ) |
140 | 141 | ); |
141 | 142 | |
142 | | - while ( $row = $this->dbr->fetchRow( $result ) ) { |
| 143 | + while ( $row = $this->dbpr->fetchRow( $result ) ) { |
143 | 144 | // Add it to the insert array |
144 | 145 | $insertArray[] = array( |
145 | 146 | 'prd_date' => $row['date'], |
— | — | @@ -181,12 +182,12 @@ |
182 | 183 | foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) { |
183 | 184 | |
184 | 185 | $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 ) ), |
187 | 188 | ); |
188 | 189 | |
189 | 190 | // Get the total for a fundraiser |
190 | | - $result = $this->dbr->select( |
| 191 | + $result = $this->dbpr->select( |
191 | 192 | 'public_reporting', |
192 | 193 | array( |
193 | 194 | 'sum( converted_amount ) AS total', |
— | — | @@ -197,7 +198,7 @@ |
198 | 199 | $conditions, |
199 | 200 | __METHOD__ |
200 | 201 | ); |
201 | | - $row = $this->dbr->fetchRow( $result ); |
| 202 | + $row = $this->dbpr->fetchRow( $result ); |
202 | 203 | |
203 | 204 | // Add it to the insert array |
204 | 205 | $insertArray[] = array( |
— | — | @@ -245,14 +246,14 @@ |
246 | 247 | $this->output( "Writing data to public_reporting_days...\n" ); |
247 | 248 | |
248 | 249 | $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 ) ), |
251 | 252 | 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
252 | 253 | 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
253 | 254 | ); |
254 | 255 | |
255 | 256 | // Get the data for a fundraiser |
256 | | - $result = $this->dbr->select( 'public_reporting', |
| 257 | + $result = $this->dbpr->select( 'public_reporting', |
257 | 258 | array( |
258 | 259 | "DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' ) AS date", |
259 | 260 | 'sum( converted_amount ) AS total', |
— | — | @@ -268,7 +269,7 @@ |
269 | 270 | ) |
270 | 271 | ); |
271 | 272 | |
272 | | - while ( $row = $this->dbr->fetchRow( $result ) ) { |
| 273 | + while ( $row = $this->dbpr->fetchRow( $result ) ) { |
273 | 274 | // Add it to the insert array |
274 | 275 | $insertArray[] = array( |
275 | 276 | 'prd_date' => $row['date'], |
— | — | @@ -286,8 +287,8 @@ |
287 | 288 | $res = $this->dbw->delete( |
288 | 289 | 'public_reporting_days', |
289 | 290 | 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 ) ) ), |
292 | 293 | ) |
293 | 294 | ); |
294 | 295 | // Insert the new totals |
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -112,8 +112,8 @@ |
113 | 113 | return $cache; |
114 | 114 | } |
115 | 115 | |
116 | | - // Use database |
117 | | - $dbr = efContributionReportingConnection(); |
| 116 | + // Use MediaWiki slave database |
| 117 | + $dbr = wfGetDB( DB_SLAVE ); |
118 | 118 | |
119 | 119 | $result = $dbr->select( |
120 | 120 | 'public_reporting_days', |
Index: trunk/extensions/ContributionReporting/ContributionStatistics_body.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | public function execute( $sub ) { |
27 | 27 | global $wgOut,$egContributionStatisticsViewDays; |
28 | 28 | |
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 |
30 | 30 | # These queries are too expensive to run on demand. |
31 | 31 | $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() ); |
32 | 32 | return; |