*Add a batch updater to move remaining page_restrictions values in page to the page_r...
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 21 Apr 2007 20:30:57 +0000 (20:30 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 21 Apr 2007 20:30:57 +0000 (20:30 +0000)
maintenance/updateRestrictions.php [new file with mode: 0644]

diff --git a/maintenance/updateRestrictions.php b/maintenance/updateRestrictions.php
new file mode 100644 (file)
index 0000000..7a26da4
--- /dev/null
@@ -0,0 +1,72 @@
+<?php\r
+\r
+/*\r
+ * Makes the required database changes for the CheckUser extension\r
+ */\r
+\r
+define( 'BATCH_SIZE', 100 );\r
+\r
+require_once 'commandLine.inc';\r
+       \r
+$db =& wfGetDB( DB_MASTER );\r
+if ( !$db->tableExists( 'page_restrictions' ) ) {\r
+       echo "page_restrictions does not exist\n";\r
+       exit( 1 );\r
+}\r
+\r
+migrate_page_restrictions( $db );\r
+\r
+function migrate_page_restrictions( $db ) {\r
+       \r
+       $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );\r
+       $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );\r
+       $blockStart = $start;\r
+       $blockEnd = $start + BATCH_SIZE - 1;\r
+       $encodedExpiry = Block::decodeExpiry('');\r
+       while ( $blockEnd <= $end ) {\r
+               $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_rescrictions !=''";\r
+               $res = $db->select( 'page', array('page_id', 'page_restrictions'), $cond, __FUNCTION__ );\r
+               $batch = array();\r
+               while ( $row = $db->fetchObject( $res ) ) {\r
+                       $oldRestrictions = array();\r
+                       foreach( explode( ':', trim( $row->page_restrictions ) ) as $restrict ) {\r
+                               $temp = explode( '=', trim( $restrict ) );\r
+                               if(count($temp) == 1) {\r
+                                       // old old format should be treated as edit/move restriction\r
+                                       $oldRestrictions["edit"] = explode( ',', trim( $temp[0] ) );\r
+                                       $oldRestrictions["move"] = explode( ',', trim( $temp[0] ) );\r
+                               } else {\r
+                                       $oldRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );\r
+                               }\r
+                       }\r
+                       # Update restrictions table\r
+                       foreach( $oldRestrictions as $action => $restrictions ) {\r
+                               $batch[] = array( \r
+                                       'pr_page' => $row->page_id,\r
+                                       'pr_type' => $action,\r
+                                       'pr_level' => $restrictions,\r
+                                       'pr_cascade' => 0,\r
+                                       'pr_expiry' => $encodedExpiry\r
+                               );\r
+                       }\r
+                       # Update page record\r
+                       $db->update( 'page',\r
+                               array( /* SET */\r
+                                       'page_restrictions' => ''\r
+                               ), array( /* WHERE */\r
+                                       'page_id' => $row->page_id\r
+                               ), 'migrate_restrictions'\r
+                       );\r
+               }\r
+               # We use insert() and not replace() as Article.php replaces\r
+               # page_restrictions with '' when protected in the restrictions table\r
+               if ( count( $batch ) ) {\r
+                       $db->insert( 'page_restictions', $batch, __FUNCTION__ );\r
+               }\r
+               $blockStart += BATCH_SIZE;\r
+               $blockEnd += BATCH_SIZE;\r
+               wfWaitForSlaves( 5 );\r
+       }\r
+}\r
+\r
+?>\r