diff --git a/src/AppConfig.php b/src/AppConfig.php index 57589ab..4b4ebab 100644 --- a/src/AppConfig.php +++ b/src/AppConfig.php @@ -4,6 +4,7 @@ use Craft; use craft\cache\DbCache; +use craft\cloud\db\Command; use craft\cloud\fs\TmpFs; use craft\cloud\Helper as CloudHelper; use craft\cloud\queue\SqsQueue; @@ -38,6 +39,8 @@ public function getConfig(): array $config['components']['session'] = $this->getSession(); } + $config['components']['db'] = $this->getDb(); + $config['components']['db2'] = $this->getDb(); $config['components']['cache'] = $this->getCache(); $config['components']['queue'] = $this->getQueue(); $config['components']['assetManager'] = $this->getAssetManager(); @@ -46,6 +49,20 @@ public function getConfig(): array return $config; } + private function getDb(): \Closure + { + return function() { + $config = [ + 'commandMap' => [ + 'pgsql' => Command::class, + 'mysql' => Command::class, + ], + ] + App::dbConfig(); + + return Craft::createObject($config); + }; + } + private function getSession(): \Closure { return function() { diff --git a/src/StaticCache.php b/src/StaticCache.php index 216ee1b..9eddfbd 100644 --- a/src/StaticCache.php +++ b/src/StaticCache.php @@ -272,6 +272,7 @@ public function purgeTags(string|StaticCacheTag ...$tags): void Craft::info(new PsrMessage('Purging tags', [ 'tags' => $tags, + 'backtrace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), ]), __METHOD__); if ($isWebResponse) { @@ -300,6 +301,7 @@ public function purgeUrlPrefixes(string ...$urlPrefixes): void Craft::info(new PsrMessage('Purging URL prefixes', [ 'urlPrefixes' => $urlPrefixes->all(), + 'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), ]), __METHOD__); // TODO: make sure we don't go over max header size diff --git a/src/db/Command.php b/src/db/Command.php new file mode 100644 index 0000000..9429dd8 --- /dev/null +++ b/src/db/Command.php @@ -0,0 +1,43 @@ + implode(' ', $_SERVER['argv'] ?? []), + ] : [ + 'method' => $_SERVER['REQUEST_METHOD'] ?? null, + 'path' => $url['path'], + 'query' => $url['query'] ?? null, + ])->map(function($value, $key) { + $key = urlencode($key); + + // allow un-encoded forward slashes and spaces + $value = str_replace(['%2F', '+'], ['/', ' '], urlencode($value)); + + $maxLength = 100; + $value = strlen($value) > $maxLength + ? substr($value, 0, $maxLength) . '...[truncated]' + : $value; + + return $value + ? sprintf("%s='%s'", $key, $value) + : null; + })->filter(); + $comment = $fields->join(','); + + return "/*$comment*/ $sql"; + } +}