// clean schema with mwdumper.
wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" );
- SiteStatsInit::doAllAndCommit( false );
+ SiteStatsInit::doAllAndCommit( wfGetDB( DB_SLAVE ) );
$row = self::doLoad( wfGetDB( DB_MASTER ) );
}
wfProfileIn( __METHOD__ );
if( !isset( self::$pageCount[$ns] ) ) {
$dbr = wfGetDB( DB_SLAVE );
- $pageCount[$ns] = (int)$dbr->selectField(
+ self::$pageCount[$ns] = (int)$dbr->selectField(
'page',
'COUNT(*)',
array( 'page_namespace' => $ns ),
);
}
wfProfileOut( __METHOD__ );
- return $pageCount[$ns];
+ return self::$pageCount[$ns];
}
/**
}
/**
- *
+ * Class for handling updates to the site_stats table
*/
-class SiteStatsUpdate {
+class SiteStatsUpdate implements DeferrableUpdate {
var $mViews, $mEdits, $mGood, $mPages, $mUsers;
/**
* Constructor
- * @param $useMaster Boolean: whether to use the master DB
+ * @param $database Boolean or DatabaseBase:
+ * - Boolean: whether to use the master DB
+ * - DatabaseBase: database connection to use
*/
- public function __construct( $useMaster = false ) {
- $this->db = wfGetDB( $useMaster ? DB_MASTER : DB_SLAVE );
+ public function __construct( $database = false ) {
+ if ( $database instanceof DatabaseBase ) {
+ $this->db = $database;
+ } else {
+ $this->db = wfGetDB( $database ? DB_MASTER : DB_SLAVE );
+ }
}
/**
$this->mPages = $this->db->selectField( 'page', 'COUNT(*)', '', __METHOD__ );
return $this->mPages;
}
-
+
/**
* Count total users
* @return Integer
$this->mUsers = $this->db->selectField( 'user', 'COUNT(*)', '', __METHOD__ );
return $this->mUsers;
}
-
+
/**
* Count views
* @return Integer
/**
* Do all updates and commit them. More or less a replacement
- * for the original initStats, but without the calls to wfOut()
- * @param $update Boolean: whether to update the current stats or write fresh
- * @param $noViews Boolean: when true, do not update the number of page views
- * @param $activeUsers Boolean: whether to update the number of active users
+ * for the original initStats, but without output.
+ *
+ * @param $database Boolean or DatabaseBase:
+ * - Boolean: whether to use the master DB
+ * - DatabaseBase: database connection to use
+ * @param $options Array of options, may contain the following values
+ * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false)
+ * - views Boolean: when true, do not update the number of page views (default: true)
+ * - activeUsers Boolean: whether to update the number of active users (default: false)
*/
- public static function doAllAndCommit( $update, $noViews = false, $activeUsers = false ) {
+ public static function doAllAndCommit( $database, array $options = array() ) {
+ $options += array( 'update' => false, 'views' => true, 'activeUsers' => false );
+
// Grab the object and count everything
- $counter = new SiteStatsInit( false );
+ $counter = new SiteStatsInit( $database );
+
$counter->edits();
$counter->articles();
$counter->pages();
$counter->files();
// Only do views if we don't want to not count them
- if( !$noViews ) {
+ if( $options['views'] ) {
$counter->views();
}
// Update/refresh
- if( $update ) {
+ if( $options['update'] ) {
$counter->update();
} else {
$counter->refresh();
}
// Count active users if need be
- if( $activeUsers ) {
+ if( $options['activeUsers'] ) {
SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
}
}