]> source.dussan.org Git - nextcloud-server.git/commitdiff
Execute UpdateLanguageCode only once
authorMorris Jobke <hey@morrisjobke.de>
Thu, 2 Mar 2017 18:12:19 +0000 (12:12 -0600)
committerMorris Jobke <hey@morrisjobke.de>
Fri, 3 Mar 2017 03:53:36 +0000 (21:53 -0600)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/Repair/NC12/UpdateLanguageCodes.php
tests/lib/Repair/NC12/UpdateLanguageCodesTest.php

index ed65a5cbbe323c631b75882a196010be1869feff..69f06df83e9744091ca29b2d811a2fa63c3d5155 100644 (file)
@@ -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 @@ class UpdateLanguageCodes implements IRepairStep {
         * {@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',
index 95ccd0935a1508fceab1ab2de3022cc0c23261ce..dfb5ea099f7c3d06e976bd7f99606925ba7182ca 100644 (file)
@@ -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 @@ class UpdateLanguageCodesTest extends TestCase {
                        ->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 @@ class UpdateLanguageCodesTest extends TestCase {
                }
        }
 
+       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);
+       }
+
 }