Completed
Pull Request — master (#347)
by Victor
02:28
created

EnableNotShippedAppsCommand::execute()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 28
ccs 0
cts 20
cp 0
rs 8.439
cc 5
eloc 16
nc 8
nop 2
crap 30
1
<?php
2
/**
3
 * @author Victor Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
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, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace Owncloud\Updater\Command;
23
24
use Symfony\Component\Console\Input\InputArgument;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Input\InputOption;
27
use Symfony\Component\Console\Output\OutputInterface;
28
29
class EnableNotShippedAppsCommand extends Command {
30
31
	protected function configure(){
32
		$this
33
				->setName('upgrade:enableNotShippedApps')
34
				->setDescription('try reenable and upgrade 3rdparty/non shipped apps. (one app after another)')
35
		;
36
	}
37
38
	protected function execute(InputInterface $input, OutputInterface $output){
39
		/** @var \Owncloud\Updater\Utils\Locator $locator */
40
		$locator = $this->container['utils.locator'];
41
		/** @var \Owncloud\Updater\Utils\Checkpoint $checkpoint */
42
		$checkpoint = $this->container['utils.checkpoint'];
43
		/** @var \Owncloud\Updater\Utils\FilesystemHelper $fsHelper */
44
		$fsHelper = $this->container['utils.filesystemhelper'];
45
46
		$registry = $this->container['utils.registry'];
47
48
		$notShippedApps = $registry->get('notShippedApps');
49
		$notShippedApps = is_array($notShippedApps) ? $notShippedApps : [];
50
51
		$lastCheckpointId = $checkpoint->getLastCheckpointId();
52
		$lastCheckpointPath = $checkpoint->getCheckpointPath($lastCheckpointId);
0 ignored issues
show
Bug introduced by
It seems like $lastCheckpointId defined by $checkpoint->getLastCheckpointId() on line 51 can also be of type boolean; however, Owncloud\Updater\Utils\C...nt::getCheckpointPath() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53
		if ($lastCheckpointId){
54
			$oldSourcesDir = $locator->getOwncloudRootPath();
55
			foreach ($notShippedApps as $notShippedApp) {
56
				$fsHelper->copyr($lastCheckpointPath . '/apps/' . $notShippedApp, $oldSourcesDir . '/apps/' . $notShippedApps, false);
57
			}
58
		}
59
60
		/** @var \Owncloud\Updater\Utils\AppManager $appManager */
61
		$appManager = $registry->get('appManager');
62
		if (!is_null($appManager)){
63
			$appManager->reenableNotShippedApps($output);
64
		}
65
	}
66
}
67