* Initialise site_stats table at upgrade time if data was missing
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 13 Jan 2007 01:52:33 +0000 (01:52 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 13 Jan 2007 01:52:33 +0000 (01:52 +0000)
RELEASE-NOTES
maintenance/initStats.inc [new file with mode: 0644]
maintenance/initStats.php
maintenance/updaters.inc

index 72b8650..49ee440 100644 (file)
@@ -57,6 +57,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   optional fields, which may be considered useful at registration time.
 * Fixed Postgres upgrade script.
 * (bug 8613) Fix error when viewing "Recent Changes" and using Postgres.
+* Initialise site_stats table at upgrade time if data was missing
+
 
 == Languages updated ==
 
diff --git a/maintenance/initStats.inc b/maintenance/initStats.inc
new file mode 100644 (file)
index 0000000..673742e
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+function wfInitStats( $options=array() ) {
+       $dbr = wfGetDB( DB_SLAVE );
+
+       echo "Counting total edits...";
+       $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ );
+       $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ );
+       echo "{$edits}\nCounting number of articles...";
+
+       global $wgContentNamespaces;
+       $good  = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ );
+       echo "{$good}\nCounting total pages...";
+
+       $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ );
+       echo "{$pages}\nCounting number of users...";
+
+       $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ );
+       echo "{$users}\nCounting number of admins...";
+
+       $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ );
+       echo "{$admin}\nCounting number of images...";
+
+       $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ );
+       echo "{$image}\n";
+
+       if( !isset( $options['noviews'] ) ) {
+               echo "Counting total page views...";
+               $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ );
+               echo "{$views}\n";
+       }
+
+       echo "\nUpdating site statistics...";
+
+       $dbw = wfGetDB( DB_MASTER );
+       $values = array( 'ss_total_edits' => $edits,
+                                       'ss_good_articles' => $good,
+                                       'ss_total_pages' => $pages,
+                                       'ss_users' => $users,
+                                       'ss_admins' => $admin,
+                                       'ss_images' => $image );
+       $conds = array( 'ss_row_id' => 1 );
+       $views = array( 'ss_total_views' => isset( $views ) ? $views : 0 );
+                               
+       if( isset( $options['update'] ) ) {
+               $dbw->update( 'site_stats', $values, $conds, __METHOD__ );
+       } else {
+               $dbw->delete( 'site_stats', $conds, __METHOD__ );
+               $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ );
+       }
+
+       echo( "done.\n" );
+}
+
+?>
\ No newline at end of file
index 291de1e..1328ad7 100644 (file)
 $options = array( 'help', 'update', 'noviews' );
 require_once( 'commandLine.inc' );
 echo( "Refresh Site Statistics\n\n" );
-$dbr =& wfGetDB( DB_SLAVE );
-$fname = 'initStats';
 
 if( isset( $options['help'] ) ) {
        showHelp();
        exit();
 }
 
-echo( "Counting total edits..." );
-$edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
-$edits += $dbr->selectField( 'archive', 'COUNT(*)', '', $fname );
-echo( "{$edits}\nCounting number of articles..." );
-
-global $wgContentNamespaces;
-$good  = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
-echo( "{$good}\nCounting total pages..." );
-
-$pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
-echo( "{$pages}\nCounting number of users..." );
-
-$users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
-echo( "{$users}\nCounting number of admins..." );
-
-$admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
-echo( "{$admin}\nCounting number of images..." );
-
-$image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
-echo( "{$image}\n" );
-
-if( !isset( $options['noviews'] ) ) {
-       echo( "Counting total page views..." );
-       $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', $fname );
-       echo( "{$views}\n" );
-}
-
-echo( "\nUpdating site statistics..." );
-
-$dbw =& wfGetDB( DB_MASTER );
-$values = array( 'ss_total_edits' => $edits,
-                               'ss_good_articles' => $good,
-                               'ss_total_pages' => $pages,
-                               'ss_users' => $users,
-                               'ss_admins' => $admin,
-                               'ss_images' => $image );
-$conds = array( 'ss_row_id' => 1 );
-$views = array( 'ss_total_views' => isset( $views ) ? $views : 0 );
-                               
-if( isset( $options['update'] ) ) {
-       $dbw->update( 'site_stats', $values, $conds, $fname );
-} else {
-       $dbw->delete( 'site_stats', $conds, $fname );
-       $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
-}
-
-echo( "done.\n\n" );
+require "$IP/maintenance/initStats.inc";
+wfInitStats( $options );
 
 function showHelp() {
        echo( "Re-initialise the site statistics tables.\n\n" );
        echo( "Usage: php initStats.php [--update|--noviews]\n\n" );
-       echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" );
+       echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" );
        echo( "--noviews : Don't update the page view counter\n\n" );
 }
 
index 4decc1f..e9958b0 100644 (file)
@@ -827,6 +827,22 @@ function do_backlinking_indices_update() {
        }
 }
 
+function do_stats_init() {
+       // Sometimes site_stats table is not properly populated.
+       global $wgDatabase;
+       echo "Checking site_stats row...";
+       $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
+       if( $row === false ) {
+               echo "data is missing! rebuilding...\n";
+               
+               global $IP;
+               require_once "$IP/maintenance/initStats.inc";
+               wfInitStats();
+       } else {
+               echo "ok.\n";
+       }
+}
+
 function purge_cache() {
        global $wgDatabase;
        # We can't guarantee that the user will be able to use TRUNCATE,
@@ -910,6 +926,8 @@ function do_all_updates( $shared = false, $purge = true ) {
        deleteDefaultMessages();
        echo "Done\n"; flush();
        
+       do_stats_init(); flush();
+       
        if( $purge ) {
                purge_cache();
                flush();