Skip to content

Plugin relies on database connection when running theme:compile #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterjaap opened this issue Dec 8, 2021 · 4 comments · Fixed by #33
Closed

Plugin relies on database connection when running theme:compile #31

peterjaap opened this issue Dec 8, 2021 · 4 comments · Fixed by #33
Labels
kind/bug Something isn't working

Comments

@peterjaap
Copy link

peterjaap commented Dec 8, 2021

PHP Version

8

Shopware Version

6.4.6.1

Actual behaviour

When running ./bin/ci theme:compile --keep-assets -vvv in CI (so when there is no database present), the compiling breaks because of this plugin;

In AbstractMySQLDriver.php line 112:                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                           
  [Doctrine\DBAL\Exception\ConnectionException]                                                                                                                                                                                                                                            
  An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known                                                                                                                                                          
                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                           
Exception trace:                                                                                                                                                                                                                                                                           
  at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112                                                                                                                                                                          
 Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:182       
 Doctrine\DBAL\DBALException::wrapException() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169                                                                 
 Doctrine\DBAL\DBALException::driverException() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:31                                            
 Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:411                                                                                                                                           
 Doctrine\DBAL\Connection->connect() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:474                                                                                                                                                       
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:436                                                                                                                                    
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:378                                           
 Doctrine\DBAL\Connection->getDatabasePlatform() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:1204                   
 Doctrine\DBAL\Query\QueryBuilder->getSQLForSelect() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:252                                                                                                                               
 Doctrine\DBAL\Query\QueryBuilder->getSQL() at /data/client/shopware/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/QueryBuilder.php:51                                                                                                                             
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\QueryBuilder->getSQL() at /data/client/shopware/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:212                                                                                                          
 Doctrine\DBAL\Query\QueryBuilder->execute() at /data/client/shopware/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/EntitySearcher.php:91                                                                                                                          
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntitySearcher->search() at /data/client/shopware/vendor/shopware/elasticsearch/Framework/DataAbstractionLayer/ElasticsearchEntitySearcher.php:57                                                                          
 Shopware\Elasticsearch\Framework\DataAbstractionLayer\ElasticsearchEntitySearcher->search() at /data/client/shopware/vendor/shopware/core/Profiling/Entity/EntitySearcherProfiler.php:36                                                                                     
 Shopware\Core\Profiling\Entity\EntitySearcherProfiler->search() at /data/client/shopware/vendor/shopware/core/Framework/DataAbstractionLayer/EntityRepository.php:179
 Shopware\Core\Framework\DataAbstractionLayer\EntityRepository->searchIds() at /data/client/shopware/vendor/shopware/core/Framework/DataAbstractionLayer/EntityRepository.php:120
 Shopware\Core\Framework\DataAbstractionLayer\EntityRepository->search() at /data/client/shopware/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/Common/RepositoryIterator.php:72
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\RepositoryIterator->fetch() at /data/client/shopware/vendor/shopware/core/System/SystemConfig/SystemConfigLoader.php:67
 Shopware\Core\System\SystemConfig\SystemConfigLoader->load() at /data/client/shopware/vendor/shopware/core/System/SystemConfig/CachedSystemConfigLoader.php:49
 Shopware\Core\System\SystemConfig\CachedSystemConfigLoader->load() at /data/client/shopware/vendor/shopware/core/System/SystemConfig/SystemConfigService.php:372
 Shopware\Core\System\SystemConfig\SystemConfigService->load() at /data/client/shopware/vendor/shopware/core/System/SystemConfig/SystemConfigService.php:95
 Shopware\Core\System\SystemConfig\SystemConfigService->get() at /data/client/shopware/vendor/store.shopware.com/froshplatformthumbnailprocessor/src/Service/ThumbnailUrlTemplate.php:14
 Frosh\ThumbnailProcessor\Service\ThumbnailUrlTemplate->__construct() at /data/client/shopware/var/cache/dev_h3bb1806f88c6b26fd718ee7610b1a192/Container2k1Oi8x/Shopware_Production_KernelDevDebugContainer.php:21678
 Container2k1Oi8x\Shopware_Production_KernelDevDebugContainer->getUrlGeneratorDecoratorService() at /data/client/shopware/var/cache/dev_h3bb1806f88c6b26fd718ee7610b1a192/Container2k1Oi8x/Shopware_Production_KernelDevDebugContainer.php:14260
 Container2k1Oi8x\Shopware_Production_KernelDevDebugContainer->getMedia_RepositoryService() at /data/client/shopware/var/cache/dev_h3bb1806f88c6b26fd718ee7610b1a192/Container2k1Oi8x/Shopware_Production_KernelDevDebugContainer.php:28013
 Container2k1Oi8x\Shopware_Production_KernelDevDebugContainer->getDatabaseConfigLoaderService() at /data/client/shopware/var/cache/dev_h3bb1806f88c6b26fd718ee7610b1a192/Container2k1Oi8x/Shopware_Production_KernelDevDebugContainer.php:28141
 Container2k1Oi8x\Shopware_Production_KernelDevDebugContainer->getThemeServiceService() at /data/client/shopware/var/cache/dev_h3bb1806f88c6b26fd718ee7610b1a192/Container2k1Oi8x/Shopware_Production_KernelDevDebugContainer.php:27935
 Container2k1Oi8x\Shopware_Production_KernelDevDebugContainer->getThemeCompileCommandService() at /data/client/shopware/vendor/symfony/dependency-injection/Container.php:422
 Symfony\Component\DependencyInjection\Container->getService() at /data/client/shopware/vendor/symfony/dependency-injection/Argument/ServiceLocator.php:42
 Symfony\Component\DependencyInjection\Argument\ServiceLocator->get() at /data/client/shopware/vendor/symfony/console/CommandLoader/ContainerCommandLoader.php:45
 Symfony\Component\Console\CommandLoader\ContainerCommandLoader->get() at /data/client/shopware/vendor/symfony/console/Application.php:558
 Symfony\Component\Console\Application->has() at /data/client/shopware/vendor/symfony/console/Application.php:647
 Symfony\Component\Console\Application->find() at /data/client/shopware/vendor/symfony/framework-bundle/Console/Application.php:116
 Symfony\Bundle\FrameworkBundle\Console\Application->find() at /data/client/shopware/vendor/symfony/console/Application.php:255
 Symfony\Component\Console\Application->doRun() at /data/client/shopware/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /data/client/shopware/vendor/symfony/console/Application.php:167 
 Symfony\Component\Console\Application->run() at /data/client/shopware/bin/ci:57

