1
0

console.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author hoellen <dev@hoellen.eu>
  8. * @author J0WI <J0WI@users.noreply.github.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Ko- <k.stoffelen@cs.ru.nl>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Michael Weimann <mail@michael-weimann.eu>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Patrick Paysant <patrick.paysant@linagora.com>
  15. * @author Roeland Jago Douma <roeland@famdouma.nl>
  16. * @author Thomas Müller <thomas.mueller@tmit.eu>
  17. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  18. *
  19. * @license AGPL-3.0
  20. *
  21. * This code is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU Affero General Public License, version 3,
  23. * as published by the Free Software Foundation.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU Affero General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Affero General Public License, version 3,
  31. * along with this program. If not, see <http://www.gnu.org/licenses/>
  32. *
  33. */
  34. require_once __DIR__ . '/lib/versioncheck.php';
  35. use OC\Console\Application;
  36. use Symfony\Component\Console\Input\ArgvInput;
  37. use Symfony\Component\Console\Output\ConsoleOutput;
  38. define('OC_CONSOLE', 1);
  39. function exceptionHandler($exception) {
  40. echo "An unhandled exception has been thrown:" . PHP_EOL;
  41. echo $exception;
  42. exit(1);
  43. }
  44. try {
  45. require_once __DIR__ . '/lib/base.php';
  46. // set to run indefinitely if needed
  47. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  48. @set_time_limit(0);
  49. }
  50. if (!OC::$CLI) {
  51. echo "This script can be run from the command line only" . PHP_EOL;
  52. exit(1);
  53. }
  54. set_exception_handler('exceptionHandler');
  55. if (!function_exists('posix_getuid')) {
  56. echo "The posix extensions are required - see https://www.php.net/manual/en/book.posix.php" . PHP_EOL;
  57. exit(1);
  58. }
  59. $user = posix_getuid();
  60. $configUser = fileowner(OC::$configDir . 'config.php');
  61. if ($user !== $configUser) {
  62. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  63. echo "Current user id: " . $user . PHP_EOL;
  64. echo "Owner id of config.php: " . $configUser . PHP_EOL;
  65. echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
  66. echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
  67. exit(1);
  68. }
  69. $oldWorkingDir = getcwd();
  70. if ($oldWorkingDir === false) {
  71. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  72. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  73. } elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  74. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  75. echo "Can't change to Nextcloud root directory." . PHP_EOL;
  76. exit(1);
  77. }
  78. if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) {
  79. 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;
  80. echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
  81. }
  82. $application = new Application(
  83. \OC::$server->getConfig(),
  84. \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
  85. \OC::$server->getRequest(),
  86. \OC::$server->get(\Psr\Log\LoggerInterface::class),
  87. \OC::$server->query(\OC\MemoryInfo::class)
  88. );
  89. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  90. $application->run();
  91. } catch (Exception $ex) {
  92. exceptionHandler($ex);
  93. } catch (Error $ex) {
  94. exceptionHandler($ex);
  95. }