Merge pull request #3684 from nextcloud/run-lang-update-only-once
Execute UpdateLanguageCode only once
This commit is contained in:
commit
8e27b8197d
|
@ -135,7 +135,7 @@ class Repair implements IOutput{
|
||||||
\OC::$server->getConfig()
|
\OC::$server->getConfig()
|
||||||
),
|
),
|
||||||
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
||||||
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection()),
|
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace OC\Repair\NC12;
|
namespace OC\Repair\NC12;
|
||||||
|
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\Migration\IOutput;
|
use OCP\Migration\IOutput;
|
||||||
use OCP\Migration\IRepairStep;
|
use OCP\Migration\IRepairStep;
|
||||||
|
@ -31,11 +32,17 @@ class UpdateLanguageCodes implements IRepairStep {
|
||||||
/** @var IDBConnection */
|
/** @var IDBConnection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
|
/** @var IConfig */
|
||||||
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IDBConnection $db
|
* @param IDBConnection $connection
|
||||||
|
* @param IConfig $config
|
||||||
*/
|
*/
|
||||||
public function __construct(IDBConnection $connection) {
|
public function __construct(IDBConnection $connection,
|
||||||
|
IConfig $config) {
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +56,13 @@ class UpdateLanguageCodes implements IRepairStep {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function run(IOutput $output) {
|
public function run(IOutput $output) {
|
||||||
|
|
||||||
|
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
|
||||||
|
|
||||||
|
if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$languages = [
|
$languages = [
|
||||||
'bg_BG' => 'bg',
|
'bg_BG' => 'bg',
|
||||||
'cs_CZ' => 'cs',
|
'cs_CZ' => 'cs',
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
namespace Test\Repair\NC12;
|
namespace Test\Repair\NC12;
|
||||||
|
|
||||||
use OC\Repair\NC12\UpdateLanguageCodes;
|
use OC\Repair\NC12\UpdateLanguageCodes;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\Migration\IOutput;
|
use OCP\Migration\IOutput;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
|
@ -38,10 +39,14 @@ class UpdateLanguageCodesTest extends TestCase {
|
||||||
/** @var \OCP\IDBConnection */
|
/** @var \OCP\IDBConnection */
|
||||||
protected $connection;
|
protected $connection;
|
||||||
|
|
||||||
|
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $config;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC::$server->getDatabaseConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
|
$this->config = $this->createMock(IConfig::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRun() {
|
public function testRun() {
|
||||||
|
@ -112,8 +117,13 @@ class UpdateLanguageCodesTest extends TestCase {
|
||||||
->method('info')
|
->method('info')
|
||||||
->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.');
|
->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.');
|
||||||
|
|
||||||
|
$this->config->expects($this->once())
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('version', '0.0.0')
|
||||||
|
->willReturn('12.0.0.13');
|
||||||
|
|
||||||
// run repair step
|
// run repair step
|
||||||
$repair = new UpdateLanguageCodes($this->connection);
|
$repair = new UpdateLanguageCodes($this->connection, $this->config);
|
||||||
$repair->run($outputMock);
|
$repair->run($outputMock);
|
||||||
|
|
||||||
// check if test data is correctly modified in DB
|
// check if test data is correctly modified in DB
|
||||||
|
@ -147,4 +157,20 @@ class UpdateLanguageCodesTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSecondRun() {
|
||||||
|
/** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */
|
||||||
|
$outputMock = $this->createMock(IOutput::class);
|
||||||
|
$outputMock->expects($this->never())
|
||||||
|
->method('info');
|
||||||
|
|
||||||
|
$this->config->expects($this->once())
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('version', '0.0.0')
|
||||||
|
->willReturn('12.0.0.14');
|
||||||
|
|
||||||
|
// run repair step
|
||||||
|
$repair = new UpdateLanguageCodes($this->connection, $this->config);
|
||||||
|
$repair->run($outputMock);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue