Completed
Push — master ( 4a9cb8...f72f55 )
by Morris
12:46
created

InstallCoreBundle::run()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 5
nop 1
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Lukas Reschke <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace OC\Repair\NC12;
23
24
use OC\App\AppStore\Bundles\BundleFetcher;
25
use OC\Installer;
26
use OCP\IConfig;
27
use OCP\Migration\IOutput;
28
use OCP\Migration\IRepairStep;
29
30
class InstallCoreBundle implements IRepairStep {
31
	/** @var BundleFetcher */
32
	private $bundleFetcher;
33
	/** @var IConfig */
34
	private $config;
35
	/** @var Installer */
36
	private $installer;
37
38
	/**
39
	 * @param BundleFetcher $bundleFetcher
40
	 * @param IConfig $config
41
	 * @param Installer $installer
42
	 */
43
	public function __construct(BundleFetcher $bundleFetcher,
44
								IConfig $config,
45
								Installer $installer) {
46
		$this->bundleFetcher = $bundleFetcher;
47
		$this->config = $config;
48
		$this->installer = $installer;
49
	}
50
51
	/**
52
	 * {@inheritdoc}
53
	 */
54
	public function getName() {
55
		return 'Install new core bundle components';
56
	}
57
58
	/**
59
	 * {@inheritdoc}
60
	 */
61
	public function run(IOutput $output) {
62
		$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
63
64
		if (version_compare($versionFromBeforeUpdate, '12.0.0.14', '>')) {
65
			return;
66
		}
67
68
		$defaultBundle = $this->bundleFetcher->getDefaultInstallationBundle();
69
		foreach($defaultBundle as $bundle) {
70
			try {
71
				$this->installer->installAppBundle($bundle);
72
				$output->info('Successfully installed core app bundle.');
73
			} catch (\Exception $e) {
74
				$output->warning('Could not install core app bundle: ' . $e->getMessage());
75
			}
76
		}
77
	}
78
}
79