Skip to content

Commit

Permalink
Add a log message when the Doctrine Query Builder is retrieved
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jul 21, 2015
1 parent f9071ed commit 20cd0ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
9 changes: 0 additions & 9 deletions lib/private/appframework/db/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}

/**
* Gets the ExpressionBuilder for the connection.
*
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
*/
public function getExpressionBuilder() {
return $this->connection->getExpressionBuilder();
}

/**
* Gets the ExpressionBuilder for the connection.
*
Expand Down
44 changes: 38 additions & 6 deletions lib/private/db/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,54 @@ public function connect() {
}
}

/**
* 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 '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/db/querybuilder/querybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(IDBConnection $connection) {
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
*/
public function expr() {
return $this->connection->getExpressionBuilder();
return new ExpressionBuilder($this->connection);
}

/**
Expand Down
8 changes: 0 additions & 8 deletions lib/public/idbconnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@
* @since 6.0.0
*/
interface IDBConnection {
/**
* Gets the ExpressionBuilder for the connection.
*
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
* @since 8.2.0
*/
public function getExpressionBuilder();

/**
* Gets the QueryBuilder for the connection.
*
Expand Down

0 comments on commit 20cd0ae

Please sign in to comment.