Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / maintenance / storage / recompressTracked.php
blob7386df8a31c2f3e27d3ce0019f3df1cdb470478f
1 <?php
2 /**
3 * Moves blobs indexed by trackBlobs.php to a specified list of destination
4 * clusters, and recompresses them in the process.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
22 * @ingroup Maintenance ExternalStorage
25 use MediaWiki\Logger\LegacyLogger;
27 $optionsWithArgs = RecompressTracked::getOptionsWithArgs();
28 require __DIR__ . '/../commandLine.inc';
30 if ( count( $args ) < 1 ) {
31 echo "Usage: php recompressTracked.php [options] <cluster> [... <cluster>...]
32 Moves blobs indexed by trackBlobs.php to a specified list of destination clusters,
33 and recompresses them in the process. Restartable.
35 Options:
36 --procs <procs> Set the number of child processes (default 1)
37 --copy-only Copy only, do not update the text table. Restart
38 without this option to complete.
39 --debug-log <file> Log debugging data to the specified file
40 --info-log <file> Log progress messages to the specified file
41 --critical-log <file> Log error messages to the specified file
43 exit( 1 );
46 $job = RecompressTracked::newFromCommandLine( $args, $options );
47 $job->execute();
49 /**
50 * Maintenance script that moves blobs indexed by trackBlobs.php to a specified
51 * list of destination clusters, and recompresses them in the process.
53 * @ingroup Maintenance ExternalStorage
55 class RecompressTracked {
56 public $destClusters;
57 public $batchSize = 1000;
58 public $orphanBatchSize = 1000;
59 public $reportingInterval = 10;
60 public $numProcs = 1;
61 public $numBatches = 0;
62 public $useDiff, $pageBlobClass, $orphanBlobClass;
63 public $slavePipes, $slaveProcs, $prevSlaveId;
64 public $copyOnly = false;
65 public $isChild = false;
66 public $slaveId = false;
67 public $noCount = false;
68 public $debugLog, $infoLog, $criticalLog;
69 public $store;
71 private static $optionsWithArgs = array(
72 'procs',
73 'slave-id',
74 'debug-log',
75 'info-log',
76 'critical-log'
79 private static $cmdLineOptionMap = array(
80 'no-count' => 'noCount',
81 'procs' => 'numProcs',
82 'copy-only' => 'copyOnly',
83 'child' => 'isChild',
84 'slave-id' => 'slaveId',
85 'debug-log' => 'debugLog',
86 'info-log' => 'infoLog',
87 'critical-log' => 'criticalLog',
90 static function getOptionsWithArgs() {
91 return self::$optionsWithArgs;
94 static function newFromCommandLine( $args, $options ) {
95 $jobOptions = array( 'destClusters' => $args );
96 foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
97 if ( isset( $options[$cmdOption] ) ) {
98 $jobOptions[$classOption] = $options[$cmdOption];
102 return new self( $jobOptions );
105 function __construct( $options ) {
106 foreach ( $options as $name => $value ) {
107 $this->$name = $value;
109 $this->store = new ExternalStoreDB;
110 if ( !$this->isChild ) {
111 $GLOBALS['wgDebugLogPrefix'] = "RCT M: ";
112 } elseif ( $this->slaveId !== false ) {
113 $GLOBALS['wgDebugLogPrefix'] = "RCT {$this->slaveId}: ";
115 $this->useDiff = function_exists( 'xdiff_string_bdiff' );
116 $this->pageBlobClass = $this->useDiff ? 'DiffHistoryBlob' : 'ConcatenatedGzipHistoryBlob';
117 $this->orphanBlobClass = 'ConcatenatedGzipHistoryBlob';
120 function debug( $msg ) {
121 wfDebug( "$msg\n" );
122 if ( $this->debugLog ) {
123 $this->logToFile( $msg, $this->debugLog );
127 function info( $msg ) {
128 echo "$msg\n";
129 if ( $this->infoLog ) {
130 $this->logToFile( $msg, $this->infoLog );
134 function critical( $msg ) {
135 echo "$msg\n";
136 if ( $this->criticalLog ) {
137 $this->logToFile( $msg, $this->criticalLog );
141 function logToFile( $msg, $file ) {
142 $header = '[' . date( 'd\TH:i:s' ) . '] ' . wfHostname() . ' ' . posix_getpid();
143 if ( $this->slaveId !== false ) {
144 $header .= "({$this->slaveId})";
146 $header .= ' ' . wfWikiID();
147 LegacyLogger::emit( sprintf( "%-50s %s\n", $header, $msg ), $file );
151 * Wait until the selected slave has caught up to the master.
152 * This allows us to use the slave for things that were committed in a
153 * previous part of this batch process.
155 function syncDBs() {
156 $dbw = wfGetDB( DB_MASTER );
157 $dbr = wfGetDB( DB_SLAVE );
158 $pos = $dbw->getMasterPos();
159 $dbr->masterPosWait( $pos, 100000 );
163 * Execute parent or child depending on the isChild option
165 function execute() {
166 if ( $this->isChild ) {
167 $this->executeChild();
168 } else {
169 $this->executeParent();
174 * Execute the parent process
176 function executeParent() {
177 if ( !$this->checkTrackingTable() ) {
178 return;
181 $this->syncDBs();
182 $this->startSlaveProcs();
183 $this->doAllPages();
184 $this->doAllOrphans();
185 $this->killSlaveProcs();
189 * Make sure the tracking table exists and isn't empty
190 * @return bool
192 function checkTrackingTable() {
193 $dbr = wfGetDB( DB_SLAVE );
194 if ( !$dbr->tableExists( 'blob_tracking' ) ) {
195 $this->critical( "Error: blob_tracking table does not exist" );
197 return false;
199 $row = $dbr->selectRow( 'blob_tracking', '*', '', __METHOD__ );
200 if ( !$row ) {
201 $this->info( "Warning: blob_tracking table contains no rows, skipping this wiki." );
203 return false;
206 return true;
210 * Start the worker processes.
211 * These processes will listen on stdin for commands.
212 * This necessary because text recompression is slow: loading, compressing and
213 * writing are all slow.
215 function startSlaveProcs() {
216 $cmd = 'php ' . wfEscapeShellArg( __FILE__ );
217 foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
218 if ( $cmdOption == 'slave-id' ) {
219 continue;
220 } elseif ( in_array( $cmdOption, self::$optionsWithArgs ) && isset( $this->$classOption ) ) {
221 $cmd .= " --$cmdOption " . wfEscapeShellArg( $this->$classOption );
222 } elseif ( $this->$classOption ) {
223 $cmd .= " --$cmdOption";
226 $cmd .= ' --child' .
227 ' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
228 ' ' . call_user_func_array( 'wfEscapeShellArg', $this->destClusters );
230 $this->slavePipes = $this->slaveProcs = array();
231 for ( $i = 0; $i < $this->numProcs; $i++ ) {
232 $pipes = array();
233 $spec = array(
234 array( 'pipe', 'r' ),
235 array( 'file', 'php://stdout', 'w' ),
236 array( 'file', 'php://stderr', 'w' )
238 MediaWiki\suppressWarnings();
239 $proc = proc_open( "$cmd --slave-id $i", $spec, $pipes );
240 MediaWiki\restoreWarnings();
241 if ( !$proc ) {
242 $this->critical( "Error opening slave process: $cmd" );
243 exit( 1 );
245 $this->slaveProcs[$i] = $proc;
246 $this->slavePipes[$i] = $pipes[0];
248 $this->prevSlaveId = -1;
252 * Gracefully terminate the child processes
254 function killSlaveProcs() {
255 $this->info( "Waiting for slave processes to finish..." );
256 for ( $i = 0; $i < $this->numProcs; $i++ ) {
257 $this->dispatchToSlave( $i, 'quit' );
259 for ( $i = 0; $i < $this->numProcs; $i++ ) {
260 $status = proc_close( $this->slaveProcs[$i] );
261 if ( $status ) {
262 $this->critical( "Warning: child #$i exited with status $status" );
265 $this->info( "Done." );
269 * Dispatch a command to the next available slave.
270 * This may block until a slave finishes its work and becomes available.
272 function dispatch( /*...*/ ) {
273 $args = func_get_args();
274 $pipes = $this->slavePipes;
275 $numPipes = stream_select( $x = array(), $pipes, $y = array(), 3600 );
276 if ( !$numPipes ) {
277 $this->critical( "Error waiting to write to slaves. Aborting" );
278 exit( 1 );
280 for ( $i = 0; $i < $this->numProcs; $i++ ) {
281 $slaveId = ( $i + $this->prevSlaveId + 1 ) % $this->numProcs;
282 if ( isset( $pipes[$slaveId] ) ) {
283 $this->prevSlaveId = $slaveId;
284 $this->dispatchToSlave( $slaveId, $args );
286 return;
289 $this->critical( "Unreachable" );
290 exit( 1 );
294 * Dispatch a command to a specified slave
295 * @param int $slaveId
296 * @param array|string $args
298 function dispatchToSlave( $slaveId, $args ) {
299 $args = (array)$args;
300 $cmd = implode( ' ', $args );
301 fwrite( $this->slavePipes[$slaveId], "$cmd\n" );
305 * Move all tracked pages to the new clusters
307 function doAllPages() {
308 $dbr = wfGetDB( DB_SLAVE );
309 $i = 0;
310 $startId = 0;
311 if ( $this->noCount ) {
312 $numPages = '[unknown]';
313 } else {
314 $numPages = $dbr->selectField( 'blob_tracking',
315 'COUNT(DISTINCT bt_page)',
316 # A condition is required so that this query uses the index
317 array( 'bt_moved' => 0 ),
318 __METHOD__
321 if ( $this->copyOnly ) {
322 $this->info( "Copying pages..." );
323 } else {
324 $this->info( "Moving pages..." );
326 while ( true ) {
327 $res = $dbr->select( 'blob_tracking',
328 array( 'bt_page' ),
329 array(
330 'bt_moved' => 0,
331 'bt_page > ' . $dbr->addQuotes( $startId )
333 __METHOD__,
334 array(
335 'DISTINCT',
336 'ORDER BY' => 'bt_page',
337 'LIMIT' => $this->batchSize,
340 if ( !$res->numRows() ) {
341 break;
343 foreach ( $res as $row ) {
344 $startId = $row->bt_page;
345 $this->dispatch( 'doPage', $row->bt_page );
346 $i++;
348 $this->report( 'pages', $i, $numPages );
350 $this->report( 'pages', $i, $numPages );
351 if ( $this->copyOnly ) {
352 $this->info( "All page copies queued." );
353 } else {
354 $this->info( "All page moves queued." );
359 * Display a progress report
360 * @param string $label
361 * @param int $current
362 * @param int $end
364 function report( $label, $current, $end ) {
365 $this->numBatches++;
366 if ( $current == $end || $this->numBatches >= $this->reportingInterval ) {
367 $this->numBatches = 0;
368 $this->info( "$label: $current / $end" );
369 wfWaitForSlaves();
374 * Move all orphan text to the new clusters
376 function doAllOrphans() {
377 $dbr = wfGetDB( DB_SLAVE );
378 $startId = 0;
379 $i = 0;
380 if ( $this->noCount ) {
381 $numOrphans = '[unknown]';
382 } else {
383 $numOrphans = $dbr->selectField( 'blob_tracking',
384 'COUNT(DISTINCT bt_text_id)',
385 array( 'bt_moved' => 0, 'bt_page' => 0 ),
386 __METHOD__ );
387 if ( !$numOrphans ) {
388 return;
391 if ( $this->copyOnly ) {
392 $this->info( "Copying orphans..." );
393 } else {
394 $this->info( "Moving orphans..." );
397 while ( true ) {
398 $res = $dbr->select( 'blob_tracking',
399 array( 'bt_text_id' ),
400 array(
401 'bt_moved' => 0,
402 'bt_page' => 0,
403 'bt_text_id > ' . $dbr->addQuotes( $startId )
405 __METHOD__,
406 array(
407 'DISTINCT',
408 'ORDER BY' => 'bt_text_id',
409 'LIMIT' => $this->batchSize
412 if ( !$res->numRows() ) {
413 break;
415 $ids = array();
416 foreach ( $res as $row ) {
417 $startId = $row->bt_text_id;
418 $ids[] = $row->bt_text_id;
419 $i++;
421 // Need to send enough orphan IDs to the child at a time to fill a blob,
422 // so orphanBatchSize needs to be at least ~100.
423 // batchSize can be smaller or larger.
424 while ( count( $ids ) > $this->orphanBatchSize ) {
425 $args = array_slice( $ids, 0, $this->orphanBatchSize );
426 $ids = array_slice( $ids, $this->orphanBatchSize );
427 array_unshift( $args, 'doOrphanList' );
428 call_user_func_array( array( $this, 'dispatch' ), $args );
430 if ( count( $ids ) ) {
431 $args = $ids;
432 array_unshift( $args, 'doOrphanList' );
433 call_user_func_array( array( $this, 'dispatch' ), $args );
436 $this->report( 'orphans', $i, $numOrphans );
438 $this->report( 'orphans', $i, $numOrphans );
439 $this->info( "All orphans queued." );
443 * Main entry point for worker processes
445 function executeChild() {
446 $this->debug( 'starting' );
447 $this->syncDBs();
449 while ( !feof( STDIN ) ) {
450 $line = rtrim( fgets( STDIN ) );
451 if ( $line == '' ) {
452 continue;
454 $this->debug( $line );
455 $args = explode( ' ', $line );
456 $cmd = array_shift( $args );
457 switch ( $cmd ) {
458 case 'doPage':
459 $this->doPage( intval( $args[0] ) );
460 break;
461 case 'doOrphanList':
462 $this->doOrphanList( array_map( 'intval', $args ) );
463 break;
464 case 'quit':
465 return;
467 wfWaitForSlaves();
472 * Move tracked text in a given page
474 * @param int $pageId
476 function doPage( $pageId ) {
477 $title = Title::newFromID( $pageId );
478 if ( $title ) {
479 $titleText = $title->getPrefixedText();
480 } else {
481 $titleText = '[deleted]';
483 $dbr = wfGetDB( DB_SLAVE );
485 // Finish any incomplete transactions
486 if ( !$this->copyOnly ) {
487 $this->finishIncompleteMoves( array( 'bt_page' => $pageId ) );
488 $this->syncDBs();
491 $startId = 0;
492 $trx = new CgzCopyTransaction( $this, $this->pageBlobClass );
494 while ( true ) {
495 $res = $dbr->select(
496 array( 'blob_tracking', 'text' ),
497 '*',
498 array(
499 'bt_page' => $pageId,
500 'bt_text_id > ' . $dbr->addQuotes( $startId ),
501 'bt_moved' => 0,
502 'bt_new_url IS NULL',
503 'bt_text_id=old_id',
505 __METHOD__,
506 array(
507 'ORDER BY' => 'bt_text_id',
508 'LIMIT' => $this->batchSize
511 if ( !$res->numRows() ) {
512 break;
515 $lastTextId = 0;
516 foreach ( $res as $row ) {
517 $startId = $row->bt_text_id;
518 if ( $lastTextId == $row->bt_text_id ) {
519 // Duplicate (null edit)
520 continue;
522 $lastTextId = $row->bt_text_id;
523 // Load the text
524 $text = Revision::getRevisionText( $row );
525 if ( $text === false ) {
526 $this->critical( "Error loading {$row->bt_rev_id}/{$row->bt_text_id}" );
527 continue;
530 // Queue it
531 if ( !$trx->addItem( $text, $row->bt_text_id ) ) {
532 $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" );
533 $trx->commit();
534 $trx = new CgzCopyTransaction( $this, $this->pageBlobClass );
535 wfWaitForSlaves();
540 $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" );
541 $trx->commit();
545 * Atomic move operation.
547 * Write the new URL to the text table and set the bt_moved flag.
549 * This is done in a single transaction to provide restartable behavior
550 * without data loss.
552 * The transaction is kept short to reduce locking.
554 * @param int $textId
555 * @param string $url
557 function moveTextRow( $textId, $url ) {
558 if ( $this->copyOnly ) {
559 $this->critical( "Internal error: can't call moveTextRow() in --copy-only mode" );
560 exit( 1 );
562 $dbw = wfGetDB( DB_MASTER );
563 $dbw->begin( __METHOD__ );
564 $dbw->update( 'text',
565 array( // set
566 'old_text' => $url,
567 'old_flags' => 'external,utf-8',
569 array( // where
570 'old_id' => $textId
572 __METHOD__
574 $dbw->update( 'blob_tracking',
575 array( 'bt_moved' => 1 ),
576 array( 'bt_text_id' => $textId ),
577 __METHOD__
579 $dbw->commit( __METHOD__ );
583 * Moves are done in two phases: bt_new_url and then bt_moved.
584 * - bt_new_url indicates that the text has been copied to the new cluster.
585 * - bt_moved indicates that the text table has been updated.
587 * This function completes any moves that only have done bt_new_url. This
588 * can happen when the script is interrupted, or when --copy-only is used.
590 * @param array $conds
592 function finishIncompleteMoves( $conds ) {
593 $dbr = wfGetDB( DB_SLAVE );
595 $startId = 0;
596 $conds = array_merge( $conds, array(
597 'bt_moved' => 0,
598 'bt_new_url IS NOT NULL'
599 ) );
600 while ( true ) {
601 $res = $dbr->select( 'blob_tracking',
602 '*',
603 array_merge( $conds, array( 'bt_text_id > ' . $dbr->addQuotes( $startId ) ) ),
604 __METHOD__,
605 array(
606 'ORDER BY' => 'bt_text_id',
607 'LIMIT' => $this->batchSize,
610 if ( !$res->numRows() ) {
611 break;
613 $this->debug( 'Incomplete: ' . $res->numRows() . ' rows' );
614 foreach ( $res as $row ) {
615 $startId = $row->bt_text_id;
616 $this->moveTextRow( $row->bt_text_id, $row->bt_new_url );
617 if ( $row->bt_text_id % 10 == 0 ) {
618 wfWaitForSlaves();
625 * Returns the name of the next target cluster
626 * @return string
628 function getTargetCluster() {
629 $cluster = next( $this->destClusters );
630 if ( $cluster === false ) {
631 $cluster = reset( $this->destClusters );
634 return $cluster;
638 * Gets a DB master connection for the given external cluster name
639 * @param string $cluster
640 * @return DatabaseBase
642 function getExtDB( $cluster ) {
643 $lb = wfGetLBFactory()->getExternalLB( $cluster );
645 return $lb->getConnection( DB_MASTER );
649 * Move an orphan text_id to the new cluster
651 * @param array $textIds
653 function doOrphanList( $textIds ) {
654 // Finish incomplete moves
655 if ( !$this->copyOnly ) {
656 $this->finishIncompleteMoves( array( 'bt_text_id' => $textIds ) );
657 $this->syncDBs();
660 $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
662 $res = wfGetDB( DB_SLAVE )->select(
663 array( 'text', 'blob_tracking' ),
664 array( 'old_id', 'old_text', 'old_flags' ),
665 array(
666 'old_id' => $textIds,
667 'bt_text_id=old_id',
668 'bt_moved' => 0,
670 __METHOD__,
671 array( 'DISTINCT' )
674 foreach ( $res as $row ) {
675 $text = Revision::getRevisionText( $row );
676 if ( $text === false ) {
677 $this->critical( "Error: cannot load revision text for old_id={$row->old_id}" );
678 continue;
681 if ( !$trx->addItem( $text, $row->old_id ) ) {
682 $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" );
683 $trx->commit();
684 $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
685 wfWaitForSlaves();
688 $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" );
689 $trx->commit();
694 * Class to represent a recompression operation for a single CGZ blob
696 class CgzCopyTransaction {
697 /** @var RecompressTracked */
698 public $parent;
699 public $blobClass;
700 /** @var ConcatenatedGzipHistoryBlob */
701 public $cgz;
702 public $referrers;
705 * Create a transaction from a RecompressTracked object
706 * @param RecompressTracked $parent
707 * @param string $blobClass
709 function __construct( $parent, $blobClass ) {
710 $this->blobClass = $blobClass;
711 $this->cgz = false;
712 $this->texts = array();
713 $this->parent = $parent;
717 * Add text.
718 * Returns false if it's ready to commit.
719 * @param string $text
720 * @param int $textId
721 * @return bool
723 function addItem( $text, $textId ) {
724 if ( !$this->cgz ) {
725 $class = $this->blobClass;
726 $this->cgz = new $class;
728 $hash = $this->cgz->addItem( $text );
729 $this->referrers[$textId] = $hash;
730 $this->texts[$textId] = $text;
732 return $this->cgz->isHappy();
735 function getSize() {
736 return count( $this->texts );
740 * Recompress text after some aberrant modification
742 function recompress() {
743 $class = $this->blobClass;
744 $this->cgz = new $class;
745 $this->referrers = array();
746 foreach ( $this->texts as $textId => $text ) {
747 $hash = $this->cgz->addItem( $text );
748 $this->referrers[$textId] = $hash;
753 * Commit the blob.
754 * Does nothing if no text items have been added.
755 * May skip the move if --copy-only is set.
757 function commit() {
758 $originalCount = count( $this->texts );
759 if ( !$originalCount ) {
760 return;
763 /* Check to see if the target text_ids have been moved already.
765 * We originally read from the slave, so this can happen when a single
766 * text_id is shared between multiple pages. It's rare, but possible
767 * if a delete/move/undelete cycle splits up a null edit.
769 * We do a locking read to prevent closer-run race conditions.
771 $dbw = wfGetDB( DB_MASTER );
772 $dbw->begin( __METHOD__ );
773 $res = $dbw->select( 'blob_tracking',
774 array( 'bt_text_id', 'bt_moved' ),
775 array( 'bt_text_id' => array_keys( $this->referrers ) ),
776 __METHOD__, array( 'FOR UPDATE' ) );
777 $dirty = false;
778 foreach ( $res as $row ) {
779 if ( $row->bt_moved ) {
780 # This row has already been moved, remove it
781 $this->parent->debug( "TRX: conflict detected in old_id={$row->bt_text_id}" );
782 unset( $this->texts[$row->bt_text_id] );
783 $dirty = true;
787 // Recompress the blob if necessary
788 if ( $dirty ) {
789 if ( !count( $this->texts ) ) {
790 // All have been moved already
791 if ( $originalCount > 1 ) {
792 // This is suspcious, make noise
793 $this->parent->critical(
794 "Warning: concurrent operation detected, are there two conflicting " .
795 "processes running, doing the same job?" );
798 return;
800 $this->recompress();
803 // Insert the data into the destination cluster
804 $targetCluster = $this->parent->getTargetCluster();
805 $store = $this->parent->store;
806 $targetDB = $store->getMaster( $targetCluster );
807 $targetDB->clearFlag( DBO_TRX ); // we manage the transactions
808 $targetDB->begin( __METHOD__ );
809 $baseUrl = $this->parent->store->store( $targetCluster, serialize( $this->cgz ) );
811 // Write the new URLs to the blob_tracking table
812 foreach ( $this->referrers as $textId => $hash ) {
813 $url = $baseUrl . '/' . $hash;
814 $dbw->update( 'blob_tracking',
815 array( 'bt_new_url' => $url ),
816 array(
817 'bt_text_id' => $textId,
818 'bt_moved' => 0, # Check for concurrent conflicting update
820 __METHOD__
824 $targetDB->commit( __METHOD__ );
825 // Critical section here: interruption at this point causes blob duplication
826 // Reversing the order of the commits would cause data loss instead
827 $dbw->commit( __METHOD__ );
829 // Write the new URLs to the text table and set the moved flag
830 if ( !$this->parent->copyOnly ) {
831 foreach ( $this->referrers as $textId => $hash ) {
832 $url = $baseUrl . '/' . $hash;
833 $this->parent->moveTextRow( $textId, $url );