28 require_once __DIR__ .
'/../Maintenance.php';
35 parent::__construct();
37 $this->
addOption(
'dry-run',
'Don\'t update any rows' );
38 $this->
addOption(
'undo',
'Undo log location',
false,
true );
48 $maxID = $dbr->newSelectQueryBuilder()
49 ->select(
'MAX(old_id)' )
51 ->caller( __METHOD__ )->fetchField();
56 $numBlocks = intval( $maxID / $blockSize ) + 1;
61 for ( $b = 0; $b < $numBlocks; $b++ ) {
62 $lbFactory->waitForReplication();
64 $this->
output( sprintf(
"%5.2f%%\n", $b / $numBlocks * 100 ) );
65 $start = $blockSize * $b + 1;
66 $end = $blockSize * ( $b + 1 );
68 $res = $dbr->newSelectQueryBuilder()
69 ->select( [
'old_id',
'old_text',
'old_flags' ] )
72 "old_id>=$start AND old_id<=$end " .
73 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
75 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\''
77 ->caller( __METHOD__ )->fetchResultSet();
78 foreach ( $res as $row ) {
79 $numResolved += $this->
resolveStub( $row, $dryRun ) ? 1 : 0;
84 $this->
output(
"$numResolved of $numTotal stubs resolved\n" );
91 $this->undoLog = $undoLog;
105 $stub = unserialize( $row->old_text );
106 $flags = SqlBlobStore::explodeFlags( $row->old_flags );
111 print
"Error at old_id $id: found object of class " . get_class( $stub ) .
112 ", expecting HistoryBlobStub\n";
116 $mainId = $stub->getLocation();
118 print
"Error at old_id $id: falsey location\n";
122 # Get the main text row
123 $mainTextRow = $dbr->newSelectQueryBuilder()
124 ->select( [
'old_text',
'old_flags' ] )
126 ->where( [
'old_id' => $mainId ] )
127 ->caller( __METHOD__ )->fetchRow();
129 if ( !$mainTextRow ) {
130 print
"Error at old_id $id: can't find main text row old_id $mainId\n";
134 $mainFlags = SqlBlobStore::explodeFlags( $mainTextRow->old_flags );
135 $mainText = $mainTextRow->old_text;
137 if ( !in_array(
'external', $mainFlags ) ) {
138 print
"Error at old_id $id: target $mainId is not external\n";
141 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9a-f]{32}$!', $mainText ) ) {
142 print
"Error at old_id $id: target $mainId is a CGZ pointer\n";
145 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9]{1,6}$!', $mainText ) ) {
146 print
"Error at old_id $id: target $mainId is a DHB pointer\n";
149 if ( !preg_match(
'!^DB://([^/]*)/([^/]*)$!', $mainText ) ) {
150 print
"Error at old_id $id: target $mainId has unrecognised text\n";
154 # Preserve the legacy encoding flag, but switch from object to external
155 if ( in_array(
'utf-8', $flags ) ) {
156 $newFlags =
'utf-8,external';
158 $newFlags =
'external';
160 $newText = $mainText .
'/' . $stub->getHash();
164 $this->
output(
"Resolve $id => $newFlags $newText\n" );
166 $updated = $this->undoLog->update(
169 'old_flags' => $newFlags,
170 'old_text' => $newText
176 $this->
output(
"Updated of old_id $id failed to match\n" );
185 require_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...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
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.