MediaWiki  1.30.0
populateLogUsertext.php
Go to the documentation of this file.
1 <?php
27 require_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";
87 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:103
PopulateLogUsertext\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateLogUsertext.php:46
PopulateLogUsertext\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateLogUsertext.php:50
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3010
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
PopulateLogUsertext\__construct
__construct()
Default constructor.
Definition: populateLogUsertext.php:36
Maintenance\beginTransaction
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
Definition: Maintenance.php:1278
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1562
PopulateLogUsertext\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateLogUsertext.php:42
DB_MASTER
const DB_MASTER
Definition: defines.php:26
$maintClass
$maintClass
Definition: populateLogUsertext.php:86
Maintenance\commitTransaction
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
Definition: Maintenance.php:1293
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
PopulateLogUsertext
Maintenance script that makes the required database updates for Special:ProtectedPages to show all pr...
Definition: populateLogUsertext.php:35
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:314