Merge pull request #17562 from nextcloud/techdebt/17509/log-error-when-setting-up-application-incorrectly

Log an error in development cases when the application class was set …
This commit is contained in:
Roeland Jago Douma 2019-10-29 21:09:26 +01:00 committed by GitHub
commit 380563fd53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 2 deletions

View File

@ -34,6 +34,7 @@ declare(strict_types=1);
namespace OCP\AppFramework;
use OC\AppFramework\Routing\RouteConfig;
use OC\ServerContainer;
use OCP\Route\IRouter;
@ -51,8 +52,8 @@ class App {
private $container;
/**
* Turns an app id into a namespace by convetion. The id is split at the
* underscores, all parts are camelcased and reassembled. e.g.:
* Turns an app id into a namespace by convention. The id is split at the
* underscores, all parts are CamelCased and reassembled. e.g.:
* some_app_id -> OCA\SomeAppId
* @param string $appId the app id
* @param string $topNamespace the namespace which should be prepended to
@ -71,6 +72,28 @@ class App {
* @since 6.0.0
*/
public function __construct(string $appName, array $urlParams = []) {
if (\OC::$server->getConfig()->getSystemValueBool('debug')) {
$applicationClassName = get_class($this);
$e = new \RuntimeException('App class ' . $applicationClassName . ' is not setup via query() but directly');
$setUpViaQuery = false;
foreach ($e->getTrace() as $step) {
if (isset($step['class'], $step['function'], $step['args'][0]) &&
$step['class'] === ServerContainer::class &&
$step['function'] === 'query' &&
$step['args'][0] === $applicationClassName) {
$setUpViaQuery = true;
break;
}
}
if (!$setUpViaQuery) {
\OC::$server->getLogger()->logException($e, [
'app' => $appName,
]);
}
}
try {
$this->container = \OC::$server->getRegisteredAppContainer($appName);
} catch (QueryException $e) {