We are facing the following situation: We use a module that is not longer maintained by the developers, but we still would like to use this module. The problem is, the code is not compatible with Magento 2.2.2. In detail, the type of aconstructor's parameter of a Magento_Framework's abstract class has changed. One of the objects in this module inherits from this abstract class and calls the old constructor. Thus, the setup:di:compile command crashes. Our preferred solution is to create a custom module and change the type of the constructor parameter through dependency injection. So, we do not have to change the code of the not-longer maintained module.
This is the error:
Compilation was started. Interception cache generation... 6/7 [========================>---] 85% 32 secs 308.0 MiBErrors during compilation: Vendor\ModuleThatIsNotLongerMaintained\Model\ResourceModel\Collection Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Magento\Framework\Model\ResourceModel\Db\AbstractDb; File: Total Errors Count: 1 [Magento\Framework\Validator\Exception] Error during compilation This is the constructor of the Vendor\ModuleThatIsNotLongerMaintained\Model\ResourceModel\Collection:
public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null ) { parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); $this->_storeManager = $storeManager; if ($storeViewId = $this->_storeManager->getStore()->getId()) { $this->_storeViewId = $storeViewId; } } And this is the constructor of the parent class (Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection):
public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null ) { $this->_eventManager = $eventManager; parent::__construct($entityFactory, $logger, $fetchStrategy, $connection); $this->_construct(); $this->_resource = $resource; $this->setConnection($this->getResource()->getConnection()); $this->_initSelect(); } We were able to solve this error by directly changing the type of the parameter connection in the Vendor\ModuleThatIsNotLongerMaintained\Model\ResourceModel\Collection to \Magento\Framework\DB\Adapter\AdapterInterface, but this is not the solution we aim at.
If we correctly understand the documentation, it should be possible to change the type of constructor parameters through dependency injection.
This is the excerpt of the di.xml of our custom module:
... <type name="Vendor\ModuleThatIsNotLongerMaintained\Model\ResourceModel\Collection"> <arguments> <argument name="connection" xsi:type="object">Magento\Framework\DB\Adapter\AdapterInterface</argument> </arguments> </type> ... We activated the new custom module and cleaned the caches. But we still get the same error when executing the setup:di:compile command.
Did me misunderstood the documentation or did me missed anything?
We appreciate any advice or help!
Vendor\ModuleThatIsNotLongerMaintained\Model\ResourceModel\Collection?