DCausse has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/335645 )
Change subject: Allow defining the name of the default TTM service
......................................................................
Allow defining the name of the default TTM service
'TTMServer' is assumed to be the default service to use.
This patch makes this value configurable in
$wgTranslateTranslationDefaultService.
This is a preliminary patch to support multi-DC configuration
for TTM services.
Allowing to override wgTranslateTranslationDefaultService will
help to switch between different services without changing
a specific service configuration.
Change-Id: I41ab5462993a9a5177cb1f075d5699ba1abcd6bd
---
M Translate.php
M api/ApiSearchTranslations.php
M api/ApiTTMServer.php
M scripts/ttmserver-export.php
M tests/phpunit/SolrTTMServerTest.php
M tests/phpunit/TTMServerTest.php
M ttmserver/TTMServer.php
7 files changed, 22 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/45/335645/1
diff --git a/Translate.php b/Translate.php
index e051196..b4b8f6c 100644
--- a/Translate.php
+++ b/Translate.php
@@ -266,6 +266,7 @@
* - source text to translate
* - private API key if provided
*/
+$wgTranslateTranslationDefaultService = 'TTMServer';
$wgTranslateTranslationServices = array();
$wgTranslateTranslationServices['TTMServer'] = array(
'database' => false, // Passed to wfGetDB
diff --git a/api/ApiSearchTranslations.php b/api/ApiSearchTranslations.php
index 7fa29e3..c2f10eb 100644
--- a/api/ApiSearchTranslations.php
+++ b/api/ApiSearchTranslations.php
@@ -55,14 +55,15 @@
}
public function getAllowedParams() {
- global $wgLanguageCode;
+ global $wgLanguageCode,
+ $wgTranslateTranslationDefaultService;
$available = $this->getAvailableTranslationServices();
$filters = $this->getAllowedFilters();
return array(
'service' => array(
ApiBase::PARAM_TYPE => $available,
- ApiBase::PARAM_DFLT => 'TTMServer',
+ ApiBase::PARAM_DFLT =>
$wgTranslateTranslationDefaultService,
),
'query' => array(
ApiBase::PARAM_TYPE => 'string',
diff --git a/api/ApiTTMServer.php b/api/ApiTTMServer.php
index a227c81..980a0af 100644
--- a/api/ApiTTMServer.php
+++ b/api/ApiTTMServer.php
@@ -52,12 +52,13 @@
}
public function getAllowedParams() {
+ global $wgTranslateTranslationDefaultService;
$available = $this->getAvailableTranslationServices();
return array(
'service' => array(
ApiBase::PARAM_TYPE => $available,
- ApiBase::PARAM_DFLT => 'TTMServer',
+ ApiBase::PARAM_DFLT =>
$wgTranslateTranslationDefaultService,
),
'sourcelanguage' => array(
ApiBase::PARAM_TYPE => 'string',
diff --git a/scripts/ttmserver-export.php b/scripts/ttmserver-export.php
index fab1f2c..74bd003 100644
--- a/scripts/ttmserver-export.php
+++ b/scripts/ttmserver-export.php
@@ -58,10 +58,11 @@
}
public function execute() {
- global $wgTranslateTranslationServices;
+ global $wgTranslateTranslationServices,
+ $wgTranslateTranslationDefaultService;
// TTMServer is the id of the enabled-by-default instance
- $configKey = $this->getOption( 'ttmserver', 'TTMServer' );
+ $configKey = $this->getOption( 'ttmserver',
$wgTranslateTranslationDefaultService );
if ( !isset( $wgTranslateTranslationServices[$configKey] ) ) {
$this->error( 'Translation memory is not configured
properly', 1 );
}
diff --git a/tests/phpunit/SolrTTMServerTest.php
b/tests/phpunit/SolrTTMServerTest.php
index bbf19c2..18994a4 100644
--- a/tests/phpunit/SolrTTMServerTest.php
+++ b/tests/phpunit/SolrTTMServerTest.php
@@ -15,12 +15,15 @@
protected function setUp() {
parent::setUp();
- global $wgHooks, $wgTranslateTranslationServices,
$wgTranslateTestTTMServer;
+ global $wgHooks,
+ $wgTranslateTranslationServices,
+ $wgTranslateTranslationDefaultService,
+ $wgTranslateTestTTMServer;
$this->setMwGlobals( array(
'wgHooks' => $wgHooks,
'wgTranslateTranslationServices' => array(),
) );
- $wgTranslateTranslationServices['TTMServer'] =
$wgTranslateTestTTMServer;
+
$wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] =
$wgTranslateTestTTMServer;
$wgHooks['TranslatePostInitGroups'] = array( array( $this,
'addGroups' ) );
diff --git a/tests/phpunit/TTMServerTest.php b/tests/phpunit/TTMServerTest.php
index c5869ce..5274cd0 100644
--- a/tests/phpunit/TTMServerTest.php
+++ b/tests/phpunit/TTMServerTest.php
@@ -48,8 +48,9 @@
get_class( $server ),
'Fake server given when default server is disabled'
);
- global $wgTranslateTranslationServices;
- $wgTranslateTranslationServices['TTMServer'] = array(
+ global $wgTranslateTranslationServices,
+ $wgTranslateTranslationDefaultService;
+
$wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] = array(
'database' => false, // Passed to wfGetDB
'cutoff' => 0.75,
'type' => 'ttmserver',
@@ -61,7 +62,7 @@
get_class( $server ),
'Real server given when default server is enabled'
);
- unset( $wgTranslateTranslationServices['TTMServer'] );
+ unset(
$wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] );
}
public function testFakeTTMServer() {
diff --git a/ttmserver/TTMServer.php b/ttmserver/TTMServer.php
index 58a970e..6dea072 100644
--- a/ttmserver/TTMServer.php
+++ b/ttmserver/TTMServer.php
@@ -48,9 +48,10 @@
* @return WritableTTMServer
*/
public static function primary() {
- global $wgTranslateTranslationServices;
- if ( isset( $wgTranslateTranslationServices['TTMServer'] ) ) {
- $obj = self::factory(
$wgTranslateTranslationServices['TTMServer'] );
+ global $wgTranslateTranslationServices,
+ $wgTranslateTranslationDefaultService;
+ if ( isset(
$wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] ) ) {
+ $obj = self::factory(
$wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] );
if ( $obj instanceof WritableTTMServer ) {
return $obj;
}
--
To view, visit https://gerrit.wikimedia.org/r/335645
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I41ab5462993a9a5177cb1f075d5699ba1abcd6bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits