X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FsyncFileBackend.php;h=158019b7d0e33b4ecf38702aa1d941b57f9fd8fd;hb=2ca33d1ce76023e8b286f21d2a6a74ba767345bc;hp=a93ad7992d5862c3a685313aee4150ea7014a1c0;hpb=677648fac6348f0832ff182c84a2a3c4614bfaa7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/syncFileBackend.php b/maintenance/syncFileBackend.php index a93ad7992d..158019b7d0 100644 --- a/maintenance/syncFileBackend.php +++ b/maintenance/syncFileBackend.php @@ -57,10 +57,11 @@ class SyncFileBackend extends Maintenance { } if ( $this->hasOption( 'postime' ) ) { $id = (int)$src->getJournal()->getPositionAtTime( $this->getOption( 'postime' ) ); + $this->output( "Requested journal position is $id.\n" ); } else { $id = (int)$src->getJournal()->getCurrentPosition(); + $this->output( "Current journal position is $id.\n" ); } - $this->output( "Current journal position is $id.\n" ); if ( file_put_contents( $posFile, $id, LOCK_EX ) !== false ) { $this->output( "Saved journal position file.\n" ); } else { @@ -95,8 +96,15 @@ class SyncFileBackend extends Maintenance { $this->output( "Ending journal position is $end.\n" ); } + // Periodically update the position file + $callback = function( $pos ) use ( $startFromPosFile, $posFile, $start ) { + if ( $startFromPosFile && $pos >= $start ) { // successfully advanced + file_put_contents( $posFile, $pos, LOCK_EX ); + } + }; + // Actually sync the dest backend with the reference backend - $lastOKPos = $this->syncBackends( $src, $dst, $start, $end ); + $lastOKPos = $this->syncBackends( $src, $dst, $start, $end, $callback ); // Update the sync position file if ( $startFromPosFile && $lastOKPos >= $start ) { // successfully advanced @@ -130,9 +138,12 @@ class SyncFileBackend extends Maintenance { * @param $dst FileBackend * @param $start integer Starting journal position * @param $end integer Starting journal position + * @param $callback Closure Callback to update any position file * @return integer|false Journal entry ID or false if there are none */ - protected function syncBackends( FileBackend $src, FileBackend $dst, $start, $end ) { + protected function syncBackends( + FileBackend $src, FileBackend $dst, $start, $end, Closure $callback + ) { $lastOKPos = 0; // failed $first = true; // first batch @@ -163,6 +174,7 @@ class SyncFileBackend extends Maintenance { $status = $this->syncFileBatch( array_keys( $pathsInBatch ), $src, $dst ); if ( $status->isOK() ) { $lastOKPos = max( $lastOKPos, $lastPosInBatch ); + $callback( $lastOKPos ); // update position file } else { $this->error( print_r( $status->getErrorsArray(), true ) ); break; // no gaps; everything up to $lastPos must be OK