From 75c6c179f3a901100890ebe06af64e0e08d3dd2c Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Fri, 11 Aug 2017 10:20:09 +0200 Subject: [PATCH 1/2] 6842 Make the MySQL connection disconnect/reconnect feature configurable (default: off). Fixes 27. --- doc/release-notes.md | 5 +++++ .../community/IntegerNet/Solr/Model/Resource/Db.php | 11 +++++++++++ .../IntegerNet/Solr/Test/Model/Resource/Db.php | 1 + .../IntegerNet/Solr/Test/fixtures/config.yaml | 1 + .../code/community/IntegerNet/Solr/etc/config.xml | 1 + .../code/community/IntegerNet/Solr/etc/system.xml | 12 +++++++++++- src/app/locale/de_DE/IntegerNet_Solr.csv | 4 +++- 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/release-notes.md b/doc/release-notes.md index 82491cf..930e443 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -2,6 +2,11 @@ IntegerNet_Solr Free for Magento 1 =============== Release Notes +Upcoming +--------------- + +- Make the MySQL connection disconnect/reconnect feature configurable (default: off) + Version 1.7.4 (Jul 17, 2017) --------------- diff --git a/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php b/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php index 77f7607..a559d89 100755 --- a/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php @@ -16,6 +16,16 @@ class IntegerNet_Solr_Model_Resource_Db */ public function disconnectMysql() { + if (!Mage::getStoreConfigFlag('integernet_solr/indexing/disconnect_mysql_connections')) { + return; + } + + /** @var $coreResource Mage_Core_Model_Resource */ + $coreResource = Mage::getSingleton('core/resource'); + if (!method_exists($coreResource, 'getConnections')) { + return; // method only exists from Magento CE 1.9.1 / EE 1.14.1 + } + /** @var Zend_Db_Adapter_Abstract $connection */ foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) { if ($connection instanceof Zend_Db_Adapter_Abstract) { @@ -25,6 +35,7 @@ public function disconnectMysql() $connection->closeConnection(); } } + // connections (adapter objects) must be fully reinitialized, otherwise initStatements are not executed Mage::unregister('_singleton/core/resource'); } diff --git a/src/app/code/community/IntegerNet/Solr/Test/Model/Resource/Db.php b/src/app/code/community/IntegerNet/Solr/Test/Model/Resource/Db.php index d4c8cc9..d210731 100644 --- a/src/app/code/community/IntegerNet/Solr/Test/Model/Resource/Db.php +++ b/src/app/code/community/IntegerNet/Solr/Test/Model/Resource/Db.php @@ -10,6 +10,7 @@ /** * @loadFixture registry + * @loadFixture config * @doNotIndexAll */ class IntegerNet_Solr_Test_Model_Resource_Db extends EcomDev_PHPUnit_Test_Case diff --git a/src/app/code/community/IntegerNet/Solr/Test/fixtures/config.yaml b/src/app/code/community/IntegerNet/Solr/Test/fixtures/config.yaml index 7bafd13..4073b17 100644 --- a/src/app/code/community/IntegerNet/Solr/Test/fixtures/config.yaml +++ b/src/app/code/community/IntegerNet/Solr/Test/fixtures/config.yaml @@ -17,6 +17,7 @@ config: default/integernet_solr/server/http_method: curl default/integernet_solr/server/use_https: 0 default/integernet_solr/server/use_http_basic_auth: 0 + default/integernet_solr/indexing/disconnect_mysql_connections: 1 default/integernet_solr/connection_check/is_active: 1 default/integernet_solr/fuzzy/is_active: 0 default/integernet_solr/category/is_active: 1 diff --git a/src/app/code/community/IntegerNet/Solr/etc/config.xml b/src/app/code/community/IntegerNet/Solr/etc/config.xml index 3570cb3..4a657bf 100644 --- a/src/app/code/community/IntegerNet/Solr/etc/config.xml +++ b/src/app/code/community/IntegerNet/Solr/etc/config.xml @@ -245,6 +245,7 @@ 1000 1 + 0 1 diff --git a/src/app/code/community/IntegerNet/Solr/etc/system.xml b/src/app/code/community/IntegerNet/Solr/etc/system.xml index df5344f..d2b7004 100644 --- a/src/app/code/community/IntegerNet/Solr/etc/system.xml +++ b/src/app/code/community/IntegerNet/Solr/etc/system.xml @@ -193,7 +193,7 @@ 1 1 - + text 40 @@ -204,6 +204,16 @@ 1 + + + Use this to avoid SQL timeout errors during indexing. Only available since Magento CE 1.9.1 / EE 1.14.1. + select + adminhtml/system_config_source_yesno + 50 + 1 + 0 + 0 + diff --git a/src/app/locale/de_DE/IntegerNet_Solr.csv b/src/app/locale/de_DE/IntegerNet_Solr.csv index f7a3193..77ac9f4 100644 --- a/src/app/locale/de_DE/IntegerNet_Solr.csv +++ b/src/app/locale/de_DE/IntegerNet_Solr.csv @@ -109,4 +109,6 @@ "Show category filter","Kategorie-Filter anzeigen" "Show products which are out of stock","Produkte anzeigen, die nicht auf Lager sind" "Solr Priority Multiplier for Products being out of Stock","Solr-Prioritäts-Multiplikator für ausverkaufte Produkte" -"0 = don't show at all, 1 = don't modify, anything between = lower priority","0 = gar nicht anzeigen, 1 = wie Produkte auf Lager, alles dazwischen = niedrigere Priorität" \ No newline at end of file +"0 = don't show at all, 1 = don't modify, anything between = lower priority","0 = gar nicht anzeigen, 1 = wie Produkte auf Lager, alles dazwischen = niedrigere Priorität" +"Disconnect and reconnect MySQL Connections during indexing","MySQL-Verbindungen während der Indizierung trennen und neu aufbauen" +"Use this to avoid SQL timeout errors during indexing. Only available since Magento CE 1.9.1 / EE 1.14.1.","Aktivieren Sie diese Option, wenn Sie Timeout-Fehler während der Indizierung erhalten. Verfügbar erst ab Magento CE 1.9.1 / EE 1.14.1." \ No newline at end of file From 03f11e58a55d3608302ab214fac7cae7c7ee45b9 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Fri, 11 Aug 2017 11:34:00 +0200 Subject: [PATCH 2/2] 6842 Refactor to reuse variable --- src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php b/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php index a559d89..a7b5811 100755 --- a/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php @@ -27,7 +27,7 @@ public function disconnectMysql() } /** @var Zend_Db_Adapter_Abstract $connection */ - foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) { + foreach ($coreResource->getConnections() as $name => $connection) { if ($connection instanceof Zend_Db_Adapter_Abstract) { if ($this->isTransactionOpen($connection)) { continue;