Finish removing boolean return values from JobQueue code
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index 6d5861d..49306d7 100644 (file)
  * @ingroup API
  */
 class ApiUpload extends ApiBase {
-
-       /**
-        * @var UploadBase
-        */
+       /** @var UploadBase */
        protected $mUpload = null;
 
        protected $mParams;
@@ -95,7 +92,7 @@ class ApiUpload extends ApiBase {
                } elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
                        // defer verification to background process
                } else {
-                       wfDebug( __METHOD__ . 'about to verify' );
+                       wfDebug( __METHOD__ . " about to verify\n" );
                        $this->verifyUpload();
                }
 
@@ -237,7 +234,7 @@ class ApiUpload extends ApiBase {
                                        array( 'result' => 'Poll',
                                                'stage' => 'queued', 'status' => Status::newGood() )
                                );
-                               $ok = JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
+                               JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
                                        Title::makeTitle( NS_FILE, $filekey ),
                                        array(
                                                'filename' => $this->mParams['filename'],
@@ -245,13 +242,7 @@ class ApiUpload extends ApiBase {
                                                'session' => $this->getContext()->exportSession()
                                        )
                                ) );
-                               if ( $ok ) {
-                                       $result['result'] = 'Poll';
-                               } else {
-                                       UploadBase::setSessionStatus( $filekey, false );
-                                       $this->dieUsage(
-                                               "Failed to start AssembleUploadChunks.php", 'stashfailed' );
-                               }
+                               $result['result'] = 'Poll';
                        } else {
                                $status = $this->mUpload->concatenateChunks();
                                if ( !$status->isGood() ) {
@@ -278,7 +269,7 @@ class ApiUpload extends ApiBase {
         * Stash the file and return the file key
         * Also re-raises exceptions with slightly more informative message strings (useful for API)
         * @throws MWException
-        * @return String file key
+        * @return string File key
         */
        private function performStash() {
                try {
@@ -449,7 +440,7 @@ class ApiUpload extends ApiBase {
        /**
         * Checks that the user has permissions to perform this upload.
         * Dies with usage message on inadequate permissions.
-        * @param $user User The user to check.
+        * @param User $user The user to check.
         */
        protected function checkPermissions( $user ) {
                // Check whether the user has the appropriate permissions to upload anyway
@@ -458,9 +449,9 @@ class ApiUpload extends ApiBase {
                if ( $permission !== true ) {
                        if ( !$user->isLoggedIn() ) {
                                $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
-                       } else {
-                               $this->dieUsageMsg( 'badaccess-groups' );
                        }
+
+                       $this->dieUsageMsg( 'badaccess-groups' );
                }
        }
 
@@ -574,7 +565,9 @@ class ApiUpload extends ApiBase {
                        if ( isset( $warnings['exists'] ) ) {
                                $warning = $warnings['exists'];
                                unset( $warnings['exists'] );
-                               $localFile = isset( $warning['normalizedFile'] ) ? $warning['normalizedFile'] : $warning['file'];
+                               $localFile = isset( $warning['normalizedFile'] )
+                                       ? $warning['normalizedFile']
+                                       : $warning['file'];
                                $warnings[$warning['warning']] = $localFile->getName();
                        }
                }
@@ -626,7 +619,7 @@ class ApiUpload extends ApiBase {
                                $this->mParams['filekey'],
                                array( 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() )
                        );
-                       $ok = JobQueueGroup::singleton()->push( new PublishStashedFileJob(
+                       JobQueueGroup::singleton()->push( new PublishStashedFileJob(
                                Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
                                array(
                                        'filename' => $this->mParams['filename'],
@@ -637,13 +630,7 @@ class ApiUpload extends ApiBase {
                                        'session' => $this->getContext()->exportSession()
                                )
                        ) );
-                       if ( $ok ) {
-                               $result['result'] = 'Poll';
-                       } else {
-                               UploadBase::setSessionStatus( $this->mParams['filekey'], false );
-                               $this->dieUsage(
-                                       "Failed to start PublishStashedFile.php", 'publishfailed' );
-                       }
+                       $result['result'] = 'Poll';
                } else {
                        /** @var $status Status */
                        $status = $this->mUpload->performUpload( $this->mParams['comment'],
@@ -659,11 +646,10 @@ class ApiUpload extends ApiBase {
                                                'result' => 'Queued',
                                                'statuskey' => $error[0][1],
                                        );
-                               } else {
-                                       $this->getResult()->setIndexedTagName( $error, 'error' );
-
-                                       $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
                                }
+
+                               $this->getResult()->setIndexedTagName( $error, 'error' );
+                               $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
                        }
                        $result['result'] = 'Success';
                }
@@ -751,16 +737,19 @@ class ApiUpload extends ApiBase {
                $params = array(
                        'filename' => 'Target filename',
                        'token' => 'Edit token. You can get one of these through prop=info',
-                       'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified',
+                       'comment' => 'Upload comment. Also used as the initial page text for new ' .
+                               'files if "text" is not specified',
                        'text' => 'Initial page text for new files',
                        'watch' => 'Watch the page',
-                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' .
+                               'use preferences or do not change watch',
                        'ignorewarnings' => 'Ignore any warnings',
                        'file' => 'File contents',
                        'url' => 'URL to fetch the file from',
                        'filekey' => 'Key that identifies a previous upload that was stashed temporarily.',
                        'sessionkey' => 'Same as filekey, maintained for backward compatibility.',
-                       'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.',
+                       'stash' => 'If set, the server will not add the file to the repository ' .
+                               'and stash it temporarily.',
 
                        'chunk' => 'Chunk contents',
                        'offset' => 'Offset of chunk in bytes',
@@ -818,7 +807,7 @@ class ApiUpload extends ApiBase {
                        ' * Have the MediaWiki server fetch a file from a URL, using the "url" parameter',
                        ' * Complete an earlier upload that failed due to warnings, using the "filekey" parameter',
                        'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
-                       'sending the "file". Also you must get and send an edit token before doing any upload stuff'
+                       'sending the "file". Also you must get and send an edit token before doing any upload stuff.'
                );
        }
 
@@ -858,7 +847,8 @@ class ApiUpload extends ApiBase {
 
        public function getExamples() {
                return array(
-                       'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
+                       'api.php?action=upload&filename=Wiki.png' .
+                       '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
                                => 'Upload from a URL',
                        'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1'
                                => 'Complete an upload that failed due to warnings',