Add ability to override mb_strtoupper in Language::ucfirst
[lhc/web/wiklou.git] / maintenance / syncFileBackend.php
index c0663a7..76a5721 100644 (file)
@@ -54,7 +54,7 @@ class SyncFileBackend extends Maintenance {
                if ( $this->hasOption( 'posdump' ) ) {
                        // Just dump the current position into the specified position dir
                        if ( !$this->hasOption( 'posdir' ) ) {
-                               $this->error( "Param posdir required!", 1 );
+                               $this->fatalError( "Param posdir required!" );
                        }
                        if ( $this->hasOption( 'postime' ) ) {
                                $id = (int)$src->getJournal()->getPositionAtTime( $this->getOption( 'postime' ) );
@@ -76,7 +76,7 @@ class SyncFileBackend extends Maintenance {
                }
 
                if ( !$this->hasOption( 'dst' ) ) {
-                       $this->error( "Param dst required!", 1 );
+                       $this->fatalError( "Param dst required!" );
                }
                $dst = FileBackendGroup::singleton()->get( $this->getOption( 'dst' ) );
 
@@ -156,12 +156,12 @@ class SyncFileBackend extends Maintenance {
                $first = true; // first batch
 
                if ( $start > $end ) { // sanity
-                       $this->error( "Error: given starting ID greater than ending ID.", 1 );
+                       $this->fatalError( "Error: given starting ID greater than ending ID." );
                }
 
                $next = null;
                do {
-                       $limit = min( $this->mBatchSize, $end - $start + 1 ); // don't go pass ending ID
+                       $limit = min( $this->getBatchSize(), $end - $start + 1 ); // don't go pass ending ID
                        $this->output( "Doing id $start to " . ( $start + $limit - 1 ) . "...\n" );
 
                        $entries = $src->getJournal()->getChangeEntries( $start, $limit, $next );
@@ -172,7 +172,7 @@ class SyncFileBackend extends Maintenance {
                        $first = false;
 
                        $lastPosInBatch = 0;
-                       $pathsInBatch = array(); // changed paths
+                       $pathsInBatch = []; // changed paths
                        foreach ( $entries as $entry ) {
                                if ( $entry['op'] !== 'null' ) { // null ops are just for reference
                                        $pathsInBatch[$entry['path']] = 1; // remove duplicates
@@ -223,20 +223,20 @@ class SyncFileBackend extends Maintenance {
                        return $status;
                }
 
-               $src->preloadFileStat( array( 'srcs' => $sPaths, 'latest' => 1 ) );
-               $dst->preloadFileStat( array( 'srcs' => $dPaths, 'latest' => 1 ) );
+               $src->preloadFileStat( [ 'srcs' => $sPaths, 'latest' => 1 ] );
+               $dst->preloadFileStat( [ 'srcs' => $dPaths, 'latest' => 1 ] );
 
-               $ops = array();
-               $fsFiles = array();
+               $ops = [];
+               $fsFiles = [];
                foreach ( $sPaths as $i => $sPath ) {
                        $dPath = $dPaths[$i]; // destination
-                       $sExists = $src->fileExists( array( 'src' => $sPath, 'latest' => 1 ) );
+                       $sExists = $src->fileExists( [ 'src' => $sPath, 'latest' => 1 ] );
                        if ( $sExists === true ) { // exists in source
                                if ( $this->filesAreSame( $src, $dst, $sPath, $dPath ) ) {
                                        continue; // avoid local copies for non-FS backends
                                }
                                // Note: getLocalReference() is fast for FS backends
-                               $fsFile = $src->getLocalReference( array( 'src' => $sPath, 'latest' => 1 ) );
+                               $fsFile = $src->getLocalReference( [ 'src' => $sPath, 'latest' => 1 ] );
                                if ( !$fsFile ) {
                                        $this->error( "Unable to sync '$dPath': could not get local copy." );
                                        $status->fatal( 'backend-fail-internal', $src->getName() );
@@ -245,16 +245,16 @@ class SyncFileBackend extends Maintenance {
                                }
                                $fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed
                                // Note: prepare() is usually fast for key/value backends
-                               $status->merge( $dst->prepare( array(
-                                       'dir' => dirname( $dPath ), 'bypassReadOnly' => 1 ) ) );
+                               $status->merge( $dst->prepare( [
+                                       'dir' => dirname( $dPath ), 'bypassReadOnly' => 1 ] ) );
                                if ( !$status->isOK() ) {
                                        return $status;
                                }
-                               $ops[] = array( 'op' => 'store',
-                                       'src' => $fsFile->getPath(), 'dst' => $dPath, 'overwrite' => 1 );
+                               $ops[] = [ 'op' => 'store',
+                                       'src' => $fsFile->getPath(), 'dst' => $dPath, 'overwrite' => 1 ];
                        } elseif ( $sExists === false ) { // does not exist in source
-                               $ops[] = array( 'op' => 'delete', 'src' => $dPath, 'ignoreMissingSource' => 1 );
-                       } else { // error
+                               $ops[] = [ 'op' => 'delete', 'src' => $dPath, 'ignoreMissingSource' => 1 ];
+                       } else {
                                $this->error( "Unable to sync '$dPath': could not stat file." );
                                $status->fatal( 'backend-fail-internal', $src->getName() );
 
@@ -263,14 +263,14 @@ class SyncFileBackend extends Maintenance {
                }
 
                $t_start = microtime( true );
-               $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
+               $status = $dst->doQuickOperations( $ops, [ 'bypassReadOnly' => 1 ] );
                if ( !$status->isOK() ) {
                        sleep( 10 ); // wait and retry copy again
-                       $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
+                       $status = $dst->doQuickOperations( $ops, [ 'bypassReadOnly' => 1 ] );
                }
-               $ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
+               $elapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
                if ( $status->isOK() && $this->getOption( 'verbose' ) ) {
-                       $this->output( "Synchronized these file(s) [{$ellapsed_ms}ms]:\n" .
+                       $this->output( "Synchronized these file(s) [{$elapsed_ms}ms]:\n" .
                                implode( "\n", $dPaths ) . "\n" );
                }
 
@@ -294,14 +294,14 @@ class SyncFileBackend extends Maintenance {
 
        protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
                return (
-                       ( $src->getFileSize( array( 'src' => $sPath ) )
-                               === $dst->getFileSize( array( 'src' => $dPath ) ) // short-circuit
-                       ) && ( $src->getFileSha1Base36( array( 'src' => $sPath ) )
-                               === $dst->getFileSha1Base36( array( 'src' => $dPath ) )
+                       ( $src->getFileSize( [ 'src' => $sPath ] )
+                               === $dst->getFileSize( [ 'src' => $dPath ] ) // short-circuit
+                       ) && ( $src->getFileSha1Base36( [ 'src' => $sPath ] )
+                               === $dst->getFileSha1Base36( [ 'src' => $dPath ] )
                        )
                );
        }
 }
 
-$maintClass = "SyncFileBackend";
+$maintClass = SyncFileBackend::class;
 require_once RUN_MAINTENANCE_IF_MAIN;