Completed
Push — stable10 ( 672c7f...4a51be )
by Roeland
40s
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 Joas Schilling <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Morris Jobke <[email protected]>
9
 * @author Thomas Müller <[email protected]>
10
 * @author Victor Dubiniuk <[email protected]>
11
 *
12
 * @license AGPL-3.0
13
 *
14
 * This code is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License, version 3,
16
 * as published by the Free Software Foundation.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License, version 3,
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
25
 *
26
 */
27
28
use OC\Console\Application;
29
use Symfony\Component\Console\Input\ArgvInput;
30
use Symfony\Component\Console\Output\ConsoleOutput;
31
32
define('OC_CONSOLE', 1);
33
34
// Show warning if a PHP version below 5.4.0 is used, this has to happen here
35
// because base.php will already use 5.4 syntax.
36
if (version_compare(PHP_VERSION, '5.4.0') === -1) {
37
	echo 'This version of Nextcloud requires at least PHP 5.4.0'.PHP_EOL;
38
	echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
39
	return;
40
}
41
42
// Show warning if PHP 7.1 is used as Nextcloud is not compatible with PHP 7.1 for now
43
// @see https://github.com/nextcloud/docker-ci/issues/10
44 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...
45
	echo 'This version of Nextcloud is not compatible with PHP 7.1.<br/>';
46
	echo 'You are currently running ' . PHP_VERSION . '.';
47
	return;
48
}
49
50
function exceptionHandler($exception) {
51
	echo "An unhandled exception has been thrown:" . PHP_EOL;
52
	echo $exception;
53
	exit(1);
54
}
55
try {
56
	require_once __DIR__ . '/lib/base.php';
57
58
	// set to run indefinitely if needed
59
	set_time_limit(0);
60
61
	if (!OC::$CLI) {
62
		echo "This script can be run from the command line only" . PHP_EOL;
63
		exit(0);
64
	}
65
66
	set_exception_handler('exceptionHandler');
67
68
	if (!function_exists('posix_getuid')) {
69
		echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
70
		exit(0);
71
	}
72
	$user = posix_getpwuid(posix_getuid());
73
	$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
74
	if ($user['name'] !== $configUser['name']) {
75
		echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
76
		echo "Current user: " . $user['name'] . PHP_EOL;
77
		echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
78
		echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;  
79
		exit(0);
80
	}
81
82
	$oldWorkingDir = getcwd();
83
	if ($oldWorkingDir === false) {
84
		echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
85
		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
86
	} else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
87
		echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
88
		echo "Can't change to ownCloud root directory." . PHP_EOL;
89
		exit(1);
90
	}
91
92
	if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
93
		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;
94
	}
95
96
	$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
97
	$application->loadCommands(new ArgvInput(), new ConsoleOutput());
98
	$application->run();
99
} catch (Exception $ex) {
100
	exceptionHandler($ex);
101
} catch (Error $ex) {
102
	exceptionHandler($ex);
103
}
104