Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
}

Expand Down
18 changes: 16 additions & 2 deletions lib/private/Repair/NC12/UpdateLanguageCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OC\Repair\NC12;

use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand All @@ -31,11 +32,17 @@ class UpdateLanguageCodes implements IRepairStep {
/** @var IDBConnection */
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->config = $config;
}

/**
Expand All @@ -49,6 +56,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',
Expand Down
28 changes: 27 additions & 1 deletion tests/lib/Repair/NC12/UpdateLanguageCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace Test\Repair\NC12;

use OC\Repair\NC12\UpdateLanguageCodes;
use OCP\IConfig;
use OCP\Migration\IOutput;
use Test\TestCase;

Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -147,4 +157,20 @@ public function testRun() {
}
}

public function testSecondRun() {
/** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->createMock(IOutput::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something like:

		$outputMock->expects($this->never())
			->method('info');

Otherwise this test always passes, even when I raise the version number

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it myself

$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);
}

}