[Upload] Improvements to async stash uploading.
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 11 Dec 2012 22:29:33 +0000 (14:29 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 11 Dec 2012 22:30:30 +0000 (14:30 -0800)
* Added a "stage" field to the status info. This lets clients detect
  if the process failed to even start much more quickly.
* Actually unset the status from $_SESSION if set to false.

Change-Id: I29703f14625b1b10e6413db27a3964324b4679e6

includes/api/ApiUpload.php
includes/upload/AssembleUploadChunks.php
includes/upload/UploadBase.php

index f88332f..89eff2e 100644 (file)
@@ -211,7 +211,8 @@ class ApiUpload extends ApiBase {
                                        }
                                        UploadBase::setSessionStatus(
                                                $this->mParams['filekey'],
-                                               array( 'result' => 'Poll', 'status' => Status::newGood() )
+                                               array( 'result' => 'Poll',
+                                                       'stage' => 'queued', 'status' => Status::newGood() )
                                        );
                                        $retVal = 1;
                                        $cmd = wfShellWikiCmd(
index 74daf2a..d933d34 100644 (file)
@@ -47,6 +47,11 @@ class AssembleUploadChunks extends Maintenance {
                                throw new MWException( "No user with ID " . $this->getOption( 'userid' ) . "." );
                        }
 
+                       UploadBase::setSessionStatus(
+                               $this->getOption( 'filekey' ),
+                               array( 'result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood() )
+                       );
+
                        $upload = new UploadFromChunks( $user );
                        $upload->continueChunks(
                                $this->getOption( 'filename' ),
@@ -60,7 +65,7 @@ class AssembleUploadChunks extends Maintenance {
                        if ( !$status->isGood() ) {
                                UploadBase::setSessionStatus(
                                        $this->getOption( 'filekey' ),
-                                       array( 'result' => 'Failure', 'status' => $status )
+                                       array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status )
                                );
                                session_write_close();
                                $this->error( $status->getWikiText() . "\n", 1 ); // die
@@ -84,6 +89,7 @@ class AssembleUploadChunks extends Maintenance {
                                $this->getOption( 'filekey' ),
                                array(
                                        'result'    => 'Success',
+                                       'stage'     => 'assembling',
                                        'filekey'   => $newFileKey,
                                        'imageinfo' => $imageInfo,
                                        'status'    => Status::newGood()
@@ -94,6 +100,7 @@ class AssembleUploadChunks extends Maintenance {
                                $this->getOption( 'filekey' ),
                                array(
                                        'result' => 'Failure',
+                                       'stage'  => 'assembling',
                                        'status' => Status::newFatal( 'api-error-stashfailed' )
                                )
                        );
index 02cf8fd..fdd5f65 100644 (file)
@@ -1519,6 +1519,10 @@ abstract class UploadBase {
         * @return void
         */
        public static function setSessionStatus( $statusKey, $value ) {
-               $_SESSION[self::SESSION_STATUS_KEY][$statusKey] = $value;
+               if ( $value === false ) {
+                       unset( $_SESSION[self::SESSION_STATUS_KEY][$statusKey] );
+               } else {
+                       $_SESSION[self::SESSION_STATUS_KEY][$statusKey] = $value;
+               }
        }
 }