Shopware: Debug SQL Queries on the CLI
Fabian Blechschmidt
You are trying to debug a Command, ScheduledTask or Message on the queue?
Symfony Profiler and toolbar
For the frontend it is easy, you can just use the Symfony Profiler – easily activated by turning on the dev mode.
This can be done, by changing APP_ENV="prod"
to APP_ENV="dev"
in your .env
file.
And then you have a toolbar in the footer which opens this:
SQL Queries on the CLI
But for the CLI it is not so easy. It took me a while to figure it out, but with this post from Alex on stackoverflow I got the right hint.
I have the problem, that @Alex doesn’t work for me, because on dev, Shopware is interfering at two positions:
src/Kernel.php:49
vendor/shopware/core/HttpKernel.php:179
So I just hacked the core:
\Shopware\Core\Profiling\Doctrine\DebugStack::startQuery
And added the few lines directly into DebugStack:
public function startQuery($sql, ?array $params = null, ?array $types = null): void
{
$this->ensureMasterSlaveCompatibility($sql);
// ADDED
$doctrineExtension = new \Shopware\Core\Profiling\Twig\DoctrineExtension();
echo $doctrineExtension->replaceQueryParameters(
$sql,
array_merge($params ?? array())
) . ';' . PHP_EOL;
// ADDED END
parent::startQuery($sql, $params, $types);
}
But don’t try this with the frontend ? Or you end up with this:
Other articles from this category
PHPStorm/IDEA, composer updates and 100% CPU
In one of our projects PHPStorm ran a while on 100% CPU, an investigation showed, that the process „checking for available composer updates“ ran and used all the resources. Most likely it got stuck somewhere. To get rid of the problem, one can turn off this feature. In IDEA Ultimate here: [Settings] -> Languages & […]
Custom Fields, dots and MySQL’s JSON_EXTRACT
We all know custom fields – hopefully – at least this is not about the basics. You can add custom fields to nearly all entites: orders, products, categories, … You can name them whatever you like, e.g. pluginname.property – but using dots . in your custom field name is a bad idea, because then you […]
gpg failed to sign the data
I was doing some work, when suddenly my git failed to commit changed. I dig a little around, asked StackOverflow but it didn’t help. Finally when running the commit manually and not through PHPStorm I got a proper error: Ah! The key is expired! Got it. Did you know you can extend a GPG key? […]