X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fupload%2FUploadFromChunks.php;h=bdcc9a1c45fde319828a1300f11359e5e74398b8;hb=3afc76a4b5ad2f73dd69a82ec08c0d0e4799f00f;hp=2e0b944415c0a4a22a96a16d87f0612ca7425829;hpb=8a4524600946b1785b4b954479e94c381a0613b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 2e0b944415..bdcc9a1c45 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -28,14 +28,17 @@ * @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 { +}