summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2021-12-02 10:27:42 +0100
committerGitHub <noreply@github.com>2021-12-02 10:27:42 +0100
commitd5e4197875bc46544e04915e546980c1f09ba48f (patch)
tree06bb5b3d82c90b48259a77b48a565dbd01ee1a9b /apps
parent061abe7afd36df72a2c2ae3dcffdeba24099a6c9 (diff)
parent168c673755eca62008d9bfa81d0185beba1ff24b (diff)
downloadnextcloud-server-d5e4197875bc46544e04915e546980c1f09ba48f.tar.gz
nextcloud-server-d5e4197875bc46544e04915e546980c1f09ba48f.zip
Merge pull request #30011 from nextcloud/techdebt/noid/allow-to-log-queries-to-db-ldap-and-redis
Allow to log queries to db, ldap and redis
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/AppInfo/Application.php9
-rw-r--r--apps/user_ldap/lib/Jobs/Sync.php2
-rw-r--r--apps/user_ldap/lib/LDAP.php16
3 files changed, 23 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php
index 8c48682eddb..79998a580e5 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -75,8 +75,13 @@ class Application extends App implements IBootstrap {
);
});
- $container->registerService(ILDAPWrapper::class, function () {
- return new LDAP();
+ $container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
+ /** @var IServerContainer $server */
+ $server = $appContainer->get(IServerContainer::class);
+
+ return new LDAP(
+ $server->getConfig()->getSystemValueString('ldap_log_file')
+ );
});
}
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php
index 10036f8dc12..3d0dd88dfd2 100644
--- a/apps/user_ldap/lib/Jobs/Sync.php
+++ b/apps/user_ldap/lib/Jobs/Sync.php
@@ -317,7 +317,7 @@ class Sync extends TimedJob {
if (isset($argument['ldapWrapper'])) {
$this->ldap = $argument['ldapWrapper'];
} else {
- $this->ldap = new LDAP();
+ $this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
}
if (isset($argument['avatarManager'])) {
diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php
index 7210977e0e4..900f5a7030f 100644
--- a/apps/user_ldap/lib/LDAP.php
+++ b/apps/user_ldap/lib/LDAP.php
@@ -38,14 +38,16 @@ use OCA\User_LDAP\PagedResults\IAdapter;
use OCA\User_LDAP\PagedResults\Php73;
class LDAP implements ILDAPWrapper {
+ protected $logFile = '';
protected $curFunc = '';
protected $curArgs = [];
/** @var IAdapter */
protected $pagedResultsAdapter;
- public function __construct() {
+ public function __construct(string $logFile = '') {
$this->pagedResultsAdapter = new Php73();
+ $this->logFile = $logFile;
}
/**
@@ -349,6 +351,18 @@ class LDAP implements ILDAPWrapper {
private function preFunctionCall($functionName, $args) {
$this->curFunc = $functionName;
$this->curArgs = $args;
+
+ if ($this->logFile !== '' && is_writable($this->logFile)) {
+ $args = array_reduce($this->curArgs, static function (array $carry, $item): array {
+ $carry[] = !is_resource($item) ? $item : '(resource)';
+ return $carry;
+ }, []);
+ file_put_contents(
+ $this->logFile,
+ $this->curFunc . '::' . json_encode($args) . "\n",
+ FILE_APPEND
+ );
+ }
}
/**