26require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Populates the rev_len and ar_len fields' );
43 return 'populate rev_len and ar_len';
48 if ( !$dbw->tableExists(
'revision' ) ) {
49 $this->
fatalError(
"revision table does not exist" );
50 } elseif ( !$dbw->tableExists(
'archive' ) ) {
51 $this->
fatalError(
"archive table does not exist" );
52 } elseif ( !$dbw->fieldExists(
'revision',
'rev_len', __METHOD__ ) ) {
53 $this->
output(
"rev_len column does not exist\n\n",
true );
58 $this->
output(
"Populating rev_len column\n" );
61 $this->
output(
"Populating ar_len column\n" );
64 $this->
output(
"rev_len and ar_len population complete "
65 .
"[$rev revision rows, $ar archive rows].\n" );
77 protected function doLenUpdates( $table, $idCol, $prefix, $queryInfo ) {
81 $start = $dbw->selectField( $table,
"MIN($idCol)",
'', __METHOD__ );
82 $end = $dbw->selectField( $table,
"MAX($idCol)",
'', __METHOD__ );
83 if ( !$start || !$end ) {
84 $this->
output(
"...$table table seems to be empty.\n" );
90 $blockStart = intval( $start );
91 $blockEnd = intval( $start ) + $batchSize - 1;
94 while ( $blockStart <= $end ) {
95 $this->
output(
"...doing $idCol from $blockStart to $blockEnd\n" );
100 "$idCol >= $blockStart",
101 "$idCol <= $blockEnd",
103 "{$prefix}_len IS NULL",
106 "{$prefix}_sha1 != " .
$dbr->addQuotes(
'phoiac9h4m842xq45sp7s6u21eteeq1' ),
107 ], IDatabase::LIST_AND )
108 ], IDatabase::LIST_OR )
115 if (
$res->numRows() > 0 ) {
117 # Go through and update rev_len from these rows.
118 foreach (
$res as $row ) {
119 if ( $this->
upgradeRow( $row, $table, $idCol, $prefix ) ) {
126 $blockStart += $batchSize;
127 $blockEnd += $batchSize;
140 protected function upgradeRow( $row, $table, $idCol, $prefix ) {
143 $rev = ( $table ===
'archive' )
149 # This should not happen, but sometimes does (T22757)
151 $this->
output(
"Content of $table $id unavailable!\n" );
157 $dbw->update( $table,
158 [
"{$prefix}_len" =>
$content->getSize() ],
159 [ $idCol => $row->$idCol ],
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
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.
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that populates the rev_len and ar_len fields when they are NULL.
__construct()
Default constructor.
doDBUpdates()
Do the actual work.
upgradeRow( $row, $table, $idCol, $prefix)
getUpdateKey()
Get the update key name to go in the update log table.
doLenUpdates( $table, $idCol, $prefix, $queryInfo)
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
require_once RUN_MAINTENANCE_IF_MAIN