Passed
Push — master ( 13e0a9...79e0b5 )
by Morris
09:24
created

SwitchUpdateChannel::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2019, Morris Jobke <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OC\Repair\NC17;
24
25
use OCP\IConfig;
26
use OCP\Migration\IOutput;
27
use OCP\Migration\IRepairStep;
28
use OCP\Support\Subscription\IRegistry;
29
/**
30
 * @deprecated - can be removed in 18
31
 */
32
class SwitchUpdateChannel implements IRepairStep {
33
34
	/** @var IConfig */
35
	private $config;
36
37
	/** @var IRegistry */
38
	private $subscriptionRegistry;
39
40
	public function __construct(IConfig $config, IRegistry $subscriptionRegistry) {
41
		$this->config = $config;
42
		$this->subscriptionRegistry = $subscriptionRegistry;
43
	}
44
45
	public function getName(): string {
46
		return 'Switches from deprecated "production" to "stable" update channel';
47
	}
48
49
	public function run(IOutput $output): void {
50
		$currentChannel = $this->config->getSystemValue('updater.release.channel', 'stable');
51
52
		if ($currentChannel === 'production') {
53
			if ($this->subscriptionRegistry->delegateHasValidSubscription()) {
54
				$this->config->setSystemValue('updater.release.channel', 'enterprise');
55
			} else {
56
				$this->config->setSystemValue('updater.release.channel', 'stable');
57
			}
58
		}
59
	}
60
}
61