* Fixed FileOp::attemptBatch() bug that had status->ok set wrong if 'force' option...
authorAaron Schulz <aaron@users.mediawiki.org>
Mon, 9 Jan 2012 21:04:48 +0000 (21:04 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Mon, 9 Jan 2012 21:04:48 +0000 (21:04 +0000)
* Added missing prepare() call to File::maybeDoTransform().
* Improved documentation.

includes/filerepo/backend/FileOp.php
includes/filerepo/file/File.php

index 4f6e226..11fe865 100644 (file)
@@ -76,6 +76,13 @@ abstract class FileOp {
         * Attempt a series of file operations.
         * Callers are responsible for handling file locking.
         * 
+        * $opts is an array of options, including:
+        * 'force'               : Errors that would normally cause a rollback do not.
+        *                         The remaining operations are still attempted if any fail.
+        * 'allowStale'          : Don't require the latest available data.
+        *                         This can increase performance for non-critical writes.
+        *                         This has no effect unless the 'force' flag is set.
+        * 
         * @param $performOps Array List of FileOp operations
         * @param $opts Array Batch operation options
         * @return Status 
@@ -129,6 +136,7 @@ abstract class FileOp {
                        }
                }
 
+               $wasOk = $status->isOK();
                // Finish each operation...
                foreach ( $performOps as $index => $fileOp ) {
                        if ( $fileOp->failed() ) {
@@ -146,7 +154,7 @@ abstract class FileOp {
                }
 
                // Make sure status is OK, despite any finish() fatals
-               $status->setResult( true, $status->value );
+               $status->setResult( $wasOk, $status->value );
 
                return $status;
        }
index b5fe481..2554af5 100644 (file)
@@ -806,10 +806,11 @@ abstract class File {
                                $thumb = $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
                        }
                } elseif ( $thumb->hasFile() && !$thumb->fileIsSource() ) {
-                       // Copy the thumbnail from the file system into storage
-                       // We don't use FileRepo::store() because of hacky suclasses
-                       // overriding File::getThumbPath() to use a different zone (e.g. 'temp').
-                       $status = $this->repo->getBackend()->store(
+                       $backend = $this->repo->getBackend();
+                       // Copy the thumbnail from the file system into storage. This avoids using
+                       // FileRepo::store(); getThumbPath() uses a different zone in some subclasses.
+                       $backend->prepare( array( 'dir' => dirname( $thumbPath ) ) );
+                       $status = $backend->store(
                                array( 'src' => $tmpThumbPath, 'dst' => $thumbPath ),
                                array( 'force' => 1, 'nonLocking' => 1, 'allowStale' => 1 )
                        );