39 public function run() {
40 $scope = RequestContext::importScopedSession( $this->params[
'session'] );
42 ScopedCallback::consume( $scope );
45 $logger = LoggerFactory::getInstance(
'upload' );
46 $context = RequestContext::getMain();
47 $user = $context->getUser();
49 if ( !$user->isRegistered() ) {
50 $this->
setLastError(
"Could not load the author user from session." );
56 $startingStatus = UploadBase::getSessionStatus( $user, $this->params[
'filekey'] );
59 ( $startingStatus[
'result'] ??
'' ) !==
'Poll' ||
60 ( $startingStatus[
'stage'] ??
'' ) !==
'queued'
62 $logger->warning(
"Tried to assemble upload that is in stage {stage}/{result}",
64 'stage' => $startingStatus[
'stage'] ??
'-',
65 'result' => $startingStatus[
'result'] ??
'-',
66 'status' => (
string)( $startingStatus[
'status'] ??
'-' ),
67 'filekey' => $this->params[
'filekey'],
68 'filename' => $this->params[
'filename'],
69 'user' => $user->getName(),
77 $startingStatus[
'stage'] ===
'assembling' &&
78 $startingStatus[
'result'] !==
'Failure'
80 $this->
setLastError( __METHOD__ .
" already in progress" );
84 UploadBase::setSessionStatus(
86 $this->params[
'filekey'],
87 [
'result' =>
'Poll',
'stage' =>
'assembling',
'status' => Status::newGood() ]
91 $upload->continueChunks(
92 $this->params[
'filename'],
93 $this->params[
'filekey'],
97 isset( $this->params[
'filesize'] ) &&
98 $this->params[
'filesize'] !== (
int)$upload->getOffset()
102 throw new UnexpectedValueException(
103 "UploadStash file size does not match job's. Potential mis-nested transaction?"
107 $status = $upload->concatenateChunks();
108 if ( !$status->isGood() ) {
109 UploadBase::setSessionStatus(
111 $this->params[
'filekey'],
112 [
'result' =>
'Failure',
'stage' =>
'assembling',
'status' => $status ]
114 $logger->info(
"Chunked upload assembly job failed for {filekey} because {status}",
116 'filekey' => $this->params[
'filekey'],
117 'filename' => $this->params[
'filename'],
118 'user' => $user->getName(),
119 'status' => (
string)$status
129 $status = Status::newGood();
131 'warnings' => UploadBase::makeWarningsSerializable(
142 $upload->stash->removeFileNoAuth( $this->params[
'filekey'] );
146 $imageInfo = $apiUpload->getUploadImageInfo( $upload );
152 UploadBase::setSessionStatus(
154 $this->params[
'filekey'],
156 'result' =>
'Success',
157 'stage' =>
'assembling',
158 'filekey' => $newFileKey,
159 'imageinfo' => $imageInfo,
163 $logger->info(
"{filekey} successfully assembled into {newkey}",
165 'filekey' => $this->params[
'filekey'],
166 'newkey' => $newFileKey,
167 'filename' => $this->params[
'filename'],
168 'user' => $user->getName(),
169 'status' => (
string)$status
172 }
catch ( Exception $e ) {
173 UploadBase::setSessionStatus(
175 $this->params[
'filekey'],
177 'result' =>
'Failure',
178 'stage' =>
'assembling',
179 'status' => Status::newFatal(
'api-error-stashfailed' )
182 $this->
setLastError( get_class( $e ) .
": " . $e->getMessage() );
184 MWExceptionHandler::rollbackPrimaryChangesAndLog( $e );