Index: trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php |
— | — | @@ -47,21 +47,6 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | | - * Wait for all the slave database servers to sync up with the master |
52 | | - */ |
53 | | - public function syncDBs() { |
54 | | - // FIXME: Copied from populateAFRevisions.php, which coppied from updateCollation.php, should be centralized somewhere |
55 | | - $lb = wfGetLB(); |
56 | | - // bug 27975 - Don't try to wait for slaves if there are none |
57 | | - // Prevents permission error when getting master position |
58 | | - if ( $lb->getServerCount() > 1 ) { |
59 | | - $dbw = $lb->getConnection( DB_MASTER ); |
60 | | - $pos = $dbw->getMasterPos(); |
61 | | - $lb->waitForAll( $pos ); |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - /** |
66 | 51 | * Bootstrap this maintenance script |
67 | 52 | * |
68 | 53 | * Performs operations necessary for this maintenance script to run which |
— | — | @@ -72,16 +57,19 @@ |
73 | 58 | * Set user-specified operations to perform |
74 | 59 | */ |
75 | 60 | $operations = explode( ',', $this->getOption( 'op' ) ); |
76 | | - // check sanity of specified operations |
| 61 | + // Check sanity of specified operations |
77 | 62 | if ( !$this->checkOperations( $operations ) ) { |
78 | 63 | $this->error( 'Invalid operation specified.', true ); |
79 | 64 | } else { |
80 | 65 | $this->operations = $operations; |
81 | 66 | } |
82 | 67 | |
83 | | - // set db objects |
| 68 | + // Set database objects |
84 | 69 | $this->dbr = wfGetDB( DB_SLAVE ); |
85 | 70 | $this->dbw = wfGetDB( DB_MASTER ); |
| 71 | + |
| 72 | + // Set timezone to UTC (contribution data will always be in UTC) |
| 73 | + date_default_timezone_set( 'UTC' ); |
86 | 74 | } |
87 | 75 | |
88 | 76 | /** |
— | — | @@ -129,8 +117,8 @@ |
130 | 118 | $this->output( "Writing data to public_reporting_days...\n" ); |
131 | 119 | |
132 | 120 | $conditions = array( |
133 | | - 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
134 | | - 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
| 121 | + 'converted_amount >= ' . intval( $egFundraiserStatisticsMinimum ), |
| 122 | + 'converted_amount <= ' . intval( $egFundraiserStatisticsMaximum ) |
135 | 123 | ); |
136 | 124 | |
137 | 125 | // Get the data for a fundraiser |
— | — | @@ -168,8 +156,8 @@ |
169 | 157 | $res = $this->dbw->delete( 'public_reporting_days', array( 1 ) ); |
170 | 158 | // Insert the new totals |
171 | 159 | $res = $this->dbw->insert( 'public_reporting_days', $insertArray, __METHOD__ ); |
172 | | - // Sync the databases |
173 | | - $this->syncDBs(); |
| 160 | + // Wait for the databases to sync |
| 161 | + wfWaitForSlaves(); |
174 | 162 | } |
175 | 163 | |
176 | 164 | $lag = time() - $begin; |
— | — | @@ -228,8 +216,8 @@ |
229 | 217 | $res = $this->dbw->delete( 'public_reporting_fundraisers', array( 1 ) ); |
230 | 218 | // Insert the new totals |
231 | 219 | $res = $this->dbw->insert( 'public_reporting_fundraisers', $insertArray, __METHOD__ ); |
232 | | - // Sync the databases |
233 | | - $this->syncDBs(); |
| 220 | + // Wait for the databases to sync |
| 221 | + wfWaitForSlaves(); |
234 | 222 | } |
235 | 223 | $lag = time() - $begin; |
236 | 224 | $this->output( "Inserted " . $records . " rows. ($lag seconds)\n" ); |
— | — | @@ -294,8 +282,6 @@ |
295 | 283 | } |
296 | 284 | |
297 | 285 | if ( $records > 0 ) { |
298 | | - // Set timezone to UTC to match donation servers |
299 | | - date_default_timezone_set( 'UTC' ); |
300 | 286 | // Empty the table of previous totals for this fundraiser |
301 | 287 | $res = $this->dbw->delete( |
302 | 288 | 'public_reporting_days', |
— | — | @@ -306,8 +292,8 @@ |
307 | 293 | ); |
308 | 294 | // Insert the new totals |
309 | 295 | $res = $this->dbw->insert( 'public_reporting_days', $insertArray, __METHOD__ ); |
310 | | - // Sync the databases |
311 | | - $this->syncDBs(); |
| 296 | + // Wait for the databases to sync |
| 297 | + wfWaitForSlaves(); |
312 | 298 | } |
313 | 299 | |
314 | 300 | $lag = time() - $begin; |
Index: trunk/extensions/ContributionReporting/patches/public-reporting-summaries.sql |
— | — | @@ -7,8 +7,8 @@ |
8 | 8 | `prf_average` decimal(8,4) NOT NULL DEFAULT '0.0000', |
9 | 9 | `prf_maximum` decimal(11,4) NOT NULL DEFAULT '0.0000', |
10 | 10 | `prf_insert_timestamp` int(10) NOT NULL, |
| 11 | + PRIMARY KEY (prf_id) |
11 | 12 | ) /*$wgDBTableOptions*/; |
12 | | -CREATE UNIQUE INDEX /*i*/prf_id ON /*$wgDBprefix*/public_reporting_fundraisers (prf_id); |
13 | 13 | |
14 | 14 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/public_reporting_days ( |
15 | 15 | `prd_date` date NOT NULL, |
— | — | @@ -17,5 +17,5 @@ |
18 | 18 | `prd_average` decimal(8,4) unsigned NOT NULL DEFAULT '0.0000', |
19 | 19 | `prd_maximum` decimal(11,4) unsigned NOT NULL DEFAULT '0.0000', |
20 | 20 | `prd_insert_timestamp` int(10) NOT NULL, |
| 21 | + PRIMARY KEY (prd_date) |
21 | 22 | ) /*$wgDBTableOptions*/; |
22 | | -CREATE UNIQUE INDEX /*i*/prf_id ON /*$wgDBprefix*/public_reporting_days (prd_date); |