MediaWiki
REL1_24
|
00001 <?php 00029 class AssembleUploadChunksJob extends Job { 00030 public function __construct( $title, $params ) { 00031 parent::__construct( 'AssembleUploadChunks', $title, $params ); 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 00043 return false; 00044 } 00045 00046 if ( count( $_SESSION ) === 0 ) { 00047 // Empty session probably indicates that we didn't associate 00048 // with the session correctly. Note that being able to load 00049 // the user does not necessarily mean the session was loaded. 00050 // Most likely cause by suhosin.session.encrypt = On. 00051 $this->setLastError( "Error associating with user session. " . 00052 "Try setting suhosin.session.encrypt = Off" ); 00053 00054 return false; 00055 } 00056 00057 UploadBase::setSessionStatus( 00058 $this->params['filekey'], 00059 array( 'result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood() ) 00060 ); 00061 00062 $upload = new UploadFromChunks( $user ); 00063 $upload->continueChunks( 00064 $this->params['filename'], 00065 $this->params['filekey'], 00066 $context->getRequest() 00067 ); 00068 00069 // Combine all of the chunks into a local file and upload that to a new stash file 00070 $status = $upload->concatenateChunks(); 00071 if ( !$status->isGood() ) { 00072 UploadBase::setSessionStatus( 00073 $this->params['filekey'], 00074 array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ) 00075 ); 00076 $this->setLastError( $status->getWikiText() ); 00077 00078 return false; 00079 } 00080 00081 // We have a new filekey for the fully concatenated file 00082 $newFileKey = $upload->getLocalFile()->getFileKey(); 00083 00084 // Remove the old stash file row and first chunk file 00085 $upload->stash->removeFileNoAuth( $this->params['filekey'] ); 00086 00087 // Build the image info array while we have the local reference handy 00088 $apiMain = new ApiMain(); // dummy object (XXX) 00089 $imageInfo = $upload->getImageInfo( $apiMain->getResult() ); 00090 00091 // Cleanup any temporary local file 00092 $upload->cleanupTempFile(); 00093 00094 // Cache the info so the user doesn't have to wait forever to get the final info 00095 UploadBase::setSessionStatus( 00096 $this->params['filekey'], 00097 array( 00098 'result' => 'Success', 00099 'stage' => 'assembling', 00100 'filekey' => $newFileKey, 00101 'imageinfo' => $imageInfo, 00102 'status' => Status::newGood() 00103 ) 00104 ); 00105 } catch ( MWException $e ) { 00106 UploadBase::setSessionStatus( 00107 $this->params['filekey'], 00108 array( 00109 'result' => 'Failure', 00110 'stage' => 'assembling', 00111 'status' => Status::newFatal( 'api-error-stashfailed' ) 00112 ) 00113 ); 00114 $this->setLastError( get_class( $e ) . ": " . $e->getText() ); 00115 // To be extra robust. 00116 MWExceptionHandler::rollbackMasterChangesAndLog( $e ); 00117 00118 return false; 00119 } 00120 00121 return true; 00122 } 00123 00124 public function getDeduplicationInfo() { 00125 $info = parent::getDeduplicationInfo(); 00126 if ( is_array( $info['params'] ) ) { 00127 $info['params'] = array( 'filekey' => $info['params']['filekey'] ); 00128 } 00129 00130 return $info; 00131 } 00132 00133 public function allowRetries() { 00134 return false; 00135 } 00136 }