Expected behaviour

This is what happens when this plugin is deactivated (bin/console plugin:deactivate FroshPlatformThumbnailProcessor);

$ ./bin/ci theme:compile --keep-assets -vvv                    
Start theme compilation

 Compiling theme for sales channel for : 70a4c67afe374daea41a9ad35144c4d8                                               

 ! [NOTE] Took 20.809277 seconds                                                                                        

 Compiling theme for sales channel for : ffaaaacac4e44b2caa5c1cc57e355288                                               

 ! [NOTE] Took 25.155885 seconds  

Steps to Reproduce?

  • Install FroshPlatformThumbnailProcessor
  • Run CI=1 ./bin/ci theme:compile --keep-assets -vvv without a database (for local testing, comment the DATABASE_URL var in .env out)

Suggested fix

Lazy loading the service that is responsible for instantiating the class that requires a database connection, see #32

@peterjaap peterjaap added the kind/bug Something isn't working label Dec 8, 2021
peterjaap added a commit to peterjaap/FroshPlatformThumbnailProcessor that referenced this issue Dec 8, 2021
@tinect
Copy link
Member

tinect commented Dec 8, 2021

I understand the problem regarding the message, but I can't reproduce this on the mentioned way.
Without any DATABASE_URL and plugins I'm getting:

dev@ebb81d810016 /var/www/html/sw6 $ CI=1 ./bin/ci theme:compile --keep-assets -vvv
Start theme compilation

In AbstractMySQLDriver.php line 112:
                                                                                                                               
  [Doctrine\DBAL\Exception\ConnectionException]                                                                                
  An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve  
                                                                                                                               

Exception trace:
  at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112
 Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:182
 Doctrine\DBAL\DBALException::wrapException() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169
 Doctrine\DBAL\DBALException::driverException() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:31
 Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:411
 Doctrine\DBAL\Connection->connect() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1951
 Doctrine\DBAL\Connection->getWrappedConnection() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1289
 Doctrine\DBAL\Connection->executeQuery() at /var/www/html/sw6/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:212
 Doctrine\DBAL\Query\QueryBuilder->execute() at /var/www/html/sw6/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/EntityReader.php:262
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityReader->fetch() at /var/www/html/sw6/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/EntityReader.php:109
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityReader->_read() at /var/www/html/sw6/vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/EntityReader.php:79
 Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityReader->read() at /var/www/html/sw6/vendor/shopware/core/Profiling/Entity/EntityReaderProfiler.php:36
 Shopware\Core\Profiling\Entity\EntityReaderProfiler->read() at /var/www/html/sw6/vendor/shopware/core/Framework/DataAbstractionLayer/EntityRepository.php:270
 Shopware\Core\Framework\DataAbstractionLayer\EntityRepository->read() at /var/www/html/sw6/vendor/shopware/core/Framework/DataAbstractionLayer/EntityRepository.php:115
 Shopware\Core\Framework\DataAbstractionLayer\EntityRepository->search() at /var/www/html/sw6/vendor/shopware/storefront/Theme/ConfigLoader/DatabaseAvailableThemeProvider.php:36
 Shopware\Storefront\Theme\ConfigLoader\DatabaseAvailableThemeProvider->load() at /var/www/html/sw6/vendor/shopware/storefront/Theme/Command/ThemeCompileCommand.php:43
 Shopware\Storefront\Theme\Command\ThemeCompileCommand->execute() at /var/www/html/sw6/vendor/symfony/console/Command/Command.php:299
 Symfony\Component\Console\Command\Command->run() at /var/www/html/sw6/vendor/symfony/console/Application.php:996
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/sw6/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/sw6/vendor/symfony/console/Application.php:295
 Symfony\Component\Console\Application->doRun() at /var/www/html/sw6/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/sw6/vendor/symfony/console/Application.php:167
 Symfony\Component\Console\Application->run() at /var/www/html/sw6/bin/ci:57

Any idea?

Could you please try this: 076ac22

@peterjaap
Copy link
Author

@tinect huh weird. That is indeed the error that you should be getting (because you don't have https://developer.shopware.com/docs/guides/hosting/installation-updates/deployments/build-w-o-db#compiling-the-storefront-without-database configured).

@peterjaap
Copy link
Author

@tinect that commit works as a charm! :)

@tinect
Copy link
Member

tinect commented Dec 8, 2021

I'm afraid I cannot reproduce the error :-(

But, good it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
2 participants