* @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.
* @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 );
}
$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 );
}
wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds.\n" );
- $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" );
$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;
}
}
}
-class UploadChunkZeroLengthFileException extends MWException {};
-class UploadChunkFileException extends MWException {};
-class UploadChunkVerificationException extends MWException {};
+class UploadChunkZeroLengthFileException extends MWException {
+}
+
+class UploadChunkFileException extends MWException {
+}
+
+class UploadChunkVerificationException extends MWException {
+}