Add a log message when the Doctrine Query Builder is retrieved
This commit is contained in:
parent
f9071ed5b7
commit
20cd0ae55b
|
@ -45,15 +45,6 @@ class Db implements IDb {
|
|||
$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.
|
||||
*
|
||||
|
|
|
@ -54,16 +54,7 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the ExpressionBuilder for the connection.
|
||||
*
|
||||
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
|
||||
*/
|
||||
public function getExpressionBuilder() {
|
||||
return new ExpressionBuilder($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the QueryBuilder for the connection.
|
||||
* Returns a QueryBuilder for the connection.
|
||||
*
|
||||
* @return \OCP\DB\QueryBuilder\IQueryBuilder
|
||||
*/
|
||||
|
@ -71,6 +62,47 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
|||
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 \Doctrine\DBAL\Query\Expression\ExpressionBuilder
|
||||
* @deprecated please use $this->getQueryBuilder()->expr() instead
|
||||
*/
|
||||
public function getExpressionBuilder() {
|
||||
$backtrace = $this->getCallerBacktrace();
|
||||
\OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]);
|
||||
return parent::getExpressionBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file and line that called the method where `getCallerBacktrace()` was used
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,14 +40,6 @@ namespace OCP;
|
|||
* @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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue