configHashGenerator = $configHashGenerator; $this->dataConfigCollector = $dataConfigCollector; $this->flagResource = $flagResource; $this->flagFactory = $flagFactory; } /** * Updates hash in the storage. * * If the specific section name is set, then hash will be updated only for this section, * in another case hash will be updated for all sections which defined in di.xml * The hash is generated based on data from configuration files. * * @param string $sectionName the specific section name * @return void * @throws LocalizedException is thrown when hash was not saved */ public function regenerate($sectionName = null) { try { $hashes = $this->get(); $configs = $this->dataConfigCollector->getConfig($sectionName); foreach ($configs as $section => $config) { $hashes[$section] = $this->configHashGenerator->generate($config); } /** @var Flag $flag */ $flag = $this->getFlagObject(); $flag->setFlagData($hashes); $this->flagResource->save($flag); } catch (\Exception $exception) { throw new LocalizedException(__("The hash isn't saved."), $exception); } } /** * Retrieves saved hashes from storage. * * @return array */ public function get() { /** @var Flag $flag */ $flag = $this->getFlagObject(); return (array) ($flag->getFlagData() ?: []); } /** * Returns flag object. * * We use it for saving hashes of sections in the DB. * * @return Flag */ private function getFlagObject() { /** @var Flag $flag */ $flag = $this->flagFactory ->create(['data' => ['flag_code' => self::CONFIG_KEY]]); $this->flagResource->load($flag, self::CONFIG_KEY, 'flag_code'); return $flag; } }