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" );
59 $rev = $this->
doLenUpdates(
'revision',
'rev_id',
'rev', Revision::getQueryInfo() );
61 $this->
output(
"Populating ar_len column\n" );
62 $ar = $this->
doLenUpdates(
'archive',
'ar_id',
'ar', Revision::getArchiveQueryInfo() );
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' )
144 ? Revision::newFromArchiveRow( $row )
147 $content =
$rev->getContent( Revision::RAW );
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.
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)
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
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