jenkins-bot has submitted this change and it was merged.
Change subject: filebackend: cleaned up the FileBackend constructor
......................................................................
filebackend: cleaned up the FileBackend constructor
* Added some b/c code with deprecation warnings
Change-Id: Ifceffbc0a37a223bcd7cd3dc60181fc85765bc46
---
M includes/filebackend/FileBackend.php
M includes/filebackend/FileBackendGroup.php
M includes/filebackend/FileBackendMultiWrite.php
M tests/parser/parserTest.inc
M tests/phpunit/includes/LocalFileTest.php
M tests/phpunit/includes/filebackend/FileBackendTest.php
M tests/phpunit/includes/filerepo/FileRepoTest.php
M tests/phpunit/includes/filerepo/StoreBatchTest.php
M tests/phpunit/includes/media/ExifRotationTest.php
M tests/phpunit/includes/media/FormatMetadataTest.php
M tests/phpunit/includes/media/GIFTest.php
M tests/phpunit/includes/media/JpegTest.php
M tests/phpunit/includes/media/PNGTest.php
M tests/phpunit/includes/media/SVGTest.php
M tests/phpunit/includes/parser/NewParserTest.php
M tests/phpunit/suites/UploadFromUrlTestSuite.php
16 files changed, 48 insertions(+), 32 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/filebackend/FileBackend.php
b/includes/filebackend/FileBackend.php
index d042dc4..6e30288 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -91,13 +91,13 @@
* 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 : 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.
+ * - 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.
* - 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,16 +110,21 @@
if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) {
throw new MWException( "Backend name `{$this->name}` is
invalid." );
}
- $this->wikiId = isset( $config['wikiId'] )
- ? $config['wikiId']
- : wfWikiID(); // e.g. "my_wiki-en_"
- $this->lockManager = ( $config['lockManager'] instanceof
LockManager )
+ if ( !isset( $config['wikiId'] ) ) {
+ $config['wikiId'] = wfWikiID();
+ wfDeprecated( __METHOD__ . ' called without "wikiID".',
'1.23' );
+ }
+ if ( isset( $config['lockManager'] ) && !is_object(
$config['lockManager'] ) ) {
+ $config['lockManager'] =
+ LockManagerGroup::singleton( $config['wikiId']
)->get( $config['lockManager'] );
+ wfDeprecated( __METHOD__ . ' called with non-object
"lockManager".', '1.23' );
+ }
+ $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_"
+ $this->lockManager = isset( $config['lockManager'] )
? $config['lockManager']
- : LockManagerGroup::singleton( $this->wikiId )->get(
$config['lockManager'] );
+ : new NullLockManager( array() );
$this->fileJournal = isset( $config['fileJournal'] )
- ? ( ( $config['fileJournal'] instanceof FileJournal )
- ? $config['fileJournal']
- : FileJournal::factory( $config['fileJournal'],
$this->name ) )
+ ? $config['fileJournal']
: 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 491424b..e451e3c 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -152,6 +152,14 @@
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 b3c46c6..cb7a58e 100644
--- a/includes/filebackend/FileBackendMultiWrite.php
+++ b/includes/filebackend/FileBackendMultiWrite.php
@@ -125,8 +125,8 @@
// 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 58ea1ed..39fa09e 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -170,7 +170,7 @@
'transformVia404' => false,
'backend' => new FSFileBackend( array(
'name' => 'local-backend',
- 'lockManager' => 'fsLockManager',
+ 'wikiId' => wfWikiId(),
'containerPaths' => array(
'local-public' => wfTempDir() .
'/test-repo/public',
'local-thumb' => wfTempDir() .
'/test-repo/thumb',
@@ -738,7 +738,7 @@
'transformVia404' => false,
'backend' => new FSFileBackend( array(
'name' => 'local-backend',
- 'lockManager' => 'fsLockManager',
+ 'wikiId' => wfWikiId(),
'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 694f4ae..d210ce5 100644
--- a/tests/phpunit/includes/LocalFileTest.php
+++ b/tests/phpunit/includes/LocalFileTest.php
@@ -21,7 +21,7 @@
'transformVia404' => false,
'backend' => new FSFileBackend( array(
'name' => 'local-backend',
- 'lockManager' => 'fsLockManager',
+ 'wikiId' => wfWikiId(),
'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 fcfa724..072cb7c 100644
--- a/tests/phpunit/includes/filebackend/FileBackendTest.php
+++ b/tests/phpunit/includes/filebackend/FileBackendTest.php
@@ -37,6 +37,8 @@
$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;
@@ -44,9 +46,8 @@
} else {
$this->singleBackend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'fsLockManager',
- #'parallelize' => 'implicit',
- 'wikiId' => wfWikiID() . $uniqueId,
+ 'lockManager' =>
LockManagerGroup::singleton()->get( 'fsLockManager' ),
+ 'wikiId' => wfWikiID(),
'containerPaths' => array(
'unittest-cont1' =>
"{$tmpPrefix}-localtesting-cont1",
'unittest-cont2' =>
"{$tmpPrefix}-localtesting-cont2" )
@@ -54,14 +55,13 @@
}
$this->multiBackend = new FileBackendMultiWrite( array(
'name' => 'localtesting',
- 'lockManager' => 'fsLockManager',
+ 'lockManager' => LockManagerGroup::singleton()->get(
'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,7 +70,6 @@
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 e3a7556..a196dca 100644
--- a/tests/phpunit/includes/filerepo/FileRepoTest.php
+++ b/tests/phpunit/includes/filerepo/FileRepoTest.php
@@ -46,7 +46,7 @@
'name' => 'FileRepoTestRepository',
'backend' => new FSFileBackend( array(
'name' => 'local-testing',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => 'test_wiki',
'containerPaths' => array()
) )
) );
diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php
b/tests/phpunit/includes/filerepo/StoreBatchTest.php
index b33c1bb..8fb85b6 100644
--- a/tests/phpunit/includes/filerepo/StoreBatchTest.php
+++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php
@@ -25,13 +25,15 @@
$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',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiID(),
'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 f4f4154..118dc85 100644
--- a/tests/phpunit/includes/media/ExifRotationTest.php
+++ b/tests/phpunit/includes/media/ExifRotationTest.php
@@ -24,7 +24,7 @@
'url' => 'http://localhost/thumbtest',
'backend' => new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'containerPaths' => array( 'temp-thumb' =>
$tmpDir, 'data' => $filePath )
) )
) );
diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php
b/tests/phpunit/includes/media/FormatMetadataTest.php
index a4f71db..44d8f00 100644
--- a/tests/phpunit/includes/media/FormatMetadataTest.php
+++ b/tests/phpunit/includes/media/FormatMetadataTest.php
@@ -16,7 +16,7 @@
$filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'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 4350cbb..7bd04b7 100644
--- a/tests/phpunit/includes/media/GIFTest.php
+++ b/tests/phpunit/includes/media/GIFTest.php
@@ -16,7 +16,7 @@
$this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'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 bff64bb..a5bf1dc 100644
--- a/tests/phpunit/includes/media/JpegTest.php
+++ b/tests/phpunit/includes/media/JpegTest.php
@@ -18,7 +18,7 @@
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'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 2cb7426..a47dc4a 100644
--- a/tests/phpunit/includes/media/PNGTest.php
+++ b/tests/phpunit/includes/media/PNGTest.php
@@ -16,7 +16,7 @@
$this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'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 b28ee56..eb79098 100644
--- a/tests/phpunit/includes/media/SVGTest.php
+++ b/tests/phpunit/includes/media/SVGTest.php
@@ -10,7 +10,7 @@
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'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 eac4de5..124b477 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -306,6 +306,8 @@
}
}
$useConfig['name'] = 'local-backend'; // swap
name
+ unset( $useConfig['lockManager'] );
+ unset( $useConfig['fileJournal'] );
$class = $conf['class'];
self::$backendToUse = new $class( $useConfig );
$backend = self::$backendToUse;
@@ -316,7 +318,7 @@
# informations.
$backend = new MockFileBackend( array(
'name' => 'local-backend',
- 'lockManager' => 'nullLockManager',
+ 'wikiId' => wfWikiId(),
'containerPaths' => array(
'local-public' => "$uploadDir",
'local-thumb' => "$uploadDir/thumb",
diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php
b/tests/phpunit/suites/UploadFromUrlTestSuite.php
index 7eb599e..fb7780d 100644
--- a/tests/phpunit/suites/UploadFromUrlTestSuite.php
+++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php
@@ -36,7 +36,7 @@
'transformVia404' => false,
'backend' => new FSFileBackend( array(
'name' => 'local-backend',
- 'lockManager' => 'fsLockManager',
+ 'wikiId' => wfWikiId(),
'containerPaths' => array(
'local-public' => wfTempDir() .
'/test-repo/public',
'local-thumb' => wfTempDir() .
'/test-repo/thumb',
--
To view, visit https://gerrit.wikimedia.org/r/98959
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifceffbc0a37a223bcd7cd3dc60181fc85765bc46
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits