67 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance for " .
$user->
getId() .
"\n" );
68 $this->stash =
new UploadStash( $this->repo, $this->user );
82 return parent::tryStashFile(
$user, $isPartial );
94 return parent::stashFile(
$user );
105 $this->mChunkIndex = 0;
109 $this->mStashFile = parent::doStashFile(
$user );
111 $this->mOffset = $this->mStashFile->getSize();
112 $this->mFileKey = $this->mStashFile->getFileKey();
115 $this->
outputChunk( $this->mStashFile->getPath() );
120 return $this->mStashFile;
131 $this->mFileKey = $key;
132 $this->mUpload = $webRequestUpload;
136 $metadata = $this->stash->getMetadata( $key );
137 $this->initializePathInfo( $name,
138 $this->getRealPath( $metadata[
'us_path'] ),
139 $metadata[
'us_size'],
150 wfDebug( __METHOD__ .
" concatenate {$this->mChunkIndex} chunks:" .
151 $this->
getOffset() .
' inx:' . $chunkIndex .
"\n" );
156 for ( $i = 0; $i <= $chunkIndex; $i++ ) {
163 $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory()
164 ->newTempFSFile(
'chunkedupload_',
$ext );
168 $tmpPath = $tmpFile->bind( $this )->getPath();
172 $tStart = microtime(
true );
174 $tAmount = microtime(
true ) - $tStart;
179 wfDebugLog(
'fileconcatenate',
"Combined $i chunks in $tAmount seconds." );
182 $this->setTempFile( $tmpPath );
185 if ( $ret[
'status'] !== UploadBase::OK ) {
186 wfDebugLog(
'fileconcatenate',
"Verification failed for chunked upload" );
187 $status->fatal( $this->getVerificationErrorCode( $ret[
'status'] ) );
194 $tStart = microtime(
true );
197 $error = $this->runUploadStashFileHook( $this->user );
203 $this->mStashFile = parent::doStashFile( $this->user );
205 $status->fatal(
'uploadstash-exception', get_class( $e ), $e->getMessage() );
209 $tAmount = microtime(
true ) - $tStart;
210 $this->mStashFile->setLocalReference( $tmpFile );
211 wfDebugLog(
'fileconcatenate',
"Stashed combined file ($i chunks) in $tAmount seconds." );
222 return $this->repo->getVirtualUrl(
'temp' ) .
224 $this->repo->getHashPath(
238 public function addChunk( $chunkPath, $chunkSize, $offset ) {
242 if ( $preAppendOffset + $chunkSize > $this->getMaxUploadSize() ) {
246 if ( $preAppendOffset == $offset ) {
248 $this->mChunkIndex++;
250 # For some reason mTempPath is set to first part
251 $oldTemp = $this->mTempPath;
252 $this->mTempPath = $chunkPath;
254 $this->mTempPath = $oldTemp;
261 $this->mOffset = $preAppendOffset + $chunkSize;
277 wfDebug( __METHOD__ .
" update chunk status for {$this->mFileKey} offset:" .
280 $dbw = $this->repo->getMasterDB();
284 'us_status' =>
'chunks',
288 [
'us_key' => $this->mFileKey ],
299 $dbw = $this->repo->getMasterDB();
300 $row = $dbw->selectRow(
307 [
'us_key' => $this->mFileKey ],
312 $this->mChunkIndex = $row->us_chunk_inx;
313 $this->mOffset = $row->us_size;
314 $this->mVirtualTempPath = $row->us_path;
323 if ( $this->mChunkIndex !==
null ) {
335 if ( $this->mOffset !==
null ) {
354 $hashPath = $this->repo->getHashPath( $fileKey );
355 $storeStatus = $this->repo->quickImport( $chunkPath,
356 $this->repo->getZonePath(
'temp' ) .
"/{$hashPath}{$fileKey}" );
359 if ( !$storeStatus->isOK() ) {
360 $error = $storeStatus->getErrorsArray();
361 $error = reset( $error );
362 if ( !count( $error ) ) {
363 $error = $storeStatus->getWarningsArray();
364 $error = reset( $error );
365 if ( !count( $error ) ) {
366 $error = [
'unknown',
'no error recorded' ];
370 implode(
'; ', $error ) );
377 if ( $index ===
null ) {
381 return $this->mFileKey .
'.' . $index;
391 $oldDesiredDestName = $this->mDesiredDestName;
393 $this->mTitle =
false;
394 $res = $this->verifyPartialFile();
395 $this->mDesiredDestName = $oldDesiredDestName;
396 $this->mTitle =
false;
397 if ( is_array(
$res ) ) {