summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-11-02 21:51:39 +0100
committerGitHub <noreply@github.com>2016-11-02 21:51:39 +0100
commitb4cf559707b48bca6d52194dec87d84a5597c317 (patch)
tree162db205cf53b8ccc69fe3695b9a88c5c066fbfd /lib
parenta8d9bf48ffed340d3b9ce7143aa8e5e1eabeb4c3 (diff)
parenta8b7df9cc19991bdb936539950400760dfafd29a (diff)
downloadnextcloud-server-b4cf559707b48bca6d52194dec87d84a5597c317.tar.gz
nextcloud-server-b4cf559707b48bca6d52194dec87d84a5597c317.zip
Merge pull request #1943 from nextcloud/log-query-builder-queries
Log QueryBuilder queries
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/Connection.php6
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php39
-rw-r--r--lib/private/Security/CSRF/TokenStorage/SessionStorage.php7
-rw-r--r--lib/private/Server.php7
4 files changed, 54 insertions, 5 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index dfe2e86b617..497ff0c8a26 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -67,7 +67,11 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
* @return \OCP\DB\QueryBuilder\IQueryBuilder
*/
public function getQueryBuilder() {
- return new QueryBuilder($this);
+ return new QueryBuilder(
+ $this,
+ \OC::$server->getSystemConfig(),
+ \OC::$server->getLogger()
+ );
}
/**
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index eac77dd98fd..d5dd9cf0366 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -31,16 +31,24 @@ use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder;
+use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\DB\QueryBuilder\IParameter;
use OCP\IDBConnection;
+use OCP\ILogger;
class QueryBuilder implements IQueryBuilder {
/** @var \OCP\IDBConnection */
private $connection;
+ /** @var SystemConfig */
+ private $systemConfig;
+
+ /** @var ILogger */
+ private $logger;
+
/** @var \Doctrine\DBAL\Query\QueryBuilder */
private $queryBuilder;
@@ -56,10 +64,14 @@ class QueryBuilder implements IQueryBuilder {
/**
* Initializes a new QueryBuilder.
*
- * @param \OCP\IDBConnection $connection
+ * @param IDBConnection $connection
+ * @param SystemConfig $systemConfig
+ * @param ILogger $logger
*/
- public function __construct(IDBConnection $connection) {
+ public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) {
$this->connection = $connection;
+ $this->systemConfig = $systemConfig;
+ $this->logger = $logger;
$this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
$this->helper = new QuoteHelper();
}
@@ -139,6 +151,29 @@ class QueryBuilder implements IQueryBuilder {
* @return \Doctrine\DBAL\Driver\Statement|int
*/
public function execute() {
+ if ($this->systemConfig->getValue('log_query', false)) {
+ $params = [];
+ foreach ($this->getParameters() as $placeholder => $value) {
+ if (is_array($value)) {
+ $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
+ } else {
+ $params[] = $placeholder . ' => \'' . $value . '\'';
+ }
+ }
+ if (empty($params)) {
+ $this->logger->debug('DB QueryBuilder: \'{query}\'', [
+ 'query' => $this->getSQL(),
+ 'app' => 'core',
+ ]);
+ } else {
+ $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
+ 'query' => $this->getSQL(),
+ 'params' => implode(', ', $params),
+ 'app' => 'core',
+ ]);
+ }
+ }
+
return $this->queryBuilder->execute();
}
diff --git a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php
index cf4cdfa5036..9d2e723a6d3 100644
--- a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php
+++ b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php
@@ -41,6 +41,13 @@ class SessionStorage {
}
/**
+ * @param ISession $session
+ */
+ public function setSession(ISession $session) {
+ $this->session = $session;
+ }
+
+ /**
* Returns the current token or throws an exception if none is found.
*
* @return string
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6f25098eb35..dca50c15733 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -710,13 +710,15 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerService('CsrfTokenManager', function (Server $c) {
$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
- $sessionStorage = new SessionStorage($c->getSession());
return new CsrfTokenManager(
$tokenGenerator,
- $sessionStorage
+ $c->query(SessionStorage::class)
);
});
+ $this->registerService(SessionStorage::class, function (Server $c) {
+ return new SessionStorage($c->getSession());
+ });
$this->registerService('ContentSecurityPolicyManager', function (Server $c) {
return new ContentSecurityPolicyManager();
});
@@ -945,6 +947,7 @@ class Server extends ServerContainer implements IServerContainer {
* @param \OCP\ISession $session
*/
public function setSession(\OCP\ISession $session) {
+ $this->query(SessionStorage::class)->setSession($session);
return $this->query('UserSession')->setSession($session);
}