2011-11-30 14:56:40 +00:00
|
|
|
<?php
|
2012-06-05 22:58:54 +00:00
|
|
|
/**
|
|
|
|
|
* Backend for uploading files from chunks.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Upload
|
|
|
|
|
*/
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Implements uploading from chunks
|
|
|
|
|
*
|
2012-02-08 17:03:43 +00:00
|
|
|
* @ingroup Upload
|
2011-11-30 14:56:40 +00:00
|
|
|
* @author Michael Dale
|
|
|
|
|
*/
|
|
|
|
|
class UploadFromChunks extends UploadFromFile {
|
2013-10-04 13:43:09 +00:00
|
|
|
protected $mOffset;
|
|
|
|
|
protected $mChunkIndex;
|
|
|
|
|
protected $mFileKey;
|
|
|
|
|
protected $mVirtualTempPath;
|
2014-07-08 21:40:06 +00:00
|
|
|
/** @var LocalRepo */
|
|
|
|
|
private $repo;
|
2012-08-09 15:20:09 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2013-04-11 05:29:05 +00:00
|
|
|
* Setup local pointers to stash, repo and user (similar to UploadFromStash)
|
2012-08-09 15:20:09 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param User|null $user Default: null
|
|
|
|
|
* @param UploadStash|bool $stash Default: false
|
|
|
|
|
* @param FileRepo|bool $repo Default: false
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-11-19 08:07:50 +00:00
|
|
|
public function __construct( $user = null, $stash = false, $repo = false ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
// user object. sometimes this won't exist, as when running from cron.
|
|
|
|
|
$this->user = $user;
|
|
|
|
|
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $repo ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->repo = $repo;
|
|
|
|
|
} else {
|
|
|
|
|
$this->repo = RepoGroup::singleton()->getLocalRepo();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $stash ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->stash = $stash;
|
|
|
|
|
} else {
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $user ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
wfDebug( __METHOD__ . " creating new UploadFromChunks instance for " . $user->getId() . "\n" );
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . " creating new UploadFromChunks instance with no user\n" );
|
|
|
|
|
}
|
|
|
|
|
$this->stash = new UploadStash( $this->repo, $this->user );
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-19 08:07:50 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2012-09-09 04:40:17 +00:00
|
|
|
* Calls the parent stashFile and updates the uploadsession table to handle "chunks"
|
2011-11-30 14:56:40 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param User|null $user
|
2014-07-24 17:43:44 +00:00
|
|
|
* @return UploadStashFile Stashed file
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2013-03-14 23:46:30 +00:00
|
|
|
public function stashFile( User $user = null ) {
|
2012-09-09 04:40:17 +00:00
|
|
|
// Stash file is the called on creating a new chunk session:
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->mChunkIndex = 0;
|
|
|
|
|
$this->mOffset = 0;
|
2013-05-16 22:09:44 +00:00
|
|
|
|
|
|
|
|
$this->verifyChunk();
|
2011-11-30 14:56:40 +00:00
|
|
|
// Create a local stash target
|
2015-01-30 20:06:07 +00:00
|
|
|
$this->mLocalFile = parent::stashFile( $user );
|
2013-04-11 05:29:05 +00:00
|
|
|
// Update the initial file offset (based on file size)
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->mOffset = $this->mLocalFile->getSize();
|
|
|
|
|
$this->mFileKey = $this->mLocalFile->getFileKey();
|
|
|
|
|
|
|
|
|
|
// Output a copy of this first to chunk 0 location:
|
2012-10-08 00:05:49 +00:00
|
|
|
$this->outputChunk( $this->mLocalFile->getPath() );
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2012-09-09 04:40:17 +00:00
|
|
|
// Update db table to reflect initial "chunk" state
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->updateChunkStatus();
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $this->mLocalFile;
|
|
|
|
|
}
|
2012-08-09 15:20:09 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Continue chunk uploading
|
2014-04-19 15:19:17 +00:00
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @param WebRequestUpload $webRequestUpload
|
2012-09-09 04:40:17 +00:00
|
|
|
*/
|
2011-11-30 14:56:40 +00:00
|
|
|
public function continueChunks( $name, $key, $webRequestUpload ) {
|
|
|
|
|
$this->mFileKey = $key;
|
|
|
|
|
$this->mUpload = $webRequestUpload;
|
2012-09-09 04:40:17 +00:00
|
|
|
// Get the chunk status form the db:
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->getChunkStatus();
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
$metadata = $this->stash->getMetadata( $key );
|
|
|
|
|
$this->initializePathInfo( $name,
|
2011-12-23 18:59:39 +00:00
|
|
|
$this->getRealPath( $metadata['us_path'] ),
|
2011-11-30 14:56:40 +00:00
|
|
|
$metadata['us_size'],
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Append the final chunk and ready file for parent::performUpload()
|
2012-01-03 15:36:46 +00:00
|
|
|
* @return FileRepoStatus
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
|
|
|
|
public function concatenateChunks() {
|
2013-10-04 13:43:09 +00:00
|
|
|
$chunkIndex = $this->getChunkIndex();
|
2012-09-09 04:40:17 +00:00
|
|
|
wfDebug( __METHOD__ . " concatenate {$this->mChunkIndex} chunks:" .
|
2013-10-04 13:43:09 +00:00
|
|
|
$this->getOffset() . ' inx:' . $chunkIndex . "\n" );
|
2011-12-23 18:59:39 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// Concatenate all the chunks to mVirtualTempPath
|
2016-02-17 09:09:32 +00:00
|
|
|
$fileList = [];
|
2011-11-30 14:56:40 +00:00
|
|
|
// The first chunk is stored at the mVirtualTempPath path so we start on "chunk 1"
|
2013-10-04 13:43:09 +00:00
|
|
|
for ( $i = 0; $i <= $chunkIndex; $i++ ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$fileList[] = $this->getVirtualChunkLocation( $i );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-23 18:59:39 +00:00
|
|
|
// Get the file extension from the last chunk
|
|
|
|
|
$ext = FileBackend::extensionFromPath( $this->mVirtualTempPath );
|
|
|
|
|
// Get a 0-byte temp file to perform the concatenation at
|
|
|
|
|
$tmpFile = TempFSFile::factory( 'chunkedupload_', $ext );
|
2013-10-04 13:43:09 +00:00
|
|
|
$tmpPath = false; // fail in concatenate()
|
2013-11-19 18:03:54 +00:00
|
|
|
if ( $tmpFile ) {
|
2013-10-04 13:43:09 +00:00
|
|
|
// keep alive with $this
|
|
|
|
|
$tmpPath = $tmpFile->bind( $this )->getPath();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-23 18:59:39 +00:00
|
|
|
// Concatenate the chunks at the temp file
|
2012-11-18 10:32:50 +00:00
|
|
|
$tStart = microtime( true );
|
2011-12-23 18:59:39 +00:00
|
|
|
$status = $this->repo->concatenate( $fileList, $tmpPath, FileRepo::DELETE_SOURCE );
|
2012-11-18 10:32:50 +00:00
|
|
|
$tAmount = microtime( true ) - $tStart;
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( !$status->isOk() ) {
|
2012-09-09 04:40:17 +00:00
|
|
|
return $status;
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2014-02-04 21:16:13 +00:00
|
|
|
wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds." );
|
2013-05-16 22:09:44 +00:00
|
|
|
|
2013-10-04 13:43:09 +00:00
|
|
|
// File system path
|
|
|
|
|
$this->mTempPath = $tmpPath;
|
|
|
|
|
// Since this was set for the last chunk previously
|
|
|
|
|
$this->mFileSize = filesize( $this->mTempPath );
|
2013-05-16 22:09:44 +00:00
|
|
|
$ret = $this->verifyUpload();
|
|
|
|
|
if ( $ret['status'] !== UploadBase::OK ) {
|
|
|
|
|
wfDebugLog( 'fileconcatenate', "Verification failed for chunked upload" );
|
|
|
|
|
$status->fatal( $this->getVerificationErrorCode( $ret['status'] ) );
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2013-05-16 22:09:44 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-27 04:49:08 +00:00
|
|
|
// Update the mTempPath and mLocalFile
|
2013-04-11 05:29:05 +00:00
|
|
|
// (for FileUpload or normal Stash to take over)
|
2012-11-18 10:32:50 +00:00
|
|
|
$tStart = microtime( true );
|
2012-11-19 08:07:50 +00:00
|
|
|
$this->mLocalFile = parent::stashFile( $this->user );
|
2012-11-18 10:32:50 +00:00
|
|
|
$tAmount = microtime( true ) - $tStart;
|
|
|
|
|
$this->mLocalFile->setLocalReference( $tmpFile ); // reuse (e.g. for getImageInfo())
|
2014-02-04 21:16:13 +00:00
|
|
|
wfDebugLog( 'fileconcatenate', "Stashed combined file ($i chunks) in $tAmount seconds." );
|
2011-12-27 04:49:08 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2012-09-09 04:40:17 +00:00
|
|
|
* Returns the virtual chunk location:
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param int $index
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return string
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-12-20 15:09:25 +00:00
|
|
|
function getVirtualChunkLocation( $index ) {
|
2012-09-09 04:40:17 +00:00
|
|
|
return $this->repo->getVirtualUrl( 'temp' ) .
|
2014-05-09 14:53:19 +00:00
|
|
|
'/' .
|
|
|
|
|
$this->repo->getHashPath(
|
|
|
|
|
$this->getChunkFileKey( $index )
|
|
|
|
|
) .
|
|
|
|
|
$this->getChunkFileKey( $index );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2012-02-09 19:29:36 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Add a chunk to the temporary directory
|
|
|
|
|
*
|
2014-07-24 17:43:44 +00:00
|
|
|
* @param string $chunkPath Path to temporary chunk file
|
|
|
|
|
* @param int $chunkSize Size of the current chunk
|
|
|
|
|
* @param int $offset Offset of current chunk ( mutch match database chunk offset )
|
2011-11-30 14:56:40 +00:00
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function addChunk( $chunkPath, $chunkSize, $offset ) {
|
|
|
|
|
// Get the offset before we add the chunk to the file system
|
|
|
|
|
$preAppendOffset = $this->getOffset();
|
2012-09-09 04:40:17 +00:00
|
|
|
|
2013-03-24 10:01:51 +00:00
|
|
|
if ( $preAppendOffset + $chunkSize > $this->getMaxUploadSize() ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$status = Status::newFatal( 'file-too-large' );
|
|
|
|
|
} else {
|
|
|
|
|
// Make sure the client is uploading the correct chunk with a matching offset.
|
|
|
|
|
if ( $preAppendOffset == $offset ) {
|
2012-09-09 04:40:17 +00:00
|
|
|
// Update local chunk index for the current chunk
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->mChunkIndex++;
|
2013-05-16 22:09:44 +00:00
|
|
|
try {
|
|
|
|
|
# For some reason mTempPath is set to first part
|
|
|
|
|
$oldTemp = $this->mTempPath;
|
|
|
|
|
$this->mTempPath = $chunkPath;
|
|
|
|
|
$this->verifyChunk();
|
|
|
|
|
$this->mTempPath = $oldTemp;
|
|
|
|
|
} catch ( UploadChunkVerificationException $e ) {
|
|
|
|
|
return Status::newFatal( $e->getMessage() );
|
|
|
|
|
}
|
2011-11-30 14:56:40 +00:00
|
|
|
$status = $this->outputChunk( $chunkPath );
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $status->isGood() ) {
|
2012-09-09 04:40:17 +00:00
|
|
|
// Update local offset:
|
2011-11-30 14:56:40 +00:00
|
|
|
$this->mOffset = $preAppendOffset + $chunkSize;
|
2012-09-09 04:40:17 +00:00
|
|
|
// Update chunk table status db
|
|
|
|
|
$this->updateChunkStatus();
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$status = Status::newFatal( 'invalid-chunk-offset' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2012-09-09 04:40:17 +00:00
|
|
|
* Update the chunk db table with the current status:
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-12-20 15:09:25 +00:00
|
|
|
private function updateChunkStatus() {
|
2012-09-09 04:40:17 +00:00
|
|
|
wfDebug( __METHOD__ . " update chunk status for {$this->mFileKey} offset:" .
|
2014-05-09 14:53:19 +00:00
|
|
|
$this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n" );
|
2012-08-09 15:20:09 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
$dbw = $this->repo->getMasterDb();
|
2012-11-18 10:32:50 +00:00
|
|
|
// Use a quick transaction since we will upload the full temp file into shared
|
|
|
|
|
// storage, which takes time for large files. We don't want to hold locks then.
|
2011-11-30 14:56:40 +00:00
|
|
|
$dbw->update(
|
|
|
|
|
'uploadstash',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2011-11-30 14:56:40 +00:00
|
|
|
'us_status' => 'chunks',
|
|
|
|
|
'us_chunk_inx' => $this->getChunkIndex(),
|
|
|
|
|
'us_size' => $this->getOffset()
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'us_key' => $this->mFileKey ],
|
2011-11-30 14:56:40 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2015-10-07 18:06:55 +00:00
|
|
|
$dbw->commit( __METHOD__, 'flush' );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the chunk db state and populate update relevant local values
|
|
|
|
|
*/
|
2012-12-20 15:09:25 +00:00
|
|
|
private function getChunkStatus() {
|
2012-09-09 04:40:17 +00:00
|
|
|
// get Master db to avoid race conditions.
|
2011-12-20 23:02:42 +00:00
|
|
|
// Otherwise, if chunk upload time < replag there will be spurious errors
|
|
|
|
|
$dbw = $this->repo->getMasterDb();
|
|
|
|
|
$row = $dbw->selectRow(
|
2012-09-09 04:40:17 +00:00
|
|
|
'uploadstash',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2011-11-30 14:56:40 +00:00
|
|
|
'us_chunk_inx',
|
|
|
|
|
'us_size',
|
|
|
|
|
'us_path',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'us_key' => $this->mFileKey ],
|
2011-11-30 14:56:40 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
// Handle result:
|
|
|
|
|
if ( $row ) {
|
|
|
|
|
$this->mChunkIndex = $row->us_chunk_inx;
|
|
|
|
|
$this->mOffset = $row->us_size;
|
|
|
|
|
$this->mVirtualTempPath = $row->us_path;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2012-09-09 04:40:17 +00:00
|
|
|
* Get the current Chunk index
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return int Index of the current chunk
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-12-20 15:09:25 +00:00
|
|
|
private function getChunkIndex() {
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $this->mChunkIndex !== null ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
return $this->mChunkIndex;
|
|
|
|
|
}
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2015-02-12 15:59:09 +00:00
|
|
|
* Get the offset at which the next uploaded chunk will be appended to
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return int Current byte offset of the chunk file set
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2015-02-12 15:59:09 +00:00
|
|
|
public function getOffset() {
|
2013-01-26 18:15:35 +00:00
|
|
|
if ( $this->mOffset !== null ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
return $this->mOffset;
|
|
|
|
|
}
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2012-08-07 23:47:25 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Output the chunk to disk
|
2012-08-09 15:20:09 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $chunkPath
|
2012-08-09 15:20:09 +00:00
|
|
|
* @throws UploadChunkFileException
|
2012-02-13 16:35:59 +00:00
|
|
|
* @return FileRepoStatus
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-12-20 15:09:25 +00:00
|
|
|
private function outputChunk( $chunkPath ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
// Key is fileKey + chunk index
|
|
|
|
|
$fileKey = $this->getChunkFileKey();
|
2012-09-09 04:40:17 +00:00
|
|
|
|
|
|
|
|
// Store the chunk per its indexed fileKey:
|
2012-01-01 23:28:18 +00:00
|
|
|
$hashPath = $this->repo->getHashPath( $fileKey );
|
2012-09-09 04:40:17 +00:00
|
|
|
$storeStatus = $this->repo->quickImport( $chunkPath,
|
|
|
|
|
$this->repo->getZonePath( 'temp' ) . "/{$hashPath}{$fileKey}" );
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// Check for error in stashing the chunk:
|
2014-05-09 14:53:19 +00:00
|
|
|
if ( !$storeStatus->isOK() ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$error = $storeStatus->getErrorsArray();
|
|
|
|
|
$error = reset( $error );
|
2014-05-09 14:53:19 +00:00
|
|
|
if ( !count( $error ) ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$error = $storeStatus->getWarningsArray();
|
|
|
|
|
$error = reset( $error );
|
2014-05-09 14:53:19 +00:00
|
|
|
if ( !count( $error ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$error = [ 'unknown', 'no error recorded' ];
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-10-04 13:43:09 +00:00
|
|
|
throw new UploadChunkFileException( "Error storing file in '$chunkPath': " .
|
|
|
|
|
implode( '; ', $error ) );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $storeStatus;
|
|
|
|
|
}
|
2012-08-09 15:20:09 +00:00
|
|
|
|
2012-12-20 15:09:25 +00:00
|
|
|
private function getChunkFileKey( $index = null ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $index === null ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
$index = $this->getChunkIndex();
|
|
|
|
|
}
|
2014-05-09 14:53:19 +00:00
|
|
|
|
2013-02-09 21:44:24 +00:00
|
|
|
return $this->mFileKey . '.' . $index;
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2013-05-16 22:09:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify that the chunk isn't really an evil html file
|
|
|
|
|
*
|
|
|
|
|
* @throws UploadChunkVerificationException
|
|
|
|
|
*/
|
|
|
|
|
private function verifyChunk() {
|
|
|
|
|
// Rest mDesiredDestName here so we verify the name as if it were mFileKey
|
|
|
|
|
$oldDesiredDestName = $this->mDesiredDestName;
|
|
|
|
|
$this->mDesiredDestName = $this->mFileKey;
|
|
|
|
|
$this->mTitle = false;
|
|
|
|
|
$res = $this->verifyPartialFile();
|
|
|
|
|
$this->mDesiredDestName = $oldDesiredDestName;
|
|
|
|
|
$this->mTitle = false;
|
2013-08-24 15:06:25 +00:00
|
|
|
if ( is_array( $res ) ) {
|
2013-05-16 22:09:44 +00:00
|
|
|
throw new UploadChunkVerificationException( $res[0] );
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-04 13:43:09 +00:00
|
|
|
class UploadChunkZeroLengthFileException extends MWException {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class UploadChunkFileException extends MWException {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class UploadChunkVerificationException extends MWException {
|
|
|
|
|
}
|