From cd13f50a3f1fbcae757672b4a471d8fbcf959b08 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Oct 2016 11:29:38 +0200 Subject: Log the queries of the QueryBuilder as well Signed-off-by: Joas Schilling --- lib/private/DB/QueryBuilder/QueryBuilder.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/private/DB') diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index eac77dd98fd..aefc84f9c9a 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -139,6 +139,29 @@ class QueryBuilder implements IQueryBuilder { * @return \Doctrine\DBAL\Driver\Statement|int */ public function execute() { + if (\OC::$server->getConfig()->getSystemValue('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)) { + \OC::$server->getLogger()->debug('DB QueryBuilder: \'{query}\'', [ + 'query' => $this->getSQL(), + 'app' => 'core', + ]); + } else { + \OC::$server->getLogger()->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ + 'query' => $this->getSQL(), + 'params' => implode(', ', $params), + 'app' => 'core', + ]); + } + } + return $this->queryBuilder->execute(); } -- cgit v1.2.3