jenkins-bot has submitted this change and it was merged.

Change subject: Move some FileBackend related classes to /libs
......................................................................


Move some FileBackend related classes to /libs

Change-Id: I0c3a84c2ed8b869519f4d38475a77539c24a88a8
---
M autoload.php
M includes/filebackend/FileBackendGroup.php
R includes/libs/filebackend/FileBackend.php
A includes/libs/filebackend/FileBackendException.php
R includes/libs/filebackend/filejournal/FileJournal.php
A includes/libs/filebackend/filejournal/NullFileJournal.php
R includes/libs/lockmanager/ScopedLock.php
M tests/phpunit/includes/filebackend/FileBackendTest.php
8 files changed, 94 insertions(+), 92 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index ff7d488..998450c 100644
--- a/autoload.php
+++ b/autoload.php
@@ -454,10 +454,10 @@
        'Field' => __DIR__ . '/includes/libs/rdbms/field/Field.php',
        'File' => __DIR__ . '/includes/filerepo/file/File.php',
        'FileAwareNodeVisitor' => __DIR__ . '/maintenance/findDeprecated.php',
-       'FileBackend' => __DIR__ . '/includes/filebackend/FileBackend.php',
+       'FileBackend' => __DIR__ . '/includes/libs/filebackend/FileBackend.php',
        'FileBackendDBRepoWrapper' => __DIR__ . 
'/includes/filerepo/FileBackendDBRepoWrapper.php',
-       'FileBackendError' => __DIR__ . '/includes/filebackend/FileBackend.php',
-       'FileBackendException' => __DIR__ . 
'/includes/filebackend/FileBackend.php',
+       'FileBackendError' => __DIR__ . 
'/includes/libs/filebackend/FileBackendException.php',
+       'FileBackendException' => __DIR__ . 
'/includes/libs/filebackend/FileBackendException.php',
        'FileBackendGroup' => __DIR__ . 
'/includes/filebackend/FileBackendGroup.php',
        'FileBackendMultiWrite' => __DIR__ . 
'/includes/filebackend/FileBackendMultiWrite.php',
        'FileBackendStore' => __DIR__ . 
'/includes/filebackend/FileBackendStore.php',
@@ -471,7 +471,7 @@
        'FileDeleteForm' => __DIR__ . '/includes/FileDeleteForm.php',
        'FileDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
        'FileDuplicateSearchPage' => __DIR__ . 
'/includes/specials/SpecialFileDuplicateSearch.php',
-       'FileJournal' => __DIR__ . 
'/includes/filebackend/filejournal/FileJournal.php',
+       'FileJournal' => __DIR__ . 
'/includes/libs/filebackend/filejournal/FileJournal.php',
        'FileOp' => __DIR__ . '/includes/filebackend/FileOp.php',
        'FileOpBatch' => __DIR__ . '/includes/filebackend/FileOpBatch.php',
        'FileRepo' => __DIR__ . '/includes/filerepo/FileRepo.php',
@@ -975,7 +975,7 @@
        'NotRecursiveIterator' => __DIR__ . 
'/includes/utils/iterators/NotRecursiveIterator.php',
        'NukeNS' => __DIR__ . '/maintenance/nukeNS.php',
        'NukePage' => __DIR__ . '/maintenance/nukePage.php',
-       'NullFileJournal' => __DIR__ . 
'/includes/filebackend/filejournal/FileJournal.php',
+       'NullFileJournal' => __DIR__ . 
'/includes/libs/filebackend/filejournal/NullFileJournal.php',
        'NullFileOp' => __DIR__ . '/includes/filebackend/FileOp.php',
        'NullIndexField' => __DIR__ . '/includes/search/NullIndexField.php',
        'NullJob' => __DIR__ . '/includes/jobqueue/jobs/NullJob.php',
