From: Aaron Schulz Date: Sun, 10 Mar 2013 06:44:17 +0000 (-0800) Subject: Made backend sync script update the pos file periorically. X-Git-Tag: 1.31.0-rc.0~20389^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=db5903f36e0d72befaf6c179569be2f9b0dff9f9;p=lhc%2Fweb%2Fwiklou.git Made backend sync script update the pos file periorically. Change-Id: I5b4028c8d69a6bf78b372f0d1cdb258207465f30 --- diff --git a/maintenance/syncFileBackend.php b/maintenance/syncFileBackend.php index 8f6e41929d..158019b7d0 100644 --- a/maintenance/syncFileBackend.php +++ b/maintenance/syncFileBackend.php @@ -96,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 @@ -131,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 @@ -164,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