diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-04-10 16:33:01 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-04-10 16:33:01 +0200 |
commit | 77afef328d285fd97b020399c42227d89fc71d18 (patch) | |
tree | f42736af6e32c0064c7821f651ade2d09d161374 /lib | |
parent | 294f14a79385e5265d7208baaa03a230f2c8f35f (diff) | |
parent | f7c906902ac67fda541c200c23f7ee2a1dabc3e4 (diff) | |
download | nextcloud-server-77afef328d285fd97b020399c42227d89fc71d18.tar.gz nextcloud-server-77afef328d285fd97b020399c42227d89fc71d18.zip |
Merge pull request #15458 from owncloud/web-shell-master
Move console application to it's own class - allows reuse in the web shell
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/console/application.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/private/console/application.php b/lib/private/console/application.php new file mode 100644 index 00000000000..551d69ef53c --- /dev/null +++ b/lib/private/console/application.php @@ -0,0 +1,77 @@ +<?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(''); + } + throw new \Exception("Environment not properly prepared."); + } + } + } + + 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); + } +} |