X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=blobdiff_plain;f=includes%2Fupload%2FUploadBase.php;h=9837a95f50a8574cc22976c73a6d093f27fa6f73;hb=ed6ddf74106d544d32ae395cf79708ab5057c36c;hp=c1e538a2353952e92cbd78ef13063d6f955c186b;hpb=40a628a501fc05bb00e834fe359ca4061925f320;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index c1e538a235..9837a95f50 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -36,7 +36,11 @@ * @author Michael Dale */ abstract class UploadBase { + /** @var string Local file system path to the file to upload (or a local copy) */ protected $mTempPath; + /** @var TempFSFile|null Wrapper to handle deleting the temp file */ + protected $tempFileObj; + protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType; protected $mTitle = false, $mTitleError = 0; protected $mFilteredName, $mFinalExtension; @@ -219,8 +223,8 @@ abstract class UploadBase { if ( FileBackend::isStoragePath( $tempPath ) ) { throw new MWException( __METHOD__ . " given storage path `$tempPath`." ); } - $this->mTempPath = $tempPath; - $this->mFileSize = $fileSize; + + $this->setTempFile( $tempPath, $fileSize ); $this->mRemoveTempFile = $removeTempFile; } @@ -231,6 +235,23 @@ abstract class UploadBase { */ abstract public function initializeFromRequest( &$request ); + /** + * @param string $tempPath File system path to temporary file containing the upload + * @param integer $fileSize + */ + protected function setTempFile( $tempPath, $fileSize = null ) { + $this->mTempPath = $tempPath; + $this->mFileSize = $fileSize ?: null; + if ( strlen( $this->mTempPath ) && file_exists( $this->mTempPath ) ) { + $this->tempFileObj = new TempFSFile( $this->mTempPath ); + if ( !$fileSize ) { + $this->mFileSize = filesize( $this->mTempPath ); + } + } else { + $this->tempFileObj = null; + } + } + /** * Fetch the file. Usually a no-op * @return Status @@ -645,7 +666,7 @@ abstract class UploadBase { } if ( $this->mFileSize == 0 ) { - $warnings['emptyfile'] = true; + $warnings['empty-file'] = true; } $exists = self::getExistsWarning( $localFile ); @@ -716,7 +737,7 @@ abstract class UploadBase { WatchAction::doWatch( $this->getLocalFile()->getTitle(), $user, - WatchedItem::IGNORE_USER_RIGHTS + User::IGNORE_USER_RIGHTS ); } Hooks::run( 'UploadComplete', [ &$this ] ); @@ -952,9 +973,10 @@ abstract class UploadBase { * on exit to clean up. */ public function cleanupTempFile() { - if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) { - wfDebug( __METHOD__ . ": Removing temporary file {$this->mTempPath}\n" ); - unlink( $this->mTempPath ); + if ( $this->mRemoveTempFile && $this->tempFileObj ) { + // Delete when all relevant TempFSFile handles go out of scope + wfDebug( __METHOD__ . ": Marked temporary file '{$this->mTempPath}' for removal\n" ); + $this->tempFileObj->autocollect(); } }