MediaWiki REL1_30
populateLogUsertext.php
Go to the documentation of this file.
1<?php
27require_once __DIR__ . '/Maintenance.php';
28
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Populates the log_user_text field' );
39 $this->setBatchSize( 100 );
40 }
41
42 protected function getUpdateKey() {
43 return 'populate log_usertext';
44 }
45
46 protected function updateSkippedMessage() {
47 return 'log_user_text column of logging table already populated.';
48 }
49
50 protected function doDBUpdates() {
51 $db = $this->getDB( DB_MASTER );
52 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
53 if ( !$start ) {
54 $this->output( "Nothing to do.\n" );
55
56 return true;
57 }
58 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __METHOD__ );
59
60 # Do remaining chunk
61 $end += $this->mBatchSize - 1;
62 $blockStart = $start;
63 $blockEnd = $start + $this->mBatchSize - 1;
64 while ( $blockEnd <= $end ) {
65 $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
66 $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";
67 $res = $db->select( [ 'logging', 'user' ],
68 [ 'log_id', 'user_name' ], $cond, __METHOD__ );
69
70 $this->beginTransaction( $db, __METHOD__ );
71 foreach ( $res as $row ) {
72 $db->update( 'logging', [ 'log_user_text' => $row->user_name ],
73 [ 'log_id' => $row->log_id ], __METHOD__ );
74 }
75 $this->commitTransaction( $db, __METHOD__ );
76 $blockStart += $this->mBatchSize;
77 $blockEnd += $this->mBatchSize;
79 }
80 $this->output( "Done populating log_user_text field.\n" );
81
82 return true;
83 }
84}
85
86$maintClass = "PopulateLogUsertext";
87require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
int $mBatchSize
Batch size.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
Maintenance script that makes the required database updates for Special:ProtectedPages to show all pr...
doDBUpdates()
Do the actual work.
getUpdateKey()
Get the update key name to go in the update log table.
__construct()
Default constructor.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
$res
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:26