summaryrefslogtreecommitdiffstats
path: root/lib/private/db
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-07-21 14:17:47 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-21 15:53:28 +0200
commit20cd0ae55b3e56e0fbe34033a023f6a5f1c2b7d6 (patch)
tree1894f259aa1e0b6736740ee23108712d7744360a /lib/private/db
parentf9071ed5b7449c5f0dfa99a7715a744742281cf1 (diff)
downloadnextcloud-server-20cd0ae55b3e56e0fbe34033a023f6a5f1c2b7d6.tar.gz
nextcloud-server-20cd0ae55b3e56e0fbe34033a023f6a5f1c2b7d6.zip
Add a log message when the Doctrine Query Builder is retrieved
Diffstat (limited to 'lib/private/db')
-rw-r--r--lib/private/db/connection.php44
-rw-r--r--lib/private/db/querybuilder/querybuilder.php2
2 files changed, 39 insertions, 7 deletions
diff --git a/lib/private/db/connection.php b/lib/private/db/connection.php
index ae5d22bf4d8..def3f2fd120 100644
--- a/lib/private/db/connection.php
+++ b/lib/private/db/connection.php
@@ -54,21 +54,53 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
}
/**
+ * Returns a QueryBuilder for the connection.
+ *
+ * @return \OCP\DB\QueryBuilder\IQueryBuilder
+ */
+ public function getQueryBuilder() {
+ return new QueryBuilder($this);
+ }
+
+ /**
+ * Gets the QueryBuilder for the connection.
+ *
+ * @return \Doctrine\DBAL\Query\QueryBuilder
+ * @deprecated please use $this->getQueryBuilder() instead
+ */
+ public function createQueryBuilder() {
+ $backtrace = $this->getCallerBacktrace();
+ \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
+ return parent::createQueryBuilder();
+ }
+
+ /**
* Gets the ExpressionBuilder for the connection.
*
- * @return \OCP\DB\QueryBuilder\IExpressionBuilder
+ * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder
+ * @deprecated please use $this->getQueryBuilder()->expr() instead
*/
public function getExpressionBuilder() {
- return new ExpressionBuilder($this);
+ $backtrace = $this->getCallerBacktrace();
+ \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
+ return parent::getExpressionBuilder();
}
/**
- * Gets the QueryBuilder for the connection.
+ * Get the file and line that called the method where `getCallerBacktrace()` was used
*
- * @return \OCP\DB\QueryBuilder\IQueryBuilder
+ * @return string
*/
- public function getQueryBuilder() {
- return new QueryBuilder($this);
+ protected function getCallerBacktrace() {
+ $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
+
+ // 0 is the method where we use `getCallerBacktrace`
+ // 1 is the target method which uses the method we want to log
+ if (isset($traces[1])) {
+ return $traces[1]['file'] . ':' . $traces[1]['line'];
+ }
+
+ return '';
}
/**
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index 38c3966d9a0..1a1408876f1 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -65,7 +65,7 @@ class QueryBuilder implements IQueryBuilder {
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
*/
public function expr() {
- return $this->connection->getExpressionBuilder();
+ return new ExpressionBuilder($this->connection);
}
/**