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