From 0b12eb06403687d700fdcfc130f3dcc7164518ea Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 2 Mar 2017 12:12:19 -0600 Subject: [PATCH 1/3] Execute UpdateLanguageCode only once Signed-off-by: Morris Jobke --- .../Repair/NC12/UpdateLanguageCodes.php | 15 ++++++++++- .../Repair/NC12/UpdateLanguageCodesTest.php | 26 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/private/Repair/NC12/UpdateLanguageCodes.php b/lib/private/Repair/NC12/UpdateLanguageCodes.php index ed65a5cbbe323..69f06df83e974 100644 --- a/lib/private/Repair/NC12/UpdateLanguageCodes.php +++ b/lib/private/Repair/NC12/UpdateLanguageCodes.php @@ -23,6 +23,7 @@ namespace OC\Repair\NC12; +use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -31,11 +32,16 @@ class UpdateLanguageCodes implements IRepairStep { /** @var IDBConnection */ private $connection; + /** @var IConfig */ + private $config; + /** * @param IDBConnection $db */ - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, + IConfig $config) { $this->connection = $connection; + $this->config = $config; } /** @@ -49,6 +55,13 @@ public function getName() { * {@inheritdoc} */ public function run(IOutput $output) { + + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + + if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) { + return; + } + $languages = [ 'bg_BG' => 'bg', 'cs_CZ' => 'cs', diff --git a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php index 95ccd0935a150..dfb5ea099f7c3 100644 --- a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php +++ b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php @@ -24,6 +24,7 @@ namespace Test\Repair\NC12; use OC\Repair\NC12\UpdateLanguageCodes; +use OCP\IConfig; use OCP\Migration\IOutput; use Test\TestCase; @@ -38,10 +39,14 @@ class UpdateLanguageCodesTest extends TestCase { /** @var \OCP\IDBConnection */ protected $connection; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + private $config; + protected function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); + $this->config = $this->createMock(IConfig::class); } public function testRun() { @@ -112,8 +117,13 @@ public function testRun() { ->method('info') ->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 - $repair = new UpdateLanguageCodes($this->connection); + $repair = new UpdateLanguageCodes($this->connection, $this->config); $repair->run($outputMock); // check if test data is correctly modified in DB @@ -147,4 +157,18 @@ public function testRun() { } } + public function testSecondRun() { + /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->createMock(IOutput::class); + + $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); + } + } From 342ee51dad64652720f86edf92f10f5a9ac54bae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 3 Mar 2017 12:01:38 +0100 Subject: [PATCH 2/3] Make the test useful Signed-off-by: Joas Schilling --- tests/lib/Repair/NC12/UpdateLanguageCodesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php index dfb5ea099f7c3..4379d1ba589a6 100644 --- a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php +++ b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php @@ -160,6 +160,8 @@ public function testRun() { 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') From 0beb78517fa06a27509161f5b77d1bf8fec91054 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 3 Mar 2017 12:20:02 +0100 Subject: [PATCH 3/3] Fix DI Signed-off-by: Joas Schilling --- lib/private/Repair.php | 2 +- lib/private/Repair/NC12/UpdateLanguageCodes.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 7f142a808aa3c..e808774ec935d 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -135,7 +135,7 @@ public static function getRepairSteps() { \OC::$server->getConfig() ), new FixMountStorages(\OC::$server->getDatabaseConnection()), - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection()), + new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), ]; } diff --git a/lib/private/Repair/NC12/UpdateLanguageCodes.php b/lib/private/Repair/NC12/UpdateLanguageCodes.php index 69f06df83e974..891473f51a711 100644 --- a/lib/private/Repair/NC12/UpdateLanguageCodes.php +++ b/lib/private/Repair/NC12/UpdateLanguageCodes.php @@ -36,7 +36,8 @@ class UpdateLanguageCodes implements IRepairStep { private $config; /** - * @param IDBConnection $db + * @param IDBConnection $connection + * @param IConfig $config */ public function __construct(IDBConnection $connection, IConfig $config) {