console.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. use Symfony\Component\Console\Application;
  9. try {
  10. require_once 'lib/base.php';
  11. // set to run indefinitely if needed
  12. set_time_limit(0);
  13. // Don't do anything if ownCloud has not been installed yet
  14. if (!\OC::$server->getConfig()->getSystemValue('installed', false)) {
  15. echo "Console can only be used once ownCloud has been installed" . PHP_EOL;
  16. exit(0);
  17. }
  18. if (!OC::$CLI) {
  19. echo "This script can be run from the command line only" . PHP_EOL;
  20. exit(0);
  21. }
  22. if (!OC_Util::runningOnWindows()) {
  23. if (!function_exists('posix_getuid')) {
  24. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  25. exit(0);
  26. }
  27. $user = posix_getpwuid(posix_getuid());
  28. $configUser = posix_getpwuid(fileowner(OC::$SERVERROOT . '/config/config.php'));
  29. if ($user['name'] !== $configUser['name']) {
  30. echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
  31. echo "Current user: " . $user['name'] . PHP_EOL;
  32. echo "Web server user: " . $configUser['name'] . PHP_EOL;
  33. exit(0);
  34. }
  35. }
  36. // only load apps if no update is due,
  37. // else only core commands will be available
  38. if (!\OCP\Util::needUpgrade()) {
  39. // load all apps to get all api routes properly setup
  40. OC_App::loadApps();
  41. }
  42. $defaults = new OC_Defaults;
  43. $application = new Application($defaults->getName(), \OC_Util::getVersionString());
  44. require_once 'core/register_command.php';
  45. if (!\OCP\Util::needUpgrade()) {
  46. foreach(OC_App::getAllApps() as $app) {
  47. $file = OC_App::getAppPath($app).'/appinfo/register_command.php';
  48. if(file_exists($file)) {
  49. require $file;
  50. }
  51. }
  52. }
  53. $application->run();
  54. } catch (Exception $ex) {
  55. echo "An unhandled exception has been thrown:" . PHP_EOL;
  56. echo $ex;
  57. }