Used DIRECTORY_SEPARATOR instead of '/' in GitInfo.php
[lhc/web/wiklou.git] / includes / upload / UploadFromChunks.php
index 2e0b944..bdcc9a1 100644 (file)
  * @author Michael Dale
  */
 class UploadFromChunks extends UploadFromFile {
-       protected $mOffset, $mChunkIndex, $mFileKey, $mVirtualTempPath;
+       protected $mOffset;
+       protected $mChunkIndex;
+       protected $mFileKey;
+       protected $mVirtualTempPath;
 
        /**
         * Setup local pointers to stash, repo and user (similar to UploadFromStash)
         *
-        * @param $user User
-        * @param $stash UploadStash
-        * @param $repo FileRepo
+        * @param $user User|null Default: null
+        * @param $stash UploadStash|bool Default: false
+        * @param $repo FileRepo|bool Default: false
         */
        public function __construct( $user = null, $stash = false, $repo = false ) {
                // user object. sometimes this won't exist, as when running from cron.
@@ -108,13 +111,14 @@ class UploadFromChunks extends UploadFromFile {
         * @return FileRepoStatus
         */
        public function concatenateChunks() {
+               $chunkIndex = $this->getChunkIndex();
                wfDebug( __METHOD__ . " concatenate {$this->mChunkIndex} chunks:" .
-                       $this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n" );
+                       $this->getOffset() . ' inx:' . $chunkIndex . "\n" );
 
                // Concatenate all the chunks to mVirtualTempPath
-               $fileList = Array();
+               $fileList = array();
                // The first chunk is stored at the mVirtualTempPath path so we start on "chunk 1"
-               for ( $i = 0; $i <= $this->getChunkIndex(); $i++ ) {
+               for ( $i = 0; $i <= $chunkIndex; $i++ ) {
                        $fileList[] = $this->getVirtualChunkLocation( $i );
                }
 
@@ -122,9 +126,12 @@ class UploadFromChunks extends UploadFromFile {
                $ext = FileBackend::extensionFromPath( $this->mVirtualTempPath );
                // Get a 0-byte temp file to perform the concatenation at
                $tmpFile = TempFSFile::factory( 'chunkedupload_', $ext );
-               $tmpPath = $tmpFile
-                       ? $tmpFile->bind( $this )->getPath() // keep alive with $this
-                       : false; // fail in concatenate()
+               $tmpPath = false; // fail in concatenate()
+               if ( $tmpFile ) {
+                       // keep alive with $this
+                       $tmpPath = $tmpFile->bind( $this )->getPath();
+               }
+
                // Concatenate the chunks at the temp file
                $tStart = microtime( true );
                $status = $this->repo->concatenate( $fileList, $tmpPath, FileRepo::DELETE_SOURCE );
@@ -132,10 +139,12 @@ class UploadFromChunks extends UploadFromFile {
                if ( !$status->isOk() ) {
                        return $status;
                }
-               wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds.\n" );
+               wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds." );
 
-               $this->mTempPath = $tmpPath; // file system path
-               $this->mFileSize = filesize( $this->mTempPath ); //Since this was set for the last chunk previously
+               // File system path
+               $this->mTempPath = $tmpPath;
+               // Since this was set for the last chunk previously
+               $this->mFileSize = filesize( $this->mTempPath );
                $ret = $this->verifyUpload();
                if ( $ret['status'] !== UploadBase::OK ) {
                        wfDebugLog( 'fileconcatenate', "Verification failed for chunked upload" );
@@ -149,7 +158,7 @@ class UploadFromChunks extends UploadFromFile {
                $this->mLocalFile = parent::stashFile( $this->user );
                $tAmount = microtime( true ) - $tStart;
                $this->mLocalFile->setLocalReference( $tmpFile ); // reuse (e.g. for getImageInfo())
-               wfDebugLog( 'fileconcatenate', "Stashed combined file ($i chunks) in $tAmount seconds.\n" );
+               wfDebugLog( 'fileconcatenate', "Stashed combined file ($i chunks) in $tAmount seconds." );
 
                return $status;
        }
@@ -321,7 +330,8 @@ class UploadFromChunks extends UploadFromFile {
                                        $error = array( 'unknown', 'no error recorded' );
                                }
                        }
-                       throw new UploadChunkFileException( "error storing file in '$chunkPath': " . implode( '; ', $error ) );
+                       throw new UploadChunkFileException( "Error storing file in '$chunkPath': " .
+                               implode( '; ', $error ) );
                }
                return $storeStatus;
        }
@@ -352,6 +362,11 @@ class UploadFromChunks extends UploadFromFile {
        }
 }
 
-class UploadChunkZeroLengthFileException extends MWException {};
-class UploadChunkFileException extends MWException {};
-class UploadChunkVerificationException extends MWException {};
+class UploadChunkZeroLengthFileException extends MWException {
+}
+
+class UploadChunkFileException extends MWException {
+}
+
+class UploadChunkVerificationException extends MWException {
+}