From 8a573aa1f5fed19b9eea49525c60d997d86e65a4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 18 Sep 2016 00:54:54 -0700 Subject: [PATCH] Move some FileBackend related classes to /libs Change-Id: I0c3a84c2ed8b869519f4d38475a77539c24a88a8 --- autoload.php | 12 ++--- includes/filebackend/FileBackendGroup.php | 1 + .../{ => libs}/filebackend/FileBackend.php | 21 +------- .../libs/filebackend/FileBackendException.php | 18 +++++++ .../filebackend/filejournal/FileJournal.php | 53 +------------------ .../filejournal/NullFileJournal.php | 51 ++++++++++++++++++ .../lockmanager/ScopedLock.php | 4 +- .../includes/filebackend/FileBackendTest.php | 26 ++++----- 8 files changed, 94 insertions(+), 92 deletions(-) rename includes/{ => libs}/filebackend/FileBackend.php (99%) create mode 100644 includes/libs/filebackend/FileBackendException.php rename includes/{ => libs}/filebackend/filejournal/FileJournal.php (83%) create mode 100644 includes/libs/filebackend/filejournal/NullFileJournal.php rename includes/{filebackend => libs}/lockmanager/ScopedLock.php (96%) diff --git a/autoload.php b/autoload.php index ff7d488205..998450ced1 100644 --- a/autoload.php +++ b/autoload.php @@ -454,10 +454,10 @@ $wgAutoloadLocalClasses = [ '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 @@ $wgAutoloadLocalClasses = [ '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 @@ $wgAutoloadLocalClasses = [ '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 @@ $wgAutoloadLocalClasses = [ '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 57461a48ea..0bae5ffea2 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -167,6 +167,7 @@ class FileBackendGroup { : 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 99% rename from includes/filebackend/FileBackend.php rename to includes/libs/filebackend/FileBackend.php index ed2bdcc140..4ff342f929 100644 --- a/includes/filebackend/FileBackend.php +++ b/includes/libs/filebackend/FileBackend.php @@ -159,8 +159,7 @@ abstract class FileBackend { $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; } /** @@ -1565,21 +1564,3 @@ abstract class FileBackend { 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 0000000000..949bce838c --- /dev/null +++ b/includes/libs/filebackend/FileBackendException.php @@ -0,0 +1,18 @@ +backend = $backend; @@ -198,54 +198,3 @@ abstract class FileJournal { */ 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 0000000000..8d472abf2c --- /dev/null +++ b/includes/libs/filebackend/filejournal/NullFileJournal.php @@ -0,0 +1,51 @@ +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 254cfbd677..d023b32d5f 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -1914,7 +1914,7 @@ class FileBackendTest extends MediaWikiTestCase { // 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 @@ class FileBackendTest extends MediaWikiTestCase { 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 @@ class FileBackendTest extends MediaWikiTestCase { # # 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 @@ class FileBackendTest extends MediaWikiTestCase { $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 @@ class FileBackendTest extends MediaWikiTestCase { 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 @@ class FileBackendTest extends MediaWikiTestCase { } } - 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 ); } } -- 2.20.1