Skip to content

Commit 4e125f8

Browse files
Fixing Config\Loader to not depend on broken cloning Proxy logic
Config/Loader was getting Config\Data\Collection from deprecated getCollection() method which was cloning a Proxy of a Collection which was causing the Collection object to have state in some cases which is totally broken. Switched to using CollectionFactory as per technical guidelines and deprecated warnings. Also modified AbstractModel to prefer Service Locator Pattern over cloning Collection to try to avoid other unclean Collections being returned by this broken deprecated method.
1 parent 6337684 commit 4e125f8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

app/code/Magento/Config/Model/Config/Loader.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
namespace Magento\Config\Model\Config;
1111

12+
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
13+
use Magento\Framework\App\ObjectManager;
14+
1215
/**
1316
* Class which can read config by paths
1417
*
@@ -22,15 +25,26 @@ class Loader
2225
* Config data factory
2326
*
2427
* @var \Magento\Framework\App\Config\ValueFactory
28+
* @deprecated
29+
* @see $collectionFactory
2530
*/
2631
protected $_configValueFactory;
2732

33+
/**
34+
* @var CollectionFactory
35+
*/
36+
private $collectionFactory;
37+
2838
/**
2939
* @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
40+
* @param ?CollectionFactory $collectionFactory
3041
*/
31-
public function __construct(\Magento\Framework\App\Config\ValueFactory $configValueFactory)
32-
{
42+
public function __construct(
43+
\Magento\Framework\App\Config\ValueFactory $configValueFactory,
44+
CollectionFactory $collectionFactory = null
45+
) {
3346
$this->_configValueFactory = $configValueFactory;
47+
$this->collectionFactory = $collectionFactory ?: ObjectManager::getInstance()->get(CollectionFactory::class);
3448
}
3549

3650
/**
@@ -44,9 +58,8 @@ public function __construct(\Magento\Framework\App\Config\ValueFactory $configVa
4458
*/
4559
public function getConfigByPath($path, $scope, $scopeId, $full = true)
4660
{
47-
$configDataCollection = $this->_configValueFactory->create();
48-
$configDataCollection = $configDataCollection->getCollection()->addScopeFilter($scope, $scopeId, $path);
49-
61+
$configDataCollection = $this->collectionFactory->create();
62+
$configDataCollection->addScopeFilter($scope, $scopeId, $path);
5063
$config = [];
5164
$configDataCollection->load();
5265
foreach ($configDataCollection->getItems() as $data) {

lib/internal/Magento/Framework/Model/AbstractModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public function getResourceCollection()
511511
new \Magento\Framework\Phrase('Model collection resource name is not defined.')
512512
);
513513
}
514-
return $this->_resourceCollection ? clone $this
514+
return !$this->_collectionName ? clone $this
515515
->_resourceCollection : \Magento\Framework\App\ObjectManager::getInstance()
516516
->create(
517517
$this->_collectionName

0 commit comments

Comments
 (0)