https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113413

Revision: 113413
Author:   aaron
Date:     2012-03-08 22:34:28 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
MFT r113412

Modified Paths:
--------------
    branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php
    branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php
    branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php

Property Changed:
----------------
    branches/wmf/1.19wmf1/
    branches/wmf/1.19wmf1/includes/


Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111795,111802-111803,111827,111881,111920,111965-111967,112021,112034,112037,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112100,112128,112132-112133,112141,112152,112169-112170,112172-112173,112179,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112533-112534,112563,112566,112573,112700,112750,112839-112840,112843,112855,112866,112951,112995,113039,113085,113099,113169,113312
   + /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111795,111802-111803,111827,111881,111920,111965-111967,112021,112034,112037,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112100,112128,112132-112133,112141,112152,112169-112170,112172-112173,112179,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112533-112534,112563,112566,112573,112700,112750,112839-112840,112843,112855,112866,112951,112995,113039,113085,113099,113169,113312,113412


Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112951,112995,113099,113169,113312
   + /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112951,112995,113099,113169,113312,113412

Modified: branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php
===================================================================
--- branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php     
2012-03-08 22:31:04 UTC (rev 113412)
+++ branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php     
2012-03-08 22:34:28 UTC (rev 113413)
@@ -180,8 +180,9 @@
         * Return value:
         * This returns a Status, which contains all warnings and fatals that 
occured
         * during the operation. The 'failCount', 'successCount', and 'success' 
members
-        * will reflect each operation attempted. The status will be "OK" 
unless any
-        * of the operations failed and the 'force' parameter was not set.
+        * will reflect each operation attempted. The status will be "OK" 
unless:
+        *     a) unexpected operation errors occurred (network partitions, 
disk full...)
+        *     b) significant operation errors occured and 'force' was not set
         * 
         * @param $ops Array List of operations to execute in order
         * @param $opts Array Batch operation options

Modified: branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php
===================================================================
--- branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php  2012-03-08 
22:31:04 UTC (rev 113412)
+++ branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php  2012-03-08 
22:34:28 UTC (rev 113413)
@@ -81,6 +81,10 @@
         * '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.
+        *
+        * The resulting Status will be "OK" unless:
+        *     a) unexpected operation errors occurred (network partitions, 
disk full...)
+        *     b) significant operation errors occured and 'force' was not set
         * 
         * @param $performOps Array List of FileOp operations
         * @param $opts Array Batch operation options
@@ -115,6 +119,11 @@
                        }
                }
 
+               if ( $ignoreErrors ) {
+                       # Treat all precheck() fatals as merely warnings
+                       $status->setResult( true, $status->value );
+               }
+
                // Restart PHP's execution timer and set the timeout to safe 
amount.
                // This handles cases where the operations take a long time or 
where we are
                // already running low on time left. The old timeout is 
restored afterwards.

Modified: 
branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php
===================================================================
--- branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php   
2012-03-08 22:31:04 UTC (rev 113412)
+++ branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php   
2012-03-08 22:34:28 UTC (rev 113413)
@@ -1032,6 +1032,16 @@
                $this->doTestDoOperations();
                $this->tearDownFiles();
 
+               $this->backend = $this->singleBackend;
+               $this->tearDownFiles();
+               $this->doTestDoOperationsFailing();
+               $this->tearDownFiles();
+
+               $this->backend = $this->multiBackend;
+               $this->tearDownFiles();
+               $this->doTestDoOperationsFailing();
+               $this->tearDownFiles();
+
                // @TODO: test some cases where the ops should fail
        }
 
@@ -1055,9 +1065,9 @@
 
                $status = $this->backend->doOperations( array(
                        array( 'op' => 'copy', 'src' => $fileA, 'dst' => 
$fileC, 'overwrite' => 1 ),
-                       // Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal 
contents>)
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal 
contents>)
                        array( 'op' => 'copy', 'src' => $fileC, 'dst' => 
$fileA, 'overwriteSame' => 1 ),
-                       // Now: A:<A>, B:<B>, C:<A>, D:<D>
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty>
                        array( 'op' => 'move', 'src' => $fileC, 'dst' => 
$fileD, 'overwrite' => 1 ),
                        // Now: A:<A>, B:<B>, C:<empty>, D:<A>
                        array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC 
),
@@ -1107,6 +1117,68 @@
                        "Correct file SHA-1 of $fileC" );
        }
 
