Added script to populate log_user_text
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 27 Jun 2009 10:33:47 +0000 (10:33 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 27 Jun 2009 10:33:47 +0000 (10:33 +0000)
maintenance/populateLogUsertext.inc [new file with mode: 0644]
maintenance/populateLogUsertext.php [new file with mode: 0644]

diff --git a/maintenance/populateLogUsertext.inc b/maintenance/populateLogUsertext.inc
new file mode 100644 (file)
index 0000000..2734852
--- /dev/null
@@ -0,0 +1,54 @@
+<?php\r
+/**\r
+ * Makes the required database updates for the log_user_text column\r
+ *\r
+ * Run via update.php or directly through populateLogUsertext.php\r
+ *\r
+ * @file\r
+ * @ingroup Maintenance\r
+ */\r
+\r
+define( 'LOG_USERTEXT_BATCH_SIZE', 100 );\r
+\r
+function populate_logusertext( $db ) {\r
+       $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );\r
+       if( !$start ) {\r
+               echo "Nothing to do.\n";\r
+               return true;\r
+       }\r
+       $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );\r
+       \r
+       # Do remaining chunk\r
+       $end += LOG_USERTEXT_BATCH_SIZE - 1;\r
+       $blockStart = $start;\r
+       $blockEnd = $start + LOG_USERTEXT_BATCH_SIZE - 1;\r
+       while( $blockEnd <= $end ) {\r
+               echo "...doing log_id from $blockStart to $blockEnd\n";\r
+               $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";\r
+               $res = $db->select( array('logging','user'), \r
+                       array('log_id','user_name'), $cond, __FUNCTION__ );\r
+               $batch = array();\r
+               $db->begin();\r
+               while( $row = $db->fetchObject( $res ) ) {\r
+                       $db->update( 'logging', array('log_user_text' => $row->user_name),\r
+                               array('log_id' => $row->log_id), __FUNCTION__ );\r
+               }\r
+               $db->commit();\r
+               $blockStart += LOG_USERTEXT_BATCH_SIZE;\r
+               $blockEnd += LOG_USERTEXT_BATCH_SIZE;\r
+               wfWaitForSlaves( 5 );\r
+       }\r
+       if( $db->insert(\r
+                       'updatelog',\r
+                       array( 'ul_key' => 'populate log_usertext' ),\r
+                       __FUNCTION__,\r
+                       'IGNORE'\r
+               )\r
+       ) {\r
+               wfOut( "log_usertext population complete.\n" );\r
+               return true;\r
+       } else {\r
+               wfOut( "Could not insert log_usertext population row.\n" );\r
+               return false;\r
+       }\r
+}\r
diff --git a/maintenance/populateLogUsertext.php b/maintenance/populateLogUsertext.php
new file mode 100644 (file)
index 0000000..99aedf2
--- /dev/null
@@ -0,0 +1,17 @@
+<?php\r
+/**\r
+ * Makes the required database updates for Special:ProtectedPages\r
+ * to show all protected pages, even ones before the page restrictions\r
+ * schema change. All remaining page_restriction column values are moved\r
+ * to the new table.\r
+ *\r
+ * @file\r
+ * @ingroup Maintenance\r
+ */\r
+\r
+require_once 'commandLine.inc';\r
+require_once 'populateLogUsertext.inc';\r
+       \r
+$db =& wfGetDB( DB_MASTER );\r
+\r
+populate_logusertext( $db );\r