scopeConfig = $scopeConfig; $this->resourceConnection = $resourceConnection; $this->configFactory = $configFactory; $this->xmlPath = $xmlPath . (strpos($xmlPath, '/') === false ? '/general/new_changes' : ''); } /** * @return bool */ public function check(): bool { return (bool) $this->scopeConfig->getValue($this->xmlPath); } /** * @return $this */ public function switchToCollect(): StatusInterface { return $this->changeStatus(1); } /** * @return $this */ public function switchToMiss(): StatusInterface { return $this->changeStatus(0); } /** * @param int $status * @return $this */ private function changeStatus(int $status): self { /** @var \Magento\Config\Model\Config $config */ $config = $this->configFactory->create(); $connection = $this->resourceConnection->getConnection('core_write'); $connection->delete( $this->resourceConnection->getTableName('core_config_data'), [ $connection->quoteInto('path = ?', $this->xmlPath) ] ); $config->setDataByPath($this->xmlPath, $status); try { $config->save(); } catch (\Exception $e) { return $this; } return $this; } }