12 class SiteStatsUpdate
{
14 var $mViews, $mEdits, $mGood, $mPages, $mUsers;
16 function SiteStatsUpdate( $views, $edits, $good, $pages = 0, $users = 0 ) {
17 $this->mViews
= $views;
18 $this->mEdits
= $edits;
20 $this->mPages
= $pages;
21 $this->mUsers
= $users;
24 function appendUpdate( &$sql, $field, $delta ) {
30 $sql .= "$field=$field-1";
32 $sql .= "$field=$field+1";
38 $fname = 'SiteStatsUpdate::doUpdate';
39 $dbw =& wfGetDB( DB_MASTER
);
41 # First retrieve the row just to find out which schema we're in
42 $row = $dbw->selectRow( 'site_stats', '*', false, $fname );
46 $this->appendUpdate( $updates, 'ss_total_views', $this->mViews
);
47 $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits
);
48 $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood
);
50 if ( isset( $row->ss_total_pages
) ) {
51 # Update schema if required
52 if ( $row->ss_total_pages
== -1 && !$this->mViews
) {
53 $dbr =& wfGetDB( DB_SLAVE
, array( 'SpecialStatistics', 'vslow') );
54 extract( $dbr->tableNames( 'page', 'user' ) );
56 $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
57 $res = $dbr->query( $sql, $fname );
58 $pageRow = $dbr->fetchObject( $res );
59 $pages = $pageRow->total +
$this->mPages
;
61 $sql = "SELECT COUNT(user_id) AS total FROM $user";
62 $res = $dbr->query( $sql, $fname );
63 $userRow = $dbr->fetchObject( $res );
64 $users = $userRow->total +
$this->mUsers
;
69 $updates .= "ss_total_pages=$pages, ss_users=$users";
71 $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages
);
72 $this->appendUpdate( $updates, 'ss_users', $this->mUsers
);
76 $site_stats = $dbw->tableName( 'site_stats' );
77 $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1);
78 $dbw->query( $sql, $fname );