application.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace OC\Console;
  3. use OC_App;
  4. use OC_Defaults;
  5. use OCP\IConfig;
  6. use Symfony\Component\Console\Application as SymfonyApplication;
  7. use Symfony\Component\Console\Input\ArgvInput;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. class Application {
  11. /**
  12. * @var IConfig
  13. */
  14. private $config;
  15. /**
  16. * @param IConfig $config
  17. */
  18. public function __construct(IConfig $config) {
  19. $defaults = new OC_Defaults;
  20. $this->config = $config;
  21. $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
  22. }
  23. /**
  24. * @param OutputInterface $output
  25. */
  26. public function loadCommands(OutputInterface $output) {
  27. // $application is required to be defined in the register_command scripts
  28. $application = $this->application;
  29. require_once \OC::$SERVERROOT . '/core/register_command.php';
  30. if ($this->config->getSystemValue('installed', false)) {
  31. if (!\OCP\Util::needUpgrade()) {
  32. OC_App::loadApps();
  33. foreach (OC_App::getAllApps() as $app) {
  34. $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
  35. if (file_exists($file)) {
  36. require $file;
  37. }
  38. }
  39. } else {
  40. $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
  41. }
  42. } else {
  43. $output->writeln("ownCloud is not installed - only a limited number of commands are available");
  44. }
  45. $input = new ArgvInput();
  46. if ($input->getFirstArgument() !== 'check') {
  47. $errors = \OC_Util::checkServer(\OC::$server->getConfig());
  48. if (!empty($errors)) {
  49. foreach ($errors as $error) {
  50. $output->writeln((string)$error['error']);
  51. $output->writeln((string)$error['hint']);
  52. $output->writeln('');
  53. }
  54. throw new \Exception("Environment not properly prepared.");
  55. }
  56. }
  57. }
  58. public function setAutoExit($boolean) {
  59. $this->application->setAutoExit($boolean);
  60. }
  61. /**
  62. * @param InputInterface $input
  63. * @param OutputInterface $output
  64. * @return int
  65. * @throws \Exception
  66. */
  67. public function run(InputInterface $input = null, OutputInterface $output = null) {
  68. return $this->application->run($input, $output);
  69. }
  70. }