docs: Remove odd colons after @todo
[lhc/web/wiklou.git] / includes / filebackend / FileOp.php
index bb0ab57..e4059d7 100644 (file)
@@ -46,7 +46,7 @@ abstract class FileOp {
 
        protected $doOperation = true; // boolean; operation is not a no-op
        protected $sourceSha1; // string
-       protected $destSameAsSource; // boolean
+       protected $overwriteSameCase; // boolean
        protected $destExists; // boolean
 
        /* Object life-cycle */
@@ -55,7 +55,7 @@ abstract class FileOp {
        const STATE_ATTEMPTED = 3;
 
        /**
-        * Build a new file operation transaction
+        * Build a new batch file operation transaction
         *
         * @param $backend FileBackendStore
         * @param $params Array
@@ -64,8 +64,10 @@ abstract class FileOp {
        final public function __construct( FileBackendStore $backend, array $params ) {
                $this->backend = $backend;
                list( $required, $optional ) = $this->allowedParams();
+               // @todo normalizeAnyStoragePaths() calls are overzealous, use a parameter list
                foreach ( $required as $name ) {
                        if ( isset( $params[$name] ) ) {
+                               // Normalize paths so the paths to the same file have the same string
                                $this->params[$name] = self::normalizeAnyStoragePaths( $params[$name] );
                        } else {
                                throw new MWException( "File operation missing parameter '$name'." );
@@ -73,6 +75,7 @@ abstract class FileOp {
                }
                foreach ( $optional as $name ) {
                        if ( isset( $params[$name] ) ) {
+                               // Normalize paths so the paths to the same file have the same string
                                $this->params[$name] = self::normalizeAnyStoragePaths( $params[$name] );
                        }
                }
@@ -209,22 +212,22 @@ abstract class FileOp {
                $pathsUsed = array_merge( $this->storagePathsRead(), $this->storagePathsChanged() );
                foreach ( array_unique( $pathsUsed ) as $path ) {
                        $nullEntries[] = array( // assertion for recovery
-                               'op'      => 'null',
-                               'path'    => $path,
+                               'op' => 'null',
+                               'path' => $path,
                                'newSha1' => $this->fileSha1( $path, $oPredicates )
                        );
                }
                foreach ( $this->storagePathsChanged() as $path ) {
                        if ( $nPredicates['sha1'][$path] === false ) { // deleted
                                $deleteEntries[] = array(
-                                       'op'      => 'delete',
-                                       'path'    => $path,
+                                       'op' => 'delete',
+                                       'path' => $path,
                                        'newSha1' => ''
                                );
                        } else { // created/updated
                                $updateEntries[] = array(
-                                       'op'      => $this->fileExists( $path, $oPredicates ) ? 'update' : 'create',
-                                       'path'    => $path,
+                                       'op' => $this->fileExists( $path, $oPredicates ) ? 'update' : 'create',
+                                       'path' => $path,
                                        'newSha1' => $nPredicates['sha1'][$path]
                                );
                        }
@@ -341,7 +344,7 @@ abstract class FileOp {
 
        /**
         * Check for errors with regards to the destination file already existing.
-        * Also set the destExists, destSameAsSource and sourceSha1 member variables.
+        * Also set the destExists, overwriteSameCase and sourceSha1 member variables.
         * A bad status will be returned if there is no chance it can be overwritten.
         *
         * @param $predicates Array
@@ -354,7 +357,7 @@ abstract class FileOp {
                if ( $this->sourceSha1 === null ) { // file in storage?
                        $this->sourceSha1 = $this->fileSha1( $this->params['src'], $predicates );
                }
-               $this->destSameAsSource = false;
+               $this->overwriteSameCase = false;
                $this->destExists = $this->fileExists( $this->params['dst'], $predicates );
                if ( $this->destExists ) {
                        if ( $this->getParam( 'overwrite' ) ) {
@@ -368,7 +371,7 @@ abstract class FileOp {
                                        // Give an error if the files are not identical
                                        $status->fatal( 'backend-fail-notsame', $this->params['dst'] );
                                } else {
-                                       $this->destSameAsSource = true; // OK
+                                       $this->overwriteSameCase = true; // OK
                                }
                                return $status; // do nothing; either OK or bad status
                        } else {
@@ -457,7 +460,7 @@ abstract class FileOp {
 class CreateFileOp extends FileOp {
        protected function allowedParams() {
                return array( array( 'content', 'dst' ),
-                       array( 'overwrite', 'overwriteSame', 'disposition', 'headers' ) );
+                       array( 'overwrite', 'overwriteSame', 'headers' ) );
        }
 
        protected function doPrecheck( array &$predicates ) {
@@ -489,7 +492,7 @@ class CreateFileOp extends FileOp {
         * @return Status
         */
        protected function doAttempt() {
-               if ( !$this->destSameAsSource ) {
+               if ( !$this->overwriteSameCase ) {
                        // Create the file at the destination
                        return $this->backend->createInternal( $this->setFlags( $this->params ) );
                }
@@ -521,7 +524,7 @@ class StoreFileOp extends FileOp {
         */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ),
-                       array( 'overwrite', 'overwriteSame', 'disposition', 'headers' ) );
+                       array( 'overwrite', 'overwriteSame', 'headers' ) );
        }
 
        /**
@@ -561,8 +564,8 @@ class StoreFileOp extends FileOp {
         * @return Status
         */
        protected function doAttempt() {
-               // Store the file at the destination
-               if ( !$this->destSameAsSource ) {
+               if ( !$this->overwriteSameCase ) {
+                       // Store the file at the destination
                        return $this->backend->storeInternal( $this->setFlags( $this->params ) );
                }
                return Status::newGood();
@@ -596,7 +599,7 @@ class CopyFileOp extends FileOp {
         */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ),
-                       array( 'overwrite', 'overwriteSame', 'ignoreMissingSource', 'disposition' ) );
+                       array( 'overwrite', 'overwriteSame', 'ignoreMissingSource', 'headers' ) );
        }
 
        /**
@@ -638,14 +641,19 @@ class CopyFileOp extends FileOp {
         * @return Status
         */
        protected function doAttempt() {
-               // Do nothing if the src/dst paths are the same
-               if ( $this->params['src'] !== $this->params['dst'] ) {
-                       // Copy the file into the destination
-                       if ( !$this->destSameAsSource ) {
-                               return $this->backend->copyInternal( $this->setFlags( $this->params ) );
-                       }
+               if ( $this->overwriteSameCase ) {
+                       $status = Status::newGood(); // nothing to do
+               } elseif ( $this->params['src'] === $this->params['dst'] ) {
+                       // Just update the destination file headers
+                       $headers = $this->getParam( 'headers' ) ?: array();
+                       $status = $this->backend->describeInternal( $this->setFlags( array(
+                               'src' => $this->params['dst'], 'headers' => $headers
+                       ) ) );
+               } else {
+                       // Copy the file to the destination
+                       $status = $this->backend->copyInternal( $this->setFlags( $this->params ) );
                }
-               return Status::newGood();
+               return $status;
        }
 
        /**
@@ -673,7 +681,7 @@ class MoveFileOp extends FileOp {
         */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ),
