Go to the documentation of this file.
27 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
39 $this->
addDescription(
'Populates the rev_len and ar_len fields' );
44 return 'populate rev_len and ar_len';
49 if ( !$dbw->tableExists(
'revision' ) ) {
50 $this->
fatalError(
"revision table does not exist" );
51 } elseif ( !$dbw->tableExists(
'archive' ) ) {
52 $this->
fatalError(
"archive table does not exist" );
53 } elseif ( !$dbw->fieldExists(
'revision',
'rev_len', __METHOD__ ) ) {
54 $this->
output(
"rev_len column does not exist\n\n",
true );
59 $this->
output(
"Populating rev_len column\n" );
62 $this->
output(
"Populating ar_len column\n" );
65 $this->
output(
"rev_len and ar_len population complete "
66 .
"[$rev revision rows, $ar archive rows].\n" );
78 protected function doLenUpdates( $table, $idCol, $prefix, $queryInfo ) {
82 $start = $dbw->selectField( $table,
"MIN($idCol)",
'', __METHOD__ );
83 $end = $dbw->selectField( $table,
"MAX($idCol)",
'', __METHOD__ );
84 if ( !$start || !$end ) {
85 $this->
output(
"...$table table seems to be empty.\n" );
91 $blockStart = intval( $start );
92 $blockEnd = intval( $start ) + $batchSize - 1;
95 while ( $blockStart <= $end ) {
96 $this->
output(
"...doing $idCol from $blockStart to $blockEnd\n" );
101 "$idCol >= $blockStart",
102 "$idCol <= $blockEnd",
104 "{$prefix}_len IS NULL",
107 "{$prefix}_sha1 != " .
$dbr->addQuotes(
'phoiac9h4m842xq45sp7s6u21eteeq1' ),
116 if (
$res->numRows() > 0 ) {
118 # Go through and update rev_len from these rows.
119 foreach (
$res as $row ) {
120 if ( $this->
upgradeRow( $row, $table, $idCol, $prefix ) ) {
127 $blockStart += $batchSize;
128 $blockEnd += $batchSize;
141 protected function upgradeRow( $row, $table, $idCol, $prefix ) {
144 $rev = ( $table ===
'archive' )
148 $content = $rev->getContent( RevisionRecord::RAW );
150 # This should not happen, but sometimes does (T22757)
152 $this->
output(
"Content of $table $id unavailable!\n" );
158 $dbw->update( $table,
159 [
"{$prefix}_len" =>
$content->getSize() ],
160 [ $idCol => $row->$idCol ],
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that populates the rev_len and ar_len fields when they are NULL.
doDBUpdates()
Do the actual work.
upgradeRow( $row, $table, $idCol, $prefix)
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getUpdateKey()
Get the update key name to go in the update log table.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
__construct()
Default constructor.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
doLenUpdates( $table, $idCol, $prefix, $queryInfo)
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
setBatchSize( $s=0)
Set the batch size.