Merge "Ensure users are able to edit the page after changing the content model"
[lhc/web/wiklou.git] / includes / filebackend / FileOpBatch.php
index 95a7897..e34ad8c 100644 (file)
@@ -45,17 +45,17 @@ class FileOpBatch {
         *   - nonJournaled : Don't log this operation batch in the file journal.
         *   - concurrency  : Try to do this many operations in parallel when possible.
         *
-        * The resulting Status will be "OK" unless:
+        * The resulting StatusValue will be "OK" unless:
         *   - a) unexpected operation errors occurred (network partitions, disk full...)
         *   - b) significant operation errors occurred and 'force' was not set
         *
         * @param FileOp[] $performOps List of FileOp operations
         * @param array $opts Batch operation options
         * @param FileJournal $journal Journal to log operations to
-        * @return Status
+        * @return StatusValue
         */
        public static function attempt( array $performOps, array $opts, FileJournal $journal ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $n = count( $performOps );
                if ( $n > self::MAX_BATCH_SIZE ) {
@@ -69,11 +69,11 @@ class FileOpBatch {
                $journaled = empty( $opts['nonJournaled'] );
                $maxConcurrency = isset( $opts['concurrency'] ) ? $opts['concurrency'] : 1;
 
-               $entries = array(); // file journal entry list
+               $entries = []; // file journal entry list
                $predicates = FileOp::newPredicates(); // account for previous ops in prechecks
-               $curBatch = array(); // concurrent FileOp sub-batch accumulation
+               $curBatch = []; // concurrent FileOp sub-batch accumulation
                $curBatchDeps = FileOp::newDependencies(); // paths used in FileOp sub-batch
-               $pPerformOps = array(); // ordered list of concurrent FileOp sub-batches
+               $pPerformOps = []; // ordered list of concurrent FileOp sub-batches
                $lastBackend = null; // last op backend name
                // Do pre-checks for each operation; abort on failure...
                foreach ( $performOps as $index => $fileOp ) {
@@ -86,7 +86,7 @@ class FileOpBatch {
                                || ( $backendName !== $lastBackend && count( $curBatch ) )
                        ) {
                                $pPerformOps[] = $curBatch; // push this batch
-                               $curBatch = array(); // start a new sub-batch
+                               $curBatch = []; // start a new sub-batch
                                $curBatchDeps = FileOp::newDependencies();
                        }
                        $lastBackend = $backendName;
@@ -119,7 +119,9 @@ class FileOpBatch {
                if ( count( $entries ) ) {
                        $subStatus = $journal->logChangeBatch( $entries, $batchId );
                        if ( !$subStatus->isOK() ) {
-                               return $subStatus; // abort
+                               $status->merge( $subStatus );
+
+                               return $status; // abort
                        }
                }
 
@@ -142,9 +144,9 @@ class FileOpBatch {
         * This will abort remaining ops on failure.
         *
         * @param array $pPerformOps Batches of file ops (batches use original indexes)
-        * @param Status $status
+        * @param StatusValue $status
         */
-       protected static function runParallelBatches( array $pPerformOps, Status $status ) {
+       protected static function runParallelBatches( array $pPerformOps, StatusValue $status ) {
                $aborted = false; // set to true on unexpected errors
                foreach ( $pPerformOps as $performOpsBatch ) {
                        /** @var FileOp[] $performOpsBatch */
@@ -158,13 +160,13 @@ class FileOpBatch {
                                }
                                continue;
                        }
-                       /** @var Status[] $statuses */
-                       $statuses = array();
-                       $opHandles = array();
+                       /** @var StatusValue[] $statuses */
+                       $statuses = [];
+                       $opHandles = [];
                        // Get the backend; all sub-batch ops belong to a single backend
                        $backend = reset( $performOpsBatch )->getBackend();
                        // Get the operation handles or actually do it if there is just one.
-                       // If attemptAsync() returns a Status, it was either due to an error
+                       // If attemptAsync() returns a StatusValue, it was either due to an error
                        // or the backend does not support async ops and did it synchronously.
                        foreach ( $performOpsBatch as $i => $fileOp ) {
                                if ( !isset( $status->success[$i] ) ) { // didn't already fail in precheck()