Passed
Push — master ( 3c693d...ccd5ca )
by Roeland
28:56 queued 14:09
created

InstallCoreBundle::run()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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