Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / includes / jobqueue / jobs / AssembleUploadChunksJob.php
index 4de19bc..e2914be 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Upload
  */
+use Wikimedia\ScopedCallback;
 
 /**
  * Assemble the segments of a chunked upload.
@@ -33,8 +34,11 @@ class AssembleUploadChunksJob extends Job {
        }
 
        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 {
@@ -47,7 +51,7 @@ class AssembleUploadChunksJob extends Job {
                        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 );
@@ -63,15 +67,19 @@ class AssembleUploadChunksJob extends Job {
                                UploadBase::setSessionStatus(
                                        $user,
                                        $this->params['filekey'],
-                                       array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status )
+                                       [ 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ]
                                );
-                               $this->setLastError( $status->getWikiText() );
+                               $this->setLastError( $status->getWikiText( false, false, 'en' ) );
 
                                return false;
                        }
 
+                       // We can only get warnings like 'duplicate' after concatenating the chunks
+                       $status = Status::newGood();
+                       $status->value = [ 'warnings' => $upload->checkWarnings() ];
+
                        // We have a new filekey for the fully concatenated file
-                       $newFileKey = $upload->getLocalFile()->getFileKey();
+                       $newFileKey = $upload->getStashFile()->getFileKey();
 
                        // Remove the old stash file row and first chunk file
                        $upload->stash->removeFileNoAuth( $this->params['filekey'] );
@@ -87,23 +95,23 @@ class AssembleUploadChunksJob extends Job {
                        UploadBase::setSessionStatus(
                                $user,
                                $this->params['filekey'],
-                               array(
+                               [
                                        'result' => 'Success',
                                        'stage' => 'assembling',
                                        'filekey' => $newFileKey,
                                        'imageinfo' => $imageInfo,
-                                       'status' => Status::newGood()
-                               )
+                                       'status' => $status
+                               ]
                        );
                } 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->getMessage() );
                        // To be extra robust.
@@ -118,7 +126,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;