Completed
Pull Request — stable9 (#2488)
by Robin
06:36
created

console.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Christian Kampka <[email protected]>
7
 * @author Edward Crompton <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Jost Baron <[email protected]>
10
 * @author Lukas Reschke <[email protected]>
11
 * @author Morris Jobke <[email protected]>
12
 * @author Philippe Le Brouster <[email protected]>
13
 * @author Thomas Müller <[email protected]>
14
 * @author Victor Dubiniuk <[email protected]>
15
 *
16
 * @license AGPL-3.0
17
 *
18
 * This code is free software: you can redistribute it and/or modify
19
 * it under the terms of the GNU Affero General Public License, version 3,
20
 * as published by the Free Software Foundation.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License, version 3,
28
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
29
 *
30
 */
31
32
use OC\Console\Application;
33
use Symfony\Component\Console\Input\ArgvInput;
34
use Symfony\Component\Console\Output\ConsoleOutput;
35
36
define('OC_CONSOLE', 1);
37
38
// Show warning if a PHP version below 5.4.0 is used, this has to happen here
39
// because base.php will already use 5.4 syntax.
40
if (version_compare(PHP_VERSION, '5.4.0') === -1) {
41
	echo 'This version of Nextcloud requires at least PHP 5.4.0'.PHP_EOL;
42
	echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
43
	return;
44
}
45
46
// Show warning if PHP 7.1 is used as Nextcloud is not compatible with PHP 7.1 for now
47
// @see https://github.com/nextcloud/docker-ci/issues/10
48 View Code Duplication
if (version_compare(PHP_VERSION, '7.1.0') !== -1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
	echo 'This version of Nextcloud is not compatible with PHP 7.1.<br/>';
50
	echo 'You are currently running ' . PHP_VERSION . '.';
51
	return;
52
}
53
54
try {
55
	require_once __DIR__ . '/lib/base.php';
56
57
	// set to run indefinitely if needed
58
	set_time_limit(0);
59
60
	if (!OC::$CLI) {
61
		echo "This script can be run from the command line only" . PHP_EOL;
62
		exit(0);
63
	}
64
65
	if (!OC_Util::runningOnWindows())  {
66
		if (!function_exists('posix_getuid')) {
67
			echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
68
			exit(0);
69
		}
70
		$user = posix_getpwuid(posix_getuid());
71
		$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
72
		if ($user['name'] !== $configUser['name']) {
73
			echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
74
			echo "Current user: " . $user['name'] . PHP_EOL;
75
			echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
76
			echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;  
77
			exit(0);
78
		}
79
	}
80
81
	$oldWorkingDir = getcwd();
82
	if ($oldWorkingDir === false) {
83
		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
84
		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
85
	} else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
86
		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
87
		echo "Can't change to Nextcloud root directory." . PHP_EOL;
88
		exit(1);
89
	}
90
91
	if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
92
		echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
93
	}
94
95
	$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
96
	$application->loadCommands(new ArgvInput(), new ConsoleOutput());
97
	$application->run();
98
} catch (Exception $ex) {
99
	echo "An unhandled exception has been thrown:" . PHP_EOL;
100
	echo $ex;
101
	exit(1);
102
}
103