@@ -1228,7 +1228,7 @@
        'Sanitizer' => __DIR__ . '/includes/Sanitizer.php',
        'SavepointPostgres' => __DIR__ . '/includes/db/DatabasePostgres.php',
        'ScopedCallback' => __DIR__ . '/includes/libs/ScopedCallback.php',
-       'ScopedLock' => __DIR__ . 
'/includes/filebackend/lockmanager/ScopedLock.php',
+       'ScopedLock' => __DIR__ . '/includes/libs/lockmanager/ScopedLock.php',
        'SearchApi' => __DIR__ . '/includes/api/SearchApi.php',
        'SearchDatabase' => __DIR__ . '/includes/search/SearchDatabase.php',
        'SearchDump' => __DIR__ . '/maintenance/dumpIterator.php',
diff --git a/includes/filebackend/FileBackendGroup.php 
b/includes/filebackend/FileBackendGroup.php
index 57461a4..0bae5ff 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -167,6 +167,7 @@
                                : FileJournal::factory( [ 'class' => 
'NullFileJournal' ], $name );
                        $config['wanCache'] = ObjectCache::getMainWANInstance();
                        $config['mimeCallback'] = [ $this, 'guessMimeInternal' 
];
+                       $config['statusWrapper'] = [ 'Status', 'wrap' ];
 
                        $this->backends[$name]['instance'] = new $class( 
$config );
                }
diff --git a/includes/filebackend/FileBackend.php 
b/includes/libs/filebackend/FileBackend.php
similarity index 98%
rename from includes/filebackend/FileBackend.php
rename to includes/libs/filebackend/FileBackend.php
index ed2bdcc..4ff342f 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/libs/filebackend/FileBackend.php
@@ -159,8 +159,7 @@
                $this->concurrency = isset( $config['concurrency'] )
                        ? (int)$config['concurrency']
                        : 50;
-               // @TODO: dependency inject this
-               $this->statusWrapper = [ 'Status', 'wrap' ];
+               $this->statusWrapper = isset( $config['statusWrapper'] ) ? 
$config['statusWrapper'] : null;
        }
 
        /**
@@ -1564,22 +1563,4 @@
        final protected function wrapStatus( StatusValue $sv ) {
                return $this->statusWrapper ? call_user_func( 
$this->statusWrapper, $sv ) : $sv;
        }
-}
-
-/**
- * Generic file backend exception for checked and unexpected (e.g. config) 
exceptions
- *
- * @ingroup FileBackend
- * @since 1.23
- */
-class FileBackendException extends Exception {
-}
-
-/**
- * File backend exception for checked exceptions (e.g. I/O errors)
- *
- * @ingroup FileBackend
- * @since 1.22
- */
-class FileBackendError extends FileBackendException {
 }
