16require_once __DIR__ .
'/../Maintenance.php';
24 parent::__construct();
26 $this->
addOption(
'dry-run',
'Don\'t update any rows' );
27 $this->
addOption(
'undo',
'Undo log location',
false,
true );
37 $maxID = $dbr->newSelectQueryBuilder()
38 ->select(
'MAX(old_id)' )
40 ->caller( __METHOD__ )->fetchField();
45 $numBlocks = intval( $maxID / $blockSize ) + 1;
49 for ( $b = 0; $b < $numBlocks; $b++ ) {
52 $this->
output( sprintf(
"%5.2f%%\n", $b / $numBlocks * 100 ) );
53 $start = $blockSize * $b + 1;
54 $end = $blockSize * ( $b + 1 );
56 $res = $dbr->newSelectQueryBuilder()
57 ->select( [
'old_id',
'old_text',
'old_flags' ] )
60 "old_id>=$start AND old_id<=$end " .
61 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
63 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\''
65 ->caller( __METHOD__ )->fetchResultSet();
66 foreach ( $res as $row ) {
67 $numResolved += $this->
resolveStub( $row, $dryRun ) ? 1 : 0;
72 $this->
output(
"$numResolved of $numTotal stubs resolved\n" );
76 $this->undoLog = $undoLog;
90 $stub = unserialize( $row->old_text );
91 $flags = SqlBlobStore::explodeFlags( $row->old_flags );
96 print
"Error at old_id $id: found object of class " . get_class( $stub ) .
97 ", expecting HistoryBlobStub\n";
101 $mainId = $stub->getLocation();
103 print
"Error at old_id $id: falsey location\n";
107 # Get the main text row
108 $mainTextRow = $dbr->newSelectQueryBuilder()
109 ->select( [
'old_text',
'old_flags' ] )
111 ->where( [
'old_id' => $mainId ] )
112 ->caller( __METHOD__ )->fetchRow();
114 if ( !$mainTextRow ) {
115 print
"Error at old_id $id: can't find main text row old_id $mainId\n";
119 $mainFlags = SqlBlobStore::explodeFlags( $mainTextRow->old_flags );
120 $mainText = $mainTextRow->old_text;
122 if ( !in_array(
'external', $mainFlags ) ) {
123 print
"Error at old_id $id: target $mainId is not external\n";
126 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9a-f]{32}$!', $mainText ) ) {
127 print
"Error at old_id $id: target $mainId is a CGZ pointer\n";
130 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9]{1,6}$!', $mainText ) ) {
131 print
"Error at old_id $id: target $mainId is a DHB pointer\n";
134 if ( !preg_match(
'!^DB://([^/]*)/([^/]*)$!', $mainText ) ) {
135 print
"Error at old_id $id: target $mainId has unrecognised text\n";
139 # Preserve the legacy encoding flag, but switch from object to external
140 if ( in_array(
'utf-8', $flags ) ) {
141 $newFlags =
'utf-8,external';
143 $newFlags =
'external';
145 $newText = $mainText .
'/' . $stub->getHash();
149 $this->
output(
"Resolve $id => $newFlags $newText\n" );
151 $updated = $this->undoLog->update(
154 'old_flags' => $newFlags,
155 'old_text' => $newText
161 $this->
output(
"Updated of old_id $id failed to match\n" );
171require_once RUN_MAINTENANCE_IF_MAIN;
Pointer object for an item within a CGZ blob stored in the text table.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
getOption( $name, $default=null)
Get an option, or return the default.
getReplicaDB(string|false $virtualDomain=false)
getPrimaryDB(string|false $virtualDomain=false)
Update a database while optionally writing SQL that reverses the update to a file.
setUndoLog(UndoLog $undoLog)
resolveStub( $row, $dryRun)
Resolve a history stub.
__construct()
Default constructor.
execute()
Convert history stubs that point to an external row to direct external pointers.