48 $dbw = $this->getPrimaryDB();
49 $dbr = $this->getReplicaDB();
50 $maxID = $dbr->newSelectQueryBuilder()
51 ->select(
'MAX(old_id)' )
53 ->caller( __METHOD__ )->fetchField();
54 $blockSize = $this->getBatchSize();
55 $dryRun = $this->getOption(
'dry-run' );
58 $numBlocks = intval( $maxID / $blockSize ) + 1;
62 for ( $b = 0; $b < $numBlocks; $b++ ) {
63 $this->waitForReplication();
65 $this->output( sprintf(
"%5.2f%%\n", $b / $numBlocks * 100 ) );
66 $start = $blockSize * $b + 1;
67 $end = $blockSize * ( $b + 1 );
69 $res = $dbr->newSelectQueryBuilder()
70 ->select( [
'old_id',
'old_text',
'old_flags' ] )
73 "old_id>=$start AND old_id<=$end " .
74 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
76 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\''
78 ->caller( __METHOD__ )->fetchResultSet();
79 foreach ( $res as $row ) {
80 $numResolved += $this->
resolveStub( $row, $dryRun ) ? 1 : 0;
84 $this->output(
"100%\n" );
85 $this->output(
"$numResolved of $numTotal stubs resolved\n" );
103 $stub = unserialize( $row->old_text );
104 $flags = SqlBlobStore::explodeFlags( $row->old_flags );
106 $dbr = $this->getReplicaDB();
109 print
"Error at old_id $id: found object of class " . get_class( $stub ) .
110 ", expecting HistoryBlobStub\n";
114 $mainId = $stub->getLocation();
116 print
"Error at old_id $id: falsey location\n";
120 # Get the main text row
121 $mainTextRow = $dbr->newSelectQueryBuilder()
122 ->select( [
'old_text',
'old_flags' ] )
124 ->where( [
'old_id' => $mainId ] )
125 ->caller( __METHOD__ )->fetchRow();
127 if ( !$mainTextRow ) {
128 print
"Error at old_id $id: can't find main text row old_id $mainId\n";
132 $mainFlags = SqlBlobStore::explodeFlags( $mainTextRow->old_flags );
133 $mainText = $mainTextRow->old_text;
135 if ( !in_array(
'external', $mainFlags ) ) {
136 print
"Error at old_id $id: target $mainId is not external\n";
139 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9a-f]{32}$!', $mainText ) ) {
140 print
"Error at old_id $id: target $mainId is a CGZ pointer\n";
143 if ( preg_match(
'!^DB://([^/]*)/([^/]*)/[0-9]{1,6}$!', $mainText ) ) {
144 print
"Error at old_id $id: target $mainId is a DHB pointer\n";
147 if ( !preg_match(
'!^DB://([^/]*)/([^/]*)$!', $mainText ) ) {
148 print
"Error at old_id $id: target $mainId has unrecognised text\n";
152 # Preserve the legacy encoding flag, but switch from object to external
153 if ( in_array(
'utf-8', $flags ) ) {
154 $newFlags =
'utf-8,external';
156 $newFlags =
'external';
158 $newText = $mainText .
'/' . $stub->getHash();
162 $this->output(
"Resolve $id => $newFlags $newText\n" );
164 $updated = $this->undoLog->update(
167 'old_flags' => $newFlags,
168 'old_text' => $newText
174 $this->output(
"Updated of old_id $id failed to match\n" );