27require_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' ),
108 ], IDatabase::LIST_AND )
109 ], IDatabase::LIST_OR )
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 ],
const RUN_MAINTENANCE_IF_MAIN
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.
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.