https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106362
Revision: 106362
Author: kaldari
Date: 2011-12-15 20:04:50 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
reorganizing how were connecting to the databases, fixing spelling of emergency
Modified Paths:
--------------
trunk/extensions/ContributionReporting/ContributionHistory_body.php
trunk/extensions/ContributionReporting/ContributionReporting.php
trunk/extensions/ContributionReporting/ContributionStatistics_body.php
trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
trunk/extensions/ContributionReporting/DailyTotal_body.php
trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
Modified: trunk/extensions/ContributionReporting/ContributionHistory_body.php
===================================================================
--- trunk/extensions/ContributionReporting/ContributionHistory_body.php
2011-12-15 19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/ContributionHistory_body.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -7,7 +7,7 @@
function execute( $language ) {
global $wgRequest, $wgOut, $wgLang;
- # Emergecny short cut until post donation comments are enabled
+ # Emergency short cut until post donation comments are enabled
$wgOut->redirect( SpecialPage::getTitleFor(
'FundraiserStatistics' )->getFullURL() );
return;
Modified: trunk/extensions/ContributionReporting/ContributionReporting.php
===================================================================
--- trunk/extensions/ContributionReporting/ContributionReporting.php
2011-12-15 19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/ContributionReporting.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -11,12 +11,18 @@
$wgContributionReportingBaseURL =
"http://meta.wikimedia.org/w/index.php?title=Special:NoticeTemplate/view&template=";
-// Override these with appropriate DB settings for the CiviCRM database...
+// Override these with appropriate DB settings for the CiviCRM master
database...
$wgContributionReportingDBserver = $wgDBserver;
$wgContributionReportingDBuser = $wgDBuser;
$wgContributionReportingDBpassword = $wgDBpassword;
$wgContributionReportingDBname = $wgDBname;
+// Override these with appropriate DB settings for the CiviCRM slave
database...
+$wgContributionReportingReadDBserver = $wgDBserver;
+$wgContributionReportingReadDBuser = $wgDBuser;
+$wgContributionReportingReadDBpassword = $wgDBpassword;
+$wgContributionReportingReadDBname = $wgDBname;
+
// And now the tracking database
$wgContributionTrackingDBserver = $wgDBserver;
$wgContributionTrackingDBuser = $wgDBuser;
@@ -163,6 +169,7 @@
/**
* Automatically use a local or special database connection for reporting
+ * This connection will typically be to the CiviCRM master database
* @return DatabaseMysql
*/
function efContributionReportingConnection() {
@@ -184,6 +191,29 @@
}
/**
+ * Automatically use a local or special database connection for reporting
+ * This connection will typically be to a CiviCRM slave database
+ * @return DatabaseMysql
+ */
+function efContributionReportingReadConnection() {
+ global $wgContributionReportingReadDBserver,
$wgContributionReportingReadDBname;
+ global $wgContributionReportingReadDBuser,
$wgContributionReportingReadDBpassword;
+
+ static $db;
+
+ if ( !$db ) {
+ $db = new DatabaseMysql(
+ $wgContributionReportingReadDBserver,
+ $wgContributionReportingReadDBuser,
+ $wgContributionReportingReadDBpassword,
+ $wgContributionReportingReadDBname );
+ $db->query( "SET names utf8" );
+ }
+
+ return $db;
+}
+
+/**
* Automatically use a local or special database connection for tracking
* @return DatabaseMysql
*/
@@ -221,7 +251,7 @@
return $cache;
}
- $dbr = efContributionReportingConnection();
+ $dbr = wfGetDB( DB_SLAVE );
// Find the index number for the requested fundraiser
$myFundraiserIndex = false;
Modified: trunk/extensions/ContributionReporting/ContributionStatistics_body.php
===================================================================
--- trunk/extensions/ContributionReporting/ContributionStatistics_body.php
2011-12-15 19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/ContributionStatistics_body.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -25,7 +25,7 @@
public function execute( $sub ) {
global $wgOut,$egContributionStatisticsViewDays;
- # Emergecny short cut until this can be changed to use
cron-generated data
+ # Emergency short cut until this can be changed to use
cron-generated data
# These queries are too expensive to run on demand.
$wgOut->redirect( SpecialPage::getTitleFor(
'FundraiserStatistics' )->getFullURL() );
return;
Modified:
trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
===================================================================
---
trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
2011-12-15 19:53:05 UTC (rev 106361)
+++
trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -20,7 +20,7 @@
public function execute( $sub ) {
global $wgOut, $wgRequest;
- # Emergecny short cut until this is back in working order
+ # Emergency short cut until this is back in working order
$wgOut->redirect( SpecialPage::getTitleFor(
'FundraiserStatistics' )->getFullURL() );
return;
Modified: trunk/extensions/ContributionReporting/DailyTotal_body.php
===================================================================
--- trunk/extensions/ContributionReporting/DailyTotal_body.php 2011-12-15
19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/DailyTotal_body.php 2011-12-15
20:04:50 UTC (rev 106362)
@@ -112,8 +112,8 @@
return $cache;
}
- // Use database
- $dbr = efContributionReportingConnection();
+ // Use MediaWiki slave database
+ $dbr = wfGetDB( DB_SLAVE );
$result = $dbr->select(
'public_reporting_days',
Modified: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
===================================================================
--- trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
2011-12-15 19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -323,8 +323,8 @@
return $cache;
}
- // Use database
- $dbr = efContributionReportingConnection();
+ // Use MediaWiki slave database
+ $dbr = wfGetDB( DB_SLAVE );
// Set timezone to UTC (contribution data will always be in UTC)
date_default_timezone_set( 'UTC' );
Modified:
trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
===================================================================
--- trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
2011-12-15 19:53:05 UTC (rev 106361)
+++ trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
2011-12-15 20:04:50 UTC (rev 106362)
@@ -67,6 +67,7 @@
// Set database objects
$this->dbr = wfGetDB( DB_SLAVE );
$this->dbw = wfGetDB( DB_MASTER );
+ $this->dbpr = efContributionReportingReadConnection();
// Set timezone to UTC (contribution data will always be in UTC)
date_default_timezone_set( 'UTC' );
@@ -122,7 +123,7 @@
);
// Get the data for a fundraiser
- $result = $this->dbr->select( 'public_reporting',
+ $result = $this->dbpr->select( 'public_reporting',
array(
"DATE_FORMAT( FROM_UNIXTIME( received
),'%Y-%m-%d' ) AS date",
'sum( converted_amount ) AS total',
@@ -138,7 +139,7 @@
)
);
- while ( $row = $this->dbr->fetchRow( $result ) ) {
+ while ( $row = $this->dbpr->fetchRow( $result ) ) {
// Add it to the insert array
$insertArray[] = array(
'prd_date' => $row['date'],
@@ -181,12 +182,12 @@
foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) {
$conditions = array(
- 'received >= ' . $this->dbr->addQuotes(
wfTimestamp( TS_UNIX, strtotime( $fundraiser['start'] ) ) ),
- 'received <= ' . $this->dbr->addQuotes(
wfTimestamp( TS_UNIX, strtotime( $fundraiser['end'] ) + 24 * 60 * 60 ) ),
+ 'received >= ' . $this->dbpr->addQuotes(
wfTimestamp( TS_UNIX, strtotime( $fundraiser['start'] ) ) ),
+ 'received <= ' . $this->dbpr->addQuotes(
wfTimestamp( TS_UNIX, strtotime( $fundraiser['end'] ) + 24 * 60 * 60 ) ),
);
// Get the total for a fundraiser
- $result = $this->dbr->select(
+ $result = $this->dbpr->select(
'public_reporting',
array(
'sum( converted_amount ) AS total',
@@ -197,7 +198,7 @@
$conditions,
__METHOD__
);
- $row = $this->dbr->fetchRow( $result );
+ $row = $this->dbpr->fetchRow( $result );
// Add it to the insert array
$insertArray[] = array(
@@ -245,14 +246,14 @@
$this->output( "Writing data to public_reporting_days...\n" );
$conditions = array(
- 'received >= ' . $this->dbr->addQuotes( wfTimestamp(
TS_UNIX, strtotime( $start ) ) ),
- 'received <= ' . $this->dbr->addQuotes( wfTimestamp(
TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ),
+ 'received >= ' . $this->dbpr->addQuotes( wfTimestamp(
TS_UNIX, strtotime( $start ) ) ),
+ 'received <= ' . $this->dbpr->addQuotes( wfTimestamp(
TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ),
'converted_amount >= ' . $egFundraiserStatisticsMinimum,
'converted_amount <= ' . $egFundraiserStatisticsMaximum
);
// Get the data for a fundraiser
- $result = $this->dbr->select( 'public_reporting',
+ $result = $this->dbpr->select( 'public_reporting',
array(
"DATE_FORMAT( FROM_UNIXTIME( received
),'%Y-%m-%d' ) AS date",
'sum( converted_amount ) AS total',
@@ -268,7 +269,7 @@
)
);
- while ( $row = $this->dbr->fetchRow( $result ) ) {
+ while ( $row = $this->dbpr->fetchRow( $result ) ) {
// Add it to the insert array
$insertArray[] = array(
'prd_date' => $row['date'],
@@ -286,8 +287,8 @@
$res = $this->dbw->delete(
'public_reporting_days',
array(
- 'prd_date >= ' . $this->dbr->addQuotes(
wfTimestamp( TS_DB, strtotime( $start ) ) ),
- 'prd_date <= ' . $this->dbr->addQuotes(
wfTimestamp( TS_DB, strtotime( $end ) ) ),
+ 'prd_date >= ' .
$this->dbpr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ),
+ 'prd_date <= ' .
$this->dbpr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ),
)
);
// Insert the new totals
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs