-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hi!
Not super important, but since I put a bit of time into researching this, I might as well post it here.
There are some dependencies injected in the console commands of this module that try to connect to the database.
Since constructors of console commands are executed whenever bin/magento
gets executed, this causes an unneeded db connection attempt every single time.
Steps to reproduce:
- Have a working Magento install (I'm using Magento 2.4.6-p1, but any version will probaby have the same issue)
- Have experius/module-missingtranslations version 4.0.2 installed
- Change your
app/etc/env.php
file and change the database user to one that doesn't exist - Run
bin/magento
Expected is no error mesages
But we are getting the following at the bottom:
In Abstract.php line 144:
SQLSTATE[HY000] [1045] Access denied for user 'non-existing-user'@'localhost' (using password: YES)
In Abstract.php line 124:
SQLSTATE[HY000] [1045] Access denied for user 'non-existing-user'@'localhost' (using password: YES)
After some quick playing around with the dependencies in the console commands of this module, I found that adding proxies like so fixes the issue:
diff -ur CollectMissingTranslationsCommand.php CollectMissingTranslationsCommand.php
--- CollectMissingTranslationsCommand.php 2023-03-07 10:20:53.000000000 +0100
+++ CollectMissingTranslationsCommand.php 2023-07-10 12:28:44.000000000 +0200
@@ -56,9 +56,9 @@
* @param Data $helper
*/
public function __construct(
- Emulation $emulation,
+ Emulation\Proxy $emulation,
State $state,
- Data $helper
+ Data\Proxy $helper
) {
$this->emulation = $emulation;
$this->state = $state;
diff -ur ExistingTranslationsToDatabase.php ExistingTranslationsToDatabase.php
--- ExistingTranslationsToDatabase.php 2023-03-07 10:20:53.000000000 +0100
+++ ExistingTranslationsToDatabase.php 2023-07-10 12:28:44.000000000 +0200
@@ -48,7 +48,7 @@
*/
public function __construct(
State $state,
- TranslationCollector $translationCollector
+ TranslationCollector\Proxy $translationCollector
) {
$this->state = $state;
$this->translationCollector = $translationCollector;
diff -ur MissingTranslationsToDatabase.php MissingTranslationsToDatabase.php
--- MissingTranslationsToDatabase.php 2023-03-07 10:20:53.000000000 +0100
+++ MissingTranslationsToDatabase.php 2023-07-10 12:28:44.000000000 +0200
@@ -48,7 +48,7 @@
*/
public function __construct(
State $state,
- TranslationCollector $translationCollector
+ TranslationCollector\Proxy $translationCollector
) {
$this->state = $state;
$this->translationCollector = $translationCollector;
You can probably also inject them as proxy's using the di.xml
file, but I haven't tested it.
(you might need magento/magento2#37424 as well, to fully test if this got fixed)
Thanks for considering this fix! 🙂