From 2f29c7551b3106f75eb4a3818c295e5ef9919a47 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 3 Dec 2013 20:40:24 +0000 Subject: [PATCH] Revert "filebackend: cleaned up the FileBackend constructor" Actually this messes with the implicit backend made for things like Math (when unconfigured), which uses the "new" operator. This reverts commit 1f129a22cbc8546b89dd4b49b2f567c1f758a968. Change-Id: I4c72c4f7c8b82e38df5496cf2b90fc9e19c40334 --- includes/filebackend/FileBackend.php | 20 +++++++++++-------- includes/filebackend/FileBackendGroup.php | 8 -------- .../filebackend/FileBackendMultiWrite.php | 2 +- tests/parser/parserTest.inc | 4 ++-- tests/phpunit/includes/LocalFileTest.php | 2 +- .../includes/filebackend/FileBackendTest.php | 11 +++++----- .../includes/filerepo/FileRepoTest.php | 2 +- .../includes/filerepo/StoreBatchTest.php | 4 +--- .../includes/media/ExifRotationTest.php | 2 +- .../includes/media/FormatMetadataTest.php | 2 +- tests/phpunit/includes/media/GIFTest.php | 2 +- tests/phpunit/includes/media/JpegTest.php | 2 +- tests/phpunit/includes/media/PNGTest.php | 2 +- tests/phpunit/includes/media/SVGTest.php | 2 +- .../phpunit/includes/parser/NewParserTest.php | 4 +--- .../phpunit/suites/UploadFromUrlTestSuite.php | 2 +- 16 files changed, 32 insertions(+), 39 deletions(-) diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php index f007cae5d9..d042dc4ba3 100644 --- a/includes/filebackend/FileBackend.php +++ b/includes/filebackend/FileBackend.php @@ -91,13 +91,13 @@ abstract class FileBackend { * This name should not be changed after use (e.g. with journaling). * Note that the name is *not* used in actual container names. * - wikiId : Prefix to container names that is unique to this backend. + * If not provided, this defaults to the current wiki ID. * It should only consist of alphanumberic, '-', and '_' characters. * This ID is what avoids collisions if multiple logical backends * use the same storage system, so this should be set carefully. - * - lockManager : LockManager object to use for any file locking. - * If not provided, then no file locking will be enforced. - * - fileJournal : FileJournal object to use for logging changes to files. - * If not provided, then change journaling will be disabled. + * - lockManager : Registered name of a file lock manager to use. + * - fileJournal : File journal configuration; see FileJournal::factory(). + * Journals simply log changes to files stored in the backend. * - readOnly : Write operations are disallowed if this is a non-empty string. * It should be an explanation for the backend being read-only. * - parallelize : When to do file operations in parallel (when possible). @@ -110,12 +110,16 @@ abstract class FileBackend { if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) { throw new MWException( "Backend name `{$this->name}` is invalid." ); } - $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_" - $this->lockManager = isset( $config['lockManager'] ) + $this->wikiId = isset( $config['wikiId'] ) + ? $config['wikiId'] + : wfWikiID(); // e.g. "my_wiki-en_" + $this->lockManager = ( $config['lockManager'] instanceof LockManager ) ? $config['lockManager'] - : new NullLockManager( array() ); + : LockManagerGroup::singleton( $this->wikiId )->get( $config['lockManager'] ); $this->fileJournal = isset( $config['fileJournal'] ) - ? $config['fileJournal'] + ? ( ( $config['fileJournal'] instanceof FileJournal ) + ? $config['fileJournal'] + : FileJournal::factory( $config['fileJournal'], $this->name ) ) : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $this->name ); $this->readOnly = isset( $config['readOnly'] ) ? (string)$config['readOnly'] diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index e451e3c102..491424bf61 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -152,14 +152,6 @@ class FileBackendGroup { if ( !isset( $this->backends[$name]['instance'] ) ) { $class = $this->backends[$name]['class']; $config = $this->backends[$name]['config']; - $config['wikiId'] = isset( $config['wikiId'] ) - ? $config['wikiId'] - : wfWikiID(); // e.g. "my_wiki-en_" - $config['lockManager'] = - LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $name ); $this->backends[$name]['instance'] = new $class( $config ); } diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php index cb7a58e79e..b3c46c6121 100644 --- a/includes/filebackend/FileBackendMultiWrite.php +++ b/includes/filebackend/FileBackendMultiWrite.php @@ -125,8 +125,8 @@ class FileBackendMultiWrite extends FileBackend { // Alter certain sub-backend settings for sanity unset( $config['readOnly'] ); // use proxy backend setting unset( $config['fileJournal'] ); // use proxy backend journal - unset( $config['lockManager'] ); // lock under proxy backend $config['wikiId'] = $this->wikiId; // use the proxy backend wiki ID + $config['lockManager'] = 'nullLockManager'; // lock under proxy backend if ( !empty( $config['isMultiMaster'] ) ) { if ( $this->masterIndex >= 0 ) { throw new MWException( 'More than one master backend defined.' ); diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 39fa09e24d..58ea1ed0b1 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -170,7 +170,7 @@ class ParserTest { 'transformVia404' => false, 'backend' => new FSFileBackend( array( 'name' => 'local-backend', - 'wikiId' => wfWikiId(), + 'lockManager' => 'fsLockManager', 'containerPaths' => array( 'local-public' => wfTempDir() . '/test-repo/public', 'local-thumb' => wfTempDir() . '/test-repo/thumb', @@ -738,7 +738,7 @@ class ParserTest { 'transformVia404' => false, 'backend' => new FSFileBackend( array( 'name' => 'local-backend', - 'wikiId' => wfWikiId(), + 'lockManager' => 'fsLockManager', 'containerPaths' => array( 'local-public' => $this->uploadDir, 'local-thumb' => $this->uploadDir . '/thumb', diff --git a/tests/phpunit/includes/LocalFileTest.php b/tests/phpunit/includes/LocalFileTest.php index d210ce51b5..694f4aef35 100644 --- a/tests/phpunit/includes/LocalFileTest.php +++ b/tests/phpunit/includes/LocalFileTest.php @@ -21,7 +21,7 @@ class LocalFileTest extends MediaWikiTestCase { 'transformVia404' => false, 'backend' => new FSFileBackend( array( 'name' => 'local-backend', - 'wikiId' => wfWikiId(), + 'lockManager' => 'fsLockManager', 'containerPaths' => array( 'cont1' => "/testdir/local-backend/tempimages/cont1", 'cont2' => "/testdir/local-backend/tempimages/cont2" diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index 072cb7c524..fcfa724fc5 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -37,8 +37,6 @@ class FileBackendTest extends MediaWikiTestCase { $useConfig['shardViaHashLevels'] = array( // test sharding 'unittest-cont1' => array( 'levels' => 1, 'base' => 16, 'repeat' => 1 ) ); - $useConfig['fileJournal'] = FileJournal::factory( $config['fileJournal'], $name ); - $useConfig['lockManager'] = LockManagerGroup::singleton()->get( $useConfig['lockManager'] ); $class = $useConfig['class']; self::$backendToUse = new $class( $useConfig ); $this->singleBackend = self::$backendToUse; @@ -46,8 +44,9 @@ class FileBackendTest extends MediaWikiTestCase { } else { $this->singleBackend = new FSFileBackend( array( 'name' => 'localtesting', - 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), - 'wikiId' => wfWikiID(), + 'lockManager' => 'fsLockManager', + #'parallelize' => 'implicit', + 'wikiId' => wfWikiID() . $uniqueId, 'containerPaths' => array( 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" ) @@ -55,13 +54,14 @@ class FileBackendTest extends MediaWikiTestCase { } $this->multiBackend = new FileBackendMultiWrite( array( 'name' => 'localtesting', - 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), + 'lockManager' => 'fsLockManager', 'parallelize' => 'implicit', 'wikiId' => wfWikiId() . $uniqueId, 'backends' => array( array( 'name' => 'localmultitesting1', 'class' => 'FSFileBackend', + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ), @@ -70,6 +70,7 @@ class FileBackendTest extends MediaWikiTestCase { array( 'name' => 'localmultitesting2', 'class' => 'FSFileBackend', + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ), diff --git a/tests/phpunit/includes/filerepo/FileRepoTest.php b/tests/phpunit/includes/filerepo/FileRepoTest.php index a196dca83b..e3a755673d 100644 --- a/tests/phpunit/includes/filerepo/FileRepoTest.php +++ b/tests/phpunit/includes/filerepo/FileRepoTest.php @@ -46,7 +46,7 @@ class FileRepoTest extends MediaWikiTestCase { 'name' => 'FileRepoTestRepository', 'backend' => new FSFileBackend( array( 'name' => 'local-testing', - 'wikiId' => 'test_wiki', + 'lockManager' => 'nullLockManager', 'containerPaths' => array() ) ) ) ); diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php index 8fb85b6946..b33c1bbb39 100644 --- a/tests/phpunit/includes/filerepo/StoreBatchTest.php +++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php @@ -25,15 +25,13 @@ class StoreBatchTest extends MediaWikiTestCase { $useConfig = $conf; } } - $useConfig['lockManager'] = LockManagerGroup::singleton()->get( $useConfig['lockManager'] ); - unset( $useConfig['fileJournal'] ); $useConfig['name'] = 'local-testing'; // swap name $class = $useConfig['class']; $backend = new $class( $useConfig ); } else { $backend = new FSFileBackend( array( 'name' => 'local-testing', - 'wikiId' => wfWikiID(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'unittests-public' => "{$tmpPrefix}-public", 'unittests-thumb' => "{$tmpPrefix}-thumb", diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php index 118dc851fd..f4f415428b 100644 --- a/tests/phpunit/includes/media/ExifRotationTest.php +++ b/tests/phpunit/includes/media/ExifRotationTest.php @@ -24,7 +24,7 @@ class ExifRotationTest extends MediaWikiTestCase { 'url' => 'http://localhost/thumbtest', 'backend' => new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath ) ) ) ) ); diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index 44d8f004f0..a4f71db547 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -16,7 +16,7 @@ class FormatMetadataTest extends MediaWikiTestCase { $filePath = __DIR__ . '/../../data/media'; $this->backend = new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'data' => $filePath ) ) ); $this->repo = new FSRepo( array( diff --git a/tests/phpunit/includes/media/GIFTest.php b/tests/phpunit/includes/media/GIFTest.php index 7bd04b7c90..4350cbbad3 100644 --- a/tests/phpunit/includes/media/GIFTest.php +++ b/tests/phpunit/includes/media/GIFTest.php @@ -16,7 +16,7 @@ class GIFHandlerTest extends MediaWikiTestCase { $this->filePath = __DIR__ . '/../../data/media'; $this->backend = new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'data' => $this->filePath ) ) ); $this->repo = new FSRepo( array( diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php index a5bf1dcf4a..bff64bbe74 100644 --- a/tests/phpunit/includes/media/JpegTest.php +++ b/tests/phpunit/includes/media/JpegTest.php @@ -18,7 +18,7 @@ class JpegTest extends MediaWikiTestCase { $this->backend = new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'data' => $this->filePath ) ) ); $this->repo = new FSRepo( array( diff --git a/tests/phpunit/includes/media/PNGTest.php b/tests/phpunit/includes/media/PNGTest.php index a47dc4a5a8..2cb7426062 100644 --- a/tests/phpunit/includes/media/PNGTest.php +++ b/tests/phpunit/includes/media/PNGTest.php @@ -16,7 +16,7 @@ class PNGHandlerTest extends MediaWikiTestCase { $this->filePath = __DIR__ . '/../../data/media'; $this->backend = new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'data' => $this->filePath ) ) ); $this->repo = new FSRepo( array( diff --git a/tests/phpunit/includes/media/SVGTest.php b/tests/phpunit/includes/media/SVGTest.php index eb790986ad..b28ee56c9b 100644 --- a/tests/phpunit/includes/media/SVGTest.php +++ b/tests/phpunit/includes/media/SVGTest.php @@ -10,7 +10,7 @@ class SVGTest extends MediaWikiTestCase { $this->backend = new FSFileBackend( array( 'name' => 'localtesting', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'data' => $this->filePath ) ) ); $this->repo = new FSRepo( array( diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 124b477ffc..eac4de5c0c 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -306,8 +306,6 @@ class NewParserTest extends MediaWikiTestCase { } } $useConfig['name'] = 'local-backend'; // swap name - unset( $useConfig['lockManager'] ); - unset( $useConfig['fileJournal'] ); $class = $conf['class']; self::$backendToUse = new $class( $useConfig ); $backend = self::$backendToUse; @@ -318,7 +316,7 @@ class NewParserTest extends MediaWikiTestCase { # informations. $backend = new MockFileBackend( array( 'name' => 'local-backend', - 'wikiId' => wfWikiId(), + 'lockManager' => 'nullLockManager', 'containerPaths' => array( 'local-public' => "$uploadDir", 'local-thumb' => "$uploadDir/thumb", diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php b/tests/phpunit/suites/UploadFromUrlTestSuite.php index fb7780d0ec..7eb599e393 100644 --- a/tests/phpunit/suites/UploadFromUrlTestSuite.php +++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php @@ -36,7 +36,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { 'transformVia404' => false, 'backend' => new FSFileBackend( array( 'name' => 'local-backend', - 'wikiId' => wfWikiId(), + 'lockManager' => 'fsLockManager', 'containerPaths' => array( 'local-public' => wfTempDir() . '/test-repo/public', 'local-thumb' => wfTempDir() . '/test-repo/thumb', -- 2.20.1