Maintenance script to recount images and update the site statistics
authorRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 15:22:56 +0000 (15:22 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 15:22:56 +0000 (15:22 +0000)
RELEASE-NOTES
maintenance/recountImages.php [new file with mode: 0644]

index 5e0ad4d..dd1ab18 100644 (file)
@@ -178,6 +178,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   formatted according to the current user's settings
 * (bug 218) Redirects do not support named anchors
 * (bug 5780) Thousands and decimal separators for Norwegian
+* Maintenance script to recount images and update the site statistics
 
 == Compatibility ==
 
diff --git a/maintenance/recountImages.php b/maintenance/recountImages.php
new file mode 100644 (file)
index 0000000..613082f
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * Maintenance script to update the site_stats.ss_images field
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+
+require_once( 'commandLine.inc' );
+
+function recountImages() {
+       $dbw =& wfGetDB( DB_MASTER );
+       $count = $dbw->selectField( 'images', 'COUNT(*)', '', 'recountImages' );
+       # Replication safe update; set to NULL first to force the change to slaves
+       $dbw->update( 'site_stats', array( 'ss_images' => NULL ), array( 'ss_row_id' => 1 ), 'recountImages' );
+       $dbw->update( 'site_stats', array( 'ss_images' => $count ), array( 'ss_row_id' => 1 ), 'recountImages' );
+       return $count;
+}
+
+echo( "Updating image count in site statistics..." );
+recountImages();
+echo( "set to {$count}.\n\n" );
+
+?>
\ No newline at end of file