Merge "filebackend: throw exceptions during file iteration."
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index 5563087..8f71fbe 100644 (file)
@@ -88,9 +88,10 @@ class ApiUpload extends ApiBase {
                        if ( !$this->mUpload->getTitle() ) {
                                $this->dieUsage( 'Invalid file title supplied', 'internal-error' );
                        }
-               } elseif ( $this->mParams['async'] ) {
+               } elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
                        // defer verification to background process
                } else {
+                       wfDebug( __METHOD__ . 'about to verify' );
                        $this->verifyUpload();
                }
 
@@ -195,7 +196,12 @@ class ApiUpload extends ApiBase {
                $chunkPath = $request->getFileTempname( 'chunk' );
                $chunkSize = $request->getUpload( 'chunk' )->getSize();
                if ( $this->mParams['offset'] == 0 ) {
-                       $filekey = $this->performStash();
+                       try {
+                               $filekey = $this->performStash();
+                       } catch ( MWException $e ) {
+                               // FIXME: Error handling here is wrong/different from rest of this
+                               $this->dieUsage( $e->getMessage(), 'stashfailed' );
+                       }
                } else {
                        $filekey = $this->mParams['filekey'];
                        /** @var $status Status */
@@ -210,27 +216,27 @@ class ApiUpload extends ApiBase {
                // Check we added the last chunk:
                if ( $this->mParams['offset'] + $chunkSize == $this->mParams['filesize'] ) {
                        if ( $this->mParams['async'] ) {
-                               $progress = UploadBase::getSessionStatus( $this->mParams['filekey'] );
+                               $progress = UploadBase::getSessionStatus( $filekey );
                                if ( $progress && $progress['result'] === 'Poll' ) {
                                        $this->dieUsage( "Chunk assembly already in progress.", 'stashfailed' );
                                }
                                UploadBase::setSessionStatus(
-                                       $this->mParams['filekey'],
+                                       $filekey,
                                        array( 'result' => 'Poll',
                                                'stage' => 'queued', 'status' => Status::newGood() )
                                );
                                $ok = JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
-                                       Title::makeTitle( NS_FILE, $this->mParams['filekey'] ),
+                                       Title::makeTitle( NS_FILE, $filekey ),
                                        array(
                                                'filename' => $this->mParams['filename'],
-                                               'filekey' => $this->mParams['filekey'],
+                                               'filekey' => $filekey,
                                                'session' => $this->getContext()->exportSession()
                                        )
                                ) );
                                if ( $ok ) {
                                        $result['result'] = 'Poll';
                                } else {
-                                       UploadBase::setSessionStatus( $this->mParams['filekey'], false );
+                                       UploadBase::setSessionStatus( $filekey, false );
                                        $this->dieUsage(
                                                "Failed to start AssembleUploadChunks.php", 'stashfailed' );
                                }