config = $config; $this->resourceConnection = $resourceConnection; $this->getExtensionInformation = $getExtensionInformation; $this->objectManager = $objectManager; $this->disableExtensionLogger = $disableExtensionLogger; } /** * @param string $moduleName * @param string $description * @return bool */ public function execute(string $moduleName, string $description = ''): bool { // TODO: remove usage of 'disableExtension' after finished integration with all extensions $helper = $this->getHelper($moduleName); if ($helper && method_exists($helper, 'disableExtension')) { $helper->disableExtension(); $this->disableExtensionLogger->log($moduleName, $description); return true; } $configPath = $this->getExtensionInformation->execute($moduleName)->getIsEnabledFieldConfigPath(); if (! $configPath) { return false; } $connection = $this->resourceConnection->getConnection('core_write'); $connection->delete( $this->resourceConnection->getTableName('core_config_data'), [ $connection->quoteInto('path = ?', $configPath) ] ); $this->disableExtensionLogger->log($moduleName, $description); try { $this->config->setDataByPath($configPath, 0); $this->config->save(); return true; } catch (\Exception $e) { return false; } } /** * Receive data helper * * @param string $moduleName * @return \Magento\Framework\App\Helper\AbstractHelper|false */ private function getHelper(string $moduleName) { $type = "Plumrocket\\{$moduleName}\Helper\Data"; try { return $this->objectManager->get($type); } catch (\ReflectionException $reflectionException) { return false; } } }