r92213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92212‎ | r92213 | r92214 >
Date:23:01, 14 July 2011
Author:raindrift
Status:ok (Comments)
Tags:
Comment:
properly handle the case where a file disappears during the uploadwizard process
remove database records for files that move out of the stash
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromStash.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromStash.php
@@ -100,10 +100,10 @@
101101 * There is no need to stash the image twice
102102 */
103103 public function stashFile( $key = null ) {
104 - if ( !empty( $this->mFileKey ) ) {
105 - return $this->mFileKey;
 104+ if ( !empty( $this->mLocalFile ) ) {
 105+ return $this->mLocalFile;
106106 }
107 - return parent::stashFileGetKey();
 107+ return parent::stashFile( $key );
108108 }
109109
110110 /**
@@ -118,7 +118,16 @@
119119 * @return success
120120 */
121121 public function unsaveUploadedFile() {
122 - return $stash->removeFile( $this->mFileKey );
 122+ return $this->stash->removeFile( $this->mFileKey );
123123 }
124124
 125+ /**
 126+ * Perform the upload, then remove the database record afterward.
 127+ */
 128+ public function performUpload( $comment, $pageText, $watch, $user ) {
 129+ $rv = parent::performUpload( $comment, $pageText, $watch, $user );
 130+ $this->unsaveUploadedFile();
 131+ return $rv;
 132+ }
 133+
125134 }
\ No newline at end of file
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -589,7 +589,7 @@
590590 if ( $watch ) {
591591 $user->addWatch( $this->getLocalFile()->getTitle() );
592592 }
593 -
 593+
594594 wfRunHooks( 'UploadComplete', array( &$this ) );
595595 }
596596
Index: trunk/phase3/includes/upload/UploadStash.php
@@ -131,6 +131,11 @@
132132 $this->fileProps[$key] = File::getPropsFromPath( $path );
133133 }
134134
 135+ if ( ! $this->files[$key]->exists() ) {
 136+ wfDebug( __METHOD__ . " tried to get file at $key, but it doesn't exist\n" );
 137+ throw new UploadStashBadPathException( "path doesn't exist" );
 138+ }
 139+
135140 if( !$noAuth ) {
136141 if( $this->fileMetadata[$key]['us_user'] != $this->userId ) {
137142 throw new UploadStashWrongOwnerException( "This file ($key) doesn't belong to the current user." );
@@ -671,6 +676,10 @@
672677 return $this->repo->freeTemp( $this->path );
673678 }
674679
 680+ public function exists() {
 681+ return $this->repo->fileExists( $this->path, FileRepo::FILES_ONLY );
 682+ }
 683+
675684 }
676685
677686 class UploadStashNotAvailableException extends MWException {};
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -147,6 +147,7 @@
148148 */
149149 function performStash() {
150150 try {
 151+ xdebug_break();
151152 $fileKey = $this->mUpload->stashFile()->getFileKey();
152153 } catch ( MWException $e ) {
153154 $message = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();

Follow-up revisions

RevisionCommit summaryAuthorDate
r92456removing xdebug callneilk18:59, 18 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:36, 15 July 2011

xdebug_break?

#Comment by NeilK (talk | contribs)   03:05, 23 July 2011

xdebug_break() call removed in r92456

#Comment by Catrope (talk | contribs)   12:36, 15 August 2011
-
+						

Check your diffs before you commit and you'll notice things like this. In this case, your only change to UploadBase.php was changing an empty line to one with 6 tabs.

Status & tagging log