Merge "[FileBackend] Added getScopedLocksForOps() function."
[lhc/web/wiklou.git] / includes / filerepo / backend / FileBackendMultiWrite.php
index 7f2c5b7..efc6053 100644 (file)
@@ -1,5 +1,22 @@
 <?php
 /**
+ * Proxy backend that mirrors writes to several internal backends.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup FileBackend
  * @author Aaron Schulz
@@ -40,6 +57,9 @@ class FileBackendMultiWrite extends FileBackend {
         *                     FileBackendStore class, but with these additional settings:
         *                         'class'         : The name of the backend class
         *                         'isMultiMaster' : This must be set for one backend.
+        *                         'template:      : If given a backend name, this will use
+        *                                           the config of that backend as a template.
+        *                                           Values specified here take precedence.
         *     'syncChecks'  : Integer bitfield of internal backend sync checks to perform.
         *                     Possible bits include self::CHECK_SIZE and self::CHECK_TIME.
         *                     The checks are done before allowing any file operations.
@@ -51,6 +71,11 @@ class FileBackendMultiWrite extends FileBackend {
                // Construct backends here rather than via registration
                // to keep these backends hidden from outside the proxy.
                foreach ( $config['backends'] as $index => $config ) {
+                       if ( isset( $config['template'] ) ) {
+                               // Config is just a modified version of a registered backend's.
+                               // This should only be used when that config is used only be this backend.
+                               $config = $config + FileBackendGroup::singleton()->config( $config['template'] );
+                       }
                        $name = $config['name'];
                        if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
                                throw new MWException( "Two or more backends defined with the name $name." );
@@ -126,7 +151,7 @@ class FileBackendMultiWrite extends FileBackend {
                }
 
                // Actually attempt the operation batch...
-               $subStatus = FileOp::attemptBatch( $performOps, $opts, $this->fileJournal );
+               $subStatus = FileOpBatch::attempt( $performOps, $opts, $this->fileJournal );
 
                $success = array();
                $failCount = 0;
@@ -235,7 +260,7 @@ class FileBackendMultiWrite extends FileBackend {
        /**
         * Same as substOpBatchPaths() but for a single operation
         *
-        * @param $op File operation array
+        * @param $ops array File operation array
         * @param $backend FileBackendStore
         * @return Array
         */
@@ -273,6 +298,24 @@ class FileBackendMultiWrite extends FileBackend {
                );
        }
 
+       /**
+        * @see FileBackend::doQuickOperationsInternal()
+        * @return Status
+        */
+       public function doQuickOperationsInternal( array $ops ) {
+               // Do the operations on the master backend; setting Status fields...
+               $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
+               $status = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
+               // Propagate the operations to the clone backends...
+               foreach ( $this->backends as $index => $backend ) {
+                       if ( $index !== $this->masterIndex ) { // not done already
+                               $realOps = $this->substOpBatchPaths( $ops, $backend );
+                               $status->merge( $backend->doQuickOperations( $realOps ) );
+                       }
+               }
+               return $status;
+       }
+
        /**
         * @see FileBackend::doPrepare()
         * @return Status
@@ -288,6 +331,7 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::doSecure()
+        * @param $params array
         * @return Status
         */
        protected function doSecure( array $params ) {
@@ -301,6 +345,7 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::doClean()
+        * @param $params array
         * @return Status
         */
        protected function doClean( array $params ) {
@@ -314,6 +359,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::concatenate()
+        * @param $params array
+        * @return Status
         */
        public function concatenate( array $params ) {
                // We are writing to an FS file, so we don't need to do this per-backend
@@ -323,6 +370,7 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::fileExists()
+        * @param $params array
         */
        public function fileExists( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -331,6 +379,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileTimestamp()
+        * @param $params array
+        * @return bool|string
         */
        public function getFileTimestamp( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -339,6 +389,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileSize()
+        * @param $params array
+        * @return bool|int
         */
        public function getFileSize( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -347,6 +399,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileStat()
+        * @param $params array
+        * @return Array|bool|null
         */
        public function getFileStat( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -355,6 +409,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileContents()
+        * @param $params array
+        * @return bool|string
         */
        public function getFileContents( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -363,6 +419,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileSha1Base36()
+        * @param $params array
+        * @return bool|string
         */
        public function getFileSha1Base36( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -371,6 +429,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileProps()
+        * @param $params array
+        * @return Array
         */
        public function getFileProps( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -379,6 +439,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::streamFile()
+        * @param $params array
+        * @return \Status
         */
        public function streamFile( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -387,6 +449,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getLocalReference()
+        * @param $params array
+        * @return FSFile|null
         */
        public function getLocalReference( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -395,6 +459,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getLocalCopy()
+        * @param $params array
+        * @return null|TempFSFile
         */
        public function getLocalCopy( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -403,6 +469,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::directoryExists()
+        * @param $params array
+        * @return bool|null
         */
        public function directoryExists( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -411,6 +479,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getSubdirectoryList()
+        * @param $params array
+        * @return Array|null|Traversable
         */
        public function getDirectoryList( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
@@ -419,6 +489,8 @@ class FileBackendMultiWrite extends FileBackend {
 
        /**
         * @see FileBackend::getFileList()
+        * @param $params array
+        * @return Array|null|\Traversable
         */
        public function getFileList( array $params ) {
                $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );