MediaWiki  REL1_21
AssembleUploadChunksJob.php
Go to the documentation of this file.
00001 <?php
00029 class AssembleUploadChunksJob extends Job {
00030         public function __construct( $title, $params, $id = 0 ) {
00031                 parent::__construct( 'AssembleUploadChunks', $title, $params, $id );
00032                 $this->removeDuplicates = true;
00033         }
00034 
00035         public function run() {
00036                 $scope = RequestContext::importScopedSession( $this->params['session'] );
00037                 $context = RequestContext::getMain();
00038                 try {
00039                         $user = $context->getUser();
00040                         if ( !$user->isLoggedIn() ) {
00041                                 $this->setLastError( "Could not load the author user from session." );
00042                                 return false;
00043                         }
00044 
00045                         UploadBase::setSessionStatus(
00046                                 $this->params['filekey'],
00047                                 array( 'result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood() )
00048                         );
00049 
00050                         $upload = new UploadFromChunks( $user );
00051                         $upload->continueChunks(
00052                                 $this->params['filename'],
00053                                 $this->params['filekey'],
00054                                 $context->getRequest()
00055                         );
00056 
00057                         // Combine all of the chunks into a local file and upload that to a new stash file
00058                         $status = $upload->concatenateChunks();
00059                         if ( !$status->isGood() ) {
00060                                 UploadBase::setSessionStatus(
00061                                         $this->params['filekey'],
00062                                         array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status )
00063                                 );
00064                                 $this->setLastError( $status->getWikiText() );
00065                                 return false;
00066                         }
00067 
00068                         // We have a new filekey for the fully concatenated file
00069                         $newFileKey = $upload->getLocalFile()->getFileKey();
00070 
00071                         // Remove the old stash file row and first chunk file
00072                         $upload->stash->removeFileNoAuth( $this->params['filekey'] );
00073 
00074                         // Build the image info array while we have the local reference handy
00075                         $apiMain = new ApiMain(); // dummy object (XXX)
00076                         $imageInfo = $upload->getImageInfo( $apiMain->getResult() );
00077 
00078                         // Cleanup any temporary local file
00079                         $upload->cleanupTempFile();
00080 
00081                         // Cache the info so the user doesn't have to wait forever to get the final info
00082                         UploadBase::setSessionStatus(
00083                                 $this->params['filekey'],
00084                                 array(
00085                                         'result'    => 'Success',
00086                                         'stage'     => 'assembling',
00087                                         'filekey'   => $newFileKey,
00088                                         'imageinfo' => $imageInfo,
00089                                         'status'    => Status::newGood()
00090                                 )
00091                         );
00092                 } catch ( MWException $e ) {
00093                         UploadBase::setSessionStatus(
00094                                 $this->params['filekey'],
00095                                 array(
00096                                         'result' => 'Failure',
00097                                         'stage'  => 'assembling',
00098                                         'status' => Status::newFatal( 'api-error-stashfailed' )
00099                                 )
00100                         );
00101                         $this->setLastError( get_class( $e ) . ": " . $e->getText() );
00102                         return false;
00103                 }
00104                 return true;
00105         }
00106 
00107         public function getDeduplicationInfo() {
00108                 $info = parent::getDeduplicationInfo();
00109                 if ( is_array( $info['params'] ) ) {
00110                         $info['params'] = array( 'filekey' => $info['params']['filekey'] );
00111                 }
00112                 return $info;
00113         }
00114 
00115         public function allowRetries() {
00116                 return false;
00117         }
00118 }