diff --git a/composer.json b/composer.json index 69271c4f..ce451c9f 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require-dev": { "cakephp/authorization": "^3.0", "cakephp/cakephp-codesniffer": "^5.0", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.1.0 <=10.5.3" }, "suggest": { "ext-pdo_sqlite": "DebugKit needs to store panel data in a database. SQLite is simple and easy to use." diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 64cd4758..4f97615d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,10 @@ - + + + + jsonSerialize + + _composerPaths]]> diff --git a/src/Database/Log/DebugLog.php b/src/Database/Log/DebugLog.php index 9e3acb16..3e069f4d 100644 --- a/src/Database/Log/DebugLog.php +++ b/src/Database/Log/DebugLog.php @@ -127,13 +127,33 @@ public function totalTime(): float */ public function log($level, string|Stringable $message, array $context = []): void { - $query = $context['query']; + $query = $context['query'] ?? null; if ($this->_logger) { $this->_logger->log($level, $message, $context); } - if ($this->_includeSchema === false && $this->isSchemaQuery($query)) { + // This specific to Elastic Search + if (!$query instanceof LoggedQuery && isset($context['request']) && isset($context['response'])) { + $this->_totalTime += $context['response']['took']; + + $this->_queries[] = [ + 'query' => json_encode([ + 'method' => $context['request']['method'], + 'path' => $context['request']['path'], + 'data' => $context['request']['data'], + ], JSON_PRETTY_PRINT), + 'took' => $context['response']['took'] ?: 0, + 'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0, + ]; + + return; + } + + if ( + !$query instanceof LoggedQuery || + ($this->_includeSchema === false && $this->isSchemaQuery($query)) + ) { return; } diff --git a/src/Panel/SqlLogPanel.php b/src/Panel/SqlLogPanel.php index b199fd22..1d0b2194 100644 --- a/src/Panel/SqlLogPanel.php +++ b/src/Panel/SqlLogPanel.php @@ -15,6 +15,7 @@ namespace DebugKit\Panel; use Cake\Core\Configure; +use Cake\Database\Driver; use Cake\Datasource\ConnectionInterface; use Cake\Datasource\ConnectionManager; use Cake\ORM\Locator\LocatorAwareTrait; @@ -57,7 +58,14 @@ public function initialize(): void ) { continue; } - $logger = $connection->getDriver()->getLogger(); + $driver = $connection->getDriver(); + $logger = null; + if ($driver instanceof Driver) { + $logger = $driver->getLogger(); + } elseif (method_exists($connection, 'getLogger')) { + // ElasticSearch connection holds the logger, not the Elastica Driver + $logger = $connection->getLogger(); + } if ($logger instanceof DebugLog) { $logger->setIncludeSchema($includeSchemaReflection);