@@ -23,98 +23,98 @@ |
||
| 23 | 23 | define('OC_CONSOLE', 1); |
| 24 | 24 | |
| 25 | 25 | function exceptionHandler($exception) { |
| 26 | - echo 'An unhandled exception has been thrown:' . PHP_EOL; |
|
| 27 | - echo $exception; |
|
| 28 | - exit(1); |
|
| 26 | + echo 'An unhandled exception has been thrown:' . PHP_EOL; |
|
| 27 | + echo $exception; |
|
| 28 | + exit(1); |
|
| 29 | 29 | } |
| 30 | 30 | try { |
| 31 | - require_once __DIR__ . '/lib/base.php'; |
|
| 32 | - |
|
| 33 | - // set to run indefinitely if needed |
|
| 34 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 35 | - @set_time_limit(0); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (!OC::$CLI) { |
|
| 39 | - echo 'This script can be run from the command line only' . PHP_EOL; |
|
| 40 | - exit(1); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $config = Server::get(IConfig::class); |
|
| 44 | - set_exception_handler('exceptionHandler'); |
|
| 45 | - |
|
| 46 | - if (!function_exists('posix_getuid')) { |
|
| 47 | - echo 'The posix extensions are required - see https://www.php.net/manual/en/book.posix.php' . PHP_EOL; |
|
| 48 | - exit(1); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $user = posix_getuid(); |
|
| 52 | - $configUser = fileowner(OC::$configDir . 'config.php'); |
|
| 53 | - if ($user !== $configUser) { |
|
| 54 | - echo 'Console has to be executed with the user that owns the file config/config.php' . PHP_EOL; |
|
| 55 | - echo 'Current user id: ' . $user . PHP_EOL; |
|
| 56 | - echo 'Owner id of config.php: ' . $configUser . PHP_EOL; |
|
| 57 | - echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 58 | - echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL; |
|
| 59 | - exit(1); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $oldWorkingDir = getcwd(); |
|
| 63 | - if ($oldWorkingDir === false) { |
|
| 64 | - echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 65 | - echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 66 | - } elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
|
| 67 | - echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 68 | - echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 69 | - exit(1); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) { |
|
| 73 | - echo 'The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php' . PHP_EOL; |
|
| 74 | - echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $eventLogger = Server::get(IEventLogger::class); |
|
| 78 | - $eventLogger->start('console:build_application', 'Build Application instance and load commands'); |
|
| 79 | - |
|
| 80 | - $application = Server::get(Application::class); |
|
| 81 | - /* base.php will have removed eventual debug options from argv in $_SERVER */ |
|
| 82 | - $argv = $_SERVER['argv']; |
|
| 83 | - $input = new ArgvInput($argv); |
|
| 84 | - $output = new ConsoleOutput(); |
|
| 85 | - $application->loadCommands($input, $output); |
|
| 86 | - |
|
| 87 | - $eventLogger->end('console:build_application'); |
|
| 88 | - $eventLogger->start('console:run', 'Run the command'); |
|
| 89 | - |
|
| 90 | - $application->setAutoExit(false); |
|
| 91 | - $exitCode = $application->run($input); |
|
| 92 | - |
|
| 93 | - $eventLogger->end('console:run'); |
|
| 94 | - |
|
| 95 | - $profiler = Server::get(IProfiler::class); |
|
| 96 | - if ($profiler->isEnabled()) { |
|
| 97 | - $eventLogger->end('runtime'); |
|
| 98 | - $profile = $profiler->collect(Server::get(IRequest::class), new Response()); |
|
| 99 | - $profile->setMethod('occ'); |
|
| 100 | - $profile->setUrl(implode(' ', $argv)); |
|
| 101 | - $profiler->saveProfile($profile); |
|
| 102 | - |
|
| 103 | - $urlGenerator = Server::get(\OCP\IURLGenerator::class); |
|
| 104 | - $url = $urlGenerator->linkToRouteAbsolute('profiler.main.profiler', [ |
|
| 105 | - 'profiler' => 'db', |
|
| 106 | - 'token' => $profile->getToken(), |
|
| 107 | - ]); |
|
| 108 | - $output->getErrorOutput()->writeln('Profiler output available at ' . $url); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if ($exitCode > 255) { |
|
| 112 | - $exitCode = 255; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - exit($exitCode); |
|
| 31 | + require_once __DIR__ . '/lib/base.php'; |
|
| 32 | + |
|
| 33 | + // set to run indefinitely if needed |
|
| 34 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 35 | + @set_time_limit(0); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (!OC::$CLI) { |
|
| 39 | + echo 'This script can be run from the command line only' . PHP_EOL; |
|
| 40 | + exit(1); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $config = Server::get(IConfig::class); |
|
| 44 | + set_exception_handler('exceptionHandler'); |
|
| 45 | + |
|
| 46 | + if (!function_exists('posix_getuid')) { |
|
| 47 | + echo 'The posix extensions are required - see https://www.php.net/manual/en/book.posix.php' . PHP_EOL; |
|
| 48 | + exit(1); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $user = posix_getuid(); |
|
| 52 | + $configUser = fileowner(OC::$configDir . 'config.php'); |
|
| 53 | + if ($user !== $configUser) { |
|
| 54 | + echo 'Console has to be executed with the user that owns the file config/config.php' . PHP_EOL; |
|
| 55 | + echo 'Current user id: ' . $user . PHP_EOL; |
|
| 56 | + echo 'Owner id of config.php: ' . $configUser . PHP_EOL; |
|
| 57 | + echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 58 | + echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL; |
|
| 59 | + exit(1); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $oldWorkingDir = getcwd(); |
|
| 63 | + if ($oldWorkingDir === false) { |
|
| 64 | + echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 65 | + echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 66 | + } elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
|
| 67 | + echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 68 | + echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 69 | + exit(1); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) { |
|
| 73 | + echo 'The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php' . PHP_EOL; |
|
| 74 | + echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $eventLogger = Server::get(IEventLogger::class); |
|
| 78 | + $eventLogger->start('console:build_application', 'Build Application instance and load commands'); |
|
| 79 | + |
|
| 80 | + $application = Server::get(Application::class); |
|
| 81 | + /* base.php will have removed eventual debug options from argv in $_SERVER */ |
|
| 82 | + $argv = $_SERVER['argv']; |
|
| 83 | + $input = new ArgvInput($argv); |
|
| 84 | + $output = new ConsoleOutput(); |
|
| 85 | + $application->loadCommands($input, $output); |
|
| 86 | + |
|
| 87 | + $eventLogger->end('console:build_application'); |
|
| 88 | + $eventLogger->start('console:run', 'Run the command'); |
|
| 89 | + |
|
| 90 | + $application->setAutoExit(false); |
|
| 91 | + $exitCode = $application->run($input); |
|
| 92 | + |
|
| 93 | + $eventLogger->end('console:run'); |
|
| 94 | + |
|
| 95 | + $profiler = Server::get(IProfiler::class); |
|
| 96 | + if ($profiler->isEnabled()) { |
|
| 97 | + $eventLogger->end('runtime'); |
|
| 98 | + $profile = $profiler->collect(Server::get(IRequest::class), new Response()); |
|
| 99 | + $profile->setMethod('occ'); |
|
| 100 | + $profile->setUrl(implode(' ', $argv)); |
|
| 101 | + $profiler->saveProfile($profile); |
|
| 102 | + |
|
| 103 | + $urlGenerator = Server::get(\OCP\IURLGenerator::class); |
|
| 104 | + $url = $urlGenerator->linkToRouteAbsolute('profiler.main.profiler', [ |
|
| 105 | + 'profiler' => 'db', |
|
| 106 | + 'token' => $profile->getToken(), |
|
| 107 | + ]); |
|
| 108 | + $output->getErrorOutput()->writeln('Profiler output available at ' . $url); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if ($exitCode > 255) { |
|
| 112 | + $exitCode = 255; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + exit($exitCode); |
|
| 116 | 116 | } catch (Exception $ex) { |
| 117 | - exceptionHandler($ex); |
|
| 117 | + exceptionHandler($ex); |
|
| 118 | 118 | } catch (Error $ex) { |
| 119 | - exceptionHandler($ex); |
|
| 119 | + exceptionHandler($ex); |
|
| 120 | 120 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
| 11 | 11 | * SPDX-License-Identifier: AGPL-3.0-only |
| 12 | 12 | */ |
| 13 | -require_once __DIR__ . '/lib/versioncheck.php'; |
|
| 13 | +require_once __DIR__.'/lib/versioncheck.php'; |
|
| 14 | 14 | |
| 15 | 15 | use OC\Console\Application; |
| 16 | 16 | use OCP\AppFramework\Http\Response; |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | define('OC_CONSOLE', 1); |
| 24 | 24 | |
| 25 | 25 | function exceptionHandler($exception) { |
| 26 | - echo 'An unhandled exception has been thrown:' . PHP_EOL; |
|
| 26 | + echo 'An unhandled exception has been thrown:'.PHP_EOL; |
|
| 27 | 27 | echo $exception; |
| 28 | 28 | exit(1); |
| 29 | 29 | } |
| 30 | 30 | try { |
| 31 | - require_once __DIR__ . '/lib/base.php'; |
|
| 31 | + require_once __DIR__.'/lib/base.php'; |
|
| 32 | 32 | |
| 33 | 33 | // set to run indefinitely if needed |
| 34 | 34 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if (!OC::$CLI) { |
| 39 | - echo 'This script can be run from the command line only' . PHP_EOL; |
|
| 39 | + echo 'This script can be run from the command line only'.PHP_EOL; |
|
| 40 | 40 | exit(1); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,34 +44,34 @@ discard block |
||
| 44 | 44 | set_exception_handler('exceptionHandler'); |
| 45 | 45 | |
| 46 | 46 | if (!function_exists('posix_getuid')) { |
| 47 | - echo 'The posix extensions are required - see https://www.php.net/manual/en/book.posix.php' . PHP_EOL; |
|
| 47 | + echo 'The posix extensions are required - see https://www.php.net/manual/en/book.posix.php'.PHP_EOL; |
|
| 48 | 48 | exit(1); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $user = posix_getuid(); |
| 52 | - $configUser = fileowner(OC::$configDir . 'config.php'); |
|
| 52 | + $configUser = fileowner(OC::$configDir.'config.php'); |
|
| 53 | 53 | if ($user !== $configUser) { |
| 54 | - echo 'Console has to be executed with the user that owns the file config/config.php' . PHP_EOL; |
|
| 55 | - echo 'Current user id: ' . $user . PHP_EOL; |
|
| 56 | - echo 'Owner id of config.php: ' . $configUser . PHP_EOL; |
|
| 57 | - echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 58 | - echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL; |
|
| 54 | + echo 'Console has to be executed with the user that owns the file config/config.php'.PHP_EOL; |
|
| 55 | + echo 'Current user id: '.$user.PHP_EOL; |
|
| 56 | + echo 'Owner id of config.php: '.$configUser.PHP_EOL; |
|
| 57 | + echo "Try adding 'sudo -u #".$configUser."' to the beginning of the command (without the single quotes)".PHP_EOL; |
|
| 58 | + echo "If running with 'docker exec' try adding the option '-u ".$configUser."' to the docker command (without the single quotes)".PHP_EOL; |
|
| 59 | 59 | exit(1); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $oldWorkingDir = getcwd(); |
| 63 | 63 | if ($oldWorkingDir === false) { |
| 64 | - echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 65 | - echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 64 | + echo 'This script can be run from the Nextcloud root directory only.'.PHP_EOL; |
|
| 65 | + echo "Can't determine current working dir - the script will continue to work but be aware of the above fact.".PHP_EOL; |
|
| 66 | 66 | } elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
| 67 | - echo 'This script can be run from the Nextcloud root directory only.' . PHP_EOL; |
|
| 68 | - echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 67 | + echo 'This script can be run from the Nextcloud root directory only.'.PHP_EOL; |
|
| 68 | + echo "Can't change to Nextcloud root directory.".PHP_EOL; |
|
| 69 | 69 | exit(1); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) { |
| 73 | - echo 'The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php' . PHP_EOL; |
|
| 74 | - echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL; |
|
| 73 | + echo 'The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php'.PHP_EOL; |
|
| 74 | + echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini.".PHP_EOL; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $eventLogger = Server::get(IEventLogger::class); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | 'profiler' => 'db', |
| 106 | 106 | 'token' => $profile->getToken(), |
| 107 | 107 | ]); |
| 108 | - $output->getErrorOutput()->writeln('Profiler output available at ' . $url); |
|
| 108 | + $output->getErrorOutput()->writeln('Profiler output available at '.$url); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | if ($exitCode > 255) { |