You are here

function commerce_exchanger_update_8001 in Commerce Exchanger 8

Fix issues with wrongly set configuration rates schema.

File

./commerce_exchanger.install, line 13
Install file for commerce_exchanger.

Code

function commerce_exchanger_update_8001() {

  // Load all existing and set properly new structure.

  /** @var \Drupal\commerce_exchanger\Entity\ExchangeRatesInterface[] $exchange_rates */
  if ($exchange_rates = ExchangeRates::loadMultiple()) {
    foreach ($exchange_rates as $exchange_rate) {
      $config_name = $exchange_rate
        ->getExchangerConfigName();
      $config_file = \Drupal::configFactory()
        ->getEditable($config_name);
      $config_file
        ->setData([
        'rates' => $config_file
          ->getRawData(),
      ]);
      $config_file
        ->save();
    }
  }
}