From 6ef90f24e46664e91290d3c5f6e8638f7c248318 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 11 Dec 2012 14:29:33 -0800 Subject: [PATCH] [Upload] Improvements to async stash uploading. * 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 | 3 ++- includes/upload/AssembleUploadChunks.php | 9 ++++++++- includes/upload/UploadBase.php | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index f88332f903..89eff2e1a2 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -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( diff --git a/includes/upload/AssembleUploadChunks.php b/includes/upload/AssembleUploadChunks.php index 74daf2a94c..d933d34d47 100644 --- a/includes/upload/AssembleUploadChunks.php +++ b/includes/upload/AssembleUploadChunks.php @@ -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' ) ) ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 02cf8fda24..fdd5f653b7 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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; + } } } -- 2.20.1