-                       array( 'overwrite', 'overwriteSame', 'ignoreMissingSource', 'disposition' ) );
+                       array( 'overwrite', 'overwriteSame', 'ignoreMissingSource', 'headers' ) );
        }
 
        /**
@@ -717,18 +725,27 @@ class MoveFileOp extends FileOp {
         * @return Status
         */
        protected function doAttempt() {
-               // Do nothing if the src/dst paths are the same
-               if ( $this->params['src'] !== $this->params['dst'] ) {
-                       if ( !$this->destSameAsSource ) {
-                               // Move the file into the destination
-                               return $this->backend->moveInternal( $this->setFlags( $this->params ) );
+               if ( $this->overwriteSameCase ) {
+                       if ( $this->params['src'] === $this->params['dst'] ) {
+                               // Do nothing to the destination (which is also the source)
+                               $status = Status::newGood();
                        } else {
-                               // Just delete source as the destination needs no changes
-                               $params = array( 'src' => $this->params['src'] );
-                               return $this->backend->deleteInternal( $this->setFlags( $params ) );
+                               // Just delete the source as the destination file needs no changes
+                               $status = $this->backend->deleteInternal( $this->setFlags(
+                                       array( 'src' => $this->params['src'] )
+                               ) );
                        }
+               } elseif ( $this->params['src'] === $this->params['dst'] ) {
+                       // Just update the destination file headers
+                       $headers = $this->getParam( 'headers' ) ?: array();
+                       $status = $this->backend->describeInternal( $this->setFlags(
+                               array( 'src' => $this->params['dst'], 'headers' => $headers )
+                       ) );
+               } else {
+                       // Move the file to the destination
+                       $status = $this->backend->moveInternal( $this->setFlags( $this->params ) );
                }
-               return Status::newGood();
+               return $status;
        }
 
        /**
@@ -813,7 +830,7 @@ class DescribeFileOp extends FileOp {
         * @return array
         */
        protected function allowedParams() {
-               return array( array( 'src' ), array( 'disposition', 'headers' ) );
+               return array( array( 'src' ), array( 'headers' ) );
        }
 
        /**