+       function doTestDoOperationsFailing() {
+               $base = $this->baseStorePath();
+
+               $fileA = "$base/unittest-cont2/a/b/fileA.txt";
+               $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
+               $fileB = "$base/unittest-cont2/a/b/fileB.txt";
+               $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
+               $fileC = "$base/unittest-cont2/a/b/fileC.txt";
+               $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
+               $fileD = "$base/unittest-cont2/a/b/fileD.txt";
+
+               $this->prepare( array( 'dir' => dirname( $fileA ) ) );
+               $this->backend->create( array( 'dst' => $fileA, 'content' => 
$fileAContents ) );
+               $this->prepare( array( 'dir' => dirname( $fileB ) ) );
+               $this->backend->create( array( 'dst' => $fileB, 'content' => 
$fileBContents ) );
+               $this->prepare( array( 'dir' => dirname( $fileC ) ) );
+               $this->backend->create( array( 'dst' => $fileC, 'content' => 
$fileCContents ) );
+
+               $status = $this->backend->doOperations( array(
+                       array( 'op' => 'copy', 'src' => $fileA, 'dst' => 
$fileC, 'overwrite' => 1 ),
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal 
contents>)
+                       array( 'op' => 'copy', 'src' => $fileC, 'dst' => 
$fileA, 'overwriteSame' => 1 ),
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty>
+                       array( 'op' => 'copy', 'src' => $fileB, 'dst' => 
$fileD, 'overwrite' => 1 ),
+                       // Now: A:<A>, B:<B>, C:<A>, D:<B>
+                       array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD 
),
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
+                       array( 'op' => 'move', 'src' => $fileB, 'dst' => 
$fileC, 'overwriteSame' => 1 ),
+                       // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
+                       array( 'op' => 'move', 'src' => $fileB, 'dst' => 
$fileA, 'overwrite' => 1 ),
+                       // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
+                       array( 'op' => 'delete', 'src' => $fileD ),
+                       // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
+                       array( 'op' => 'null' ),
+                       // Does nothing
+               ), array( 'force' => 1 ) );
+
+               $this->assertNotEquals( array(), $status->errors, "Operation 
had warnings" );
+               $this->assertEquals( true, $status->isOK(), "Operation batch 
succeeded" );
+               $this->assertEquals( 8, count( $status->success ),
+                       "Operation batch has correct success array" );
+
+               $this->assertEquals( false, $this->backend->fileExists( array( 
'src' => $fileB ) ),
+                       "File does not exist at $fileB" );
+               $this->assertEquals( false, $this->backend->fileExists( array( 
'src' => $fileD ) ),
+                       "File does not exist at $fileD" );
+
+               $this->assertEquals( true, $this->backend->fileExists( array( 
'src' => $fileA ) ),
+                       "File does not exist at $fileA" );
+               $this->assertEquals( true, $this->backend->fileExists( array( 
'src' => $fileC ) ),
+                       "File exists at $fileC" );
+               $this->assertEquals( $fileBContents,
+                       $this->backend->getFileContents( array( 'src' => $fileA 
) ),
+                       "Correct file contents of $fileA" );
+               $this->assertEquals( strlen( $fileBContents ),
+                       $this->backend->getFileSize( array( 'src' => $fileA ) ),
+                       "Correct file size of $fileA" );
+               $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 
36, 31 ),
+                       $this->backend->getFileSha1Base36( array( 'src' => 
$fileA ) ),
+                       "Correct file SHA-1 of $fileA" );
+       }
+
        public function testGetFileList() {
                $this->backend = $this->singleBackend;
                $this->tearDownFiles();


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to