properly handle the case where a file disappears during the uploadwizard process
authorIan Baker <raindrift@users.mediawiki.org>
Thu, 14 Jul 2011 23:01:00 +0000 (23:01 +0000)
committerIan Baker <raindrift@users.mediawiki.org>
Thu, 14 Jul 2011 23:01:00 +0000 (23:01 +0000)
remove database records for files that move out of the stash

includes/api/ApiUpload.php
includes/upload/UploadBase.php
includes/upload/UploadFromStash.php
includes/upload/UploadStash.php

index 3a8326f..b101ecc 100644 (file)
@@ -147,6 +147,7 @@ class ApiUpload extends ApiBase {
         */
        function performStash() {
                try {
+                       xdebug_break();
                        $fileKey = $this->mUpload->stashFile()->getFileKey();
                } catch ( MWException $e ) {
                        $message = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();
index 67d275f..fc64818 100644 (file)
@@ -589,7 +589,7 @@ abstract class UploadBase {
                        if ( $watch ) {
                                $user->addWatch( $this->getLocalFile()->getTitle() );
                        }
-
+                                               
                        wfRunHooks( 'UploadComplete', array( &$this ) );
                }
 
index 1ee720a..feb14a8 100644 (file)
@@ -100,10 +100,10 @@ class UploadFromStash extends UploadBase {
         * There is no need to stash the image twice
         */
        public function stashFile( $key = null ) {
-               if ( !empty( $this->mFileKey ) ) {
-                       return $this->mFileKey;
+               if ( !empty( $this->mLocalFile ) ) {
+                       return $this->mLocalFile;
                }
-               return parent::stashFileGetKey();
+               return parent::stashFile( $key );
        }
 
        /**
@@ -118,7 +118,16 @@ class UploadFromStash extends UploadBase {
         * @return success
         */
        public function unsaveUploadedFile() {
-               return $stash->removeFile( $this->mFileKey );
+               return $this->stash->removeFile( $this->mFileKey );
+       }
+
+       /**
+        * Perform the upload, then remove the database record afterward.
+        */
+       public function performUpload( $comment, $pageText, $watch, $user ) {
+               $rv = parent::performUpload( $comment, $pageText, $watch, $user );
+               $this->unsaveUploadedFile();
+               return $rv;
        }
 
 }
\ No newline at end of file
index 66bf33f..8ebacbb 100644 (file)
@@ -131,6 +131,11 @@ class UploadStash {
                        $this->fileProps[$key] = File::getPropsFromPath( $path );
                }
                
+               if ( ! $this->files[$key]->exists() ) {
+                       wfDebug( __METHOD__ . " tried to get file at $key, but it doesn't exist\n" );
+                       throw new UploadStashBadPathException( "path doesn't exist" );
+               }
+               
                if( !$noAuth ) {
                        if( $this->fileMetadata[$key]['us_user'] != $this->userId ) {
                                throw new UploadStashWrongOwnerException( "This file ($key) doesn't belong to the current user." );
@@ -671,6 +676,10 @@ class UploadStashFile extends UnregisteredLocalFile {
                return $this->repo->freeTemp( $this->path );
        }
 
+       public function exists() {
+               return $this->repo->fileExists( $this->path, FileRepo::FILES_ONLY );
+       }
+
 }
 
 class UploadStashNotAvailableException extends MWException {};