diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-08 10:53:03 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-09 16:28:53 +0200 |
commit | 890a18e1a634c700e7acd451c75f6fc324d7be82 (patch) | |
tree | 2e46b2bde124ea2c0bb254dfe2840c63a95a91b3 /lib/private/console | |
parent | f5a145b410ce8e8002b634264f146c21de346050 (diff) | |
download | nextcloud-server-890a18e1a634c700e7acd451c75f6fc324d7be82.tar.gz nextcloud-server-890a18e1a634c700e7acd451c75f6fc324d7be82.zip |
Introduce own console application class
Diffstat (limited to 'lib/private/console')
-rw-r--r-- | lib/private/console/application.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/private/console/application.php b/lib/private/console/application.php new file mode 100644 index 00000000000..d7f8ac53f91 --- /dev/null +++ b/lib/private/console/application.php @@ -0,0 +1,76 @@ +<?php + +namespace OC\Console; + +use OC_App; +use OC_Defaults; +use OCP\IConfig; +use Symfony\Component\Console\Application as SymfonyApplication; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Application { + /** + * @var IConfig + */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $defaults = new OC_Defaults; + $this->config = $config; + $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); + } + + /** + * @param OutputInterface $output + */ + public function loadCommands(OutputInterface $output) { + // $application is required to be defined in the register_command scripts + $application = $this->application; + require_once \OC::$SERVERROOT . '/core/register_command.php'; + if ($this->config->getSystemValue('installed', false)) { + if (!\OCP\Util::needUpgrade()) { + OC_App::loadApps(); + foreach (OC_App::getAllApps() as $app) { + $file = OC_App::getAppPath($app) . '/appinfo/register_command.php'; + if (file_exists($file)) { + require $file; + } + } + } else { + $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); + } + } else { + $output->writeln("ownCloud is not installed - only a limited number of commands are available"); + } + $input = new ArgvInput(); + if ($input->getFirstArgument() !== 'check') { + $errors = \OC_Util::checkServer(\OC::$server->getConfig()); + if (!empty($errors)) { + foreach ($errors as $error) { + $output->writeln($error['error']); + $output->writeln($error['hint']); + $output->writeln(''); + } + } + } + } + + public function setAutoExit($boolean) { + $this->application->setAutoExit($boolean); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + * @throws \Exception + */ + public function run(InputInterface $input = null, OutputInterface $output = null) { + return $this->application->run($input, $output); + } +} |