diff --git a/includes/libs/filebackend/FileBackendException.php 
b/includes/libs/filebackend/FileBackendException.php
new file mode 100644
index 0000000..949bce8
--- /dev/null
+++ b/includes/libs/filebackend/FileBackendException.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Generic file backend exception for checked and unexpected (e.g. config) 
exceptions
+ *
+ * @ingroup FileBackend
+ * @since 1.23
+ */
+class FileBackendException extends Exception {
+}
+
+/**
+ * File backend exception for checked exceptions (e.g. I/O errors)
+ *
+ * @ingroup FileBackend
+ * @since 1.22
+ */
+class FileBackendError extends FileBackendException {
+}
diff --git a/includes/filebackend/filejournal/FileJournal.php 
b/includes/libs/filebackend/filejournal/FileJournal.php
similarity index 83%
rename from includes/filebackend/filejournal/FileJournal.php
rename to includes/libs/filebackend/filejournal/FileJournal.php
index f0bb92d..116c303 100644
--- a/includes/filebackend/filejournal/FileJournal.php
+++ b/includes/libs/filebackend/filejournal/FileJournal.php
@@ -64,7 +64,7 @@
                $class = $config['class'];
                $jrn = new $class( $config );
                if ( !$jrn instanceof self ) {
-                       throw new Exception( "Class given is not an instance of 
FileJournal." );
+                       throw new InvalidArgumentException( "Class given is not 
an instance of FileJournal." );
                }
                $jrn->backend = $backend;
 
@@ -197,55 +197,4 @@
         * @return StatusValue
         */
        abstract protected function doPurgeOldLogs();
-}
-
-/**
- * Simple version of FileJournal that does nothing
- * @since 1.20
- */
-class NullFileJournal extends FileJournal {
-       /**
-        * @see FileJournal::doLogChangeBatch()
-        * @param array $entries
-        * @param string $batchId
-        * @return StatusValue
-        */
-       protected function doLogChangeBatch( array $entries, $batchId ) {
-               return StatusValue::newGood();
-       }
-
-       /**
-        * @see FileJournal::doGetCurrentPosition()
-        * @return int|bool
-        */
-       protected function doGetCurrentPosition() {
-               return false;
-       }
-
-       /**
-        * @see FileJournal::doGetPositionAtTime()
-        * @param int|string $time Timestamp
-        * @return int|bool
-        */
-       protected function doGetPositionAtTime( $time ) {
-               return false;
-       }
-
-       /**
-        * @see FileJournal::doGetChangeEntries()
-        * @param int $start
-        * @param int $limit
-        * @return array
-        */
-       protected function doGetChangeEntries( $start, $limit ) {
-               return [];
-       }
-
-       /**
-        * @see FileJournal::doPurgeOldLogs()
-        * @return StatusValue
-        */
-       protected function doPurgeOldLogs() {
-               return StatusValue::newGood();
-       }
 }
diff --git a/includes/libs/filebackend/filejournal/NullFileJournal.php 
b/includes/libs/filebackend/filejournal/NullFileJournal.php
new file mode 100644
index 0000000..8d472ab
--- /dev/null
+++ b/includes/libs/filebackend/filejournal/NullFileJournal.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Simple version of FileJournal that does nothing
+ * @since 1.20
+ */
+class NullFileJournal extends FileJournal {
+       /**
+        * @see FileJournal::doLogChangeBatch()
+        * @param array $entries
+        * @param string $batchId
+        * @return StatusValue
+        */
+       protected function doLogChangeBatch( array $entries, $batchId ) {
+               return StatusValue::newGood();
+       }
+
+       /**
+        * @see FileJournal::doGetCurrentPosition()
+        * @return int|bool
+        */
+       protected function doGetCurrentPosition() {
+               return false;
+       }
+
+       /**
+        * @see FileJournal::doGetPositionAtTime()
+        * @param int|string $time Timestamp
+        * @return int|bool
+        */
+       protected function doGetPositionAtTime( $time ) {
+               return false;
+       }
+
+       /**
+        * @see FileJournal::doGetChangeEntries()
+        * @param int $start
+        * @param int $limit
+        * @return array
+        */
+       protected function doGetChangeEntries( $start, $limit ) {
+               return [];
+       }
+
+       /**
+        * @see FileJournal::doPurgeOldLogs()
+        * @return StatusValue
+        */
+       protected function doPurgeOldLogs() {
+               return StatusValue::newGood();
+       }
+}
diff --git a/includes/filebackend/lockmanager/ScopedLock.php 
b/includes/libs/lockmanager/ScopedLock.php
similarity index 96%
rename from includes/filebackend/lockmanager/ScopedLock.php
rename to includes/libs/lockmanager/ScopedLock.php
index 05ab289..ac8bee8 100644
--- a/includes/filebackend/lockmanager/ScopedLock.php
+++ b/includes/libs/lockmanager/ScopedLock.php
@@ -46,7 +46,9 @@
         * @param array $pathsByType Map of lock types to path lists
         * @param StatusValue $status
         */
-       protected function __construct( LockManager $manager, array 
$pathsByType, StatusValue $status ) {
+       protected function __construct(
+               LockManager $manager, array $pathsByType, StatusValue $status
+       ) {
                $this->manager = $manager;
                $this->pathsByType = $pathsByType;
                $this->status = $status;
diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php 
b/tests/phpunit/includes/filebackend/FileBackendTest.php
index 254cfbd..d023b32 100644
--- a/tests/phpunit/includes/filebackend/FileBackendTest.php
+++ b/tests/phpunit/includes/filebackend/FileBackendTest.php
@@ -1914,7 +1914,7 @@
                        // Does nothing
                ], [ 'force' => 1 ] );
 
-               $this->assertNotEquals( [], $status->errors, "Operation had 
warnings" );
+               $this->assertNotEquals( [], $status->getErrors(), "Operation 
had warnings" );
                $this->assertEquals( true, $status->isOK(), "Operation batch 
succeeded" );
                $this->assertEquals( 8, count( $status->success ),
                        "Operation batch has correct success array" );
@@ -2371,25 +2371,25 @@
 
                for ( $i = 0; $i < 25; $i++ ) {
                        $status = $this->backend->lockFiles( $paths, 
LockManager::LOCK_EX );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->lockFiles( $paths, 
LockManager::LOCK_SH );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->unlockFiles( $paths, 
LockManager::LOCK_SH );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->unlockFiles( $paths, 
LockManager::LOCK_EX );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName). 
($i)" );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
@@ -2397,25 +2397,25 @@
                        # # Flip the acquire/release ordering around ##
 
                        $status = $this->backend->lockFiles( $paths, 
LockManager::LOCK_SH );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->lockFiles( $paths, 
LockManager::LOCK_EX );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->unlockFiles( $paths, 
LockManager::LOCK_EX );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName). 
($i)" );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
 
                        $status = $this->backend->unlockFiles( $paths, 
LockManager::LOCK_SH );
-                       $this->assertEquals( print_r( [], true ), print_r( 
$status->errors, true ),
+                       $this->assertEquals( print_r( [], true ), print_r( 
$status->getErrors(), true ),
                                "Locking of files succeeded ($backendName) 
($i)." );
                        $this->assertEquals( true, $status->isOK(),
                                "Locking of files succeeded with OK status 
($backendName) ($i)." );
@@ -2425,7 +2425,7 @@
                $sl = $this->backend->getScopedFileLocks( $paths, 
LockManager::LOCK_EX, $status );
                $this->assertInstanceOf( 'ScopedLock', $sl,
                        "Scoped locking of files succeeded ($backendName)." );
-               $this->assertEquals( [], $status->errors,
+               $this->assertEquals( [], $status->getErrors(),
                        "Scoped locking of files succeeded ($backendName)." );
                $this->assertEquals( true, $status->isOK(),
                        "Scoped locking of files succeeded with OK status 
($backendName)." );
@@ -2433,7 +2433,7 @@
                ScopedLock::release( $sl );
                $this->assertEquals( null, $sl,
                        "Scoped unlocking of files succeeded ($backendName)." );
-               $this->assertEquals( [], $status->errors,
+               $this->assertEquals( [], $status->getErrors(),
                        "Scoped unlocking of files succeeded ($backendName)." );
                $this->assertEquals( true, $status->isOK(),
                        "Scoped unlocking of files succeeded with OK status 
($backendName)." );
@@ -2647,7 +2647,7 @@
                }
        }
 
-       function assertGoodStatus( $status, $msg ) {
-               $this->assertEquals( print_r( [], 1 ), print_r( 
$status->errors, 1 ), $msg );
+       function assertGoodStatus( StatusValue $status, $msg ) {
+               $this->assertEquals( print_r( [], 1 ), print_r( 
$status->getErrors(), 1 ), $msg );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/311347
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0c3a84c2ed8b869519f4d38475a77539c24a88a8
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to