jenkins-bot has submitted this change and it was merged.
Change subject: Provide a smooth migration path of dblist files to dblists/
......................................................................
Provide a smooth migration path of dblist files to dblists/
Facilitate a smooth transition of dblists file from the repository root to the
dblists/ subdirectory by making MWWikiversions::readDbListFile() try a fallback
file path when the specified $srcPath doesn't exist: for file paths with the
form '/foo/bar.dblist', try '/foo/dblists/bar.dblist', and vice versa.
Change-Id: I9d4cbd3d67f746a07c3f5e6e9f837fc1d8db952a
---
M multiversion/MWWikiversions.php
M tests/dblistTest.php
2 files changed, 44 insertions(+), 1 deletion(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/multiversion/MWWikiversions.php b/multiversion/MWWikiversions.php
index 8a20900..a8e173a 100644
--- a/multiversion/MWWikiversions.php
+++ b/multiversion/MWWikiversions.php
@@ -67,13 +67,38 @@
}
/**
+ * Get an alternate file path for dblist file represented by $path.
+ *
+ * Map '/foo/bar.dblist' to '/foo/dblists/bar.dblist' and vice versa.
+ *
+ * @param $path string
+ * @return string
+ */
+ public static function getAlternatePath( $path ) {
+ $dirName = dirname( $path );
+ if ( basename( $dirName ) !== 'dblists' ) {
+ return $dirName . '/dblists/' . basename( $path );
+ } else {
+ return dirname( $dirName ) . '/' . basename( $path );
+ }
+ }
+
+ /**
* Get an array of DB names from a .dblist file.
*
* @param $srcPath string
* @return Array
*/
public static function readDbListFile( $srcPath ) {
- $lines = @file( $srcPath, FILE_IGNORE_NEW_LINES |
FILE_SKIP_EMPTY_LINES );
+ $flags = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;
+ $lines = @file( $srcPath, $flags );
+
+ // Provide a means of migrating dblist files to `dblists/`
+ // by checking both `/foo/bar.dblist` and
`/foo/dblists/bar.dblist`.
+ if ( !$lines ) {
+ $lines = @file( self::getAlternatePath( $srcPath ),
$flags );
+ }
+
if ( !$lines ) {
throw new Exception( "Unable to read $srcPath.\n" );
}
diff --git a/tests/dblistTest.php b/tests/dblistTest.php
index c0f6695..3fda3a1 100644
--- a/tests/dblistTest.php
+++ b/tests/dblistTest.php
@@ -94,5 +94,23 @@
$this->assertEquals( $exprDbs, $expectedDbs );
}
+ /**
+ * @covers MWWikiversions::getAlternatePath
+ */
+ function testGetAlternatePath() {
+ $variants = array(
+ '/foo/bar/baz.dblist',
+ '/foo/bar/dblists/baz.dblist',
+ );
+ $this->assertEquals(
+ $variants[0],
+ MWWikiversions::getAlternatePath( $variants[1] )
+ );
+ $this->assertEquals(
+ $variants[1],
+ MWWikiversions::getAlternatePath( $variants[0] )
+ );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/244733
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9d4cbd3d67f746a07c3f5e6e9f837fc1d8db952a
Gerrit-PatchSet: 2
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits