Translate the maintenance mode message in webdav

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2020-05-06 18:11:54 +02:00
parent afc5966558
commit ecbc009e2f
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
12 changed files with 42 additions and 20 deletions

View File

@ -82,7 +82,7 @@ $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
$server->setBaseUri($baseuri);
// Add plugins
$server->addPlugin(new MaintenancePlugin());
$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new \Sabre\CalDAV\Plugin());

View File

@ -80,7 +80,7 @@ $server::$exposeVersion = false;
$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
$server->setBaseUri($baseuri);
// Add plugins
$server->addPlugin(new MaintenancePlugin());
$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new Plugin());

View File

@ -55,7 +55,8 @@ $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
\OC::$server->getTagManager(),
\OC::$server->getRequest(),
\OC::$server->getPreviewManager(),
\OC::$server->getEventDispatcher()
\OC::$server->getEventDispatcher(),
\OC::$server->getL10N('dav')
);
$requestUri = \OC::$server->getRequest()->getRequestUri();

View File

@ -46,7 +46,8 @@ $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
\OC::$server->getTagManager(),
\OC::$server->getRequest(),
\OC::$server->getPreviewManager(),
\OC::$server->getEventDispatcher()
\OC::$server->getEventDispatcher(),
\OC::$server->getL10N('dav')
);
// Backends

View File

@ -35,7 +35,7 @@ ignore_user_abort(true);
$requestUri = \OC::$server->getRequest()->getRequestUri();
$serverFactory = new \OCA\DAV\Direct\ServerFactory(\OC::$server->getConfig());
$serverFactory = new \OCA\DAV\Direct\ServerFactory(\OC::$server->getConfig(), \OC::$server->getL10N('dav'));
$server = $serverFactory->createServer(
$baseuri,
$requestUri,

View File

@ -52,7 +52,7 @@ class InvitationResponseServer {
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
// Add maintenance plugin
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
// Set URL explicitly due to reverse-proxy situations
$this->server->httpRequest->setUrl($baseUri);

View File

@ -28,6 +28,7 @@
namespace OCA\DAV\Connector\Sabre;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Util;
use Sabre\DAV\Exception\ServiceUnavailable;
use Sabre\DAV\ServerPlugin;
@ -37,6 +38,9 @@ class MaintenancePlugin extends ServerPlugin {
/** @var IConfig */
private $config;
/** @var \OCP\IL10N */
private $l10n;
/**
* Reference to main server object
*
@ -47,11 +51,9 @@ class MaintenancePlugin extends ServerPlugin {
/**
* @param IConfig $config
*/
public function __construct(IConfig $config = null) {
public function __construct(IConfig $config, IL10N $l10n) {
$this->config = $config;
if (is_null($config)) {
$this->config = \OC::$server->getConfig();
}
$this->l10n = \OC::$server->getL10N('dav');
}
@ -80,10 +82,10 @@ class MaintenancePlugin extends ServerPlugin {
*/
public function checkMaintenanceMode() {
if ($this->config->getSystemValueBool('maintenance')) {
throw new ServiceUnavailable('System in maintenance mode.');
throw new ServiceUnavailable($this->l10n->t('System in maintenance mode.'));
}
if (Util::needUpgrade()) {
throw new ServiceUnavailable('Upgrade needed');
throw new ServiceUnavailable($this->l10n->t('Upgrade needed'));
}
return true;

View File

@ -38,6 +38,7 @@ use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IPreview;
use OCP\IRequest;
@ -66,6 +67,8 @@ class ServerFactory {
private $previewManager;
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var IL10N */
private $l10n;
/**
* @param IConfig $config
@ -86,7 +89,8 @@ class ServerFactory {
ITagManager $tagManager,
IRequest $request,
IPreview $previewManager,
EventDispatcherInterface $eventDispatcher
EventDispatcherInterface $eventDispatcher,
IL10N $l10n
) {
$this->config = $config;
$this->logger = $logger;
@ -97,6 +101,7 @@ class ServerFactory {
$this->request = $request;
$this->previewManager = $previewManager;
$this->eventDispatcher = $eventDispatcher;
$this->l10n = $l10n;
}
/**
@ -118,7 +123,7 @@ class ServerFactory {
$server->setBaseUri($baseUri);
// Load plugins
$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin());
$server->addPlugin($authPlugin);

View File

@ -31,14 +31,18 @@ use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
class ServerFactory {
/** @var IConfig */
private $config;
/** @var IL10N */
private $l10n;
public function __construct(IConfig $config) {
public function __construct(IConfig $config, IL10N $l10n) {
$this->config = $config;
$this->l10n = $l10n;
}
public function createServer(string $baseURI,
@ -54,7 +58,7 @@ class ServerFactory {
$server->httpRequest->setUrl($requestURI);
$server->setBaseUri($baseURI);
$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n));
return $server;
}

View File

@ -92,7 +92,7 @@ class Server {
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
// Add maintenance plugin
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
// Backends
$authBackend = new Auth(

View File

@ -28,6 +28,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
use OCP\IConfig;
use OCP\IL10N;
use Test\TestCase;
/**
@ -38,6 +39,8 @@ use Test\TestCase;
class MaintenancePluginTest extends TestCase {
/** @var IConfig */
private $config;
/** @var \PHPUnit\Framework\MockObject\Builder\InvocationMocker|\PHPUnit_Framework_MockObject_Builder_InvocationMocker|IL10N */
private $l10n;
/** @var MaintenancePlugin */
private $maintenancePlugin;
@ -45,7 +48,8 @@ class MaintenancePluginTest extends TestCase {
parent::setUp();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
$this->maintenancePlugin = new MaintenancePlugin($this->config);
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->maintenancePlugin = new MaintenancePlugin($this->config, $this->l10n);
}
@ -58,6 +62,10 @@ class MaintenancePluginTest extends TestCase {
->method('getSystemValueBool')
->with('maintenance')
->willReturn(true);
$this->l10n
->expects($this->any())
->method('t')
->willReturnArgument(0);
$this->maintenancePlugin->checkMaintenanceMode();
}

View File

@ -70,7 +70,8 @@ abstract class RequestTestCase extends TestCase {
->disableOriginalConstructor()
->getMock(),
\OC::$server->getPreviewManager(),
\OC::$server->getEventDispatcher()
\OC::$server->getEventDispatcher(),
\OC::$server->getL10N('dav')
);
}