X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fjobqueue%2Fjobs%2FAssembleUploadChunksJob.php;h=b7f09e776888caba280efc13ce8b0bf8d60bb91b;hb=d716155c8b2d6e4a51a4110195cee7a1794846e8;hp=19b05586d4430132470fda5298162fd950f68e90;hpb=84fa4c83016089396c64c9cfccf5bb32cde40a57;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/jobs/AssembleUploadChunksJob.php b/includes/jobqueue/jobs/AssembleUploadChunksJob.php index 19b05586d4..bc2f7c458a 100644 --- a/includes/jobqueue/jobs/AssembleUploadChunksJob.php +++ b/includes/jobqueue/jobs/AssembleUploadChunksJob.php @@ -27,51 +27,47 @@ * @ingroup Upload */ class AssembleUploadChunksJob extends Job { - public function __construct( $title, $params ) { + public function __construct( Title $title, array $params ) { parent::__construct( 'AssembleUploadChunks', $title, $params ); $this->removeDuplicates = true; } public function run() { + /** @noinspection PhpUnusedLocalVariableInspection */ $scope = RequestContext::importScopedSession( $this->params['session'] ); + $this->addTeardownCallback( function () use ( &$scope ) { + ScopedCallback::consume( $scope ); // T126450 + } ); + $context = RequestContext::getMain(); + $user = $context->getUser(); try { - $user = $context->getUser(); if ( !$user->isLoggedIn() ) { $this->setLastError( "Could not load the author user from session." ); return false; } - if ( count( $_SESSION ) === 0 ) { - // Empty session probably indicates that we didn't associate - // with the session correctly. Note that being able to load - // the user does not necessarily mean the session was loaded. - // Most likely cause by suhosin.session.encrypt = On. - $this->setLastError( "Error associating with user session. " . - "Try setting suhosin.session.encrypt = Off" ); - - return false; - } - UploadBase::setSessionStatus( + $user, $this->params['filekey'], - array( 'result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood() ) + [ 'result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood() ] ); $upload = new UploadFromChunks( $user ); $upload->continueChunks( $this->params['filename'], $this->params['filekey'], - $context->getRequest() + new WebRequestUpload( $context->getRequest(), 'null' ) ); // Combine all of the chunks into a local file and upload that to a new stash file $status = $upload->concatenateChunks(); if ( !$status->isGood() ) { UploadBase::setSessionStatus( + $user, $this->params['filekey'], - array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ) + [ 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ] ); $this->setLastError( $status->getWikiText() ); @@ -93,25 +89,29 @@ class AssembleUploadChunksJob extends Job { // Cache the info so the user doesn't have to wait forever to get the final info UploadBase::setSessionStatus( + $user, $this->params['filekey'], - array( + [ 'result' => 'Success', 'stage' => 'assembling', 'filekey' => $newFileKey, 'imageinfo' => $imageInfo, 'status' => Status::newGood() - ) + ] ); - } catch ( MWException $e ) { + } catch ( Exception $e ) { UploadBase::setSessionStatus( + $user, $this->params['filekey'], - array( + [ 'result' => 'Failure', 'stage' => 'assembling', 'status' => Status::newFatal( 'api-error-stashfailed' ) - ) + ] ); - $this->setLastError( get_class( $e ) . ": " . $e->getText() ); + $this->setLastError( get_class( $e ) . ": " . $e->getMessage() ); + // To be extra robust. + MWExceptionHandler::rollbackMasterChangesAndLog( $e ); return false; } @@ -122,7 +122,7 @@ class AssembleUploadChunksJob extends Job { public function getDeduplicationInfo() { $info = parent::getDeduplicationInfo(); if ( is_array( $info['params'] ) ) { - $info['params'] = array( 'filekey' => $info['params']['filekey'] ); + $info['params'] = [ 'filekey' => $info['params']['filekey'] ]; } return $info;