handle errors in apps while registering commands

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2016-11-24 12:28:40 +01:00
parent f4cf125a4a
commit 65ace7c5a7
No known key found for this signature in database
GPG Key ID: 425003AC385454C5
2 changed files with 12 additions and 3 deletions

View File

@ -85,7 +85,7 @@ try {
echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL; echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
} }
$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest()); $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger());
$application->loadCommands(new ArgvInput(), new ConsoleOutput()); $application->loadCommands(new ArgvInput(), new ConsoleOutput());
$application->run(); $application->run();
} catch (Exception $ex) { } catch (Exception $ex) {

View File

@ -31,6 +31,7 @@ use OC_App;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
use OCP\Console\ConsoleEvent; use OCP\Console\ConsoleEvent;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -45,18 +46,22 @@ class Application {
private $dispatcher; private $dispatcher;
/** @var IRequest */ /** @var IRequest */
private $request; private $request;
/** @var ILogger */
private $logger;
/** /**
* @param IConfig $config * @param IConfig $config
* @param EventDispatcherInterface $dispatcher * @param EventDispatcherInterface $dispatcher
* @param IRequest $request * @param IRequest $request
* @param ILogger $logger
*/ */
public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request) { public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) {
$defaults = \OC::$server->getThemingDefaults(); $defaults = \OC::$server->getThemingDefaults();
$this->config = $config; $this->config = $config;
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
$this->request = $request; $this->request = $request;
$this->logger = $logger;
} }
/** /**
@ -110,7 +115,11 @@ class Application {
\OC_App::registerAutoloading($app, $appPath); \OC_App::registerAutoloading($app, $appPath);
$file = $appPath . '/appinfo/register_command.php'; $file = $appPath . '/appinfo/register_command.php';
if (file_exists($file)) { if (file_exists($file)) {
require $file; try {
require $file;
} catch (\Exception $e) {
$this->logger->logException($e);
}
} }
} }
} }